]> git.lizzy.rs Git - rust.git/commitdiff
Intern `GenericArgs`
authorJonas Schievink <jonasschievink@gmail.com>
Mon, 24 May 2021 13:35:46 +0000 (15:35 +0200)
committerJonas Schievink <jonasschievink@gmail.com>
Mon, 24 May 2021 13:35:46 +0000 (15:35 +0200)
This shaves off another ~4 mb or so

crates/hir_def/src/intern.rs
crates/hir_def/src/item_tree/lower.rs
crates/hir_def/src/path.rs
crates/hir_def/src/path/lower.rs

index 8b3f799e2cb2f4511d65a1977c43258d60a610f0..1189c9327d631713a86ce6968313aa57031bd9ce 100644 (file)
@@ -218,6 +218,7 @@ fn storage() -> &'static InternStorage<Self> {
     crate::type_ref::TraitRef,
     crate::type_ref::TypeBound,
     crate::path::ModPath,
+    crate::path::GenericArgs,
     GenericParams,
     str,
 );
index 1a0e54413c3eec0630e77083cca942a9145d99b3..b4389371fbba1beed83af1c3d58b7ae80a5e712b 100644 (file)
@@ -811,7 +811,7 @@ fn desugar_future_path(orig: TypeRef) -> Path {
     let binding =
         AssociatedTypeBinding { name: name![Output], type_ref: Some(orig), bounds: Vec::new() };
     last.bindings.push(binding);
-    generic_args.push(Some(Arc::new(last)));
+    generic_args.push(Some(Interned::new(last)));
 
     Path::from_known_path(path, generic_args)
 }
index 7bd7d9d4f21d90a5b7f907a60e71e1896f4462a9..45ab9d0ffbfc72f7027fe5325e93fd7e73579888 100644 (file)
@@ -4,7 +4,6 @@
 use std::{
     fmt::{self, Display},
     iter,
-    sync::Arc,
 };
 
 use crate::{body::LowerCtx, db::DefDatabase, intern::Interned, type_ref::LifetimeRef};
@@ -136,7 +135,7 @@ pub struct Path {
     type_anchor: Option<Interned<TypeRef>>,
     mod_path: Interned<ModPath>,
     /// Invariant: the same len as `self.mod_path.segments`
-    generic_args: Vec<Option<Arc<GenericArgs>>>,
+    generic_args: Vec<Option<Interned<GenericArgs>>>,
 }
 
 /// Generic arguments to a path segment (e.g. the `i32` in `Option<i32>`). This
@@ -185,7 +184,7 @@ pub fn from_src(path: ast::Path, ctx: &LowerCtx) -> Option<Path> {
     /// Converts a known mod path to `Path`.
     pub(crate) fn from_known_path(
         path: ModPath,
-        generic_args: Vec<Option<Arc<GenericArgs>>>,
+        generic_args: Vec<Option<Interned<GenericArgs>>>,
     ) -> Path {
         Path { type_anchor: None, mod_path: Interned::new(path), generic_args }
     }
@@ -239,7 +238,7 @@ pub struct PathSegment<'a> {
 
 pub struct PathSegments<'a> {
     segments: &'a [Name],
-    generic_args: &'a [Option<Arc<GenericArgs>>],
+    generic_args: &'a [Option<Interned<GenericArgs>>],
 }
 
 impl<'a> PathSegments<'a> {
index cf4e7c02eee2490760e71091a87ccf74c03b5144..5d5dd9c8f8a8159538e87f88f40f8fcac7ada5e7 100644 (file)
@@ -3,7 +3,6 @@
 mod lower_use;
 
 use crate::intern::Interned;
-use std::sync::Arc;
 
 use either::Either;
 use hir_expand::name::{name, AsName};
@@ -48,7 +47,7 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx) -> Option<Path> {
                                     segment.ret_type(),
                                 )
                             })
-                            .map(Arc::new);
+                            .map(Interned::new);
                         segments.push(name);
                         generic_args.push(args)
                     }
@@ -87,13 +86,13 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx) -> Option<Path> {
                         // Insert the type reference (T in the above example) as Self parameter for the trait
                         let last_segment =
                             generic_args.iter_mut().rev().nth(num_segments.saturating_sub(1))?;
-                        if last_segment.is_none() {
-                            *last_segment = Some(Arc::new(GenericArgs::empty()));
+                        let mut args_inner = match last_segment {
+                            Some(it) => it.as_ref().clone(),
+                            None => GenericArgs::empty(),
                         };
-                        let args = last_segment.as_mut().unwrap();
-                        let mut args_inner = Arc::make_mut(args);
                         args_inner.has_self_type = true;
                         args_inner.args.insert(0, GenericArg::Type(self_type));
+                        *last_segment = Some(Interned::new(args_inner));
                     }
                 }
             }