Skip to content

Commit e9c2685

Browse files
committedOct 21, 2019
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

+2-2
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

+2-4
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

+2-5
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

+1-1
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

+3-3
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

+6-1
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

+1-1
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

+1-1
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

+11-12
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

+5-9
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
}

‎src/librustc/ty/sty.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2373,6 +2373,4 @@ pub enum InferConst<'tcx> {
23732373
Var(ConstVid<'tcx>),
23742374
/// A fresh const variable. See `infer::freshen` for more details.
23752375
Fresh(u32),
2376-
/// Canonicalized const variable, used only when preparing a trait query.
2377-
Canonical(DebruijnIndex, BoundVar),
23782376
}

‎src/librustc/ty/subst.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use crate::hir::def_id::DefId;
44
use crate::infer::canonical::Canonical;
5-
use crate::ty::{self, Lift, List, Ty, TyCtxt, InferConst, ParamConst};
5+
use crate::ty::{self, Lift, List, Ty, TyCtxt, ParamConst};
66
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
77
use crate::mir::interpret::ConstValue;
88
use crate::ty::sty::{ClosureSubsts, GeneratorSubsts};
@@ -234,9 +234,7 @@ impl<'a, 'tcx> InternalSubsts<'tcx> {
234234

235235
ty::GenericParamDefKind::Const => {
236236
tcx.mk_const(ty::Const {
237-
val: ConstValue::Infer(
238-
InferConst::Canonical(ty::INNERMOST, ty::BoundVar::from(param.index))
239-
),
237+
val: ConstValue::Bound(ty::INNERMOST, ty::BoundVar::from(param.index)),
240238
ty: tcx.type_of(def_id),
241239
}).into()
242240
}

‎src/librustc_codegen_ssa/mir/operand.rs

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
7979
ConstValue::Unevaluated(..) => bug!("unevaluated constant in `OperandRef::from_const`"),
8080
ConstValue::Param(_) => bug!("encountered a ConstValue::Param in codegen"),
8181
ConstValue::Infer(_) => bug!("encountered a ConstValue::Infer in codegen"),
82+
ConstValue::Bound(..) => bug!("encountered a ConstValue::Bound in codegen"),
8283
ConstValue::Placeholder(_) => bug!("encountered a ConstValue::Placeholder in codegen"),
8384
ConstValue::Scalar(x) => {
8485
let scalar = match layout.abi {

‎src/librustc_mir/interpret/operand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
589589
let ptr = self.tag_static_base_pointer(Pointer::new(id, offset));
590590
Operand::Indirect(MemPlace::from_ptr(ptr, layout.align.abi))
591591
},
592-
ConstValue::Scalar(x) =>
593-
Operand::Immediate(tag_scalar(x).into()),
592+
ConstValue::Scalar(x) => Operand::Immediate(tag_scalar(x).into()),
594593
ConstValue::Slice { data, start, end } => {
595594
// We rely on mutability being set correctly in `data` to prevent writes
596595
// where none should happen.
@@ -606,6 +605,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
606605
}
607606
ConstValue::Param(..) |
608607
ConstValue::Infer(..) |
608+
ConstValue::Bound(..) |
609609
ConstValue::Placeholder(..) |
610610
ConstValue::Unevaluated(..) =>
611611
bug!("eval_const_to_op: Unexpected ConstValue {:?}", val),

‎src/librustc_traits/chalk_context/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use rustc::traits::{
3333
InEnvironment,
3434
ChalkCanonicalGoal,
3535
};
36-
use rustc::ty::{self, TyCtxt, InferConst};
36+
use rustc::ty::{self, TyCtxt};
3737
use rustc::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
3838
use rustc::ty::query::Providers;
3939
use rustc::ty::subst::{GenericArg, GenericArgKind};
@@ -286,7 +286,7 @@ impl context::ContextOps<ChalkArenas<'tcx>> for ChalkContext<'tcx> {
286286
_ => false,
287287
},
288288
GenericArgKind::Const(ct) => match ct.val {
289-
ConstValue::Infer(InferConst::Canonical(debruijn, bound_ct)) => {
289+
ConstValue::Bound(debruijn, bound_ct) => {
290290
debug_assert_eq!(debruijn, ty::INNERMOST);
291291
cvar == bound_ct
292292
}

‎src/librustc_traits/chalk_context/resolvent_ops.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc::traits::{
1616
Environment,
1717
InEnvironment,
1818
};
19-
use rustc::ty::{self, Ty, TyCtxt, InferConst};
19+
use rustc::ty::{self, Ty, TyCtxt};
2020
use rustc::ty::subst::GenericArg;
2121
use rustc::ty::relate::{Relate, RelateResult, TypeRelation};
2222
use rustc::mir::interpret::ConstValue;
@@ -287,10 +287,7 @@ impl TypeRelation<'tcx> for AnswerSubstitutor<'cx, 'tcx> {
287287
a: &'tcx ty::Const<'tcx>,
288288
b: &'tcx ty::Const<'tcx>,
289289
) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> {
290-
if let ty::Const {
291-
val: ConstValue::Infer(InferConst::Canonical(debruijn, bound_ct)),
292-
..
293-
} = a {
290+
if let ty::Const { val: ConstValue::Bound(debruijn, bound_ct), .. } = a {
294291
if *debruijn == self.binder_index {
295292
self.unify_free_answer_var(*bound_ct, b.into())?;
296293
return Ok(b);
@@ -299,14 +296,8 @@ impl TypeRelation<'tcx> for AnswerSubstitutor<'cx, 'tcx> {
299296

300297
match (a, b) {
301298
(
302-
ty::Const {
303-
val: ConstValue::Infer(InferConst::Canonical(a_debruijn, a_bound)),
304-
..
305-
},
306-
ty::Const {
307-
val: ConstValue::Infer(InferConst::Canonical(b_debruijn, b_bound)),
308-
..
309-
},
299+
ty::Const { val: ConstValue::Bound(a_debruijn, a_bound), .. },
300+
ty::Const { val: ConstValue::Bound(b_debruijn, b_bound), .. },
310301
) => {
311302
assert_eq!(a_debruijn, b_debruijn);
312303
assert_eq!(a_bound, b_bound);

‎src/test/ui/symbol-names/impl1.legacy.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ error: def-path(bar::<impl foo::Foo>::baz)
4646
LL | #[rustc_def_path]
4747
| ^^^^^^^^^^^^^^^^^
4848

49-
error: symbol-name(_ZN209_$LT$$u5b$$RF$dyn$u20$impl1..Foo$u2b$Assoc$u20$$u3d$$u20$extern$u20$$u22$C$u22$$u20$fn$LP$$RF$u8$C$$u20$...$RP$$u2b$impl1..AutoTrait$u3b$$u20$_$u5d$$u20$as$u20$impl1..main..$u7b$$u7b$closure$u7d$$u7d$..Bar$GT$6method17h059bf53000885489E)
49+
error: symbol-name(_ZN209_$LT$$u5b$$RF$dyn$u20$impl1..Foo$u2b$Assoc$u20$$u3d$$u20$extern$u20$$u22$C$u22$$u20$fn$LP$$RF$u8$C$$u20$...$RP$$u2b$impl1..AutoTrait$u3b$$u20$_$u5d$$u20$as$u20$impl1..main..$u7b$$u7b$closure$u7d$$u7d$..Bar$GT$6method17h636bc933fc62ee2fE)
5050
--> $DIR/impl1.rs:61:13
5151
|
5252
LL | #[rustc_symbol_name]
5353
| ^^^^^^^^^^^^^^^^^^^^
5454

55-
error: demangling(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8, ::.)+impl1::AutoTrait; _] as impl1::main::{{closure}}::Bar>::method::h059bf53000885489)
55+
error: demangling(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8, ::.)+impl1::AutoTrait; _] as impl1::main::{{closure}}::Bar>::method::h636bc933fc62ee2f)
5656
--> $DIR/impl1.rs:61:13
5757
|
5858
LL | #[rustc_symbol_name]

0 commit comments

Comments
 (0)
Please sign in to comment.