Skip to content

Commit e9c2685

Browse files
committed
Rename ConstValue::Infer(InferConst::Canonical(..)) to ConstValue::Bound(..)
1 parent 10f12fe commit e9c2685

File tree

17 files changed

+47
-64
lines changed

17 files changed

+47
-64
lines changed

src/librustc/infer/canonical/canonicalizer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
468468
ConstValue::Infer(InferConst::Fresh(_)) => {
469469
bug!("encountered a fresh const during canonicalization")
470470
}
471-
ConstValue::Infer(InferConst::Canonical(debruijn, _)) => {
471+
ConstValue::Bound(debruijn, _) => {
472472
if debruijn >= self.binder_index {
473473
bug!("escaping bound type during canonicalization")
474474
} else {
@@ -700,7 +700,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
700700
let var = self.canonical_var(info, const_var.into());
701701
self.tcx().mk_const(
702702
ty::Const {
703-
val: ConstValue::Infer(InferConst::Canonical(self.binder_index, var.into())),
703+
val: ConstValue::Bound(self.binder_index, var.into()),
704704
ty: self.fold_ty(const_var.ty),
705705
}
706706
)

src/librustc/infer/canonical/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use std::ops::Index;
3333
use syntax::source_map::Span;
3434
use crate::ty::fold::TypeFoldable;
3535
use crate::ty::subst::GenericArg;
36-
use crate::ty::{self, BoundVar, InferConst, Lift, List, Region, TyCtxt};
36+
use crate::ty::{self, BoundVar, Lift, List, Region, TyCtxt};
3737

3838
mod canonicalizer;
3939

@@ -510,9 +510,7 @@ impl<'tcx> CanonicalVarValues<'tcx> {
510510
GenericArgKind::Const(ct) => {
511511
tcx.mk_const(ty::Const {
512512
ty: ct.ty,
513-
val: ConstValue::Infer(
514-
InferConst::Canonical(ty::INNERMOST, ty::BoundVar::from_u32(i))
515-
),
513+
val: ConstValue::Bound(ty::INNERMOST, ty::BoundVar::from_u32(i)),
516514
}).into()
517515
}
518516
})

src/librustc/infer/canonical/query_response.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::traits::TraitEngine;
2626
use crate::traits::{Obligation, ObligationCause, PredicateObligation};
2727
use crate::ty::fold::TypeFoldable;
2828
use crate::ty::subst::{GenericArg, GenericArgKind};
29-
use crate::ty::{self, BoundVar, InferConst, Ty, TyCtxt};
29+
use crate::ty::{self, BoundVar, Ty, TyCtxt};
3030
use crate::util::captures::Captures;
3131

3232
impl<'tcx> InferCtxtBuilder<'tcx> {
@@ -493,10 +493,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
493493
}
494494
}
495495
GenericArgKind::Const(result_value) => {
496-
if let ty::Const {
497-
val: ConstValue::Infer(InferConst::Canonical(debrujin, b)),
498-
..
499-
} = result_value {
496+
if let ty::Const { val: ConstValue::Bound(debrujin, b), .. } = result_value {
500497
// ...in which case we would set `canonical_vars[0]` to `Some(const X)`.
501498

502499
// We only allow a `ty::INNERMOST` index in substitutions.

src/librustc/infer/freshen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
252252
return ct;
253253
}
254254

255-
ConstValue::Infer(ty::InferConst::Canonical(..)) |
255+
ConstValue::Bound(..) |
256256
ConstValue::Placeholder(_) => {
257257
bug!("unexpected const {:?}", ct)
258258
}

src/librustc/infer/nll_relate/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::ty::error::TypeError;
2727
use crate::ty::fold::{TypeFoldable, TypeVisitor};
2828
use crate::ty::relate::{self, Relate, RelateResult, TypeRelation};
2929
use crate::ty::subst::GenericArg;
30-
use crate::ty::{self, Ty, TyCtxt, InferConst};
30+
use crate::ty::{self, Ty, TyCtxt};
3131
use crate::mir::interpret::ConstValue;
3232
use rustc_data_structures::fx::FxHashMap;
3333
use std::fmt::Debug;
@@ -618,7 +618,7 @@ where
618618
a: &'tcx ty::Const<'tcx>,
619619
b: &'tcx ty::Const<'tcx>,
620620
) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> {
621-
if let ty::Const { val: ConstValue::Infer(InferConst::Canonical(_, _)), .. } = a {
621+
if let ty::Const { val: ConstValue::Bound(..), .. } = a {
622622
// FIXME(const_generics): I'm unsure how this branch should actually be handled,
623623
// so this is probably not correct.
624624
self.infcx.super_combine_consts(self, a, b)
@@ -993,7 +993,7 @@ where
993993
) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> {
994994
debug!("TypeGeneralizer::consts(a={:?})", a);
995995

996-
if let ty::Const { val: ConstValue::Infer(InferConst::Canonical(_, _)), .. } = a {
996+
if let ty::Const { val: ConstValue::Bound(..), .. } = a {
997997
bug!(
998998
"unexpected inference variable encountered in NLL generalization: {:?}",
999999
a

src/librustc/mir/interpret/value.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use rustc_apfloat::{Float, ieee::{Double, Single}};
55
use crate::ty::{Ty, InferConst, ParamConst, layout::{HasDataLayout, Size}, subst::SubstsRef};
66
use crate::ty::PlaceholderConst;
77
use crate::hir::def_id::DefId;
8+
use crate::ty::{BoundVar, DebruijnIndex};
89

910
use super::{InterpResult, Pointer, PointerArithmetic, Allocation, AllocId, sign_extend, truncate};
1011

@@ -28,6 +29,9 @@ pub enum ConstValue<'tcx> {
2829
/// Infer the value of the const.
2930
Infer(InferConst<'tcx>),
3031

32+
/// Bound const variable, used only when preparing a trait query.
33+
Bound(DebruijnIndex, BoundVar),
34+
3135
/// A placeholder const - universally quantified higher-ranked const.
3236
Placeholder(PlaceholderConst),
3337

@@ -66,8 +70,9 @@ impl<'tcx> ConstValue<'tcx> {
6670
match *self {
6771
ConstValue::Param(_) |
6872
ConstValue::Infer(_) |
73+
ConstValue::Bound(..) |
6974
ConstValue::Placeholder(_) |
70-
ConstValue::ByRef{ .. } |
75+
ConstValue::ByRef { .. } |
7176
ConstValue::Unevaluated(..) |
7277
ConstValue::Slice { .. } => None,
7378
ConstValue::Scalar(val) => Some(val),

src/librustc/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ impl CanonicalUserType<'tcx> {
882882
},
883883

884884
GenericArgKind::Const(ct) => match ct.val {
885-
ConstValue::Infer(InferConst::Canonical(debruijn, b)) => {
885+
ConstValue::Bound(debruijn, b) => {
886886
// We only allow a `ty::INNERMOST` index in substitutions.
887887
assert_eq!(debruijn, ty::INNERMOST);
888888
cvar == b

src/librustc/ty/flags.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,10 @@ impl FlagComputation {
240240
self.add_flags(TypeFlags::HAS_FREE_LOCAL_NAMES | TypeFlags::HAS_CT_INFER);
241241
match infer {
242242
InferConst::Fresh(_) => {}
243-
InferConst::Canonical(debruijn, _) => self.add_binder(debruijn),
244243
InferConst::Var(_) => self.add_flags(TypeFlags::KEEP_IN_LOCAL_TCX),
245244
}
246245
}
246+
ConstValue::Bound(debruijn, _) => self.add_binder(debruijn),
247247
ConstValue::Param(_) => {
248248
self.add_flags(TypeFlags::HAS_FREE_LOCAL_NAMES | TypeFlags::HAS_PARAMS);
249249
}

src/librustc/ty/fold.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -521,10 +521,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for BoundVarReplacer<'a, 'tcx> {
521521
}
522522

523523
fn fold_const(&mut self, ct: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
524-
if let ty::Const {
525-
val: ConstValue::Infer(ty::InferConst::Canonical(debruijn, bound_const)),
526-
ty,
527-
} = *ct {
524+
if let ty::Const { val: ConstValue::Bound(debruijn, bound_const), ty } = *ct {
528525
if debruijn == self.current_index {
529526
let fld_c = &mut self.fld_c;
530527
let ct = fld_c(bound_const, ty);
@@ -570,7 +567,10 @@ impl<'tcx> TyCtxt<'tcx> {
570567
// identity for bound types and consts
571568
let fld_t = |bound_ty| self.mk_ty(ty::Bound(ty::INNERMOST, bound_ty));
572569
let fld_c = |bound_ct, ty| {
573-
self.mk_const_infer(ty::InferConst::Canonical(ty::INNERMOST, bound_ct), ty)
570+
self.mk_const(ty::Const {
571+
val: ConstValue::Bound(ty::INNERMOST, bound_ct),
572+
ty,
573+
})
574574
};
575575
self.replace_escaping_bound_vars(value.skip_binder(), fld_r, fld_t, fld_c)
576576
}
@@ -802,10 +802,7 @@ impl TypeFolder<'tcx> for Shifter<'tcx> {
802802
}
803803

804804
fn fold_const(&mut self, ct: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
805-
if let ty::Const {
806-
val: ConstValue::Infer(ty::InferConst::Canonical(debruijn, bound_const)),
807-
ty,
808-
} = *ct {
805+
if let ty::Const { val: ConstValue::Bound(debruijn, bound_ct), ty } = *ct {
809806
if self.amount == 0 || debruijn < self.current_index {
810807
ct
811808
} else {
@@ -816,7 +813,10 @@ impl TypeFolder<'tcx> for Shifter<'tcx> {
816813
debruijn.shifted_out(self.amount)
817814
}
818815
};
819-
self.tcx.mk_const_infer(ty::InferConst::Canonical(debruijn, bound_const), ty)
816+
self.tcx.mk_const(ty::Const {
817+
val: ConstValue::Bound(debruijn, bound_ct),
818+
ty,
819+
})
820820
}
821821
} else {
822822
ct.super_fold_with(self)
@@ -920,8 +920,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasEscapingVarsVisitor {
920920
// const, as it has types/regions embedded in a lot of other
921921
// places.
922922
match ct.val {
923-
ConstValue::Infer(ty::InferConst::Canonical(debruijn, _))
924-
if debruijn >= self.outer_index => true,
923+
ConstValue::Bound(debruijn, _) if debruijn >= self.outer_index => true,
925924
_ => ct.super_visit_with(self),
926925
}
927926
}

src/librustc/ty/structural_impls.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,27 +1379,23 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Const<'tcx> {
13791379
impl<'tcx> TypeFoldable<'tcx> for ConstValue<'tcx> {
13801380
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
13811381
match *self {
1382-
ConstValue::ByRef { alloc, offset } =>
1383-
ConstValue::ByRef { alloc, offset },
13841382
ConstValue::Infer(ic) => ConstValue::Infer(ic.fold_with(folder)),
13851383
ConstValue::Param(p) => ConstValue::Param(p.fold_with(folder)),
1386-
ConstValue::Placeholder(p) => ConstValue::Placeholder(p),
1387-
ConstValue::Scalar(a) => ConstValue::Scalar(a),
1388-
ConstValue::Slice { data, start, end } => ConstValue::Slice { data, start, end },
13891384
ConstValue::Unevaluated(did, substs)
13901385
=> ConstValue::Unevaluated(did, substs.fold_with(folder)),
1386+
ConstValue::ByRef { .. } | ConstValue::Bound(..) | ConstValue::Placeholder(..)
1387+
| ConstValue::Scalar(..) | ConstValue::Slice { .. } => *self,
1388+
13911389
}
13921390
}
13931391

13941392
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
13951393
match *self {
1396-
ConstValue::ByRef { .. } => false,
13971394
ConstValue::Infer(ic) => ic.visit_with(visitor),
13981395
ConstValue::Param(p) => p.visit_with(visitor),
1399-
ConstValue::Placeholder(_) => false,
1400-
ConstValue::Scalar(_) => false,
1401-
ConstValue::Slice { .. } => false,
14021396
ConstValue::Unevaluated(_, substs) => substs.visit_with(visitor),
1397+
ConstValue::ByRef { .. } | ConstValue::Bound(..) | ConstValue::Placeholder(_)
1398+
| ConstValue::Scalar(_) | ConstValue::Slice { .. } => false,
14031399
}
14041400
}
14051401
}

0 commit comments

Comments
 (0)