Skip to content

Create multiple universes at once #56234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/librustc/infer/canonical/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,14 +315,11 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
T: TypeFoldable<'tcx>,
{
// For each universe that is referred to in the incoming
// query, create a universe in our local inference context. In
// practice, as of this writing, all queries have no universes
// in them, so this code has no effect, but it is looking
// forward to the day when we *do* want to carry universes
// through into queries.
// query, create a universe in our local inference context.
let universes: IndexVec<ty::UniverseIndex, _> = std::iter::once(ty::UniverseIndex::ROOT)
.chain((0..canonical.max_universe.as_u32()).map(|_| self.create_next_universe()))
.collect();
.chain(
self.create_next_universes(canonical.max_universe.as_u32())
).collect();

let canonical_inference_vars =
self.instantiate_canonical_vars(span, canonical.variables, |ui| universes[ui]);
Expand Down
11 changes: 11 additions & 0 deletions src/librustc/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
self.universe.set(u);
u
}

/// Creates `amount` new universes at once and returns all the created universes
/// in ascending order.
pub fn create_next_universes(&self, amount: u32) -> impl Iterator<Item = ty::UniverseIndex> {
let start = self.universe.get();
let end = start.advance_by(amount);
self.universe.set(end);

// Empty range if `amount == 0`
(start.next_universe() ..= end).into_iter()
}
}

impl<'a, 'gcx, 'tcx> TypeTrace<'tcx> {
Expand Down
5 changes: 5 additions & 0 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,11 @@ impl UniverseIndex {
UniverseIndex::from_u32(self.private.checked_add(1).unwrap())
}

/// Increases the universe index by `amount`.
pub fn advance_by(self, amount: u32) -> UniverseIndex {
UniverseIndex::from_u32(self.private.checked_add(amount).unwrap())
}

/// Returns `true` if `self` can name a name from `other` -- in other words,
/// if the set of names in `self` is a superset of those in
/// `other` (`self >= other`).
Expand Down