Skip to content

Commit c8b2882

Browse files
leoyvensnikomatsakis
authored andcommitted
Pack lifetimes from the same binder into the same universe
This changes the output of some tests, should not alter any semantics
1 parent 82bf5d6 commit c8b2882

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

chalk-solve/src/infer/instantiate.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,24 @@ impl InferenceTable {
100100
T: Fold,
101101
{
102102
let (binders, value) = arg.split();
103+
let lifetime_ui = self.new_universe();
104+
let mut idx = 0;
103105
let parameters: Vec<_> = binders
104106
.iter()
105107
.map(|pk| {
106-
let new_universe = self.new_universe();
107108
match *pk {
108109
ParameterKind::Lifetime(()) => {
109-
let lt = Lifetime::ForAll(UniversalIndex { ui: new_universe, idx: 0 });
110+
let lt = Lifetime::ForAll(UniversalIndex { ui: lifetime_ui, idx });
111+
idx += 1;
110112
ParameterKind::Lifetime(lt)
111113
}
112-
ParameterKind::Ty(()) => ParameterKind::Ty(Ty::Apply(ApplicationTy {
113-
name: TypeName::ForAll(new_universe),
114-
parameters: vec![],
115-
})),
114+
ParameterKind::Ty(()) => {
115+
let new_universe = self.new_universe();
116+
ParameterKind::Ty(Ty::Apply(ApplicationTy {
117+
name: TypeName::ForAll(new_universe),
118+
parameters: vec![],
119+
}))
120+
}
116121
}
117122
})
118123
.collect();

chalk-solve/src/infer/unify.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,22 @@ impl<'t> Unifier<'t> {
166166
}
167167

168168
fn unify_forall_tys(&mut self, ty1: &QuantifiedTy, ty2: &QuantifiedTy) -> Fallible<()> {
169-
// for<'a...> T == for<'b...> U where 'a != 'b
169+
// for<'a...> T == for<'b...> U
170170
//
171171
// if:
172172
//
173173
// for<'a...> exists<'b...> T == U &&
174174
// for<'b...> exists<'a...> T == U
175+
//
176+
// Here we only check for<'a...> exists<'b...> T == U,
177+
// can someone smart comment why this is sufficient?
175178

176179
debug!("unify_forall_tys({:?}, {:?})", ty1, ty2);
177180

181+
let ui = self.table.new_universe();
178182
let lifetimes1: Vec<_> = (0..ty1.num_binders)
179-
.map(|_| {
180-
let new_universe = self.table.new_universe();
181-
Lifetime::ForAll(UniversalIndex { ui: new_universe, idx: 0 }).cast()
183+
.map(|idx| {
184+
Lifetime::ForAll(UniversalIndex { ui, idx }).cast()
182185
})
183186
.collect();
184187

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ fn basic_region_constraint_from_positive_impl() {
550550
constraints: [
551551
InEnvironment {
552552
environment: Env([]),
553-
goal: '!2'0 == '!1'0
553+
goal: '!1'1 == '!1'0
554554
}
555555
]
556556
},

chalk-solve/src/solve/test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ fn region_equality() {
922922
} yields {
923923
"Unique; substitution [],
924924
lifetime constraints \
925-
[InEnvironment { environment: Env([]), goal: '!2'0 == '!1'0 }]
925+
[InEnvironment { environment: Env([]), goal: '!1'1 == '!1'0 }]
926926
"
927927
}
928928

@@ -966,12 +966,12 @@ fn forall_equality() {
966966
// this is because the region constraints are unsolvable.
967967
//
968968
// Note that `?0` (in universe 2) must be equal to both
969-
// `!1` and `!2`, which of course it cannot be.
969+
// `!1'0` and `!1'1`, which of course it cannot be.
970970
for<'a, 'b> Ref<'a, Ref<'b, Ref<'a, Unit>>>: Eq<
971971
for<'c, 'd> Ref<'c, Ref<'d, Ref<'d, Unit>>>>
972972
} yields {
973973
"Unique; substitution [], lifetime constraints [
974-
InEnvironment { environment: Env([]), goal: '!2'0 == '!1'0 }
974+
InEnvironment { environment: Env([]), goal: '!1'1 == '!1'0 }
975975
]"
976976
}
977977
}

0 commit comments

Comments
 (0)