aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/traits
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2021-04-08 17:45:07 +0100
committerFlorian Diebold <[email protected]>2021-04-08 21:48:47 +0100
commit90656f86745afe073a5b590d51b22ec5f6b60e1b (patch)
tree9255a2e5e39c0daab36f03d3102c33e9ebec7f36 /crates/hir_ty/src/traits
parent37cb6805afc397adf769391cec99b2e11d0d52e0 (diff)
Intern consts & lifetimes
Slight memory usage reduction.
Diffstat (limited to 'crates/hir_ty/src/traits')
-rw-r--r--crates/hir_ty/src/traits/chalk/interner.rs25
1 files changed, 19 insertions, 6 deletions
diff --git a/crates/hir_ty/src/traits/chalk/interner.rs b/crates/hir_ty/src/traits/chalk/interner.rs
index 83787b8c0..3a6ceef05 100644
--- a/crates/hir_ty/src/traits/chalk/interner.rs
+++ b/crates/hir_ty/src/traits/chalk/interner.rs
@@ -39,16 +39,29 @@ pub struct InternedSubstitutionInner(SmallVec<[GenericArg; 2]>);
39#[derive(PartialEq, Eq, Hash, Debug)] 39#[derive(PartialEq, Eq, Hash, Debug)]
40pub struct InternedTypeInner(chalk_ir::TyData<Interner>); 40pub struct InternedTypeInner(chalk_ir::TyData<Interner>);
41 41
42#[derive(PartialEq, Eq, Hash, Debug)]
43pub struct InternedWrapper<T>(T);
44
45impl<T> std::ops::Deref for InternedWrapper<T> {
46 type Target = T;
47
48 fn deref(&self) -> &Self::Target {
49 &self.0
50 }
51}
52
42impl_internable!( 53impl_internable!(
43 InternedVariableKindsInner, 54 InternedVariableKindsInner,
44 InternedSubstitutionInner, 55 InternedSubstitutionInner,
45 InternedTypeInner, 56 InternedTypeInner,
57 InternedWrapper<chalk_ir::LifetimeData<Interner>>,
58 InternedWrapper<chalk_ir::ConstData<Interner>>,
46); 59);
47 60
48impl chalk_ir::interner::Interner for Interner { 61impl chalk_ir::interner::Interner for Interner {
49 type InternedType = Interned<InternedTypeInner>; 62 type InternedType = Interned<InternedTypeInner>;
50 type InternedLifetime = chalk_ir::LifetimeData<Self>; 63 type InternedLifetime = Interned<InternedWrapper<chalk_ir::LifetimeData<Self>>>;
51 type InternedConst = Arc<chalk_ir::ConstData<Self>>; 64 type InternedConst = Interned<InternedWrapper<chalk_ir::ConstData<Self>>>;
52 type InternedConcreteConst = (); 65 type InternedConcreteConst = ();
53 type InternedGenericArg = chalk_ir::GenericArgData<Self>; 66 type InternedGenericArg = chalk_ir::GenericArgData<Self>;
54 type InternedGoal = Arc<GoalData<Self>>; 67 type InternedGoal = Arc<GoalData<Self>>;
@@ -221,22 +234,22 @@ impl chalk_ir::interner::Interner for Interner {
221 } 234 }
222 235
223 fn intern_lifetime(&self, lifetime: chalk_ir::LifetimeData<Self>) -> Self::InternedLifetime { 236 fn intern_lifetime(&self, lifetime: chalk_ir::LifetimeData<Self>) -> Self::InternedLifetime {
224 lifetime 237 Interned::new(InternedWrapper(lifetime))
225 } 238 }
226 239
227 fn lifetime_data<'a>( 240 fn lifetime_data<'a>(
228 &self, 241 &self,
229 lifetime: &'a Self::InternedLifetime, 242 lifetime: &'a Self::InternedLifetime,
230 ) -> &'a chalk_ir::LifetimeData<Self> { 243 ) -> &'a chalk_ir::LifetimeData<Self> {
231 lifetime 244 &lifetime.0
232 } 245 }
233 246
234 fn intern_const(&self, constant: chalk_ir::ConstData<Self>) -> Self::InternedConst { 247 fn intern_const(&self, constant: chalk_ir::ConstData<Self>) -> Self::InternedConst {
235 Arc::new(constant) 248 Interned::new(InternedWrapper(constant))
236 } 249 }
237 250
238 fn const_data<'a>(&self, constant: &'a Self::InternedConst) -> &'a chalk_ir::ConstData<Self> { 251 fn const_data<'a>(&self, constant: &'a Self::InternedConst) -> &'a chalk_ir::ConstData<Self> {
239 constant 252 &constant.0
240 } 253 }
241 254
242 fn const_eq( 255 fn const_eq(