diff options
author | Jonas Schievink <[email protected]> | 2021-05-24 14:35:46 +0100 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2021-05-24 14:35:46 +0100 |
commit | 533e9207d39c27dc22de2645fc65891189a71739 (patch) | |
tree | aeb89306e864bff3fc612d26ab6242a75b3e3885 | |
parent | 8ebb8d29e18d7cb18bd2b57b004dcecd65a96232 (diff) |
Intern `GenericArgs`
This shaves off another ~4 mb or so
-rw-r--r-- | crates/hir_def/src/intern.rs | 1 | ||||
-rw-r--r-- | crates/hir_def/src/item_tree/lower.rs | 2 | ||||
-rw-r--r-- | crates/hir_def/src/path.rs | 7 | ||||
-rw-r--r-- | crates/hir_def/src/path/lower.rs | 11 |
4 files changed, 10 insertions, 11 deletions
diff --git a/crates/hir_def/src/intern.rs b/crates/hir_def/src/intern.rs index 8b3f799e2..1189c9327 100644 --- a/crates/hir_def/src/intern.rs +++ b/crates/hir_def/src/intern.rs | |||
@@ -218,6 +218,7 @@ impl_internable!( | |||
218 | crate::type_ref::TraitRef, | 218 | crate::type_ref::TraitRef, |
219 | crate::type_ref::TypeBound, | 219 | crate::type_ref::TypeBound, |
220 | crate::path::ModPath, | 220 | crate::path::ModPath, |
221 | crate::path::GenericArgs, | ||
221 | GenericParams, | 222 | GenericParams, |
222 | str, | 223 | str, |
223 | ); | 224 | ); |
diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index 1a0e54413..b4389371f 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs | |||
@@ -811,7 +811,7 @@ fn desugar_future_path(orig: TypeRef) -> Path { | |||
811 | let binding = | 811 | let binding = |
812 | AssociatedTypeBinding { name: name![Output], type_ref: Some(orig), bounds: Vec::new() }; | 812 | AssociatedTypeBinding { name: name![Output], type_ref: Some(orig), bounds: Vec::new() }; |
813 | last.bindings.push(binding); | 813 | last.bindings.push(binding); |
814 | generic_args.push(Some(Arc::new(last))); | 814 | generic_args.push(Some(Interned::new(last))); |
815 | 815 | ||
816 | Path::from_known_path(path, generic_args) | 816 | Path::from_known_path(path, generic_args) |
817 | } | 817 | } |
diff --git a/crates/hir_def/src/path.rs b/crates/hir_def/src/path.rs index 7bd7d9d4f..45ab9d0ff 100644 --- a/crates/hir_def/src/path.rs +++ b/crates/hir_def/src/path.rs | |||
@@ -4,7 +4,6 @@ mod lower; | |||
4 | use std::{ | 4 | use std::{ |
5 | fmt::{self, Display}, | 5 | fmt::{self, Display}, |
6 | iter, | 6 | iter, |
7 | sync::Arc, | ||
8 | }; | 7 | }; |
9 | 8 | ||
10 | use crate::{body::LowerCtx, db::DefDatabase, intern::Interned, type_ref::LifetimeRef}; | 9 | use crate::{body::LowerCtx, db::DefDatabase, intern::Interned, type_ref::LifetimeRef}; |
@@ -136,7 +135,7 @@ pub struct Path { | |||
136 | type_anchor: Option<Interned<TypeRef>>, | 135 | type_anchor: Option<Interned<TypeRef>>, |
137 | mod_path: Interned<ModPath>, | 136 | mod_path: Interned<ModPath>, |
138 | /// Invariant: the same len as `self.mod_path.segments` | 137 | /// Invariant: the same len as `self.mod_path.segments` |
139 | generic_args: Vec<Option<Arc<GenericArgs>>>, | 138 | generic_args: Vec<Option<Interned<GenericArgs>>>, |
140 | } | 139 | } |
141 | 140 | ||
142 | /// Generic arguments to a path segment (e.g. the `i32` in `Option<i32>`). This | 141 | /// Generic arguments to a path segment (e.g. the `i32` in `Option<i32>`). This |
@@ -185,7 +184,7 @@ impl Path { | |||
185 | /// Converts a known mod path to `Path`. | 184 | /// Converts a known mod path to `Path`. |
186 | pub(crate) fn from_known_path( | 185 | pub(crate) fn from_known_path( |
187 | path: ModPath, | 186 | path: ModPath, |
188 | generic_args: Vec<Option<Arc<GenericArgs>>>, | 187 | generic_args: Vec<Option<Interned<GenericArgs>>>, |
189 | ) -> Path { | 188 | ) -> Path { |
190 | Path { type_anchor: None, mod_path: Interned::new(path), generic_args } | 189 | Path { type_anchor: None, mod_path: Interned::new(path), generic_args } |
191 | } | 190 | } |
@@ -239,7 +238,7 @@ pub struct PathSegment<'a> { | |||
239 | 238 | ||
240 | pub struct PathSegments<'a> { | 239 | pub struct PathSegments<'a> { |
241 | segments: &'a [Name], | 240 | segments: &'a [Name], |
242 | generic_args: &'a [Option<Arc<GenericArgs>>], | 241 | generic_args: &'a [Option<Interned<GenericArgs>>], |
243 | } | 242 | } |
244 | 243 | ||
245 | impl<'a> PathSegments<'a> { | 244 | impl<'a> PathSegments<'a> { |
diff --git a/crates/hir_def/src/path/lower.rs b/crates/hir_def/src/path/lower.rs index cf4e7c02e..5d5dd9c8f 100644 --- a/crates/hir_def/src/path/lower.rs +++ b/crates/hir_def/src/path/lower.rs | |||
@@ -3,7 +3,6 @@ | |||
3 | mod lower_use; | 3 | mod lower_use; |
4 | 4 | ||
5 | use crate::intern::Interned; | 5 | use crate::intern::Interned; |
6 | use std::sync::Arc; | ||
7 | 6 | ||
8 | use either::Either; | 7 | use either::Either; |
9 | use hir_expand::name::{name, AsName}; | 8 | use hir_expand::name::{name, AsName}; |
@@ -48,7 +47,7 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx) -> Option<Path> { | |||
48 | segment.ret_type(), | 47 | segment.ret_type(), |
49 | ) | 48 | ) |
50 | }) | 49 | }) |
51 | .map(Arc::new); | 50 | .map(Interned::new); |
52 | segments.push(name); | 51 | segments.push(name); |
53 | generic_args.push(args) | 52 | generic_args.push(args) |
54 | } | 53 | } |
@@ -87,13 +86,13 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx) -> Option<Path> { | |||
87 | // Insert the type reference (T in the above example) as Self parameter for the trait | 86 | // Insert the type reference (T in the above example) as Self parameter for the trait |
88 | let last_segment = | 87 | let last_segment = |
89 | generic_args.iter_mut().rev().nth(num_segments.saturating_sub(1))?; | 88 | generic_args.iter_mut().rev().nth(num_segments.saturating_sub(1))?; |
90 | if last_segment.is_none() { | 89 | let mut args_inner = match last_segment { |
91 | *last_segment = Some(Arc::new(GenericArgs::empty())); | 90 | Some(it) => it.as_ref().clone(), |
91 | None => GenericArgs::empty(), | ||
92 | }; | 92 | }; |
93 | let args = last_segment.as_mut().unwrap(); | ||
94 | let mut args_inner = Arc::make_mut(args); | ||
95 | args_inner.has_self_type = true; | 93 | args_inner.has_self_type = true; |
96 | args_inner.args.insert(0, GenericArg::Type(self_type)); | 94 | args_inner.args.insert(0, GenericArg::Type(self_type)); |
95 | *last_segment = Some(Interned::new(args_inner)); | ||
97 | } | 96 | } |
98 | } | 97 | } |
99 | } | 98 | } |