about summary refs log tree commit diff
path: root/src/librustc/infer
diff options
context:
space:
mode:
authorFabian Drinck <fabian.drinck@rwth-aachen.de>2018-10-20 19:07:17 +0200
committerFabian Drinck <fabian.drinck@rwth-aachen.de>2018-10-20 19:16:23 +0200
commit2f41c0d194ddbf7742aac2d4ff2b0942aa98f96e (patch)
treeb5140e1f8f9531039a59c765269440205552ffde /src/librustc/infer
parent2581bdc143b90bcfc81e82a62c7bb4a6ae2c1301 (diff)
downloadrust-2f41c0d194ddbf7742aac2d4ff2b0942aa98f96e.tar.gz
rust-2f41c0d194ddbf7742aac2d4ff2b0942aa98f96e.zip
Rename InferTy::CanonicalTy to BoundTy and add DebruijnIndex to variant type
Diffstat (limited to 'src/librustc/infer')
-rw-r--r--src/librustc/infer/canonical/canonicalizer.rs23
-rw-r--r--src/librustc/infer/canonical/query_response.rs4
-rw-r--r--src/librustc/infer/canonical/substitute.rs7
-rw-r--r--src/librustc/infer/freshen.rs2
4 files changed, 22 insertions, 14 deletions
diff --git a/src/librustc/infer/canonical/canonicalizer.rs b/src/librustc/infer/canonical/canonicalizer.rs
index 46e32f2374c..2b085a3407c 100644
--- a/src/librustc/infer/canonical/canonicalizer.rs
+++ b/src/librustc/infer/canonical/canonicalizer.rs
@@ -23,7 +23,7 @@ use infer::InferCtxt;
 use std::sync::atomic::Ordering;
 use ty::fold::{TypeFoldable, TypeFolder};
 use ty::subst::Kind;
-use ty::{self, BoundTyIndex, Lift, List, Ty, TyCtxt, TypeFlags};
+use ty::{self, BoundTy, BoundTyIndex, Lift, List, Ty, TyCtxt, TypeFlags};
 
 use rustc_data_structures::fx::FxHashMap;
 use rustc_data_structures::indexed_vec::Idx;
@@ -283,7 +283,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Canonicalizer<'cx, 'gcx, 'tcx>
                 bug!("encountered a fresh type during canonicalization")
             }
 
-            ty::Infer(ty::CanonicalTy(_)) => {
+            ty::Infer(ty::BoundTy(_)) => {
                 bug!("encountered a canonical type during canonicalization")
             }
 
@@ -393,7 +393,7 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
     /// or returns an existing variable if `kind` has already been
     /// seen. `kind` is expected to be an unbound variable (or
     /// potentially a free region).
-    fn canonical_var(&mut self, info: CanonicalVarInfo, kind: Kind<'tcx>) -> BoundTyIndex {
+    fn canonical_var(&mut self, info: CanonicalVarInfo, kind: Kind<'tcx>) -> BoundTy {
         let Canonicalizer {
             variables,
             query_state,
@@ -408,7 +408,7 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
         // avoid allocations in those cases. We also don't use `indices` to
         // determine if a kind has been seen before until the limit of 8 has
         // been exceeded, to also avoid allocations for `indices`.
-        if !var_values.spilled() {
+        let var = if !var_values.spilled() {
             // `var_values` is stack-allocated. `indices` isn't used yet. Do a
             // direct linear search of `var_values`.
             if let Some(idx) = var_values.iter().position(|&k| k == kind) {
@@ -442,6 +442,11 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
                 assert_eq!(variables.len(), var_values.len());
                 BoundTyIndex::new(variables.len() - 1)
             })
+        };
+
+        BoundTy {
+            level: ty::INNERMOST,
+            var,
         }
     }
 
@@ -449,8 +454,9 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
         let info = CanonicalVarInfo {
             kind: CanonicalVarKind::Region,
         };
-        let cvar = self.canonical_var(info, r.into());
-        self.tcx().mk_region(ty::ReCanonical(cvar))
+        let b = self.canonical_var(info, r.into());
+        debug_assert_eq!(ty::INNERMOST, b.level);
+        self.tcx().mk_region(ty::ReCanonical(b.var))
     }
 
     /// Given a type variable `ty_var` of the given kind, first check
@@ -466,8 +472,9 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
             let info = CanonicalVarInfo {
                 kind: CanonicalVarKind::Ty(ty_kind),
             };
-            let cvar = self.canonical_var(info, ty_var.into());
-            self.tcx().mk_infer(ty::InferTy::CanonicalTy(cvar))
+            let b = self.canonical_var(info, ty_var.into());
+            debug_assert_eq!(ty::INNERMOST, b.level);
+            self.tcx().mk_infer(ty::InferTy::BoundTy(b))
         }
     }
 }
diff --git a/src/librustc/infer/canonical/query_response.rs b/src/librustc/infer/canonical/query_response.rs
index 3d4dc36a9be..38788186eb0 100644
--- a/src/librustc/infer/canonical/query_response.rs
+++ b/src/librustc/infer/canonical/query_response.rs
@@ -417,9 +417,9 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
             match result_value.unpack() {
                 UnpackedKind::Type(result_value) => {
                     // e.g., here `result_value` might be `?0` in the example above...
-                    if let ty::Infer(ty::InferTy::CanonicalTy(index)) = result_value.sty {
+                    if let ty::Infer(ty::InferTy::BoundTy(b)) = result_value.sty {
                         // in which case we would set `canonical_vars[0]` to `Some(?U)`.
-                        opt_values[index] = Some(*original_value);
+                        opt_values[b.var] = Some(*original_value);
                     }
                 }
                 UnpackedKind::Lifetime(result_value) => {
diff --git a/src/librustc/infer/canonical/substitute.rs b/src/librustc/infer/canonical/substitute.rs
index f3fe01d5fd1..03441c3dee3 100644
--- a/src/librustc/infer/canonical/substitute.rs
+++ b/src/librustc/infer/canonical/substitute.rs
@@ -85,10 +85,11 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for CanonicalVarValuesSubst<'cx, 'g
 
     fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
         match t.sty {
-            ty::Infer(ty::InferTy::CanonicalTy(c)) => {
-                match self.var_values.var_values[c].unpack() {
+            ty::Infer(ty::InferTy::BoundTy(b)) => {
+                debug_assert_eq!(ty::INNERMOST, b.level);
+                match self.var_values.var_values[b.var].unpack() {
                     UnpackedKind::Type(ty) => ty,
-                    r => bug!("{:?} is a type but value is {:?}", c, r),
+                    r => bug!("{:?} is a type but value is {:?}", b, r),
                 }
             }
             _ => {
diff --git a/src/librustc/infer/freshen.rs b/src/librustc/infer/freshen.rs
index c7785d83171..1647f259db9 100644
--- a/src/librustc/infer/freshen.rs
+++ b/src/librustc/infer/freshen.rs
@@ -171,7 +171,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for TypeFreshener<'a, 'gcx, 'tcx> {
                 t
             }
 
-            ty::Infer(ty::CanonicalTy(..)) =>
+            ty::Infer(ty::BoundTy(..)) =>
                 bug!("encountered canonical ty during freshening"),
 
             ty::Generator(..) |