Skip to content

Commit c6935e5

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

21 files changed

+55
-133
lines changed

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/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-15
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

+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()
@@ -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

-2
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

+1-2
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(),

src/librustc/traits/specialize/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ fn fulfill_implication<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
221221
target_impl: DefId)
222222
-> Result<&'tcx Substs<'tcx>, ()> {
223223
let selcx = &mut SelectionContext::new(&infcx);
224-
let target_substs = infcx.fresh_substs_for_item(param_env.universe, DUMMY_SP, target_impl);
224+
let target_substs = infcx.fresh_substs_for_item(DUMMY_SP, target_impl);
225225
let (target_trait_ref, mut obligations) = impl_trait_ref_and_oblig(selcx,
226226
param_env,
227227
target_impl,

src/librustc_typeck/check/_match.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
329329
let element_tys_iter = (0..max_len).map(|_| self.next_ty_var(
330330
// FIXME: MiscVariable for now, obtaining the span and name information
331331
// from all tuple elements isn't trivial.
332-
ty::UniverseIndex::ROOT,
333332
TypeVariableOrigin::TypeInference(pat.span)));
334333
let element_tys = tcx.mk_type_list(element_tys_iter);
335334
let pat_ty = tcx.mk_ty(ty::TyTuple(element_tys));
@@ -340,8 +339,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
340339
pat_ty
341340
}
342341
PatKind::Box(ref inner) => {
343-
let inner_ty = self.next_ty_var(ty::UniverseIndex::ROOT,
344-
TypeVariableOrigin::TypeInference(inner.span));
342+
let inner_ty = self.next_ty_var(TypeVariableOrigin::TypeInference(inner.span));
345343
let uniq_ty = tcx.mk_box(inner_ty);
346344

347345
if self.check_dereferencable(pat.span, expected, &inner) {
@@ -374,7 +372,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
374372
}
375373
_ => {
376374
let inner_ty = self.next_ty_var(
377-
ty::UniverseIndex::ROOT,
378375
TypeVariableOrigin::TypeInference(inner.span));
379376
let mt = ty::TypeAndMut { ty: inner_ty, mutbl: mutbl };
380377
let region = self.next_region_var(infer::PatternRegion(pat.span));
@@ -633,8 +630,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
633630
// ...but otherwise we want to use any supertype of the
634631
// discriminant. This is sort of a workaround, see note (*) in
635632
// `check_pat` for some details.
636-
discrim_ty = self.next_ty_var(ty::UniverseIndex::ROOT,
637-
TypeVariableOrigin::TypeInference(discrim.span));
633+
discrim_ty = self.next_ty_var(TypeVariableOrigin::TypeInference(discrim.span));
638634
self.check_expr_has_type_or_error(discrim, discrim_ty);
639635
};
640636

@@ -695,8 +691,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
695691
// arm for inconsistent arms or to the whole match when a `()` type
696692
// is required).
697693
Expectation::ExpectHasType(ety) if ety != self.tcx.mk_nil() => ety,
698-
_ => self.next_ty_var(ty::UniverseIndex::ROOT,
699-
TypeVariableOrigin::MiscVariable(expr.span)),
694+
_ => self.next_ty_var(TypeVariableOrigin::MiscVariable(expr.span)),
700695
};
701696
CoerceMany::with_coercion_sites(coerce_first, arms)
702697
};

src/librustc_typeck/check/closure.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
110110
|_, _| span_bug!(expr.span, "closure has region param"),
111111
|_, _| {
112112
self.infcx
113-
.next_ty_var(ty::UniverseIndex::ROOT,
114-
TypeVariableOrigin::ClosureSynthetic(expr.span))
113+
.next_ty_var(TypeVariableOrigin::ClosureSynthetic(expr.span))
115114
},
116115
);
117116
let substs = ty::ClosureSubsts { substs };

src/librustc_typeck/check/coercion.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> {
176176
// micro-optimization: no need for this if `b` is
177177
// already resolved in some way.
178178
let diverging_ty = self.next_diverging_ty_var(
179-
ty::UniverseIndex::ROOT,
180179
TypeVariableOrigin::AdjustmentType(self.cause.span));
181180
self.unify_and(&b, &diverging_ty, simple(Adjust::NeverToAny))
182181
} else {
@@ -510,7 +509,7 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> {
510509
// We only have the latter, so we use an inference variable
511510
// for the former and let type inference do the rest.
512511
let origin = TypeVariableOrigin::MiscVariable(self.cause.span);
513-
let coerce_target = self.next_ty_var(ty::UniverseIndex::ROOT, origin);
512+
let coerce_target = self.next_ty_var(origin);
514513
let mut coercion = self.unify_and(coerce_target, target, |target| {
515514
let unsize = Adjustment {
516515
kind: Adjust::Unsize,

src/librustc_typeck/check/dropck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ fn ensure_drop_params_and_item_params_correspond<'a, 'tcx>(
9090

9191
let drop_impl_span = tcx.def_span(drop_impl_did);
9292
let fresh_impl_substs =
93-
infcx.fresh_substs_for_item(ty::UniverseIndex::ROOT, drop_impl_span, drop_impl_did);
93+
infcx.fresh_substs_for_item(drop_impl_span, drop_impl_did);
9494
let fresh_impl_self_ty = drop_impl_ty.subst(tcx, fresh_impl_substs);
9595

9696
let cause = &ObligationCause::misc(drop_impl_span, drop_impl_node_id);

src/librustc_typeck/check/method/confirm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
259259
// the process we will unify the transformed-self-type
260260
// of the method with the actual type in order to
261261
// unify some of these variables.
262-
self.fresh_substs_for_item(ty::UniverseIndex::ROOT, self.span, trait_def_id)
262+
self.fresh_substs_for_item(self.span, trait_def_id)
263263
}
264264

265265
probe::WhereClausePick(ref poly_trait_ref) => {
@@ -336,7 +336,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
336336
{
337337
self.to_ty(ast_ty)
338338
} else {
339-
self.type_var_for_def(ty::UniverseIndex::ROOT, self.span, def)
339+
self.type_var_for_def(self.span, def)
340340
}
341341
})
342342
}

src/librustc_typeck/check/method/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
257257
} else if let Some(ref input_types) = opt_input_types {
258258
input_types[def.index as usize - 1]
259259
} else {
260-
self.type_var_for_def(ty::UniverseIndex::ROOT, span, def)
260+
self.type_var_for_def(span, def)
261261
}
262262
});
263263

0 commit comments

Comments
 (0)