diff options
author | Jonas Schievink <[email protected]> | 2021-04-05 01:03:37 +0100 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2021-04-05 01:03:37 +0100 |
commit | 24e876b52ed76710593895bc37bb8ed303075193 (patch) | |
tree | c624f31447726b83b381067d2effc1e8849fd4a7 /crates | |
parent | 19e09a4a54c75312aeaac04577f2d0e067463ab6 (diff) |
Intern more `TypeRef`s in generics
Saves ~3 MB
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir_def/src/generics.rs | 16 | ||||
-rw-r--r-- | crates/hir_def/src/path.rs | 2 | ||||
-rw-r--r-- | crates/hir_def/src/path/lower.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/utils.rs | 9 |
4 files changed, 15 insertions, 14 deletions
diff --git a/crates/hir_def/src/generics.rs b/crates/hir_def/src/generics.rs index 7c6cbff11..e02ac2c2f 100644 --- a/crates/hir_def/src/generics.rs +++ b/crates/hir_def/src/generics.rs | |||
@@ -18,6 +18,7 @@ use crate::{ | |||
18 | child_by_source::ChildBySource, | 18 | child_by_source::ChildBySource, |
19 | db::DefDatabase, | 19 | db::DefDatabase, |
20 | dyn_map::DynMap, | 20 | dyn_map::DynMap, |
21 | intern::Interned, | ||
21 | keys, | 22 | keys, |
22 | src::{HasChildSource, HasSource}, | 23 | src::{HasChildSource, HasSource}, |
23 | type_ref::{LifetimeRef, TypeBound, TypeRef}, | 24 | type_ref::{LifetimeRef, TypeBound, TypeRef}, |
@@ -29,7 +30,7 @@ use crate::{ | |||
29 | #[derive(Clone, PartialEq, Eq, Debug)] | 30 | #[derive(Clone, PartialEq, Eq, Debug)] |
30 | pub struct TypeParamData { | 31 | pub struct TypeParamData { |
31 | pub name: Option<Name>, | 32 | pub name: Option<Name>, |
32 | pub default: Option<TypeRef>, | 33 | pub default: Option<Interned<TypeRef>>, |
33 | pub provenance: TypeParamProvenance, | 34 | pub provenance: TypeParamProvenance, |
34 | } | 35 | } |
35 | 36 | ||
@@ -43,7 +44,7 @@ pub struct LifetimeParamData { | |||
43 | #[derive(Clone, PartialEq, Eq, Debug)] | 44 | #[derive(Clone, PartialEq, Eq, Debug)] |
44 | pub struct ConstParamData { | 45 | pub struct ConstParamData { |
45 | pub name: Name, | 46 | pub name: Name, |
46 | pub ty: TypeRef, | 47 | pub ty: Interned<TypeRef>, |
47 | } | 48 | } |
48 | 49 | ||
49 | #[derive(Copy, Clone, PartialEq, Eq, Debug)] | 50 | #[derive(Copy, Clone, PartialEq, Eq, Debug)] |
@@ -75,7 +76,7 @@ pub enum WherePredicate { | |||
75 | 76 | ||
76 | #[derive(Clone, PartialEq, Eq, Debug)] | 77 | #[derive(Clone, PartialEq, Eq, Debug)] |
77 | pub enum WherePredicateTypeTarget { | 78 | pub enum WherePredicateTypeTarget { |
78 | TypeRef(TypeRef), | 79 | TypeRef(Interned<TypeRef>), |
79 | /// For desugared where predicates that can directly refer to a type param. | 80 | /// For desugared where predicates that can directly refer to a type param. |
80 | TypeParam(LocalTypeParamId), | 81 | TypeParam(LocalTypeParamId), |
81 | } | 82 | } |
@@ -256,7 +257,8 @@ impl GenericParams { | |||
256 | for type_param in params.type_params() { | 257 | for type_param in params.type_params() { |
257 | let name = type_param.name().map_or_else(Name::missing, |it| it.as_name()); | 258 | let name = type_param.name().map_or_else(Name::missing, |it| it.as_name()); |
258 | // FIXME: Use `Path::from_src` | 259 | // FIXME: Use `Path::from_src` |
259 | let default = type_param.default_type().map(|it| TypeRef::from_ast(lower_ctx, it)); | 260 | let default = |
261 | type_param.default_type().map(|it| Interned::new(TypeRef::from_ast(lower_ctx, it))); | ||
260 | let param = TypeParamData { | 262 | let param = TypeParamData { |
261 | name: Some(name.clone()), | 263 | name: Some(name.clone()), |
262 | default, | 264 | default, |
@@ -280,7 +282,7 @@ impl GenericParams { | |||
280 | for const_param in params.const_params() { | 282 | for const_param in params.const_params() { |
281 | let name = const_param.name().map_or_else(Name::missing, |it| it.as_name()); | 283 | let name = const_param.name().map_or_else(Name::missing, |it| it.as_name()); |
282 | let ty = const_param.ty().map_or(TypeRef::Error, |it| TypeRef::from_ast(lower_ctx, it)); | 284 | let ty = const_param.ty().map_or(TypeRef::Error, |it| TypeRef::from_ast(lower_ctx, it)); |
283 | let param = ConstParamData { name, ty }; | 285 | let param = ConstParamData { name, ty: Interned::new(ty) }; |
284 | let param_id = self.consts.alloc(param); | 286 | let param_id = self.consts.alloc(param); |
285 | sm.const_params.insert(param_id, const_param.clone()); | 287 | sm.const_params.insert(param_id, const_param.clone()); |
286 | } | 288 | } |
@@ -334,11 +336,11 @@ impl GenericParams { | |||
334 | (Either::Left(type_ref), bound) => match hrtb_lifetimes { | 336 | (Either::Left(type_ref), bound) => match hrtb_lifetimes { |
335 | Some(hrtb_lifetimes) => WherePredicate::ForLifetime { | 337 | Some(hrtb_lifetimes) => WherePredicate::ForLifetime { |
336 | lifetimes: hrtb_lifetimes.clone(), | 338 | lifetimes: hrtb_lifetimes.clone(), |
337 | target: WherePredicateTypeTarget::TypeRef(type_ref), | 339 | target: WherePredicateTypeTarget::TypeRef(Interned::new(type_ref)), |
338 | bound, | 340 | bound, |
339 | }, | 341 | }, |
340 | None => WherePredicate::TypeBound { | 342 | None => WherePredicate::TypeBound { |
341 | target: WherePredicateTypeTarget::TypeRef(type_ref), | 343 | target: WherePredicateTypeTarget::TypeRef(Interned::new(type_ref)), |
342 | bound, | 344 | bound, |
343 | }, | 345 | }, |
344 | }, | 346 | }, |
diff --git a/crates/hir_def/src/path.rs b/crates/hir_def/src/path.rs index a3e83e2cf..f9c8328f0 100644 --- a/crates/hir_def/src/path.rs +++ b/crates/hir_def/src/path.rs | |||
@@ -122,7 +122,7 @@ impl ModPath { | |||
122 | pub struct Path { | 122 | pub struct Path { |
123 | /// Type based path like `<T>::foo`. | 123 | /// Type based path like `<T>::foo`. |
124 | /// Note that paths like `<Type as Trait>::foo` are desugard to `Trait::<Self=Type>::foo`. | 124 | /// Note that paths like `<Type as Trait>::foo` are desugard to `Trait::<Self=Type>::foo`. |
125 | type_anchor: Option<Box<TypeRef>>, | 125 | type_anchor: Option<Interned<TypeRef>>, |
126 | mod_path: Interned<ModPath>, | 126 | mod_path: Interned<ModPath>, |
127 | /// Invariant: the same len as `self.mod_path.segments` | 127 | /// Invariant: the same len as `self.mod_path.segments` |
128 | generic_args: Vec<Option<Arc<GenericArgs>>>, | 128 | generic_args: Vec<Option<Arc<GenericArgs>>>, |
diff --git a/crates/hir_def/src/path/lower.rs b/crates/hir_def/src/path/lower.rs index 28f6244da..7b29d9d4f 100644 --- a/crates/hir_def/src/path/lower.rs +++ b/crates/hir_def/src/path/lower.rs | |||
@@ -69,7 +69,7 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option<Path> | |||
69 | match trait_ref { | 69 | match trait_ref { |
70 | // <T>::foo | 70 | // <T>::foo |
71 | None => { | 71 | None => { |
72 | type_anchor = Some(Box::new(self_type)); | 72 | type_anchor = Some(Interned::new(self_type)); |
73 | kind = PathKind::Plain; | 73 | kind = PathKind::Plain; |
74 | } | 74 | } |
75 | // <T as Trait<A>>::Foo desugars to Trait<Self=T, A>::Foo | 75 | // <T as Trait<A>>::Foo desugars to Trait<Self=T, A>::Foo |
diff --git a/crates/hir_ty/src/utils.rs b/crates/hir_ty/src/utils.rs index b23e91b1b..c85c328af 100644 --- a/crates/hir_ty/src/utils.rs +++ b/crates/hir_ty/src/utils.rs | |||
@@ -32,11 +32,10 @@ fn direct_super_traits(db: &dyn DefDatabase, trait_: TraitId) -> Vec<TraitId> { | |||
32 | .filter_map(|pred| match pred { | 32 | .filter_map(|pred| match pred { |
33 | WherePredicate::ForLifetime { target, bound, .. } | 33 | WherePredicate::ForLifetime { target, bound, .. } |
34 | | WherePredicate::TypeBound { target, bound } => match target { | 34 | | WherePredicate::TypeBound { target, bound } => match target { |
35 | WherePredicateTypeTarget::TypeRef(TypeRef::Path(p)) | 35 | WherePredicateTypeTarget::TypeRef(type_ref) => match &**type_ref { |
36 | if p == &Path::from(name![Self]) => | 36 | TypeRef::Path(p) if p == &Path::from(name![Self]) => bound.as_path(), |
37 | { | 37 | _ => None, |
38 | bound.as_path() | 38 | }, |
39 | } | ||
40 | WherePredicateTypeTarget::TypeParam(local_id) if Some(*local_id) == trait_self => { | 39 | WherePredicateTypeTarget::TypeParam(local_id) if Some(*local_id) == trait_self => { |
41 | bound.as_path() | 40 | bound.as_path() |
42 | } | 41 | } |