diff options
| author | scalexm <alexandre@scalexm.fr> | 2018-10-24 10:29:42 +0200 |
|---|---|---|
| committer | scalexm <alexandre@scalexm.fr> | 2018-11-03 11:41:55 +0100 |
| commit | 45be1ac0fcb7ac2d4d8e52c6543e8384e7c1a6ea (patch) | |
| tree | c16319d9bf0c7614fc717ff81d6408bccddebde8 /src/librustc/infer | |
| parent | 1f8de94f3bb1ab148f717507ec1baf78c6a7d207 (diff) | |
| download | rust-45be1ac0fcb7ac2d4d8e52c6543e8384e7c1a6ea.tar.gz rust-45be1ac0fcb7ac2d4d8e52c6543e8384e7c1a6ea.zip | |
Remove `ReCanonical` in favor of `ReLateBound`
Diffstat (limited to 'src/librustc/infer')
| -rw-r--r-- | src/librustc/infer/canonical/canonicalizer.rs | 16 | ||||
| -rw-r--r-- | src/librustc/infer/canonical/mod.rs | 2 | ||||
| -rw-r--r-- | src/librustc/infer/canonical/query_response.rs | 48 | ||||
| -rw-r--r-- | src/librustc/infer/canonical/substitute.rs | 31 | ||||
| -rw-r--r-- | src/librustc/infer/combine.rs | 1 | ||||
| -rw-r--r-- | src/librustc/infer/error_reporting/mod.rs | 2 | ||||
| -rw-r--r-- | src/librustc/infer/freshen.rs | 1 | ||||
| -rw-r--r-- | src/librustc/infer/lexical_region_resolve/mod.rs | 4 | ||||
| -rw-r--r-- | src/librustc/infer/region_constraints/mod.rs | 4 |
9 files changed, 59 insertions, 50 deletions
diff --git a/src/librustc/infer/canonical/canonicalizer.rs b/src/librustc/infer/canonical/canonicalizer.rs index a54d977a517..9c70606349b 100644 --- a/src/librustc/infer/canonical/canonicalizer.rs +++ b/src/librustc/infer/canonical/canonicalizer.rs @@ -331,8 +331,8 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Canonicalizer<'cx, 'gcx, 'tcx> | ty::ReErased => self.canonicalize_region_mode .canonicalize_free_region(self, r), - ty::ReClosureBound(..) | ty::ReCanonical(_) => { - bug!("canonical region encountered during canonicalization") + ty::ReClosureBound(..) => { + bug!("closure bound region encountered during canonicalization") } } } @@ -407,12 +407,6 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> { where V: TypeFoldable<'tcx> + Lift<'gcx>, { - debug_assert!( - !value.has_type_flags(TypeFlags::HAS_CANONICAL_VARS), - "canonicalizing a canonical value: {:?}", - value, - ); - let needs_canonical_flags = if canonicalize_region_mode.any() { TypeFlags::HAS_FREE_REGIONS | TypeFlags::KEEP_IN_LOCAL_TCX } else { @@ -569,7 +563,11 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> { r: ty::Region<'tcx>, ) -> ty::Region<'tcx> { let var = self.canonical_var(info, r.into()); - self.tcx().mk_region(ty::ReCanonical(var)) + let region = ty::ReLateBound( + self.binder_index, + ty::BoundRegion::BrAnon(var.index() as u32) + ); + self.tcx().mk_region(region) } /// Given a type variable `ty_var` of the given kind, first check diff --git a/src/librustc/infer/canonical/mod.rs b/src/librustc/infer/canonical/mod.rs index b6f79414725..f7eb7118f41 100644 --- a/src/librustc/infer/canonical/mod.rs +++ b/src/librustc/infer/canonical/mod.rs @@ -20,7 +20,7 @@ //! - a map M (of type `CanonicalVarValues`) from those canonical //! variables back to the original. //! -//! We can then do queries using T2. These will give back constriants +//! We can then do queries using T2. These will give back constraints //! on the canonical variables which can be translated, using the map //! M, into constraints in our source context. This process of //! translating the results back is done by the diff --git a/src/librustc/infer/canonical/query_response.rs b/src/librustc/infer/canonical/query_response.rs index 06e97a71ce5..4858d1d0919 100644 --- a/src/librustc/infer/canonical/query_response.rs +++ b/src/librustc/infer/canonical/query_response.rs @@ -308,11 +308,12 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { // ...also include the other query region constraints from the query. output_query_region_constraints.extend( query_response.value.region_constraints.iter().filter_map(|r_c| { - let &ty::OutlivesPredicate(k1, r2) = r_c.skip_binder(); // reconstructed below - let k1 = substitute_value(self.tcx, &result_subst, &k1); - let r2 = substitute_value(self.tcx, &result_subst, &r2); - if k1 != r2.into() { - Some(ty::Binder::bind(ty::OutlivesPredicate(k1, r2))) + let ty::OutlivesPredicate(k1, r2) = r_c.skip_binder(); // reconstructed below + let k1 = substitute_value(self.tcx, &result_subst, &ty::Binder::bind(*k1)); + let r2 = substitute_value(self.tcx, &result_subst, &ty::Binder::bind(*r2)); + if k1 != r2.map_bound(|bound| bound.into()) { + let predicate = ty::OutlivesPredicate(*k1.skip_binder(), *r2.skip_binder()); + Some(ty::Binder::bind(predicate)) } else { None } @@ -433,16 +434,21 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { UnpackedKind::Type(result_value) => { // e.g., here `result_value` might be `?0` in the example above... if let ty::Bound(b) = result_value.sty { + // ...in which case we would set `canonical_vars[0]` to `Some(?U)`. + + // We only allow a `ty::INNERMOST` index in substitutions. assert_eq!(b.index, ty::INNERMOST); - // in which case we would set `canonical_vars[0]` to `Some(?U)`. opt_values[b.var] = Some(*original_value); } } UnpackedKind::Lifetime(result_value) => { // e.g., here `result_value` might be `'?1` in the example above... - if let &ty::RegionKind::ReCanonical(index) = result_value { - // in which case we would set `canonical_vars[0]` to `Some('static)`. - opt_values[index] = Some(*original_value); + if let &ty::RegionKind::ReLateBound(index, br) = result_value { + // ... in which case we would set `canonical_vars[0]` to `Some('static)`. + + // We only allow a `ty::INNERMOST` index in substitutions. + assert_eq!(index, ty::INNERMOST); + opt_values[br.as_bound_var()] = Some(*original_value); } } } @@ -525,21 +531,23 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { .iter() .map(move |constraint| { let ty::OutlivesPredicate(k1, r2) = constraint.skip_binder(); // restored below - let k1 = substitute_value(self.tcx, result_subst, k1); - let r2 = substitute_value(self.tcx, result_subst, r2); + let k1 = substitute_value(self.tcx, result_subst, &ty::Binder::bind(*k1)); + let r2 = substitute_value(self.tcx, result_subst, &ty::Binder::bind(*r2)); Obligation::new( cause.clone(), param_env, - match k1.unpack() { + match k1.skip_binder().unpack() { UnpackedKind::Lifetime(r1) => ty::Predicate::RegionOutlives( - ty::Binder::dummy( - ty::OutlivesPredicate(r1, r2) - )), + ty::Binder::bind( + ty::OutlivesPredicate(r1, r2.skip_binder()) + ) + ), UnpackedKind::Type(t1) => ty::Predicate::TypeOutlives( - ty::Binder::dummy(ty::OutlivesPredicate( - t1, r2 - ))) + ty::Binder::bind( + ty::OutlivesPredicate(t1, r2.skip_binder()) + ) + ), } ) }) @@ -621,11 +629,11 @@ pub fn make_query_outlives<'tcx>( } Constraint::RegSubReg(r1, r2) => ty::OutlivesPredicate(r2.into(), r1), }) - .map(ty::Binder::dummy) // no bound regions in the code above + .map(ty::Binder::dummy) // no bound vars in the code above .chain( outlives_obligations .map(|(ty, r)| ty::OutlivesPredicate(ty.into(), r)) - .map(ty::Binder::dummy), // no bound regions in the code above + .map(ty::Binder::dummy) // no bound vars in the code above ) .collect(); diff --git a/src/librustc/infer/canonical/substitute.rs b/src/librustc/infer/canonical/substitute.rs index 5b2e758d816..7839c892266 100644 --- a/src/librustc/infer/canonical/substitute.rs +++ b/src/librustc/infer/canonical/substitute.rs @@ -19,7 +19,7 @@ use infer::canonical::{Canonical, CanonicalVarValues}; use ty::fold::{TypeFoldable, TypeFolder}; use ty::subst::UnpackedKind; -use ty::{self, Ty, TyCtxt, TypeFlags}; +use ty::{self, Ty, TyCtxt}; impl<'tcx, V> Canonical<'tcx, V> { /// Instantiate the wrapped value, replacing each canonical value @@ -64,9 +64,9 @@ where T: TypeFoldable<'tcx>, { if var_values.var_values.is_empty() { - debug_assert!(!value.has_type_flags(TypeFlags::HAS_CANONICAL_VARS)); value.clone() - } else if !value.has_type_flags(TypeFlags::HAS_CANONICAL_VARS) { + } else if !value.has_escaping_bound_vars() { + // There are no bound vars to substitute. value.clone() } else { value.fold_with(&mut CanonicalVarValuesSubst { @@ -104,8 +104,8 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for CanonicalVarValuesSubst<'cx, 'g match self.var_values.var_values[b.var].unpack() { UnpackedKind::Type(ty) => ty::fold::shift_vars( self.tcx, - self.binder_index.index() as u32, - &ty + &ty, + self.binder_index.index() as u32 ), r => bug!("{:?} is a type but value is {:?}", b, r), } @@ -114,7 +114,8 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for CanonicalVarValuesSubst<'cx, 'g } } _ => { - if !t.has_type_flags(TypeFlags::HAS_CANONICAL_VARS) { + if !t.has_vars_bound_at_or_above(self.binder_index) { + // Nothing more to substitute. t } else { t.super_fold_with(self) @@ -125,10 +126,20 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for CanonicalVarValuesSubst<'cx, 'g fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> { match r { - ty::RegionKind::ReCanonical(c) => match self.var_values.var_values[*c].unpack() { - UnpackedKind::Lifetime(l) => l, - r => bug!("{:?} is a region but value is {:?}", c, r), - }, + ty::RegionKind::ReLateBound(index, br) => { + if *index == self.binder_index { + match self.var_values.var_values[br.as_bound_var()].unpack() { + UnpackedKind::Lifetime(l) => ty::fold::shift_region( + self.tcx, + l, + self.binder_index.index() as u32, + ), + r => bug!("{:?} is a region but value is {:?}", br, r), + } + } else { + r + } + } _ => r.super_fold_with(self), } } diff --git a/src/librustc/infer/combine.rs b/src/librustc/infer/combine.rs index 0ee03bc4c6e..f13210926a7 100644 --- a/src/librustc/infer/combine.rs +++ b/src/librustc/infer/combine.rs @@ -485,7 +485,6 @@ impl<'cx, 'gcx, 'tcx> TypeRelation<'cx, 'gcx, 'tcx> for Generalizer<'cx, 'gcx, ' } } - ty::ReCanonical(..) | ty::ReClosureBound(..) => { span_bug!( self.span, diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index d19c495af3b..1963d366e7a 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -152,7 +152,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } // We shouldn't encounter an error message with ReClosureBound. - ty::ReCanonical(..) | ty::ReClosureBound(..) => { + ty::ReClosureBound(..) => { bug!("encountered unexpected ReClosureBound: {:?}", region,); } }; diff --git a/src/librustc/infer/freshen.rs b/src/librustc/infer/freshen.rs index c12e64b4c2c..b53444992fa 100644 --- a/src/librustc/infer/freshen.rs +++ b/src/librustc/infer/freshen.rs @@ -114,7 +114,6 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for TypeFreshener<'a, 'gcx, 'tcx> { self.tcx().types.re_erased } - ty::ReCanonical(..) | ty::ReClosureBound(..) => { bug!( "encountered unexpected region: {:?}", diff --git a/src/librustc/infer/lexical_region_resolve/mod.rs b/src/librustc/infer/lexical_region_resolve/mod.rs index 8f28e9a320d..75f503d3bcf 100644 --- a/src/librustc/infer/lexical_region_resolve/mod.rs +++ b/src/librustc/infer/lexical_region_resolve/mod.rs @@ -260,9 +260,7 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> { fn lub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> Region<'tcx> { let tcx = self.tcx(); match (a, b) { - (&ty::ReCanonical(..), _) - | (_, &ty::ReCanonical(..)) - | (&ty::ReClosureBound(..), _) + (&ty::ReClosureBound(..), _) | (_, &ty::ReClosureBound(..)) | (&ReLateBound(..), _) | (_, &ReLateBound(..)) diff --git a/src/librustc/infer/region_constraints/mod.rs b/src/librustc/infer/region_constraints/mod.rs index c82603bf560..46b12d01829 100644 --- a/src/librustc/infer/region_constraints/mod.rs +++ b/src/librustc/infer/region_constraints/mod.rs @@ -833,10 +833,6 @@ impl<'tcx> RegionConstraintCollector<'tcx> { ty::RePlaceholder(placeholder) => placeholder.universe, ty::ReClosureBound(vid) | ty::ReVar(vid) => self.var_universe(vid), ty::ReLateBound(..) => bug!("universe(): encountered bound region {:?}", region), - ty::ReCanonical(..) => bug!( - "region_universe(): encountered canonical region {:?}", - region - ), } } |
