Skip to content

Commit dca1470

Browse files
committed
Auto merge of #49313 - sgrif:sg-revert-stuff, r=nikomatsakis
Remove universes from `ty::ParamEnv` This change was never meant to land. #48407 takes an alternate approach. However, that PR is now blocked on some issues with canonicalization, and rebasing these reverts gets harder each time, so let's just get this bit out of the way now. r? @nikomatsakis
2 parents 3615093 + dd60bea commit dca1470

32 files changed

+97
-244
lines changed

src/librustc/ich/impls_ty.rs

-10
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,6 @@ for ty::steal::Steal<T>
11111111

11121112
impl_stable_hash_for!(struct ty::ParamEnv<'tcx> {
11131113
caller_bounds,
1114-
universe,
11151114
reveal
11161115
});
11171116

@@ -1282,15 +1281,6 @@ for traits::VtableGeneratorData<'gcx, N> where N: HashStable<StableHashingContex
12821281
}
12831282
}
12841283

1285-
impl<'a> HashStable<StableHashingContext<'a>>
1286-
for ty::UniverseIndex {
1287-
fn hash_stable<W: StableHasherResult>(&self,
1288-
hcx: &mut StableHashingContext<'a>,
1289-
hasher: &mut StableHasher<W>) {
1290-
self.depth().hash_stable(hcx, hasher);
1291-
}
1292-
}
1293-
12941284
impl_stable_hash_for!(
12951285
impl<'tcx, V> for struct infer::canonical::Canonical<'tcx, V> {
12961286
variables, value

src/librustc/infer/anon_types/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -726,10 +726,7 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
726726
return anon_defn.concrete_ty;
727727
}
728728
let span = tcx.def_span(def_id);
729-
let ty_var = infcx.next_ty_var(
730-
ty::UniverseIndex::ROOT,
731-
TypeVariableOrigin::TypeInference(span),
732-
);
729+
let ty_var = infcx.next_ty_var(TypeVariableOrigin::TypeInference(span));
733730

734731
let predicates_of = tcx.predicates_of(def_id);
735732
let bounds = predicates_of.instantiate(tcx, substs);

src/librustc/infer/canonical.rs

-2
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,6 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
254254
let ty = match ty_kind {
255255
CanonicalTyVarKind::General => {
256256
self.next_ty_var(
257-
// FIXME(#48696) this handling of universes is not right.
258-
ty::UniverseIndex::ROOT,
259257
TypeVariableOrigin::MiscVariable(span),
260258
)
261259
}

src/librustc/infer/combine.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ impl<'cx, 'gcx, 'tcx> TypeRelation<'cx, 'gcx, 'tcx> for Generalizer<'cx, 'gcx, '
407407
drop(variables);
408408
self.relate(&u, &u)
409409
}
410-
TypeVariableValue::Unknown { universe } => {
410+
TypeVariableValue::Unknown { .. } => {
411411
match self.ambient_variance {
412412
// Invariant: no need to make a fresh type variable.
413413
ty::Invariant => return Ok(t),
@@ -424,7 +424,7 @@ impl<'cx, 'gcx, 'tcx> TypeRelation<'cx, 'gcx, 'tcx> for Generalizer<'cx, 'gcx, '
424424
}
425425

426426
let origin = *variables.var_origin(vid);
427-
let new_var_id = variables.new_var(universe, false, origin);
427+
let new_var_id = variables.new_var(false, origin);
428428
let u = self.tcx().mk_var(new_var_id);
429429
debug!("generalize: replacing original vid={:?} with new={:?}",
430430
vid, u);

src/librustc/infer/fudge.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for RegionFudger<'a, 'gcx, 'tcx> {
141141
// This variable was created during the
142142
// fudging. Recreate it with a fresh variable
143143
// here.
144-
//
145-
// The ROOT universe is fine because we only
146-
// ever invoke this routine at the
147-
// "item-level" of inference.
148-
self.infcx.next_ty_var(ty::UniverseIndex::ROOT, origin)
144+
self.infcx.next_ty_var(origin)
149145
}
150146
}
151147
}

src/librustc/infer/lattice.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,13 @@ pub fn super_lattice_tys<'a, 'gcx, 'tcx, L>(this: &mut L,
8888
// is (e.g.) `Box<i32>`. A more obvious solution might be to
8989
// iterate on the subtype obligations that are returned, but I
9090
// think this suffices. -nmatsakis
91-
(&ty::TyInfer(TyVar(a_vid)), _) => {
92-
let universe = infcx.type_variables.borrow_mut().probe(a_vid).universe().unwrap();
93-
let v = infcx.next_ty_var(universe,
94-
TypeVariableOrigin::LatticeVariable(this.cause().span));
91+
(&ty::TyInfer(TyVar(..)), _) => {
92+
let v = infcx.next_ty_var(TypeVariableOrigin::LatticeVariable(this.cause().span));
9593
this.relate_bound(v, b, a)?;
9694
Ok(v)
9795
}
98-
(_, &ty::TyInfer(TyVar(b_vid))) => {
99-
let universe = infcx.type_variables.borrow_mut().probe(b_vid).universe().unwrap();
100-
let v = infcx.next_ty_var(universe,
101-
TypeVariableOrigin::LatticeVariable(this.cause().span));
96+
(_, &ty::TyInfer(TyVar(..))) => {
97+
let v = infcx.next_ty_var(TypeVariableOrigin::LatticeVariable(this.cause().span));
10298
this.relate_bound(v, a, b)?;
10399
Ok(v)
104100
}

src/librustc/infer/mod.rs

+8-18
Original file line numberDiff line numberDiff line change
@@ -837,25 +837,18 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
837837
})
838838
}
839839

840-
pub fn next_ty_var_id(&self,
841-
universe: ty::UniverseIndex,
842-
diverging: bool,
843-
origin: TypeVariableOrigin)
844-
-> TyVid {
840+
pub fn next_ty_var_id(&self, diverging: bool, origin: TypeVariableOrigin) -> TyVid {
845841
self.type_variables
846842
.borrow_mut()
847-
.new_var(universe, diverging, origin)
843+
.new_var(diverging, origin)
848844
}
849845

850-
pub fn next_ty_var(&self, universe: ty::UniverseIndex, origin: TypeVariableOrigin) -> Ty<'tcx> {
851-
self.tcx.mk_var(self.next_ty_var_id(universe, false, origin))
846+
pub fn next_ty_var(&self, origin: TypeVariableOrigin) -> Ty<'tcx> {
847+
self.tcx.mk_var(self.next_ty_var_id(false, origin))
852848
}
853849

854-
pub fn next_diverging_ty_var(&self,
855-
universe: ty::UniverseIndex,
856-
origin: TypeVariableOrigin)
857-
-> Ty<'tcx> {
858-
self.tcx.mk_var(self.next_ty_var_id(universe, true, origin))
850+
pub fn next_diverging_ty_var(&self, origin: TypeVariableOrigin) -> Ty<'tcx> {
851+
self.tcx.mk_var(self.next_ty_var_id(true, origin))
859852
}
860853

861854
pub fn next_int_var_id(&self) -> IntVid {
@@ -910,14 +903,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
910903
/// use an inference variable for `C` with `[T, U]`
911904
/// as the substitutions for the default, `(T, U)`.
912905
pub fn type_var_for_def(&self,
913-
universe: ty::UniverseIndex,
914906
span: Span,
915907
def: &ty::TypeParameterDef)
916908
-> Ty<'tcx> {
917909
let ty_var_id = self.type_variables
918910
.borrow_mut()
919-
.new_var(universe,
920-
false,
911+
.new_var(false,
921912
TypeVariableOrigin::TypeParameterDefinition(span, def.name));
922913

923914
self.tcx.mk_var(ty_var_id)
@@ -926,14 +917,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
926917
/// Given a set of generics defined on a type or impl, returns a substitution mapping each
927918
/// type/region parameter to a fresh inference variable.
928919
pub fn fresh_substs_for_item(&self,
929-
universe: ty::UniverseIndex,
930920
span: Span,
931921
def_id: DefId)
932922
-> &'tcx Substs<'tcx> {
933923
Substs::for_item(self.tcx, def_id, |def, _| {
934924
self.region_var_for_def(span, def)
935925
}, |def, _| {
936-
self.type_var_for_def(universe, span, def)
926+
self.type_var_for_def(span, def)
937927
})
938928
}
939929

src/librustc/infer/region_constraints/mod.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub struct RegionConstraintCollector<'tcx> {
4848
glbs: CombineMap<'tcx>,
4949

5050
/// Number of skolemized variables currently active.
51-
skolemization_count: ty::UniverseIndex,
51+
skolemization_count: u32,
5252

5353
/// Global counter used during the GLB algorithm to create unique
5454
/// names for fresh bound regions
@@ -233,7 +233,7 @@ type CombineMap<'tcx> = FxHashMap<TwoRegions<'tcx>, RegionVid>;
233233
pub struct RegionSnapshot {
234234
length: usize,
235235
region_snapshot: ut::Snapshot<ut::InPlace<ty::RegionVid>>,
236-
skolemization_count: ty::UniverseIndex,
236+
skolemization_count: u32,
237237
}
238238

239239
/// When working with skolemized regions, we often wish to find all of
@@ -277,7 +277,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
277277
data: RegionConstraintData::default(),
278278
lubs: FxHashMap(),
279279
glbs: FxHashMap(),
280-
skolemization_count: ty::UniverseIndex::ROOT,
280+
skolemization_count: 0,
281281
bound_count: 0,
282282
undo_log: Vec::new(),
283283
unification_table: ut::UnificationTable::new(),
@@ -329,7 +329,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
329329
unification_table,
330330
} = self;
331331

332-
assert_eq!(skolemization_count.as_usize(), 0);
332+
assert_eq!(*skolemization_count, 0);
333333

334334
// Clear the tables of (lubs, glbs), so that we will create
335335
// fresh regions if we do a LUB operation. As it happens,
@@ -375,7 +375,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
375375
assert!(self.undo_log[snapshot.length] == OpenSnapshot);
376376
assert!(
377377
self.skolemization_count == snapshot.skolemization_count,
378-
"failed to pop skolemized regions: {:?} now vs {:?} at start",
378+
"failed to pop skolemized regions: {} now vs {} at start",
379379
self.skolemization_count,
380380
snapshot.skolemization_count
381381
);
@@ -485,9 +485,9 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
485485
assert!(self.in_snapshot());
486486
assert!(self.undo_log[snapshot.length] == OpenSnapshot);
487487

488-
let universe = self.skolemization_count.subuniverse();
489-
self.skolemization_count = universe;
490-
tcx.mk_region(ReSkolemized(universe, br))
488+
let sc = self.skolemization_count;
489+
self.skolemization_count = sc + 1;
490+
tcx.mk_region(ReSkolemized(ty::SkolemizedRegionVid { index: sc }, br))
491491
}
492492

493493
/// Removes all the edges to/from the skolemized regions that are
@@ -505,34 +505,34 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
505505
assert!(self.in_snapshot());
506506
assert!(self.undo_log[snapshot.length] == OpenSnapshot);
507507
assert!(
508-
self.skolemization_count.as_usize() >= skols.len(),
508+
self.skolemization_count as usize >= skols.len(),
509509
"popping more skolemized variables than actually exist, \
510510
sc now = {}, skols.len = {}",
511-
self.skolemization_count.as_usize(),
511+
self.skolemization_count,
512512
skols.len()
513513
);
514514

515-
let last_to_pop = self.skolemization_count.subuniverse();
516-
let first_to_pop = ty::UniverseIndex::from(last_to_pop.as_u32() - (skols.len() as u32));
515+
let last_to_pop = self.skolemization_count;
516+
let first_to_pop = last_to_pop - (skols.len() as u32);
517517

518518
assert!(
519519
first_to_pop >= snapshot.skolemization_count,
520520
"popping more regions than snapshot contains, \
521-
sc now = {:?}, sc then = {:?}, skols.len = {}",
521+
sc now = {}, sc then = {}, skols.len = {}",
522522
self.skolemization_count,
523523
snapshot.skolemization_count,
524524
skols.len()
525525
);
526526
debug_assert! {
527527
skols.iter()
528528
.all(|&k| match *k {
529-
ty::ReSkolemized(universe, _) =>
530-
universe >= first_to_pop &&
531-
universe < last_to_pop,
529+
ty::ReSkolemized(index, _) =>
530+
index.index >= first_to_pop &&
531+
index.index < last_to_pop,
532532
_ =>
533533
false
534534
}),
535-
"invalid skolemization keys or keys out of range ({:?}..{:?}): {:?}",
535+
"invalid skolemization keys or keys out of range ({}..{}): {:?}",
536536
snapshot.skolemization_count,
537537
self.skolemization_count,
538538
skols
@@ -867,7 +867,7 @@ impl fmt::Debug for RegionSnapshot {
867867
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
868868
write!(
869869
f,
870-
"RegionSnapshot(length={},skolemization={:?})",
870+
"RegionSnapshot(length={},skolemization={})",
871871
self.length,
872872
self.skolemization_count
873873
)

src/librustc/infer/type_variable.rs

+4-25
Original file line numberDiff line numberDiff line change
@@ -78,33 +78,17 @@ struct TypeVariableData {
7878
#[derive(Copy, Clone, Debug)]
7979
pub enum TypeVariableValue<'tcx> {
8080
Known { value: Ty<'tcx> },
81-
Unknown { universe: ty::UniverseIndex },
82-
}
83-
84-
#[derive(Copy, Clone, Debug)]
85-
pub enum ProbeTyValue<'tcx> {
86-
Ty(Ty<'tcx>),
87-
Vid(ty::TyVid),
81+
Unknown,
8882
}
8983

9084
impl<'tcx> TypeVariableValue<'tcx> {
91-
/// If this value is known, returns the type it is known to be.
92-
/// Otherwise, `None`.
9385
pub fn known(&self) -> Option<Ty<'tcx>> {
9486
match *self {
9587
TypeVariableValue::Unknown { .. } => None,
9688
TypeVariableValue::Known { value } => Some(value),
9789
}
9890
}
9991

100-
/// If this value is unknown, returns the universe, otherwise `None`.
101-
pub fn universe(&self) -> Option<ty::UniverseIndex> {
102-
match *self {
103-
TypeVariableValue::Unknown { universe } => Some(universe),
104-
TypeVariableValue::Known { .. } => None,
105-
}
106-
}
107-
10892
pub fn is_unknown(&self) -> bool {
10993
match *self {
11094
TypeVariableValue::Unknown { .. } => true,
@@ -197,11 +181,10 @@ impl<'tcx> TypeVariableTable<'tcx> {
197181
/// The code in this module doesn't care, but it can be useful
198182
/// for improving error messages.
199183
pub fn new_var(&mut self,
200-
universe: ty::UniverseIndex,
201184
diverging: bool,
202185
origin: TypeVariableOrigin)
203186
-> ty::TyVid {
204-
let eq_key = self.eq_relations.new_key(TypeVariableValue::Unknown { universe });
187+
let eq_key = self.eq_relations.new_key(TypeVariableValue::Unknown);
205188

206189
let sub_key = self.sub_relations.new_key(());
207190
assert_eq!(eq_key.vid, sub_key);
@@ -453,12 +436,8 @@ impl<'tcx> ut::UnifyValue for TypeVariableValue<'tcx> {
453436
(&TypeVariableValue::Known { .. }, &TypeVariableValue::Unknown { .. }) => Ok(*value1),
454437
(&TypeVariableValue::Unknown { .. }, &TypeVariableValue::Known { .. }) => Ok(*value2),
455438

456-
// If both sides are unknown, we need to pick the most restrictive universe.
457-
(&TypeVariableValue::Unknown { universe: universe1 },
458-
&TypeVariableValue::Unknown { universe: universe2 }) => {
459-
let universe = cmp::min(universe1, universe2);
460-
Ok(TypeVariableValue::Unknown { universe })
461-
}
439+
// If both sides are *unknown*, it hardly matters, does it?
440+
(&TypeVariableValue::Unknown, &TypeVariableValue::Unknown) => Ok(*value1),
462441
}
463442
}
464443
}

src/librustc/traits/coherence.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ fn with_fresh_ty_vars<'cx, 'gcx, 'tcx>(selcx: &mut SelectionContext<'cx, 'gcx, '
9292
-> ty::ImplHeader<'tcx>
9393
{
9494
let tcx = selcx.tcx();
95-
let impl_substs = selcx.infcx().fresh_substs_for_item(param_env.universe,
96-
DUMMY_SP,
97-
impl_def_id);
95+
let impl_substs = selcx.infcx().fresh_substs_for_item(DUMMY_SP, impl_def_id);
9896

9997
let header = ty::ImplHeader {
10098
impl_def_id,

src/librustc/traits/error_reporting.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
292292

293293
self.tcx.for_each_relevant_impl(
294294
trait_ref.def_id, trait_self_ty, |def_id| {
295-
let impl_substs = self.fresh_substs_for_item(param_env.universe,
296-
obligation.cause.span,
297-
def_id);
295+
let impl_substs = self.fresh_substs_for_item(obligation.cause.span, def_id);
298296
let impl_trait_ref = tcx
299297
.impl_trait_ref(def_id)
300298
.unwrap()
@@ -1285,7 +1283,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
12851283
-> bool {
12861284
struct ParamToVarFolder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
12871285
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
1288-
param_env: ty::ParamEnv<'tcx>,
12891286
var_map: FxHashMap<Ty<'tcx>, Ty<'tcx>>
12901287
}
12911288

@@ -1295,14 +1292,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
12951292
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
12961293
if let ty::TyParam(ty::ParamTy {name, ..}) = ty.sty {
12971294
let infcx = self.infcx;
1298-
let param_env = self.param_env;
1299-
self.var_map
1300-
.entry(ty)
1301-
.or_insert_with(|| {
1302-
let origin = TypeVariableOrigin::TypeParameterDefinition(DUMMY_SP,
1303-
name);
1304-
infcx.next_ty_var(param_env.universe, origin)
1305-
})
1295+
self.var_map.entry(ty).or_insert_with(||
1296+
infcx.next_ty_var(
1297+
TypeVariableOrigin::TypeParameterDefinition(DUMMY_SP, name)))
13061298
} else {
13071299
ty.super_fold_with(self)
13081300
}
@@ -1314,7 +1306,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
13141306

13151307
let cleaned_pred = pred.fold_with(&mut ParamToVarFolder {
13161308
infcx: self,
1317-
param_env,
13181309
var_map: FxHashMap()
13191310
});
13201311

0 commit comments

Comments
 (0)