Skip to content

Commit 52f4151

Browse files
committed
start working on intern data
1 parent dab6a15 commit 52f4151

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

chalk-ir/src/could_match.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ where
1515
fn could_match(&self, other: &T) -> bool {
1616
return Zip::zip_with(&mut MatchZipper, self, other).is_ok();
1717

18-
struct MatchZipper;
18+
struct MatchZipper<'i, I> {
19+
interner: &'i I,
20+
};
1921

20-
impl<I: Interner> Zipper<I> for MatchZipper {
22+
impl<I: Interner> Zipper<I> for MatchZipper<'_, I> {
2123
fn zip_tys(&mut self, a: &Ty<I>, b: &Ty<I>) -> Fallible<()> {
22-
let could_match = match (a.data(), b.data()) {
24+
let could_match = match (a.data(self.interner), b.data(self.interner)) {
2325
(&TyData::Apply(ref a), &TyData::Apply(ref b)) => {
2426
let names_could_match = a.name == b.name;
2527

chalk-ir/src/fold.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ where
303303
I: 'i,
304304
TI: 'i,
305305
{
306-
match self.data() {
306+
match self.data(folder.interner()) {
307307
TyData::BoundVar(depth) => {
308308
if *depth >= binders {
309309
folder.fold_free_var_ty(*depth - binders, binders)

chalk-ir/src/interner.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
138138
fn intern_ty(&self, ty: TyData<Self>) -> Self::InternedType;
139139

140140
/// Lookup the `TyData` from an interned type.
141-
fn ty_data(ty: &Self::InternedType) -> &TyData<Self>;
141+
fn ty_data<'a>(&self, ty: &'a Self::InternedType) -> &'a TyData<Self>;
142142

143143
/// Create an "interned" lifetime from `lifetime`. This is not
144144
/// normally invoked directly; instead, you invoke
@@ -276,7 +276,7 @@ mod default {
276276
Arc::new(ty)
277277
}
278278

279-
fn ty_data(ty: &Arc<TyData<ChalkIr>>) -> &TyData<Self> {
279+
fn ty_data<'a>(&self, ty: &'a Arc<TyData<ChalkIr>>) -> &'a TyData<Self> {
280280
ty
281281
}
282282

chalk-ir/src/lib.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ impl<I: Interner> Ty<I> {
168168
}
169169
}
170170

171-
pub fn data(&self) -> &TyData<I> {
172-
I::ty_data(&self.interned)
171+
pub fn data(&self, interner: &I) -> &TyData<I> {
172+
I::ty_data(interner, &self.interned)
173173
}
174174

175175
pub fn from_env(&self) -> FromEnv<I> {
@@ -181,25 +181,25 @@ impl<I: Interner> Ty<I> {
181181
}
182182

183183
/// If this is a `TyData::BoundVar(d)`, returns `Some(d)` else `None`.
184-
pub fn bound(&self) -> Option<usize> {
185-
if let TyData::BoundVar(depth) = self.data() {
184+
pub fn bound(&self, interner: &I) -> Option<usize> {
185+
if let TyData::BoundVar(depth) = self.data(interner) {
186186
Some(*depth)
187187
} else {
188188
None
189189
}
190190
}
191191

192192
/// If this is a `TyData::InferenceVar(d)`, returns `Some(d)` else `None`.
193-
pub fn inference_var(&self) -> Option<InferenceVar> {
194-
if let TyData::InferenceVar(depth) = self.data() {
193+
pub fn inference_var(&self, interner: &I) -> Option<InferenceVar> {
194+
if let TyData::InferenceVar(depth) = self.data(interner) {
195195
Some(*depth)
196196
} else {
197197
None
198198
}
199199
}
200200

201-
pub fn is_alias(&self) -> bool {
202-
match self.data() {
201+
pub fn is_alias(&self, interner: &I) -> bool {
202+
match self.data(interner) {
203203
TyData::Alias(..) => true,
204204
_ => false,
205205
}
@@ -1009,11 +1009,12 @@ pub struct UCanonical<T> {
10091009
impl<T> UCanonical<T> {
10101010
pub fn is_trivial_substitution<I: Interner>(
10111011
&self,
1012+
interner: &I,
10121013
canonical_subst: &Canonical<AnswerSubst<I>>,
10131014
) -> bool {
10141015
let subst = &canonical_subst.value.subst;
10151016
assert_eq!(self.canonical.binders.len(), subst.parameters().len());
1016-
subst.is_identity_subst()
1017+
subst.is_identity_subst(interner)
10171018
}
10181019
}
10191020

@@ -1293,11 +1294,11 @@ impl<I: Interner> Substitution<I> {
12931294
///
12941295
/// Basically, each value is mapped to a type or lifetime with its
12951296
/// same index.
1296-
pub fn is_identity_subst(&self) -> bool {
1297+
pub fn is_identity_subst(&self, interner: &I) -> bool {
12971298
self.iter()
12981299
.zip(0..)
12991300
.all(|(parameter, index)| match parameter.data() {
1300-
ParameterKind::Ty(ty) => match ty.data() {
1301+
ParameterKind::Ty(ty) => match ty.data(interner) {
13011302
TyData::BoundVar(depth) => index == *depth,
13021303
_ => false,
13031304
},

0 commit comments

Comments
 (0)