Skip to content

Commit 45be1ac

Browse files
committed
Remove ReCanonical in favor of ReLateBound
1 parent 1f8de94 commit 45be1ac

File tree

23 files changed

+98
-101
lines changed

23 files changed

+98
-101
lines changed

src/librustc/ich/impls_ty.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ for ty::RegionKind {
100100
ty::ReEmpty => {
101101
// No variant fields to hash for these ...
102102
}
103-
ty::ReCanonical(c) => {
104-
c.hash_stable(hcx, hasher);
105-
}
106103
ty::ReLateBound(db, ty::BrAnon(i)) => {
107104
db.hash_stable(hcx, hasher);
108105
i.hash_stable(hcx, hasher);

src/librustc/infer/canonical/canonicalizer.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Canonicalizer<'cx, 'gcx, 'tcx>
331331
| ty::ReErased => self.canonicalize_region_mode
332332
.canonicalize_free_region(self, r),
333333

334-
ty::ReClosureBound(..) | ty::ReCanonical(_) => {
335-
bug!("canonical region encountered during canonicalization")
334+
ty::ReClosureBound(..) => {
335+
bug!("closure bound region encountered during canonicalization")
336336
}
337337
}
338338
}
@@ -407,12 +407,6 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
407407
where
408408
V: TypeFoldable<'tcx> + Lift<'gcx>,
409409
{
410-
debug_assert!(
411-
!value.has_type_flags(TypeFlags::HAS_CANONICAL_VARS),
412-
"canonicalizing a canonical value: {:?}",
413-
value,
414-
);
415-
416410
let needs_canonical_flags = if canonicalize_region_mode.any() {
417411
TypeFlags::HAS_FREE_REGIONS | TypeFlags::KEEP_IN_LOCAL_TCX
418412
} else {
@@ -569,7 +563,11 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
569563
r: ty::Region<'tcx>,
570564
) -> ty::Region<'tcx> {
571565
let var = self.canonical_var(info, r.into());
572-
self.tcx().mk_region(ty::ReCanonical(var))
566+
let region = ty::ReLateBound(
567+
self.binder_index,
568+
ty::BoundRegion::BrAnon(var.index() as u32)
569+
);
570+
self.tcx().mk_region(region)
573571
}
574572

575573
/// Given a type variable `ty_var` of the given kind, first check

src/librustc/infer/canonical/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
//! - a map M (of type `CanonicalVarValues`) from those canonical
2121
//! variables back to the original.
2222
//!
23-
//! We can then do queries using T2. These will give back constriants
23+
//! We can then do queries using T2. These will give back constraints
2424
//! on the canonical variables which can be translated, using the map
2525
//! M, into constraints in our source context. This process of
2626
//! translating the results back is done by the

src/librustc/infer/canonical/query_response.rs

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,12 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
308308
// ...also include the other query region constraints from the query.
309309
output_query_region_constraints.extend(
310310
query_response.value.region_constraints.iter().filter_map(|r_c| {
311-
let &ty::OutlivesPredicate(k1, r2) = r_c.skip_binder(); // reconstructed below
312-
let k1 = substitute_value(self.tcx, &result_subst, &k1);
313-
let r2 = substitute_value(self.tcx, &result_subst, &r2);
314-
if k1 != r2.into() {
315-
Some(ty::Binder::bind(ty::OutlivesPredicate(k1, r2)))
311+
let ty::OutlivesPredicate(k1, r2) = r_c.skip_binder(); // reconstructed below
312+
let k1 = substitute_value(self.tcx, &result_subst, &ty::Binder::bind(*k1));
313+
let r2 = substitute_value(self.tcx, &result_subst, &ty::Binder::bind(*r2));
314+
if k1 != r2.map_bound(|bound| bound.into()) {
315+
let predicate = ty::OutlivesPredicate(*k1.skip_binder(), *r2.skip_binder());
316+
Some(ty::Binder::bind(predicate))
316317
} else {
317318
None
318319
}
@@ -433,16 +434,21 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
433434
UnpackedKind::Type(result_value) => {
434435
// e.g., here `result_value` might be `?0` in the example above...
435436
if let ty::Bound(b) = result_value.sty {
437+
// ...in which case we would set `canonical_vars[0]` to `Some(?U)`.
438+
439+
// We only allow a `ty::INNERMOST` index in substitutions.
436440
assert_eq!(b.index, ty::INNERMOST);
437-
// in which case we would set `canonical_vars[0]` to `Some(?U)`.
438441
opt_values[b.var] = Some(*original_value);
439442
}
440443
}
441444
UnpackedKind::Lifetime(result_value) => {
442445
// e.g., here `result_value` might be `'?1` in the example above...
443-
if let &ty::RegionKind::ReCanonical(index) = result_value {
444-
// in which case we would set `canonical_vars[0]` to `Some('static)`.
445-
opt_values[index] = Some(*original_value);
446+
if let &ty::RegionKind::ReLateBound(index, br) = result_value {
447+
// ... in which case we would set `canonical_vars[0]` to `Some('static)`.
448+
449+
// We only allow a `ty::INNERMOST` index in substitutions.
450+
assert_eq!(index, ty::INNERMOST);
451+
opt_values[br.as_bound_var()] = Some(*original_value);
446452
}
447453
}
448454
}
@@ -525,21 +531,23 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
525531
.iter()
526532
.map(move |constraint| {
527533
let ty::OutlivesPredicate(k1, r2) = constraint.skip_binder(); // restored below
528-
let k1 = substitute_value(self.tcx, result_subst, k1);
529-
let r2 = substitute_value(self.tcx, result_subst, r2);
534+
let k1 = substitute_value(self.tcx, result_subst, &ty::Binder::bind(*k1));
535+
let r2 = substitute_value(self.tcx, result_subst, &ty::Binder::bind(*r2));
530536

531537
Obligation::new(
532538
cause.clone(),
533539
param_env,
534-
match k1.unpack() {
540+
match k1.skip_binder().unpack() {
535541
UnpackedKind::Lifetime(r1) => ty::Predicate::RegionOutlives(
536-
ty::Binder::dummy(
537-
ty::OutlivesPredicate(r1, r2)
538-
)),
542+
ty::Binder::bind(
543+
ty::OutlivesPredicate(r1, r2.skip_binder())
544+
)
545+
),
539546
UnpackedKind::Type(t1) => ty::Predicate::TypeOutlives(
540-
ty::Binder::dummy(ty::OutlivesPredicate(
541-
t1, r2
542-
)))
547+
ty::Binder::bind(
548+
ty::OutlivesPredicate(t1, r2.skip_binder())
549+
)
550+
),
543551
}
544552
)
545553
})
@@ -621,11 +629,11 @@ pub fn make_query_outlives<'tcx>(
621629
}
622630
Constraint::RegSubReg(r1, r2) => ty::OutlivesPredicate(r2.into(), r1),
623631
})
624-
.map(ty::Binder::dummy) // no bound regions in the code above
632+
.map(ty::Binder::dummy) // no bound vars in the code above
625633
.chain(
626634
outlives_obligations
627635
.map(|(ty, r)| ty::OutlivesPredicate(ty.into(), r))
628-
.map(ty::Binder::dummy), // no bound regions in the code above
636+
.map(ty::Binder::dummy) // no bound vars in the code above
629637
)
630638
.collect();
631639

src/librustc/infer/canonical/substitute.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use infer::canonical::{Canonical, CanonicalVarValues};
2020
use ty::fold::{TypeFoldable, TypeFolder};
2121
use ty::subst::UnpackedKind;
22-
use ty::{self, Ty, TyCtxt, TypeFlags};
22+
use ty::{self, Ty, TyCtxt};
2323

2424
impl<'tcx, V> Canonical<'tcx, V> {
2525
/// Instantiate the wrapped value, replacing each canonical value
@@ -64,9 +64,9 @@ where
6464
T: TypeFoldable<'tcx>,
6565
{
6666
if var_values.var_values.is_empty() {
67-
debug_assert!(!value.has_type_flags(TypeFlags::HAS_CANONICAL_VARS));
6867
value.clone()
69-
} else if !value.has_type_flags(TypeFlags::HAS_CANONICAL_VARS) {
68+
} else if !value.has_escaping_bound_vars() {
69+
// There are no bound vars to substitute.
7070
value.clone()
7171
} else {
7272
value.fold_with(&mut CanonicalVarValuesSubst {
@@ -104,8 +104,8 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for CanonicalVarValuesSubst<'cx, 'g
104104
match self.var_values.var_values[b.var].unpack() {
105105
UnpackedKind::Type(ty) => ty::fold::shift_vars(
106106
self.tcx,
107-
self.binder_index.index() as u32,
108-
&ty
107+
&ty,
108+
self.binder_index.index() as u32
109109
),
110110
r => bug!("{:?} is a type but value is {:?}", b, r),
111111
}
@@ -114,7 +114,8 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for CanonicalVarValuesSubst<'cx, 'g
114114
}
115115
}
116116
_ => {
117-
if !t.has_type_flags(TypeFlags::HAS_CANONICAL_VARS) {
117+
if !t.has_vars_bound_at_or_above(self.binder_index) {
118+
// Nothing more to substitute.
118119
t
119120
} else {
120121
t.super_fold_with(self)
@@ -125,10 +126,20 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for CanonicalVarValuesSubst<'cx, 'g
125126

126127
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
127128
match r {
128-
ty::RegionKind::ReCanonical(c) => match self.var_values.var_values[*c].unpack() {
129-
UnpackedKind::Lifetime(l) => l,
130-
r => bug!("{:?} is a region but value is {:?}", c, r),
131-
},
129+
ty::RegionKind::ReLateBound(index, br) => {
130+
if *index == self.binder_index {
131+
match self.var_values.var_values[br.as_bound_var()].unpack() {
132+
UnpackedKind::Lifetime(l) => ty::fold::shift_region(
133+
self.tcx,
134+
l,
135+
self.binder_index.index() as u32,
136+
),
137+
r => bug!("{:?} is a region but value is {:?}", br, r),
138+
}
139+
} else {
140+
r
141+
}
142+
}
132143
_ => r.super_fold_with(self),
133144
}
134145
}

src/librustc/infer/combine.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,6 @@ impl<'cx, 'gcx, 'tcx> TypeRelation<'cx, 'gcx, 'tcx> for Generalizer<'cx, 'gcx, '
485485
}
486486
}
487487

488-
ty::ReCanonical(..) |
489488
ty::ReClosureBound(..) => {
490489
span_bug!(
491490
self.span,

src/librustc/infer/error_reporting/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
152152
}
153153

154154
// We shouldn't encounter an error message with ReClosureBound.
155-
ty::ReCanonical(..) | ty::ReClosureBound(..) => {
155+
ty::ReClosureBound(..) => {
156156
bug!("encountered unexpected ReClosureBound: {:?}", region,);
157157
}
158158
};

src/librustc/infer/freshen.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for TypeFreshener<'a, 'gcx, 'tcx> {
114114
self.tcx().types.re_erased
115115
}
116116

117-
ty::ReCanonical(..) |
118117
ty::ReClosureBound(..) => {
119118
bug!(
120119
"encountered unexpected region: {:?}",

src/librustc/infer/lexical_region_resolve/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,7 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
260260
fn lub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> Region<'tcx> {
261261
let tcx = self.tcx();
262262
match (a, b) {
263-
(&ty::ReCanonical(..), _)
264-
| (_, &ty::ReCanonical(..))
265-
| (&ty::ReClosureBound(..), _)
263+
(&ty::ReClosureBound(..), _)
266264
| (_, &ty::ReClosureBound(..))
267265
| (&ReLateBound(..), _)
268266
| (_, &ReLateBound(..))

src/librustc/infer/region_constraints/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -833,10 +833,6 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
833833
ty::RePlaceholder(placeholder) => placeholder.universe,
834834
ty::ReClosureBound(vid) | ty::ReVar(vid) => self.var_universe(vid),
835835
ty::ReLateBound(..) => bug!("universe(): encountered bound region {:?}", region),
836-
ty::ReCanonical(..) => bug!(
837-
"region_universe(): encountered canonical region {:?}",
838-
region
839-
),
840836
}
841837
}
842838

src/librustc/ty/flags.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ impl FlagComputation {
116116
}
117117

118118
&ty::Bound(bound_ty) => {
119-
self.add_flags(TypeFlags::HAS_CANONICAL_VARS);
120119
self.add_binder(bound_ty.index);
121120
}
122121

@@ -127,7 +126,6 @@ impl FlagComputation {
127126
ty::FreshTy(_) |
128127
ty::FreshIntTy(_) |
129128
ty::FreshFloatTy(_) => {
130-
self.add_flags(TypeFlags::HAS_CANONICAL_VARS);
131129
}
132130

133131
ty::TyVar(_) |

src/librustc/ty/fold.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -672,10 +672,14 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Shifter<'a, 'gcx, 'tcx> {
672672
}
673673
}
674674

675-
pub fn shift_region(region: ty::RegionKind, amount: u32) -> ty::RegionKind {
675+
pub fn shift_region<'a, 'gcx, 'tcx>(
676+
tcx: TyCtxt<'a, 'gcx, 'tcx>,
677+
region: ty::Region<'tcx>,
678+
amount: u32
679+
) -> ty::Region<'tcx> {
676680
match region {
677-
ty::ReLateBound(debruijn, br) => {
678-
ty::ReLateBound(debruijn.shifted_in(amount), br)
681+
ty::ReLateBound(debruijn, br) if amount > 0 => {
682+
tcx.mk_region(ty::ReLateBound(debruijn.shifted_in(amount), *br))
679683
}
680684
_ => {
681685
region
@@ -685,8 +689,8 @@ pub fn shift_region(region: ty::RegionKind, amount: u32) -> ty::RegionKind {
685689

686690
pub fn shift_vars<'a, 'gcx, 'tcx, T>(
687691
tcx: TyCtxt<'a, 'gcx, 'tcx>,
688-
amount: u32,
689-
value: &T
692+
value: &T,
693+
amount: u32
690694
) -> T where T: TypeFoldable<'tcx> {
691695
debug!("shift_vars(value={:?}, amount={})",
692696
value, amount);

src/librustc/ty/mod.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -463,13 +463,9 @@ bitflags! {
463463
// Currently we can't normalize projections w/ bound regions.
464464
const HAS_NORMALIZABLE_PROJECTION = 1 << 12;
465465

466-
// Set if this includes a "canonical" type or region var --
467-
// ought to be true only for the results of canonicalization.
468-
const HAS_CANONICAL_VARS = 1 << 13;
469-
470466
/// Does this have any `ReLateBound` regions? Used to check
471467
/// if a global bound is safe to evaluate.
472-
const HAS_RE_LATE_BOUND = 1 << 14;
468+
const HAS_RE_LATE_BOUND = 1 << 13;
473469

474470
const NEEDS_SUBST = TypeFlags::HAS_PARAMS.bits |
475471
TypeFlags::HAS_SELF.bits |
@@ -490,7 +486,6 @@ bitflags! {
490486
TypeFlags::HAS_TY_CLOSURE.bits |
491487
TypeFlags::HAS_FREE_LOCAL_NAMES.bits |
492488
TypeFlags::KEEP_IN_LOCAL_TCX.bits |
493-
TypeFlags::HAS_CANONICAL_VARS.bits |
494489
TypeFlags::HAS_RE_LATE_BOUND.bits;
495490
}
496491
}

0 commit comments

Comments
 (0)