From 90656f86745afe073a5b590d51b22ec5f6b60e1b Mon Sep 17 00:00:00 2001 From: Florian Diebold <flodiebold@gmail.com> Date: Thu, 8 Apr 2021 18:45:07 +0200 Subject: Intern consts & lifetimes Slight memory usage reduction. --- crates/hir_ty/src/traits/chalk/interner.rs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'crates/hir_ty/src/traits/chalk') 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]>); #[derive(PartialEq, Eq, Hash, Debug)] pub struct InternedTypeInner(chalk_ir::TyData<Interner>); +#[derive(PartialEq, Eq, Hash, Debug)] +pub struct InternedWrapper<T>(T); + +impl<T> std::ops::Deref for InternedWrapper<T> { + type Target = T; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + impl_internable!( InternedVariableKindsInner, InternedSubstitutionInner, InternedTypeInner, + InternedWrapper<chalk_ir::LifetimeData<Interner>>, + InternedWrapper<chalk_ir::ConstData<Interner>>, ); impl chalk_ir::interner::Interner for Interner { type InternedType = Interned<InternedTypeInner>; - type InternedLifetime = chalk_ir::LifetimeData<Self>; - type InternedConst = Arc<chalk_ir::ConstData<Self>>; + type InternedLifetime = Interned<InternedWrapper<chalk_ir::LifetimeData<Self>>>; + type InternedConst = Interned<InternedWrapper<chalk_ir::ConstData<Self>>>; type InternedConcreteConst = (); type InternedGenericArg = chalk_ir::GenericArgData<Self>; type InternedGoal = Arc<GoalData<Self>>; @@ -221,22 +234,22 @@ impl chalk_ir::interner::Interner for Interner { } fn intern_lifetime(&self, lifetime: chalk_ir::LifetimeData<Self>) -> Self::InternedLifetime { - lifetime + Interned::new(InternedWrapper(lifetime)) } fn lifetime_data<'a>( &self, lifetime: &'a Self::InternedLifetime, ) -> &'a chalk_ir::LifetimeData<Self> { - lifetime + &lifetime.0 } fn intern_const(&self, constant: chalk_ir::ConstData<Self>) -> Self::InternedConst { - Arc::new(constant) + Interned::new(InternedWrapper(constant)) } fn const_data<'a>(&self, constant: &'a Self::InternedConst) -> &'a chalk_ir::ConstData<Self> { - constant + &constant.0 } fn const_eq( -- cgit v1.2.3