Skip to content

Commit bb9bcfd

Browse files
committed
Auto merge of #56234 - scalexm:universe-perf, r=<try>
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!
2 parents b51632e + 685e15d commit bb9bcfd

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

src/librustc/infer/canonical/mod.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -315,14 +315,11 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
315315
T: TypeFoldable<'tcx>,
316316
{
317317
// For each universe that is referred to in the incoming
318-
// query, create a universe in our local inference context. In
319-
// practice, as of this writing, all queries have no universes
320-
// in them, so this code has no effect, but it is looking
321-
// forward to the day when we *do* want to carry universes
322-
// through into queries.
318+
// query, create a universe in our local inference context.
323319
let universes: IndexVec<ty::UniverseIndex, _> = std::iter::once(ty::UniverseIndex::ROOT)
324-
.chain((0..canonical.max_universe.as_u32()).map(|_| self.create_next_universe()))
325-
.collect();
320+
.chain(
321+
self.create_next_universes(canonical.max_universe.as_u32())
322+
).collect();
326323

327324
let canonical_inference_vars =
328325
self.instantiate_canonical_vars(span, canonical.variables, |ui| universes[ui]);

src/librustc/infer/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
15191519
self.universe.set(u);
15201520
u
15211521
}
1522+
1523+
/// Creates `amount` new universes at once and returns all the created universes
1524+
/// in ascending order.
1525+
pub fn create_next_universes(&self, amount: u32) -> impl Iterator<Item = ty::UniverseIndex> {
1526+
let start = self.universe.get();
1527+
let end = start.advance_by(amount);
1528+
self.universe.set(end);
1529+
1530+
// Empty range if `amount == 0`
1531+
(start.next_universe() ..= end).into_iter()
1532+
}
15221533
}
15231534

15241535
impl<'a, 'gcx, 'tcx> TypeTrace<'tcx> {

src/librustc/ty/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,11 @@ impl UniverseIndex {
15681568
UniverseIndex::from_u32(self.private.checked_add(1).unwrap())
15691569
}
15701570

1571+
/// Increases the universe index by `amount`.
1572+
pub fn advance_by(self, amount: u32) -> UniverseIndex {
1573+
UniverseIndex::from_u32(self.private.checked_add(amount).unwrap())
1574+
}
1575+
15711576
/// Returns `true` if `self` can name a name from `other` -- in other words,
15721577
/// if the set of names in `self` is a superset of those in
15731578
/// `other` (`self >= other`).

0 commit comments

Comments
 (0)