Skip to content

Commit c6935e5

Browse files
committed
Revert "add universes to type inference variables"
This reverts commit 13efaf0.
1 parent 1171ebf commit c6935e5

File tree

21 files changed

+55
-133
lines changed

21 files changed

+55
-133
lines changed

src/librustc/infer/anon_types/mod.rs

Lines changed: 1 addition & 4 deletions
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/combine.rs

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 5 deletions
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

Lines changed: 4 additions & 8 deletions
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

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -837,22 +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, universe: ty::UniverseIndex, origin: TypeVariableOrigin) -> Ty<'tcx> {
855-
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))
856852
}
857853

858854
pub fn next_int_var_id(&self) -> IntVid {
@@ -907,14 +903,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
907903
/// use an inference variable for `C` with `[T, U]`
908904
/// as the substitutions for the default, `(T, U)`.
909905
pub fn type_var_for_def(&self,
910-
universe: ty::UniverseIndex,
911906
span: Span,
912907
def: &ty::TypeParameterDef)
913908
-> Ty<'tcx> {
914909
let ty_var_id = self.type_variables
915910
.borrow_mut()
916-
.new_var(universe,
917-
false,
911+
.new_var(false,
918912
TypeVariableOrigin::TypeParameterDefinition(span, def.name));
919913

920914
self.tcx.mk_var(ty_var_id)
@@ -923,14 +917,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
923917
/// Given a set of generics defined on a type or impl, returns a substitution mapping each
924918
/// type/region parameter to a fresh inference variable.
925919
pub fn fresh_substs_for_item(&self,
926-
universe: ty::UniverseIndex,
927920
span: Span,
928921
def_id: DefId)
929922
-> &'tcx Substs<'tcx> {
930923
Substs::for_item(self.tcx, def_id, |def, _| {
931924
self.region_var_for_def(span, def)
932925
}, |def, _| {
933-
self.type_var_for_def(universe, span, def)
926+
self.type_var_for_def(span, def)
934927
})
935928
}
936929

src/librustc/infer/type_variable.rs

Lines changed: 4 additions & 25 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 4 additions & 13 deletions
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()
@@ -1272,7 +1270,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
12721270
-> bool {
12731271
struct ParamToVarFolder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
12741272
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
1275-
param_env: ty::ParamEnv<'tcx>,
12761273
var_map: FxHashMap<Ty<'tcx>, Ty<'tcx>>
12771274
}
12781275

@@ -1282,14 +1279,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
12821279
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
12831280
if let ty::TyParam(ty::ParamTy {name, ..}) = ty.sty {
12841281
let infcx = self.infcx;
1285-
let param_env = self.param_env;
1286-
self.var_map
1287-
.entry(ty)
1288-
.or_insert_with(|| {
1289-
let origin = TypeVariableOrigin::TypeParameterDefinition(DUMMY_SP,
1290-
name);
1291-
infcx.next_ty_var(param_env.universe, origin)
1292-
})
1282+
self.var_map.entry(ty).or_insert_with(||
1283+
infcx.next_ty_var(
1284+
TypeVariableOrigin::TypeParameterDefinition(DUMMY_SP, name)))
12931285
} else {
12941286
ty.super_fold_with(self)
12951287
}
@@ -1301,7 +1293,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
13011293

13021294
let cleaned_pred = pred.fold_with(&mut ParamToVarFolder {
13031295
infcx: self,
1304-
param_env,
13051296
var_map: FxHashMap()
13061297
});
13071298

src/librustc/traits/project.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,6 @@ pub fn normalize_projection_type<'a, 'b, 'gcx, 'tcx>(
477477
let tcx = selcx.infcx().tcx;
478478
let def_id = projection_ty.item_def_id;
479479
let ty_var = selcx.infcx().next_ty_var(
480-
param_env.universe,
481480
TypeVariableOrigin::NormalizeProjectionType(tcx.def_span(def_id)));
482481
let projection = ty::Binder(ty::ProjectionPredicate {
483482
projection_ty,
@@ -798,7 +797,6 @@ fn normalize_to_error<'a, 'gcx, 'tcx>(selcx: &mut SelectionContext<'a, 'gcx, 'tc
798797
let tcx = selcx.infcx().tcx;
799798
let def_id = projection_ty.item_def_id;
800799
let new_value = selcx.infcx().next_ty_var(
801-
param_env.universe,
802800
TypeVariableOrigin::NormalizeProjectionType(tcx.def_span(def_id)));
803801
Normalized {
804802
value: new_value,

src/librustc/traits/select.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3045,8 +3045,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
30453045
snapshot);
30463046
let skol_obligation_trait_ref = skol_obligation.trait_ref;
30473047

3048-
let impl_substs = self.infcx.fresh_substs_for_item(obligation.param_env.universe,
3049-
obligation.cause.span,
3048+
let impl_substs = self.infcx.fresh_substs_for_item(obligation.cause.span,
30503049
impl_def_id);
30513050

30523051
let impl_trait_ref = impl_trait_ref.subst(self.tcx(),

0 commit comments

Comments
 (0)