Skip to content

Commit 82bf5d6

Browse files
leoyvensnikomatsakis
authored andcommitted
Refactor fold_free_universal_lifetime to take a UniversalIndex
1 parent ad91883 commit 82bf5d6

File tree

6 files changed

+24
-22
lines changed

6 files changed

+24
-22
lines changed

chalk-ir/src/fold.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ pub trait UniversalFolder {
140140
/// As with `fold_free_universal_ty`, but for lifetimes.
141141
fn fold_free_universal_lifetime(
142142
&mut self,
143-
universe: UniverseIndex,
143+
universe: UniversalIndex,
144144
binders: usize,
145145
) -> Fallible<Lifetime>;
146146
}
@@ -157,7 +157,7 @@ impl<T: IdentityUniversalFolder> UniversalFolder for T {
157157

158158
fn fold_free_universal_lifetime(
159159
&mut self,
160-
universe: UniverseIndex,
160+
universe: UniversalIndex,
161161
_binders: usize,
162162
) -> Fallible<Lifetime> {
163163
Ok(universe.to_lifetime())
@@ -349,7 +349,7 @@ pub fn super_fold_lifetime(
349349
} else {
350350
Ok(Lifetime::Var(depth))
351351
},
352-
Lifetime::ForAll(universe) => folder.fold_free_universal_lifetime(universe.ui, binders),
352+
Lifetime::ForAll(universe) => folder.fold_free_universal_lifetime(universe, binders),
353353
}
354354
}
355355

chalk-ir/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,6 @@ impl UniverseIndex {
134134
self.counter >= ui.counter
135135
}
136136

137-
pub fn to_lifetime(self) -> Lifetime {
138-
Lifetime::ForAll(UniversalIndex { ui: self, idx: 0 })
139-
}
140-
141137
pub fn next(self) -> UniverseIndex {
142138
UniverseIndex {
143139
counter: self.counter + 1,
@@ -220,6 +216,12 @@ pub struct UniversalIndex {
220216
pub idx: usize,
221217
}
222218

219+
impl UniversalIndex {
220+
pub fn to_lifetime(self) -> Lifetime {
221+
Lifetime::ForAll(self)
222+
}
223+
}
224+
223225
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
224226
pub struct ApplicationTy {
225227
pub name: TypeName,

chalk-solve/src/infer/canonicalize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ impl<'q> UniversalFolder for Canonicalizer<'q> {
101101

102102
fn fold_free_universal_lifetime(
103103
&mut self,
104-
universe: UniverseIndex,
104+
universe: UniversalIndex,
105105
_binders: usize,
106106
) -> Fallible<Lifetime> {
107-
self.max_universe = max(self.max_universe, universe);
107+
self.max_universe = max(self.max_universe, universe.ui);
108108
Ok(universe.to_lifetime())
109109
}
110110
}

chalk-solve/src/infer/invert.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl InferenceTable {
9898
struct Inverter<'q> {
9999
table: &'q mut InferenceTable,
100100
inverted_ty: HashMap<UniverseIndex, InferenceVariable>,
101-
inverted_lifetime: HashMap<UniverseIndex, InferenceVariable>,
101+
inverted_lifetime: HashMap<UniversalIndex, InferenceVariable>,
102102
}
103103

104104
impl<'q> Inverter<'q> {
@@ -127,14 +127,14 @@ impl<'q> UniversalFolder for Inverter<'q> {
127127

128128
fn fold_free_universal_lifetime(
129129
&mut self,
130-
universe: UniverseIndex,
130+
universe: UniversalIndex,
131131
binders: usize,
132132
) -> Fallible<Lifetime> {
133133
let table = &mut self.table;
134134
Ok(
135135
self.inverted_lifetime
136136
.entry(universe)
137-
.or_insert_with(|| table.new_variable(universe))
137+
.or_insert_with(|| table.new_variable(universe.ui))
138138
.to_lifetime()
139139
.shifted_in(binders),
140140
)

chalk-solve/src/infer/ucanonicalize.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,10 @@ impl<'q> UniversalFolder for UCollector<'q> {
227227

228228
fn fold_free_universal_lifetime(
229229
&mut self,
230-
universe: UniverseIndex,
230+
universe: UniversalIndex,
231231
_binders: usize,
232232
) -> Fallible<Lifetime> {
233-
self.universes.add(universe);
233+
self.universes.add(universe.ui);
234234
Ok(universe.to_lifetime())
235235
}
236236
}
@@ -255,11 +255,11 @@ impl<'q> UniversalFolder for UMapToCanonical<'q> {
255255

256256
fn fold_free_universal_lifetime(
257257
&mut self,
258-
universe0: UniverseIndex,
258+
universe0: UniversalIndex,
259259
_binders: usize,
260260
) -> Fallible<Lifetime> {
261-
let universe = self.universes.map_universe_to_canonical(universe0);
262-
Ok(universe.to_lifetime())
261+
let universe = self.universes.map_universe_to_canonical(universe0.ui);
262+
Ok(UniversalIndex { ui: universe, idx: universe0.idx }.to_lifetime())
263263
}
264264
}
265265

@@ -283,11 +283,11 @@ impl<'q> UniversalFolder for UMapFromCanonical<'q> {
283283

284284
fn fold_free_universal_lifetime(
285285
&mut self,
286-
universe0: UniverseIndex,
286+
universe0: UniversalIndex,
287287
_binders: usize,
288288
) -> Fallible<Lifetime> {
289-
let universe = self.universes.map_universe_from_canonical(universe0);
290-
Ok(universe.to_lifetime())
289+
let universe = self.universes.map_universe_from_canonical(universe0.ui);
290+
Ok(UniversalIndex { ui: universe, idx: universe0.idx }.to_lifetime())
291291
}
292292
}
293293

chalk-solve/src/infer/unify.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,10 @@ impl<'u, 't> UniversalFolder for OccursCheck<'u, 't> {
384384

385385
fn fold_free_universal_lifetime(
386386
&mut self,
387-
ui: UniverseIndex,
387+
ui: UniversalIndex,
388388
binders: usize,
389389
) -> Fallible<Lifetime> {
390-
if self.universe_index < ui {
390+
if self.universe_index < ui.ui {
391391
// Scenario is like:
392392
//
393393
// exists<T> forall<'b> ?T = Foo<'b>

0 commit comments

Comments
 (0)