Skip to content

Commit e76fffc

Browse files
committed
Remove ReCanonical in favor of ReLateBound
1 parent 8642a23 commit e76fffc

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
@@ -277,8 +277,8 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Canonicalizer<'cx, 'gcx, 'tcx>
277277
| ty::ReEmpty
278278
| ty::ReErased => self.canonicalize_region_mode.canonicalize_free_region(self, r),
279279

280-
ty::ReClosureBound(..) | ty::ReCanonical(_) => {
281-
bug!("canonical region encountered during canonicalization")
280+
ty::ReClosureBound(..) => {
281+
bug!("closure bound region encountered during canonicalization")
282282
}
283283
}
284284
}
@@ -353,12 +353,6 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
353353
where
354354
V: TypeFoldable<'tcx> + Lift<'gcx>,
355355
{
356-
debug_assert!(
357-
!value.has_type_flags(TypeFlags::HAS_CANONICAL_VARS),
358-
"canonicalizing a canonical value: {:?}",
359-
value,
360-
);
361-
362356
let needs_canonical_flags = if canonicalize_region_mode.any() {
363357
TypeFlags::HAS_FREE_REGIONS | TypeFlags::KEEP_IN_LOCAL_TCX
364358
} else {
@@ -471,7 +465,11 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
471465
kind: CanonicalVarKind::Region,
472466
};
473467
let var = self.canonical_var(info, r.into());
474-
self.tcx().mk_region(ty::ReCanonical(var))
468+
let region = ty::ReLateBound(
469+
self.binder_index,
470+
ty::BoundRegion::BrAnon(var.index() as u32)
471+
);
472+
self.tcx().mk_region(region)
475473
}
476474

477475
/// 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
}
@@ -418,16 +419,21 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
418419
UnpackedKind::Type(result_value) => {
419420
// e.g., here `result_value` might be `?0` in the example above...
420421
if let ty::Bound(b) = result_value.sty {
422+
// ...in which case we would set `canonical_vars[0]` to `Some(?U)`.
423+
424+
// We only allow a `ty::INNERMOST` index in substitutions.
421425
assert_eq!(b.index, ty::INNERMOST);
422-
// in which case we would set `canonical_vars[0]` to `Some(?U)`.
423426
opt_values[b.var] = Some(*original_value);
424427
}
425428
}
426429
UnpackedKind::Lifetime(result_value) => {
427430
// e.g., here `result_value` might be `'?1` in the example above...
428-
if let &ty::RegionKind::ReCanonical(index) = result_value {
429-
// in which case we would set `canonical_vars[0]` to `Some('static)`.
430-
opt_values[index] = Some(*original_value);
431+
if let &ty::RegionKind::ReLateBound(index, br) = result_value {
432+
// ... in which case we would set `canonical_vars[0]` to `Some('static)`.
433+
434+
// We only allow a `ty::INNERMOST` index in substitutions.
435+
assert_eq!(index, ty::INNERMOST);
436+
opt_values[br.as_bound_var()] = Some(*original_value);
431437
}
432438
}
433439
}
@@ -499,21 +505,23 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
499505
.iter()
500506
.map(move |constraint| {
501507
let ty::OutlivesPredicate(k1, r2) = constraint.skip_binder(); // restored below
502-
let k1 = substitute_value(self.tcx, result_subst, k1);
503-
let r2 = substitute_value(self.tcx, result_subst, r2);
508+
let k1 = substitute_value(self.tcx, result_subst, &ty::Binder::bind(*k1));
509+
let r2 = substitute_value(self.tcx, result_subst, &ty::Binder::bind(*r2));
504510

505511
Obligation::new(
506512
cause.clone(),
507513
param_env,
508-
match k1.unpack() {
514+
match k1.skip_binder().unpack() {
509515
UnpackedKind::Lifetime(r1) => ty::Predicate::RegionOutlives(
510-
ty::Binder::dummy(
511-
ty::OutlivesPredicate(r1, r2)
512-
)),
516+
ty::Binder::bind(
517+
ty::OutlivesPredicate(r1, r2.skip_binder())
518+
)
519+
),
513520
UnpackedKind::Type(t1) => ty::Predicate::TypeOutlives(
514-
ty::Binder::dummy(ty::OutlivesPredicate(
515-
t1, r2
516-
)))
521+
ty::Binder::bind(
522+
ty::OutlivesPredicate(t1, r2.skip_binder())
523+
)
524+
),
517525
}
518526
)
519527
})
@@ -595,11 +603,11 @@ pub fn make_query_outlives<'tcx>(
595603
}
596604
Constraint::RegSubReg(r1, r2) => ty::OutlivesPredicate(r2.into(), r1),
597605
})
598-
.map(ty::Binder::dummy) // no bound regions in the code above
606+
.map(ty::Binder::dummy) // no bound vars in the code above
599607
.chain(
600608
outlives_obligations
601609
.map(|(ty, r)| ty::OutlivesPredicate(ty.into(), r))
602-
.map(ty::Binder::dummy), // no bound regions in the code above
610+
.map(ty::Binder::dummy) // no bound vars in the code above
603611
)
604612
.collect();
605613

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
@@ -477,7 +477,6 @@ impl<'cx, 'gcx, 'tcx> TypeRelation<'cx, 'gcx, 'tcx> for Generalizer<'cx, 'gcx, '
477477
}
478478
}
479479

480-
ty::ReCanonical(..) |
481480
ty::ReClosureBound(..) => {
482481
span_bug!(
483482
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

0 commit comments

Comments
 (0)