Skip to content

Commit 4c2fc33

Browse files
committed
create just one subuniverse per binder -- no need for more, really
1 parent f8dd084 commit 4c2fc33

File tree

2 files changed

+37
-69
lines changed
  • src/librustc/infer

2 files changed

+37
-69
lines changed

src/librustc/infer/higher_ranked/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,9 +591,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
591591
-> (T, PlaceholderMap<'tcx>)
592592
where T : TypeFoldable<'tcx>
593593
{
594+
let new_universe = self.create_subuniverse();
595+
594596
let (result, map) = self.tcx.replace_late_bound_regions(binder, |br| {
595-
self.universe.set(self.universe().subuniverse());
596-
self.tcx.mk_region(ty::RePlaceholder(self.universe(), br))
597+
self.tcx.mk_region(ty::RePlaceholder(new_universe, br))
597598
});
598599

599600
debug!("skolemize_bound_regions(binder={:?}, result={:?}, map={:?})",
@@ -795,7 +796,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
795796
let skol_regions: FxHashSet<_> = placeholder_map.values().cloned().collect();
796797
self.borrow_region_constraints()
797798
.pop_placeholders(
798-
self.universe(),
799799
&skol_regions,
800800
&snapshot.region_constraints_snapshot,
801801
);

src/librustc/infer/region_constraints/mod.rs

Lines changed: 34 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010

1111
//! See README.md
1212
13-
use self::UndoLogEntry::*;
1413
use self::CombineMapType::*;
14+
use self::UndoLogEntry::*;
1515

16-
use super::{MiscVariable, RegionVariableOrigin, SubregionOrigin};
1716
use super::unify_key;
17+
use super::{MiscVariable, RegionVariableOrigin, SubregionOrigin};
1818

19-
use rustc_data_structures::indexed_vec::IndexVec;
2019
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
20+
use rustc_data_structures::indexed_vec::IndexVec;
2121
use rustc_data_structures::unify as ut;
22-
use ty::{self, Ty, TyCtxt};
23-
use ty::{Region, RegionVid};
2422
use ty::ReStatic;
23+
use ty::{self, Ty, TyCtxt};
2524
use ty::{BrFresh, ReLateBound, ReVar};
25+
use ty::{Region, RegionVid};
2626

2727
use std::collections::BTreeMap;
2828
use std::{cmp, fmt, mem, u32};
@@ -495,13 +495,12 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
495495
}
496496
}
497497

498-
pub fn new_region_var(&mut self,
499-
universe: ty::UniverseIndex,
500-
origin: RegionVariableOrigin) -> RegionVid {
501-
let vid = self.var_infos.push(RegionVariableInfo {
502-
origin,
503-
universe,
504-
});
498+
pub fn new_region_var(
499+
&mut self,
500+
universe: ty::UniverseIndex,
501+
origin: RegionVariableOrigin,
502+
) -> RegionVid {
503+
let vid = self.var_infos.push(RegionVariableInfo { origin, universe });
505504

506505
let u_vid = self.unification_table
507506
.new_key(unify_key::RegionVidKey { min_vid: vid });
@@ -511,8 +510,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
511510
}
512511
debug!(
513512
"created new region variable {:?} with origin {:?}",
514-
vid,
515-
origin
513+
vid, origin
516514
);
517515
return vid;
518516
}
@@ -533,45 +531,19 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
533531
/// created in that time.
534532
pub fn pop_placeholders(
535533
&mut self,
536-
skolemization_count: ty::UniverseIndex,
537-
skols: &FxHashSet<ty::Region<'tcx>>,
534+
placeholders: &FxHashSet<ty::Region<'tcx>>,
538535
snapshot: &RegionSnapshot,
539536
) {
540-
debug!("pop_placeholders(skols={:?})", skols);
537+
debug!("pop_placeholders(placeholders={:?})", placeholders);
541538

542539
assert!(self.in_snapshot());
543540
assert!(self.undo_log[snapshot.length] == OpenSnapshot);
544-
assert!(
545-
skolemization_count.as_usize() >= skols.len(),
546-
"popping more placeholder variables than actually exist, \
547-
sc now = {:?}, skols.len = {:?}",
548-
skolemization_count,
549-
skols.len()
550-
);
551-
552-
let last_to_pop = skolemization_count.subuniverse();
553-
let first_to_pop = ty::UniverseIndex::from(last_to_pop.as_u32() - skols.len() as u32);
554-
555-
debug_assert! {
556-
skols.iter()
557-
.all(|&k| match *k {
558-
ty::RePlaceholder(universe, _) =>
559-
universe >= first_to_pop &&
560-
universe < last_to_pop,
561-
_ =>
562-
false
563-
}),
564-
"invalid skolemization keys or keys out of range ({:?}..{:?}): {:?}",
565-
first_to_pop,
566-
last_to_pop,
567-
skols
568-
}
569541

570542
let constraints_to_kill: Vec<usize> = self.undo_log
571543
.iter()
572544
.enumerate()
573545
.rev()
574-
.filter(|&(_, undo_entry)| kill_constraint(skols, undo_entry))
546+
.filter(|&(_, undo_entry)| kill_constraint(placeholders, undo_entry))
575547
.map(|(index, _)| index)
576548
.collect();
577549

@@ -583,20 +555,20 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
583555
return;
584556

585557
fn kill_constraint<'tcx>(
586-
skols: &FxHashSet<ty::Region<'tcx>>,
558+
placeholders: &FxHashSet<ty::Region<'tcx>>,
587559
undo_entry: &UndoLogEntry<'tcx>,
588560
) -> bool {
589561
match undo_entry {
590562
&AddConstraint(Constraint::VarSubVar(..)) => false,
591-
&AddConstraint(Constraint::RegSubVar(a, _)) => skols.contains(&a),
592-
&AddConstraint(Constraint::VarSubReg(_, b)) => skols.contains(&b),
563+
&AddConstraint(Constraint::RegSubVar(a, _)) => placeholders.contains(&a),
564+
&AddConstraint(Constraint::VarSubReg(_, b)) => placeholders.contains(&b),
593565
&AddConstraint(Constraint::RegSubReg(a, b)) => {
594-
skols.contains(&a) || skols.contains(&b)
566+
placeholders.contains(&a) || placeholders.contains(&b)
595567
}
596568
&AddGiven(..) => false,
597569
&AddVerify(_) => false,
598570
&AddCombination(_, ref two_regions) => {
599-
skols.contains(&two_regions.a) || skols.contains(&two_regions.b)
571+
placeholders.contains(&two_regions.a) || placeholders.contains(&two_regions.b)
600572
}
601573
&AddVar(..) | &OpenSnapshot | &Purged | &CommitedSnapshot => false,
602574
}
@@ -713,9 +685,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
713685
// cannot add constraints once regions are resolved
714686
debug!(
715687
"RegionConstraintCollector: make_subregion({:?}, {:?}) due to {:?}",
716-
sub,
717-
sup,
718-
origin
688+
sub, sup, origin
719689
);
720690

721691
match (sub, sup) {
@@ -854,19 +824,19 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
854824

855825
fn universe(&self, region: Region<'tcx>) -> ty::UniverseIndex {
856826
match *region {
857-
ty::ReScope(..) |
858-
ty::ReStatic |
859-
ty::ReEmpty |
860-
ty::ReErased |
861-
ty::ReFree(..) |
862-
ty::ReEarlyBound(..) => ty::UniverseIndex::ROOT,
827+
ty::ReScope(..)
828+
| ty::ReStatic
829+
| ty::ReEmpty
830+
| ty::ReErased
831+
| ty::ReFree(..)
832+
| ty::ReEarlyBound(..) => ty::UniverseIndex::ROOT,
863833
ty::RePlaceholder(universe, _) => universe,
864-
ty::ReClosureBound(vid) |
865-
ty::ReVar(vid) => self.var_universe(vid),
866-
ty::ReLateBound(..) =>
867-
bug!("universe(): encountered bound region {:?}", region),
868-
ty::ReCanonical(..) =>
869-
bug!("region_universe(): encountered canonical region {:?}", region),
834+
ty::ReClosureBound(vid) | ty::ReVar(vid) => self.var_universe(vid),
835+
ty::ReLateBound(..) => bug!("universe(): encountered bound region {:?}", region),
836+
ty::ReCanonical(..) => bug!(
837+
"region_universe(): encountered canonical region {:?}",
838+
region
839+
),
870840
}
871841
}
872842

@@ -897,9 +867,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
897867
) -> FxHashSet<ty::Region<'tcx>> {
898868
debug!(
899869
"tainted(mark={:?}, r0={:?}, directions={:?})",
900-
mark,
901-
r0,
902-
directions
870+
mark, r0, directions
903871
);
904872

905873
// `result_set` acts as a worklist: we explore all outgoing

0 commit comments

Comments
 (0)