Skip to content

Commit 90656f8

Browse files
committed
Intern consts & lifetimes
Slight memory usage reduction.
1 parent 37cb680 commit 90656f8

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

crates/hir_ty/src/chalk_ext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl TyExt for Ty {
7575
}
7676
fn as_reference(&self) -> Option<(&Ty, Lifetime, Mutability)> {
7777
match self.kind(&Interner) {
78-
TyKind::Ref(mutability, lifetime, ty) => Some((ty, *lifetime, *mutability)),
78+
TyKind::Ref(mutability, lifetime, ty) => Some((ty, lifetime.clone(), *mutability)),
7979
_ => None,
8080
}
8181
}

crates/hir_ty/src/traits/chalk/interner.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,29 @@ pub struct InternedSubstitutionInner(SmallVec<[GenericArg; 2]>);
3939
#[derive(PartialEq, Eq, Hash, Debug)]
4040
pub struct InternedTypeInner(chalk_ir::TyData<Interner>);
4141

42+
#[derive(PartialEq, Eq, Hash, Debug)]
43+
pub struct InternedWrapper<T>(T);
44+
45+
impl<T> std::ops::Deref for InternedWrapper<T> {
46+
type Target = T;
47+
48+
fn deref(&self) -> &Self::Target {
49+
&self.0
50+
}
51+
}
52+
4253
impl_internable!(
4354
InternedVariableKindsInner,
4455
InternedSubstitutionInner,
4556
InternedTypeInner,
57+
InternedWrapper<chalk_ir::LifetimeData<Interner>>,
58+
InternedWrapper<chalk_ir::ConstData<Interner>>,
4659
);
4760

4861
impl chalk_ir::interner::Interner for Interner {
4962
type InternedType = Interned<InternedTypeInner>;
50-
type InternedLifetime = chalk_ir::LifetimeData<Self>;
51-
type InternedConst = Arc<chalk_ir::ConstData<Self>>;
63+
type InternedLifetime = Interned<InternedWrapper<chalk_ir::LifetimeData<Self>>>;
64+
type InternedConst = Interned<InternedWrapper<chalk_ir::ConstData<Self>>>;
5265
type InternedConcreteConst = ();
5366
type InternedGenericArg = chalk_ir::GenericArgData<Self>;
5467
type InternedGoal = Arc<GoalData<Self>>;
@@ -221,22 +234,22 @@ impl chalk_ir::interner::Interner for Interner {
221234
}
222235

223236
fn intern_lifetime(&self, lifetime: chalk_ir::LifetimeData<Self>) -> Self::InternedLifetime {
224-
lifetime
237+
Interned::new(InternedWrapper(lifetime))
225238
}
226239

227240
fn lifetime_data<'a>(
228241
&self,
229242
lifetime: &'a Self::InternedLifetime,
230243
) -> &'a chalk_ir::LifetimeData<Self> {
231-
lifetime
244+
&lifetime.0
232245
}
233246

234247
fn intern_const(&self, constant: chalk_ir::ConstData<Self>) -> Self::InternedConst {
235-
Arc::new(constant)
248+
Interned::new(InternedWrapper(constant))
236249
}
237250

238251
fn const_data<'a>(&self, constant: &'a Self::InternedConst) -> &'a chalk_ir::ConstData<Self> {
239-
constant
252+
&constant.0
240253
}
241254

242255
fn const_eq(

0 commit comments

Comments
 (0)