Skip to content

Commit

Permalink
Auto merge of #56234 - scalexm:universe-perf, r=<try>
Browse files Browse the repository at this point in the history
Create multiple universes at once

Related to [this](#55921 (comment)) comment
cc @rust-lang/infra , could I have a try + perf run on that PR? Thanks!
  • Loading branch information
bors committed Nov 26, 2018
2 parents b51632e + 685e15d commit bb9bcfd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
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

0 comments on commit bb9bcfd

Please sign in to comment.