Skip to content

Commit 4dd5382

Browse files
committed
Do most of intern-lifetime-data
1 parent 70aff78 commit 4dd5382

File tree

8 files changed

+44
-32
lines changed

8 files changed

+44
-32
lines changed

chalk-ir/src/debug.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@ impl<I: Interner> Debug for Fn<I> {
8787
}
8888
}
8989

90+
#[allow(unreachable_code, unused_variables)]
9091
impl<I: Interner> Debug for Lifetime<I> {
9192
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
92-
write!(fmt, "{:?}", self.data())
93+
let interner = unimplemented!();
94+
write!(fmt, "{:?}", self.data(interner))
9395
}
9496
}
9597

chalk-ir/src/fold.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,14 @@ where
365365
I: 'i,
366366
TI: 'i,
367367
{
368-
match self.data() {
368+
let interner = folder.interner();
369+
let target_interner = folder.target_interner();
370+
match self.data(interner) {
369371
LifetimeData::BoundVar(depth) => {
370372
if *depth >= binders {
371373
folder.fold_free_var_lifetime(depth - binders, binders)
372374
} else {
373-
Ok(LifetimeData::<TI>::BoundVar(*depth).intern(folder.target_interner()))
375+
Ok(LifetimeData::<TI>::BoundVar(*depth).intern(target_interner))
374376
}
375377
}
376378
LifetimeData::InferenceVar(var) => folder.fold_inference_lifetime(*var, binders),

chalk-ir/src/interner.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
157157
fn intern_lifetime(&self, lifetime: LifetimeData<Self>) -> Self::InternedLifetime;
158158

159159
/// Lookup the `LifetimeData` that was interned to create a `InternedLifetime`.
160-
fn lifetime_data(lifetime: &Self::InternedLifetime) -> &LifetimeData<Self>;
160+
fn lifetime_data<'a>(&self, lifetime: &'a Self::InternedLifetime) -> &'a LifetimeData<Self>;
161161

162162
/// Create an "interned" parameter from `data`. This is not
163163
/// normally invoked directly; instead, you invoke
@@ -298,7 +298,7 @@ mod default {
298298
lifetime
299299
}
300300

301-
fn lifetime_data(lifetime: &LifetimeData<ChalkIr>) -> &LifetimeData<ChalkIr> {
301+
fn lifetime_data<'a>(&self, lifetime: &'a LifetimeData<ChalkIr>) -> &'a LifetimeData<ChalkIr> {
302302
lifetime
303303
}
304304

chalk-ir/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -342,13 +342,13 @@ impl<I: Interner> Lifetime<I> {
342342
}
343343
}
344344

345-
pub fn data(&self) -> &LifetimeData<I> {
346-
I::lifetime_data(&self.interned)
345+
pub fn data(&self, interner: &I) -> &LifetimeData<I> {
346+
I::lifetime_data(interner, &self.interned)
347347
}
348348

349349
/// If this is a `Lifetime::InferenceVar(d)`, returns `Some(d)` else `None`.
350-
pub fn inference_var(&self) -> Option<InferenceVar> {
351-
if let LifetimeData::InferenceVar(depth) = self.data() {
350+
pub fn inference_var(&self, interner: &I) -> Option<InferenceVar> {
351+
if let LifetimeData::InferenceVar(depth) = self.data(interner) {
352352
Some(*depth)
353353
} else {
354354
None
@@ -357,8 +357,8 @@ impl<I: Interner> Lifetime<I> {
357357

358358
/// True if this lifetime is a "bound" lifetime, and hence
359359
/// needs to be shifted across binders. Meant for debug assertions.
360-
pub fn needs_shift(&self) -> bool {
361-
match self.data() {
360+
pub fn needs_shift(&self, interner: &I) -> bool {
361+
match self.data(interner) {
362362
LifetimeData::BoundVar(_) => true,
363363
LifetimeData::InferenceVar(_) => false,
364364
LifetimeData::Placeholder(_) => false,
@@ -1302,7 +1302,7 @@ impl<I: Interner> Substitution<I> {
13021302
TyData::BoundVar(depth) => index == *depth,
13031303
_ => false,
13041304
},
1305-
ParameterKind::Lifetime(lifetime) => match lifetime.data() {
1305+
ParameterKind::Lifetime(lifetime) => match lifetime.data(interner) {
13061306
LifetimeData::BoundVar(depth) => index == *depth,
13071307
_ => false,
13081308
},

chalk-solve/src/infer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ impl<I: Interner> InferenceTable<I> {
143143

144144
/// If `leaf` represents an inference variable `X`, and `X` is bound,
145145
/// returns `Some(v)` where `v` is the value to which `X` is bound.
146-
pub(crate) fn normalize_lifetime(&mut self, leaf: &Lifetime<I>) -> Option<Lifetime<I>> {
147-
let var = EnaVariable::from(leaf.inference_var()?);
146+
pub(crate) fn normalize_lifetime(&mut self, interner: &I, leaf: &Lifetime<I>) -> Option<Lifetime<I>> {
147+
let var = EnaVariable::from(leaf.inference_var(interner)?);
148148
let v1 = self.probe_lifetime_var(var)?;
149-
assert!(!v1.needs_shift());
149+
assert!(!v1.needs_shift(interner));
150150
Some(v1)
151151
}
152152

chalk-solve/src/infer/unify.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ pub(crate) struct UnificationResult<I: Interner> {
5454
}
5555

5656
impl<'t, I: Interner> Unifier<'t, I> {
57-
#[allow(unreachable_code)]
5857
fn new(
5958
interner: &'t I,
6059
table: &'t mut InferenceTable<I>,
@@ -270,15 +269,15 @@ impl<'t, I: Interner> Unifier<'t, I> {
270269
fn unify_lifetime_lifetime(&mut self, a: &Lifetime<I>, b: &Lifetime<I>) -> Fallible<()> {
271270
let interner = self.interner;
272271

273-
if let Some(n_a) = self.table.normalize_lifetime(a) {
272+
if let Some(n_a) = self.table.normalize_lifetime(interner, a) {
274273
return self.unify_lifetime_lifetime(&n_a, b);
275-
} else if let Some(n_b) = self.table.normalize_lifetime(b) {
274+
} else if let Some(n_b) = self.table.normalize_lifetime(interner, b) {
276275
return self.unify_lifetime_lifetime(a, &n_b);
277276
}
278277

279278
debug_heading!("unify_lifetime_lifetime({:?}, {:?})", a, b);
280279

281-
match (a.data(), b.data()) {
280+
match (a.data(interner), b.data(interner)) {
282281
(&LifetimeData::InferenceVar(var_a), &LifetimeData::InferenceVar(var_b)) => {
283282
let var_a = EnaVariable::from(var_a);
284283
let var_b = EnaVariable::from(var_b);
@@ -485,6 +484,7 @@ where
485484
var: InferenceVar,
486485
binders: usize,
487486
) -> Fallible<Lifetime<I>> {
487+
let interner = self.interner();
488488
// a free existentially bound region; find the
489489
// inference variable it corresponds to
490490
let interner = self.interner();
@@ -510,7 +510,7 @@ where
510510
InferenceValue::Bound(l) => {
511511
let l = l.lifetime().unwrap();
512512
let l = l.fold_with(self, binders)?;
513-
assert!(!l.needs_shift());
513+
assert!(!l.needs_shift(interner));
514514
Ok(l.clone())
515515
}
516516
}

chalk-solve/src/solve/slg/aggregate.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ impl<I: Interner> AntiUnifier<'_, '_, I> {
257257
apply1: &ApplicationTy<I>,
258258
apply2: &ApplicationTy<I>,
259259
) -> Ty<I> {
260+
let interner = self.interner;
260261
let ApplicationTy {
261262
name: name1,
262263
substitution: substitution1,
@@ -268,7 +269,7 @@ impl<I: Interner> AntiUnifier<'_, '_, I> {
268269

269270
self.aggregate_name_and_substs(name1, substitution1, name2, substitution2)
270271
.map(|(&name, substitution)| {
271-
TyData::Apply(ApplicationTy { name, substitution }).intern(self.interner)
272+
TyData::Apply(ApplicationTy { name, substitution }).intern(interner)
272273
})
273274
.unwrap_or_else(|| self.new_variable())
274275
}
@@ -278,14 +279,16 @@ impl<I: Interner> AntiUnifier<'_, '_, I> {
278279
index1: &PlaceholderIndex,
279280
index2: &PlaceholderIndex,
280281
) -> Ty<I> {
282+
let interner = self.interner;
281283
if index1 != index2 {
282284
self.new_variable()
283285
} else {
284-
TyData::Placeholder(index1.clone()).intern(self.interner)
286+
TyData::Placeholder(index1.clone()).intern(interner)
285287
}
286288
}
287289

288290
fn aggregate_alias_tys(&mut self, alias1: &AliasTy<I>, alias2: &AliasTy<I>) -> Ty<I> {
291+
let interner = self.interner;
289292
let AliasTy {
290293
associated_ty_id: name1,
291294
substitution: substitution1,
@@ -301,7 +304,7 @@ impl<I: Interner> AntiUnifier<'_, '_, I> {
301304
associated_ty_id,
302305
substitution,
303306
})
304-
.intern(self.interner)
307+
.intern(interner)
305308
})
306309
.unwrap_or_else(|| self.new_variable())
307310
}
@@ -359,7 +362,8 @@ impl<I: Interner> AntiUnifier<'_, '_, I> {
359362
}
360363

361364
fn aggregate_lifetimes(&mut self, l1: &Lifetime<I>, l2: &Lifetime<I>) -> Lifetime<I> {
362-
match (l1.data(), l2.data()) {
365+
let interner = self.interner;
366+
match (l1.data(interner), l2.data(interner)) {
363367
(LifetimeData::InferenceVar(_), _) | (_, LifetimeData::InferenceVar(_)) => {
364368
self.new_lifetime_variable()
365369
}
@@ -381,13 +385,15 @@ impl<I: Interner> AntiUnifier<'_, '_, I> {
381385
}
382386

383387
fn new_variable(&mut self) -> Ty<I> {
384-
self.infer.new_variable(self.universe).to_ty(self.interner)
388+
let interner = self.interner;
389+
self.infer.new_variable(self.universe).to_ty(interner)
385390
}
386391

387392
fn new_lifetime_variable(&mut self) -> Lifetime<I> {
393+
let interner = self.interner;
388394
self.infer
389395
.new_variable(self.universe)
390-
.to_lifetime(self.interner)
396+
.to_lifetime(interner)
391397
}
392398
}
393399

chalk-solve/src/solve/slg/resolvent.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,8 @@ impl<I: Interner> AnswerSubstitutor<'_, I> {
355355
impl<I: Interner> Zipper<I> for AnswerSubstitutor<'_, I> {
356356
fn zip_tys(&mut self, answer: &Ty<I>, pending: &Ty<I>) -> Fallible<()> {
357357
let interner = self.interner;
358-
if let Some(pending) = self.table.normalize_shallow(self.interner, pending) {
358+
359+
if let Some(pending) = self.table.normalize_shallow(interner, pending) {
359360
return Zip::zip_with(self, answer, &pending);
360361
}
361362

@@ -365,7 +366,7 @@ impl<I: Interner> Zipper<I> for AnswerSubstitutor<'_, I> {
365366
// the value from our "pending subgoal".
366367
if let TyData::BoundVar(answer_depth) = answer.data(interner) {
367368
if self.unify_free_answer_var(
368-
self.interner,
369+
interner,
369370
*answer_depth,
370371
ParameterKind::Ty(pending),
371372
)? {
@@ -417,21 +418,22 @@ impl<I: Interner> Zipper<I> for AnswerSubstitutor<'_, I> {
417418
}
418419

419420
fn zip_lifetimes(&mut self, answer: &Lifetime<I>, pending: &Lifetime<I>) -> Fallible<()> {
420-
if let Some(pending) = self.table.normalize_lifetime(pending) {
421+
let interner = self.interner;
422+
if let Some(pending) = self.table.normalize_lifetime(interner, pending) {
421423
return Zip::zip_with(self, answer, &pending);
422424
}
423425

424-
if let LifetimeData::BoundVar(answer_depth) = answer.data() {
426+
if let LifetimeData::BoundVar(answer_depth) = answer.data(interner) {
425427
if self.unify_free_answer_var(
426-
self.interner,
428+
interner,
427429
*answer_depth,
428430
ParameterKind::Lifetime(pending),
429431
)? {
430432
return Ok(());
431433
}
432434
}
433435

434-
match (answer.data(), pending.data()) {
436+
match (answer.data(interner), pending.data(interner)) {
435437
(LifetimeData::BoundVar(answer_depth), LifetimeData::BoundVar(pending_depth)) => {
436438
self.assert_matching_vars(*answer_depth, *pending_depth)
437439
}

0 commit comments

Comments
 (0)