From 90656f86745afe073a5b590d51b22ec5f6b60e1b Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Thu, 8 Apr 2021 18:45:07 +0200 Subject: Intern consts & lifetimes Slight memory usage reduction. --- crates/hir_ty/src/chalk_ext.rs | 2 +- crates/hir_ty/src/traits/chalk/interner.rs | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) (limited to 'crates/hir_ty') diff --git a/crates/hir_ty/src/chalk_ext.rs b/crates/hir_ty/src/chalk_ext.rs index 28ed3aac6..8c4542956 100644 --- a/crates/hir_ty/src/chalk_ext.rs +++ b/crates/hir_ty/src/chalk_ext.rs @@ -75,7 +75,7 @@ impl TyExt for Ty { } fn as_reference(&self) -> Option<(&Ty, Lifetime, Mutability)> { match self.kind(&Interner) { - TyKind::Ref(mutability, lifetime, ty) => Some((ty, *lifetime, *mutability)), + TyKind::Ref(mutability, lifetime, ty) => Some((ty, lifetime.clone(), *mutability)), _ => None, } } 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); +#[derive(PartialEq, Eq, Hash, Debug)] +pub struct InternedWrapper(T); + +impl std::ops::Deref for InternedWrapper { + type Target = T; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + impl_internable!( InternedVariableKindsInner, InternedSubstitutionInner, InternedTypeInner, + InternedWrapper>, + InternedWrapper>, ); impl chalk_ir::interner::Interner for Interner { type InternedType = Interned; - type InternedLifetime = chalk_ir::LifetimeData; - type InternedConst = Arc>; + type InternedLifetime = Interned>>; + type InternedConst = Interned>>; type InternedConcreteConst = (); type InternedGenericArg = chalk_ir::GenericArgData; type InternedGoal = Arc>; @@ -221,22 +234,22 @@ impl chalk_ir::interner::Interner for Interner { } fn intern_lifetime(&self, lifetime: chalk_ir::LifetimeData) -> Self::InternedLifetime { - lifetime + Interned::new(InternedWrapper(lifetime)) } fn lifetime_data<'a>( &self, lifetime: &'a Self::InternedLifetime, ) -> &'a chalk_ir::LifetimeData { - lifetime + &lifetime.0 } fn intern_const(&self, constant: chalk_ir::ConstData) -> Self::InternedConst { - Arc::new(constant) + Interned::new(InternedWrapper(constant)) } fn const_data<'a>(&self, constant: &'a Self::InternedConst) -> &'a chalk_ir::ConstData { - constant + &constant.0 } fn const_eq( -- cgit v1.2.3