Skip to content

Commit ddfbf2b

Browse files
committed
Auto merge of #47861 - sgrif:sg-rebase-chalkify-universe-refactorings, r=nikomatsakis
Rebased refactorings for Chalk The code is Niko's, I just handled the rebase. r? @nikomatsakis
2 parents 3eeb5a6 + fec4d3b commit ddfbf2b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+660
-1315
lines changed

src/Cargo.lock

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/librustc/ich/impls_ty.rs

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

871871
impl_stable_hash_for!(struct ty::ParamEnv<'tcx> {
872872
caller_bounds,
873+
universe,
873874
reveal
874875
});
875876

@@ -1039,3 +1040,12 @@ for traits::VtableGeneratorData<'gcx, N> where N: HashStable<StableHashingContex
10391040
nested.hash_stable(hcx, hasher);
10401041
}
10411042
}
1043+
1044+
impl<'gcx> HashStable<StableHashingContext<'gcx>>
1045+
for ty::UniverseIndex {
1046+
fn hash_stable<W: StableHasherResult>(&self,
1047+
hcx: &mut StableHashingContext<'gcx>,
1048+
hasher: &mut StableHasher<W>) {
1049+
self.depth().hash_stable(hcx, hasher);
1050+
}
1051+
}

src/librustc/infer/anon_types/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,8 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
600600
return anon_defn.concrete_ty;
601601
}
602602
let span = tcx.def_span(def_id);
603-
let ty_var = infcx.next_ty_var(TypeVariableOrigin::TypeInference(span));
603+
let ty_var = infcx.next_ty_var(ty::UniverseIndex::ROOT,
604+
TypeVariableOrigin::TypeInference(span));
604605

605606
let predicates_of = tcx.predicates_of(def_id);
606607
let bounds = predicates_of.instantiate(tcx, substs);

src/librustc/infer/combine.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434

3535
use super::equate::Equate;
3636
use super::glb::Glb;
37+
use super::{InferCtxt, MiscVariable, TypeTrace};
3738
use super::lub::Lub;
3839
use super::sub::Sub;
39-
use super::InferCtxt;
40-
use super::{MiscVariable, TypeTrace};
40+
use super::type_variable::TypeVariableValue;
4141

4242
use hir::def_id::DefId;
4343
use ty::{IntType, UintType};
@@ -132,7 +132,7 @@ impl<'infcx, 'gcx, 'tcx> InferCtxt<'infcx, 'gcx, 'tcx> {
132132
{
133133
self.int_unification_table
134134
.borrow_mut()
135-
.unify_var_value(vid, val)
135+
.unify_var_value(vid, Some(val))
136136
.map_err(|e| int_unification_error(vid_is_expected, e))?;
137137
match val {
138138
IntType(v) => Ok(self.tcx.mk_mach_int(v)),
@@ -148,7 +148,7 @@ impl<'infcx, 'gcx, 'tcx> InferCtxt<'infcx, 'gcx, 'tcx> {
148148
{
149149
self.float_unification_table
150150
.borrow_mut()
151-
.unify_var_value(vid, val)
151+
.unify_var_value(vid, Some(ty::FloatVarValue(val)))
152152
.map_err(|e| float_unification_error(vid_is_expected, e))?;
153153
Ok(self.tcx.mk_mach_float(val))
154154
}
@@ -194,7 +194,7 @@ impl<'infcx, 'gcx, 'tcx> CombineFields<'infcx, 'gcx, 'tcx> {
194194
use self::RelationDir::*;
195195

196196
// Get the actual variable that b_vid has been inferred to
197-
debug_assert!(self.infcx.type_variables.borrow_mut().probe(b_vid).is_none());
197+
debug_assert!(self.infcx.type_variables.borrow_mut().probe(b_vid).is_unknown());
198198

199199
debug!("instantiate(a_ty={:?} dir={:?} b_vid={:?})", a_ty, dir, b_vid);
200200

@@ -402,12 +402,12 @@ impl<'cx, 'gcx, 'tcx> TypeRelation<'cx, 'gcx, 'tcx> for Generalizer<'cx, 'gcx, '
402402
// `vid` are related via subtyping.
403403
return Err(TypeError::CyclicTy(self.root_ty));
404404
} else {
405-
match variables.probe_root(vid) {
406-
Some(u) => {
405+
match variables.probe(vid) {
406+
TypeVariableValue::Known { value: u } => {
407407
drop(variables);
408408
self.relate(&u, &u)
409409
}
410-
None => {
410+
TypeVariableValue::Unknown { universe } => {
411411
match self.ambient_variance {
412412
// Invariant: no need to make a fresh type variable.
413413
ty::Invariant => return Ok(t),
@@ -423,8 +423,8 @@ impl<'cx, 'gcx, 'tcx> TypeRelation<'cx, 'gcx, 'tcx> for Generalizer<'cx, 'gcx, '
423423
ty::Covariant | ty::Contravariant => (),
424424
}
425425

426-
let origin = variables.origin(vid);
427-
let new_var_id = variables.new_var(false, origin, None);
426+
let origin = *variables.var_origin(vid);
427+
let new_var_id = variables.new_var(universe, false, origin);
428428
let u = self.tcx().mk_var(new_var_id);
429429
debug!("generalize: replacing original vid={:?} with new={:?}",
430430
vid, u);
@@ -518,9 +518,9 @@ fn int_unification_error<'tcx>(a_is_expected: bool, v: (ty::IntVarValue, ty::Int
518518
}
519519

520520
fn float_unification_error<'tcx>(a_is_expected: bool,
521-
v: (ast::FloatTy, ast::FloatTy))
521+
v: (ty::FloatVarValue, ty::FloatVarValue))
522522
-> TypeError<'tcx>
523523
{
524-
let (a, b) = v;
524+
let (ty::FloatVarValue(a), ty::FloatVarValue(b)) = v;
525525
TypeError::FloatMismatch(ty::relate::expected_found_bool(a_is_expected, &a, &b))
526526
}

src/librustc/infer/freshen.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for TypeFreshener<'a, 'gcx, 'tcx> {
133133

134134
match t.sty {
135135
ty::TyInfer(ty::TyVar(v)) => {
136-
let opt_ty = self.infcx.type_variables.borrow_mut().probe(v);
136+
let opt_ty = self.infcx.type_variables.borrow_mut().probe(v).known();
137137
self.freshen(
138138
opt_ty,
139139
ty::TyVar(v),
@@ -143,7 +143,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for TypeFreshener<'a, 'gcx, 'tcx> {
143143
ty::TyInfer(ty::IntVar(v)) => {
144144
self.freshen(
145145
self.infcx.int_unification_table.borrow_mut()
146-
.probe(v)
146+
.probe_value(v)
147147
.map(|v| v.to_type(tcx)),
148148
ty::IntVar(v),
149149
ty::FreshIntTy)
@@ -152,7 +152,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for TypeFreshener<'a, 'gcx, 'tcx> {
152152
ty::TyInfer(ty::FloatVar(v)) => {
153153
self.freshen(
154154
self.infcx.float_unification_table.borrow_mut()
155-
.probe(v)
155+
.probe_value(v)
156156
.map(|v| v.to_type(tcx)),
157157
ty::FloatVar(v),
158158
ty::FreshFloatTy)

src/librustc/infer/fudge.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,21 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for RegionFudger<'a, 'gcx, 'tcx> {
131131
// variables to their binding anyhow, we know
132132
// that it is unbound, so we can just return
133133
// it.
134-
debug_assert!(self.infcx.type_variables.borrow_mut().probe(vid).is_none());
134+
debug_assert!(self.infcx.type_variables.borrow_mut()
135+
.probe(vid)
136+
.is_unknown());
135137
ty
136138
}
137139

138140
Some(&origin) => {
139141
// This variable was created during the
140142
// fudging. Recreate it with a fresh variable
141143
// here.
142-
self.infcx.next_ty_var(origin)
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)
143149
}
144150
}
145151
}

src/librustc/infer/higher_ranked/mod.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
244244

245245
fn generalize_region<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
246246
span: Span,
247-
snapshot: &CombinedSnapshot,
247+
snapshot: &CombinedSnapshot<'a, 'tcx>,
248248
debruijn: ty::DebruijnIndex,
249249
new_vars: &[ty::RegionVid],
250250
a_map: &BTreeMap<ty::BoundRegion, ty::Region<'tcx>>,
@@ -340,7 +340,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
340340

341341
fn generalize_region<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
342342
span: Span,
343-
snapshot: &CombinedSnapshot,
343+
snapshot: &CombinedSnapshot<'a, 'tcx>,
344344
debruijn: ty::DebruijnIndex,
345345
new_vars: &[ty::RegionVid],
346346
a_map: &BTreeMap<ty::BoundRegion, ty::Region<'tcx>>,
@@ -479,7 +479,7 @@ fn fold_regions_in<'a, 'gcx, 'tcx, T, F>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
479479

480480
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
481481
fn tainted_regions(&self,
482-
snapshot: &CombinedSnapshot,
482+
snapshot: &CombinedSnapshot<'a, 'tcx>,
483483
r: ty::Region<'tcx>,
484484
directions: TaintDirections)
485485
-> FxHashSet<ty::Region<'tcx>> {
@@ -491,7 +491,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
491491
}
492492

493493
fn region_vars_confined_to_snapshot(&self,
494-
snapshot: &CombinedSnapshot)
494+
snapshot: &CombinedSnapshot<'a, 'tcx>)
495495
-> Vec<ty::RegionVid>
496496
{
497497
/*!
@@ -583,7 +583,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
583583
/// See `README.md` for more details.
584584
pub fn skolemize_late_bound_regions<T>(&self,
585585
binder: &ty::Binder<T>,
586-
snapshot: &CombinedSnapshot)
586+
snapshot: &CombinedSnapshot<'a, 'tcx>)
587587
-> (T, SkolemizationMap<'tcx>)
588588
where T : TypeFoldable<'tcx>
589589
{
@@ -609,7 +609,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
609609
overly_polymorphic: bool,
610610
_span: Span,
611611
skol_map: &SkolemizationMap<'tcx>,
612-
snapshot: &CombinedSnapshot)
612+
snapshot: &CombinedSnapshot<'a, 'tcx>)
613613
-> RelateResult<'tcx, ()>
614614
{
615615
debug!("leak_check: skol_map={:?}",
@@ -684,7 +684,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
684684
/// predicate is `for<'a> &'a int : Clone`.
685685
pub fn plug_leaks<T>(&self,
686686
skol_map: SkolemizationMap<'tcx>,
687-
snapshot: &CombinedSnapshot,
687+
snapshot: &CombinedSnapshot<'a, 'tcx>,
688688
value: T) -> T
689689
where T : TypeFoldable<'tcx>
690690
{
@@ -770,8 +770,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
770770
/// Note: popping also occurs implicitly as part of `leak_check`.
771771
pub fn pop_skolemized(&self,
772772
skol_map: SkolemizationMap<'tcx>,
773-
snapshot: &CombinedSnapshot)
774-
{
773+
snapshot: &CombinedSnapshot<'a, 'tcx>) {
775774
debug!("pop_skolemized({:?})", skol_map);
776775
let skol_regions: FxHashSet<_> = skol_map.values().cloned().collect();
777776
self.borrow_region_constraints()

src/librustc/infer/lattice.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,6 @@ pub fn super_lattice_tys<'a, 'gcx, 'tcx, L>(this: &mut L,
7070
let a = infcx.type_variables.borrow_mut().replace_if_possible(a);
7171
let b = infcx.type_variables.borrow_mut().replace_if_possible(b);
7272
match (&a.sty, &b.sty) {
73-
(&ty::TyInfer(TyVar(..)), &ty::TyInfer(TyVar(..)))
74-
if infcx.type_var_diverges(a) && infcx.type_var_diverges(b) => {
75-
let v = infcx.next_diverging_ty_var(
76-
TypeVariableOrigin::LatticeVariable(this.cause().span));
77-
this.relate_bound(v, a, b)?;
78-
Ok(v)
79-
}
80-
8173
// If one side is known to be a variable and one is not,
8274
// create a variable (`v`) to represent the LUB. Make sure to
8375
// relate `v` to the non-type-variable first (by passing it
@@ -96,13 +88,17 @@ pub fn super_lattice_tys<'a, 'gcx, 'tcx, L>(this: &mut L,
9688
// is (e.g.) `Box<i32>`. A more obvious solution might be to
9789
// iterate on the subtype obligations that are returned, but I
9890
// think this suffices. -nmatsakis
99-
(&ty::TyInfer(TyVar(..)), _) => {
100-
let v = infcx.next_ty_var(TypeVariableOrigin::LatticeVariable(this.cause().span));
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));
10195
this.relate_bound(v, b, a)?;
10296
Ok(v)
10397
}
104-
(_, &ty::TyInfer(TyVar(..))) => {
105-
let v = infcx.next_ty_var(TypeVariableOrigin::LatticeVariable(this.cause().span));
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));
106102
this.relate_bound(v, a, b)?;
107103
Ok(v)
108104
}

0 commit comments

Comments
 (0)