diff options
author | Florian Diebold <[email protected]> | 2021-04-08 17:25:18 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2021-04-08 21:48:47 +0100 |
commit | be03db0e3a75533f34d48c3014d532919b30a9e9 (patch) | |
tree | 3742a817b8238043a3a855d92532c7342815210e /crates/hir_ty/src/traits | |
parent | a169fa6a832a513cd1534d1a6566e4584ca5fb6a (diff) |
Intern Substitutions
(Costs a bit of performance, reduces memory usage on RA by ~10%.)
Diffstat (limited to 'crates/hir_ty/src/traits')
-rw-r--r-- | crates/hir_ty/src/traits/chalk/interner.rs | 23 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk/mapping.rs | 4 |
2 files changed, 17 insertions, 10 deletions
diff --git a/crates/hir_ty/src/traits/chalk/interner.rs b/crates/hir_ty/src/traits/chalk/interner.rs index 7a3bd41d4..17e056f03 100644 --- a/crates/hir_ty/src/traits/chalk/interner.rs +++ b/crates/hir_ty/src/traits/chalk/interner.rs | |||
@@ -3,11 +3,12 @@ | |||
3 | 3 | ||
4 | use super::tls; | 4 | use super::tls; |
5 | use base_db::salsa::InternId; | 5 | use base_db::salsa::InternId; |
6 | use chalk_ir::{GenericArg, Goal, GoalData}; | 6 | use chalk_ir::{Goal, GoalData}; |
7 | use hir_def::{ | 7 | use hir_def::{ |
8 | intern::{impl_internable, InternStorage, Internable, Interned}, | 8 | intern::{impl_internable, InternStorage, Internable, Interned}, |
9 | TypeAliasId, | 9 | TypeAliasId, |
10 | }; | 10 | }; |
11 | use crate::GenericArg; | ||
11 | use smallvec::SmallVec; | 12 | use smallvec::SmallVec; |
12 | use std::{fmt, sync::Arc}; | 13 | use std::{fmt, sync::Arc}; |
13 | 14 | ||
@@ -32,7 +33,13 @@ pub(crate) type Variances = chalk_ir::Variances<Interner>; | |||
32 | #[derive(PartialEq, Eq, Hash, Debug)] | 33 | #[derive(PartialEq, Eq, Hash, Debug)] |
33 | pub struct InternedVariableKindsInner(Vec<chalk_ir::VariableKind<Interner>>); | 34 | pub struct InternedVariableKindsInner(Vec<chalk_ir::VariableKind<Interner>>); |
34 | 35 | ||
35 | impl_internable!(InternedVariableKindsInner,); | 36 | #[derive(PartialEq, Eq, Hash, Debug)] |
37 | pub struct InternedSubstitutionInner(SmallVec<[GenericArg; 2]>); | ||
38 | |||
39 | impl_internable!( | ||
40 | InternedVariableKindsInner, | ||
41 | InternedSubstitutionInner, | ||
42 | ); | ||
36 | 43 | ||
37 | impl chalk_ir::interner::Interner for Interner { | 44 | impl chalk_ir::interner::Interner for Interner { |
38 | type InternedType = Arc<chalk_ir::TyData<Self>>; | 45 | type InternedType = Arc<chalk_ir::TyData<Self>>; |
@@ -42,7 +49,7 @@ impl chalk_ir::interner::Interner for Interner { | |||
42 | type InternedGenericArg = chalk_ir::GenericArgData<Self>; | 49 | type InternedGenericArg = chalk_ir::GenericArgData<Self>; |
43 | type InternedGoal = Arc<GoalData<Self>>; | 50 | type InternedGoal = Arc<GoalData<Self>>; |
44 | type InternedGoals = Vec<Goal<Self>>; | 51 | type InternedGoals = Vec<Goal<Self>>; |
45 | type InternedSubstitution = SmallVec<[GenericArg<Self>; 2]>; | 52 | type InternedSubstitution = Interned<InternedSubstitutionInner>; |
46 | type InternedProgramClause = Arc<chalk_ir::ProgramClauseData<Self>>; | 53 | type InternedProgramClause = Arc<chalk_ir::ProgramClauseData<Self>>; |
47 | type InternedProgramClauses = Arc<[chalk_ir::ProgramClause<Self>]>; | 54 | type InternedProgramClauses = Arc<[chalk_ir::ProgramClause<Self>]>; |
48 | type InternedQuantifiedWhereClauses = Vec<chalk_ir::QuantifiedWhereClause<Self>>; | 55 | type InternedQuantifiedWhereClauses = Vec<chalk_ir::QuantifiedWhereClause<Self>>; |
@@ -107,7 +114,7 @@ impl chalk_ir::interner::Interner for Interner { | |||
107 | } | 114 | } |
108 | 115 | ||
109 | fn debug_generic_arg( | 116 | fn debug_generic_arg( |
110 | parameter: &GenericArg<Interner>, | 117 | parameter: &GenericArg, |
111 | fmt: &mut fmt::Formatter<'_>, | 118 | fmt: &mut fmt::Formatter<'_>, |
112 | ) -> Option<fmt::Result> { | 119 | ) -> Option<fmt::Result> { |
113 | tls::with_current_program(|prog| Some(prog?.debug_generic_arg(parameter, fmt))) | 120 | tls::with_current_program(|prog| Some(prog?.debug_generic_arg(parameter, fmt))) |
@@ -272,16 +279,16 @@ impl chalk_ir::interner::Interner for Interner { | |||
272 | 279 | ||
273 | fn intern_substitution<E>( | 280 | fn intern_substitution<E>( |
274 | &self, | 281 | &self, |
275 | data: impl IntoIterator<Item = Result<GenericArg<Self>, E>>, | 282 | data: impl IntoIterator<Item = Result<GenericArg, E>>, |
276 | ) -> Result<Self::InternedSubstitution, E> { | 283 | ) -> Result<Self::InternedSubstitution, E> { |
277 | data.into_iter().collect() | 284 | Ok(Interned::new(InternedSubstitutionInner(data.into_iter().collect::<Result<SmallVec<_>, _>>()?))) |
278 | } | 285 | } |
279 | 286 | ||
280 | fn substitution_data<'a>( | 287 | fn substitution_data<'a>( |
281 | &self, | 288 | &self, |
282 | substitution: &'a Self::InternedSubstitution, | 289 | substitution: &'a Self::InternedSubstitution, |
283 | ) -> &'a [GenericArg<Self>] { | 290 | ) -> &'a [GenericArg] { |
284 | substitution | 291 | &substitution.as_ref().0 |
285 | } | 292 | } |
286 | 293 | ||
287 | fn intern_program_clause( | 294 | fn intern_program_clause( |
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index 7818f6387..e78581ea5 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs | |||
@@ -99,7 +99,7 @@ pub(super) fn generic_predicate_to_inline_bound( | |||
99 | // have the expected self type | 99 | // have the expected self type |
100 | return None; | 100 | return None; |
101 | } | 101 | } |
102 | let args_no_self = trait_ref.substitution.interned()[1..] | 102 | let args_no_self = trait_ref.substitution.as_slice(&Interner)[1..] |
103 | .iter() | 103 | .iter() |
104 | .map(|ty| ty.clone().cast(&Interner)) | 104 | .map(|ty| ty.clone().cast(&Interner)) |
105 | .collect(); | 105 | .collect(); |
@@ -111,7 +111,7 @@ pub(super) fn generic_predicate_to_inline_bound( | |||
111 | return None; | 111 | return None; |
112 | } | 112 | } |
113 | let trait_ = projection_ty.trait_(db); | 113 | let trait_ = projection_ty.trait_(db); |
114 | let args_no_self = projection_ty.substitution.interned()[1..] | 114 | let args_no_self = projection_ty.substitution.as_slice(&Interner)[1..] |
115 | .iter() | 115 | .iter() |
116 | .map(|ty| ty.clone().cast(&Interner)) | 116 | .map(|ty| ty.clone().cast(&Interner)) |
117 | .collect(); | 117 | .collect(); |