Skip to content

Commit 95861b1

Browse files
committed
Move BoundTy debruijn index to the TyKind enum variant
1 parent 6bf17d2 commit 95861b1

File tree

14 files changed

+57
-56
lines changed

14 files changed

+57
-56
lines changed

src/librustc/ich/impls_ty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,8 @@ for ty::TyKind<'gcx>
684684
Param(param_ty) => {
685685
param_ty.hash_stable(hcx, hasher);
686686
}
687-
Bound(bound_ty) => {
687+
Bound(debruijn, bound_ty) => {
688+
debruijn.hash_stable(hcx, hasher);
688689
bound_ty.hash_stable(hcx, hasher);
689690
}
690691
ty::Placeholder(placeholder_ty) => {

src/librustc/infer/canonical/canonicalizer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use infer::InferCtxt;
2323
use std::sync::atomic::Ordering;
2424
use ty::fold::{TypeFoldable, TypeFolder};
2525
use ty::subst::Kind;
26-
use ty::{self, BoundTy, BoundVar, Lift, List, Ty, TyCtxt, TypeFlags};
26+
use ty::{self, BoundVar, Lift, List, Ty, TyCtxt, TypeFlags};
2727

2828
use rustc_data_structures::fx::FxHashMap;
2929
use rustc_data_structures::indexed_vec::Idx;
@@ -382,8 +382,8 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Canonicalizer<'cx, 'gcx, 'tcx>
382382
t
383383
),
384384

385-
ty::Bound(bound_ty) => {
386-
if bound_ty.index >= self.binder_index {
385+
ty::Bound(debruijn, _) => {
386+
if debruijn >= self.binder_index {
387387
bug!("escaping bound type during canonicalization")
388388
} else {
389389
t
@@ -616,7 +616,7 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
616616
self.fold_ty(bound_to)
617617
} else {
618618
let var = self.canonical_var(info, ty_var.into());
619-
self.tcx().mk_ty(ty::Bound(BoundTy::new(self.binder_index, var)))
619+
self.tcx().mk_ty(ty::Bound(self.binder_index, var.into()))
620620
}
621621
}
622622
}

src/librustc/infer/canonical/query_response.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,21 +435,21 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
435435
match result_value.unpack() {
436436
UnpackedKind::Type(result_value) => {
437437
// e.g., here `result_value` might be `?0` in the example above...
438-
if let ty::Bound(b) = result_value.sty {
438+
if let ty::Bound(debruijn, b) = result_value.sty {
439439
// ...in which case we would set `canonical_vars[0]` to `Some(?U)`.
440440

441441
// We only allow a `ty::INNERMOST` index in substitutions.
442-
assert_eq!(b.index, ty::INNERMOST);
442+
assert_eq!(debruijn, ty::INNERMOST);
443443
opt_values[b.var] = Some(*original_value);
444444
}
445445
}
446446
UnpackedKind::Lifetime(result_value) => {
447447
// e.g., here `result_value` might be `'?1` in the example above...
448-
if let &ty::RegionKind::ReLateBound(index, br) = result_value {
448+
if let &ty::RegionKind::ReLateBound(debruijn, br) = result_value {
449449
// ... in which case we would set `canonical_vars[0]` to `Some('static)`.
450450

451451
// We only allow a `ty::INNERMOST` index in substitutions.
452-
assert_eq!(index, ty::INNERMOST);
452+
assert_eq!(debruijn, ty::INNERMOST);
453453
opt_values[br.assert_bound_var()] = Some(*original_value);
454454
}
455455
}

src/librustc/traits/select.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,7 +2471,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
24712471

24722472
ty::UnnormalizedProjection(..)
24732473
| ty::Placeholder(..)
2474-
| ty::Bound(_)
2474+
| ty::Bound(..)
24752475
| ty::Infer(ty::FreshTy(_))
24762476
| ty::Infer(ty::FreshIntTy(_))
24772477
| ty::Infer(ty::FreshFloatTy(_)) => {
@@ -2557,7 +2557,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
25572557

25582558
ty::UnnormalizedProjection(..)
25592559
| ty::Placeholder(..)
2560-
| ty::Bound(_)
2560+
| ty::Bound(..)
25612561
| ty::Infer(ty::FreshTy(_))
25622562
| ty::Infer(ty::FreshIntTy(_))
25632563
| ty::Infer(ty::FreshFloatTy(_)) => {
@@ -2601,7 +2601,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
26012601
| ty::Param(..)
26022602
| ty::Foreign(..)
26032603
| ty::Projection(..)
2604-
| ty::Bound(_)
2604+
| ty::Bound(..)
26052605
| ty::Infer(ty::TyVar(_))
26062606
| ty::Infer(ty::FreshTy(_))
26072607
| ty::Infer(ty::FreshIntTy(_))

src/librustc/traits/structural_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ impl<'tcx> TypeVisitor<'tcx> for BoundNamesCollector {
324324
use syntax::symbol::Symbol;
325325

326326
match t.sty {
327-
ty::Bound(bound_ty) if bound_ty.index == self.binder_index => {
327+
ty::Bound(debruijn, bound_ty) if debruijn == self.binder_index => {
328328
self.types.insert(
329329
bound_ty.var.as_u32(),
330330
match bound_ty.kind {

src/librustc/ty/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl<'a, 'gcx, 'lcx, 'tcx> ty::TyS<'tcx> {
213213
ty::Infer(ty::IntVar(_)) => "integral variable".into(),
214214
ty::Infer(ty::FloatVar(_)) => "floating-point variable".into(),
215215
ty::Placeholder(..) => "placeholder type".into(),
216-
ty::Bound(_) |
216+
ty::Bound(..) => "bound type".into(),
217217
ty::Infer(ty::FreshTy(_)) => "fresh type".into(),
218218
ty::Infer(ty::FreshIntTy(_)) => "fresh integral type".into(),
219219
ty::Infer(ty::FreshFloatTy(_)) => "fresh floating-point type".into(),

src/librustc/ty/flags.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ impl FlagComputation {
115115
self.add_substs(&substs.substs);
116116
}
117117

118-
&ty::Bound(bound_ty) => {
119-
self.add_binder(bound_ty.index);
118+
&ty::Bound(debruijn, _) => {
119+
self.add_binder(debruijn);
120120
}
121121

122122
&ty::Placeholder(..) => {

src/librustc/ty/fold.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,8 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for BoundVarReplacer<'a, 'gcx, 'tcx>
460460

461461
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
462462
match t.sty {
463-
ty::Bound(bound_ty) => {
464-
if bound_ty.index == self.current_index {
463+
ty::Bound(debruijn, bound_ty) => {
464+
if debruijn == self.current_index {
465465
let fld_t = &mut self.fld_t;
466466
let ty = fld_t(bound_ty);
467467
ty::fold::shift_vars(
@@ -526,7 +526,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
526526
T: TypeFoldable<'tcx>
527527
{
528528
// identity for bound types
529-
let fld_t = |bound_ty| self.mk_ty(ty::Bound(bound_ty));
529+
let fld_t = |bound_ty| self.mk_ty(ty::Bound(ty::INNERMOST, bound_ty));
530530
self.replace_escaping_bound_vars(value.skip_binder(), fld_r, fld_t)
531531
}
532532

@@ -722,16 +722,13 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Shifter<'a, 'gcx, 'tcx> {
722722

723723
fn fold_ty(&mut self, ty: ty::Ty<'tcx>) -> ty::Ty<'tcx> {
724724
match ty.sty {
725-
ty::Bound(bound_ty) => {
726-
if self.amount == 0 || bound_ty.index < self.current_index {
725+
ty::Bound(debruijn, bound_ty) => {
726+
if self.amount == 0 || debruijn < self.current_index {
727727
ty
728728
} else {
729-
let shifted = ty::BoundTy {
730-
index: bound_ty.index.shifted_in(self.amount),
731-
var: bound_ty.var,
732-
kind: bound_ty.kind,
733-
};
734-
self.tcx.mk_ty(ty::Bound(shifted))
729+
self.tcx.mk_ty(
730+
ty::Bound(debruijn.shifted_in(self.amount), bound_ty)
731+
)
735732
}
736733
}
737734

src/librustc/ty/sty.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ pub enum TyKind<'tcx> {
201201
Param(ParamTy),
202202

203203
/// Bound type variable, used only when preparing a trait query.
204-
Bound(BoundTy),
204+
Bound(ty::DebruijnIndex, BoundTy),
205205

206206
/// A placeholder type - universally quantified higher-ranked type.
207207
Placeholder(ty::PlaceholderType),
@@ -1245,7 +1245,6 @@ newtype_index! {
12451245

12461246
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)]
12471247
pub struct BoundTy {
1248-
pub index: DebruijnIndex,
12491248
pub var: BoundVar,
12501249
pub kind: BoundTyKind,
12511250
}
@@ -1256,13 +1255,12 @@ pub enum BoundTyKind {
12561255
Param(InternedString),
12571256
}
12581257

1259-
impl_stable_hash_for!(struct BoundTy { index, var, kind });
1258+
impl_stable_hash_for!(struct BoundTy { var, kind });
12601259
impl_stable_hash_for!(enum self::BoundTyKind { Anon, Param(a) });
12611260

1262-
impl BoundTy {
1263-
pub fn new(index: DebruijnIndex, var: BoundVar) -> Self {
1261+
impl From<BoundVar> for BoundTy {
1262+
fn from(var: BoundVar) -> Self {
12641263
BoundTy {
1265-
index,
12661264
var,
12671265
kind: BoundTyKind::Anon,
12681266
}
@@ -1957,7 +1955,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
19571955

19581956
ty::Infer(ty::TyVar(_)) => false,
19591957

1960-
ty::Bound(_) |
1958+
ty::Bound(..) |
19611959
ty::Placeholder(..) |
19621960
ty::Infer(ty::FreshTy(_)) |
19631961
ty::Infer(ty::FreshIntTy(_)) |

src/librustc/ty/subst.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,12 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
190190
Substs::for_item(tcx, def_id, |param, _| {
191191
match param.kind {
192192
ty::GenericParamDefKind::Type { .. } => {
193-
tcx.mk_ty(ty::Bound(ty::BoundTy {
194-
index: ty::INNERMOST,
195-
var: ty::BoundVar::from(param.index),
196-
kind: ty::BoundTyKind::Param(param.name),
197-
})).into()
193+
tcx.mk_ty(
194+
ty::Bound(ty::INNERMOST, ty::BoundTy {
195+
var: ty::BoundVar::from(param.index),
196+
kind: ty::BoundTyKind::Param(param.name),
197+
})
198+
).into()
198199
}
199200

200201
ty::GenericParamDefKind::Lifetime => {
@@ -584,18 +585,18 @@ impl CanonicalUserSubsts<'tcx> {
584585
self.value.substs.iter().zip(BoundVar::new(0)..).all(|(kind, cvar)| {
585586
match kind.unpack() {
586587
UnpackedKind::Type(ty) => match ty.sty {
587-
ty::Bound(b) => {
588+
ty::Bound(debruijn, b) => {
588589
// We only allow a `ty::INNERMOST` index in substitutions.
589-
assert_eq!(b.index, ty::INNERMOST);
590+
assert_eq!(debruijn, ty::INNERMOST);
590591
cvar == b.var
591592
}
592593
_ => false,
593594
},
594595

595596
UnpackedKind::Lifetime(r) => match r {
596-
ty::ReLateBound(index, br) => {
597+
ty::ReLateBound(debruijn, br) => {
597598
// We only allow a `ty::INNERMOST` index in substitutions.
598-
assert_eq!(*index, ty::INNERMOST);
599+
assert_eq!(*debruijn, ty::INNERMOST);
599600
cvar == br.assert_bound_var()
600601
}
601602
_ => false,

src/librustc/util/ppaux.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,13 +1110,13 @@ define_print! {
11101110
Infer(infer_ty) => write!(f, "{}", infer_ty),
11111111
Error => write!(f, "[type error]"),
11121112
Param(ref param_ty) => write!(f, "{}", param_ty),
1113-
Bound(bound_ty) => {
1113+
Bound(debruijn, bound_ty) => {
11141114
match bound_ty.kind {
11151115
ty::BoundTyKind::Anon => {
1116-
if bound_ty.index == ty::INNERMOST {
1116+
if debruijn == ty::INNERMOST {
11171117
write!(f, "^{}", bound_ty.var.index())
11181118
} else {
1119-
write!(f, "^{}_{}", bound_ty.index.index(), bound_ty.var.index())
1119+
write!(f, "^{}_{}", debruijn.index(), bound_ty.var.index())
11201120
}
11211121
}
11221122

src/librustc_traits/chalk_context/program_clauses.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ fn assemble_clauses_from_assoc_ty_values<'tcx>(
5959

6060
fn program_clauses_for_raw_ptr<'tcx>(tcx: ty::TyCtxt<'_, '_, 'tcx>) -> Clauses<'tcx> {
6161
let ty = ty::Bound(
62-
ty::BoundTy::new(ty::INNERMOST, ty::BoundVar::from_u32(0))
62+
ty::INNERMOST,
63+
ty::BoundVar::from_u32(0).into()
6364
);
6465
let ty = tcx.mk_ty(ty);
6566

@@ -88,9 +89,9 @@ fn program_clauses_for_fn_ptr<'tcx>(
8889
) -> Clauses<'tcx> {
8990
let inputs_and_output = tcx.mk_type_list(
9091
(0..arity_and_output).into_iter()
92+
.map(|i| ty::BoundVar::from(i))
9193
// DebruijnIndex(1) because we are going to inject these in a `PolyFnSig`
92-
.map(|i| ty::BoundTy::new(ty::DebruijnIndex::from(1usize), ty::BoundVar::from(i)))
93-
.map(|t| tcx.mk_ty(ty::Bound(t)))
94+
.map(|var| tcx.mk_ty(ty::Bound(ty::DebruijnIndex::from(1usize), var.into())))
9495
);
9596

9697
let fn_sig = ty::Binder::bind(ty::FnSig {
@@ -115,7 +116,8 @@ fn program_clauses_for_fn_ptr<'tcx>(
115116

116117
fn program_clauses_for_slice<'tcx>(tcx: ty::TyCtxt<'_, '_, 'tcx>) -> Clauses<'tcx> {
117118
let ty = ty::Bound(
118-
ty::BoundTy::new(ty::INNERMOST, ty::BoundVar::from_u32(0))
119+
ty::INNERMOST,
120+
ty::BoundVar::from_u32(0).into()
119121
);
120122
let ty = tcx.mk_ty(ty);
121123

@@ -151,7 +153,8 @@ fn program_clauses_for_array<'tcx>(
151153
length: &'tcx ty::Const<'tcx>
152154
) -> Clauses<'tcx> {
153155
let ty = ty::Bound(
154-
ty::BoundTy::new(ty::INNERMOST, ty::BoundVar::from_u32(0))
156+
ty::INNERMOST,
157+
ty::BoundVar::from_u32(0).into()
155158
);
156159
let ty = tcx.mk_ty(ty);
157160

@@ -188,8 +191,8 @@ fn program_clauses_for_tuple<'tcx>(
188191
) -> Clauses<'tcx> {
189192
let type_list = tcx.mk_type_list(
190193
(0..arity).into_iter()
191-
.map(|i| ty::BoundTy::new(ty::INNERMOST, ty::BoundVar::from(i)))
192-
.map(|t| tcx.mk_ty(ty::Bound(t)))
194+
.map(|i| ty::BoundVar::from(i))
195+
.map(|var| tcx.mk_ty(ty::Bound(ty::INNERMOST, var.into())))
193196
);
194197

195198
let tuple_ty = tcx.mk_ty(ty::Tuple(type_list));
@@ -233,7 +236,7 @@ fn program_clauses_for_ref<'tcx>(tcx: ty::TyCtxt<'_, '_, 'tcx>) -> Clauses<'tcx>
233236
ty::ReLateBound(ty::INNERMOST, ty::BoundRegion::BrAnon(0))
234237
);
235238
let ty = tcx.mk_ty(
236-
ty::Bound(ty::BoundTy::new(ty::INNERMOST, ty::BoundVar::from_u32(1)))
239+
ty::Bound(ty::INNERMOST, ty::BoundVar::from_u32(1).into())
237240
);
238241

239242
let ref_ty = tcx.mk_ref(region, ty::TypeAndMut {

src/librustc_traits/lowering/environment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl ClauseVisitor<'set, 'a, 'tcx> {
5555
ty::ReLateBound(ty::INNERMOST, ty::BoundRegion::BrAnon(0))
5656
);
5757
let ty = self.tcx.mk_ty(
58-
ty::Bound(ty::BoundTy::new(ty::INNERMOST, ty::BoundVar::from_u32(1)))
58+
ty::Bound(ty::INNERMOST, ty::BoundVar::from_u32(1).into())
5959
);
6060

6161
let ref_ty = self.tcx.mk_ref(region, ty::TypeAndMut {

src/librustc_traits/lowering/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,8 @@ pub fn program_clauses_for_associated_type_def<'a, 'tcx>(
515515
.unwrap_or(0);
516516
// Add a new type param after the existing ones (`U` in the comment above).
517517
let ty_var = ty::Bound(
518-
ty::BoundTy::new(ty::INNERMOST, ty::BoundVar::from_u32(offset + 1))
518+
ty::INNERMOST,
519+
ty::BoundVar::from_u32(offset + 1).into()
519520
);
520521

521522
// `ProjectionEq(<Self as Trait<P1..Pn>>::AssocType<Pn+1..Pm> = U)`

0 commit comments

Comments
 (0)