Skip to content

Commit 4bb9648

Browse files
committed
Merge ConstVal and ConstValue
1 parent 221a499 commit 4bb9648

35 files changed

+201
-338
lines changed

src/librustc/dep_graph/dep_node.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
//! user of the `DepNode` API of having to know how to compute the expected
6161
//! fingerprint for a given set of node parameters.
6262
63-
use mir::interpret::{GlobalId, ConstValue};
63+
use mir::interpret::GlobalId;
6464
use hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX};
6565
use hir::map::DefPathHash;
6666
use hir::{HirId, ItemLocalId};
@@ -75,7 +75,7 @@ use traits::query::{
7575
CanonicalPredicateGoal, CanonicalTypeOpProvePredicateGoal, CanonicalTypeOpNormalizeGoal,
7676
};
7777
use ty::{TyCtxt, FnSig, Instance, InstanceDef,
78-
ParamEnv, ParamEnvAnd, Predicate, PolyFnSig, PolyTraitRef, Ty};
78+
ParamEnv, ParamEnvAnd, Predicate, PolyFnSig, PolyTraitRef, Ty, self};
7979
use ty::subst::Substs;
8080

8181
// erase!() just makes tokens go away. It's used to specify which macro argument
@@ -632,7 +632,7 @@ define_dep_nodes!( <'tcx>
632632
// queries). Making them anonymous avoids hashing the result, which
633633
// may save a bit of time.
634634
[anon] EraseRegionsTy { ty: Ty<'tcx> },
635-
[anon] ConstValueToAllocation { val: ConstValue<'tcx>, ty: Ty<'tcx> },
635+
[anon] ConstValueToAllocation { val: &'tcx ty::Const<'tcx> },
636636

637637
[input] Freevars(DefId),
638638
[input] MaybeUnusedTraitImport(DefId),

src/librustc/ich/impls_ty.rs

+2-19
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,11 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::FieldDef {
370370
}
371371

372372
impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
373-
for ::mir::interpret::ConstVal<'gcx> {
373+
for ::mir::interpret::ConstValue<'gcx> {
374374
fn hash_stable<W: StableHasherResult>(&self,
375375
hcx: &mut StableHashingContext<'a>,
376376
hasher: &mut StableHasher<W>) {
377-
use mir::interpret::ConstVal::*;
377+
use mir::interpret::ConstValue::*;
378378

379379
mem::discriminant(self).hash_stable(hcx, hasher);
380380

@@ -383,23 +383,6 @@ for ::mir::interpret::ConstVal<'gcx> {
383383
def_id.hash_stable(hcx, hasher);
384384
substs.hash_stable(hcx, hasher);
385385
}
386-
Value(ref value) => {
387-
value.hash_stable(hcx, hasher);
388-
}
389-
}
390-
}
391-
}
392-
393-
impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
394-
for ::mir::interpret::ConstValue<'gcx> {
395-
fn hash_stable<W: StableHasherResult>(&self,
396-
hcx: &mut StableHashingContext<'a>,
397-
hasher: &mut StableHasher<W>) {
398-
use mir::interpret::ConstValue::*;
399-
400-
mem::discriminant(self).hash_stable(hcx, hasher);
401-
402-
match *self {
403386
Scalar(val) => {
404387
val.hash_stable(hcx, hasher);
405388
}

src/librustc/mir/interpret/error.rs

-10
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,15 @@ use super::{
1111

1212
use backtrace::Backtrace;
1313

14-
15-
use hir::def_id::DefId;
1614
use ty;
17-
use ty::subst::Substs;
1815
use ty::query::TyCtxtAt;
19-
use mir::interpret::ConstValue;
2016
use errors::DiagnosticBuilder;
2117

2218
use syntax_pos::Span;
2319
use syntax::ast;
2420

2521
pub type ConstEvalResult<'tcx> = Result<&'tcx ty::Const<'tcx>, Lrc<ConstEvalErr<'tcx>>>;
2622

27-
#[derive(Copy, Clone, Debug, Hash, RustcEncodable, RustcDecodable, Eq, PartialEq, Ord, PartialOrd)]
28-
pub enum ConstVal<'tcx> {
29-
Unevaluated(DefId, &'tcx Substs<'tcx>),
30-
Value(ConstValue<'tcx>),
31-
}
32-
3323
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
3424
pub struct ConstEvalErr<'tcx> {
3525
pub span: Span,

src/librustc/mir/interpret/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod error;
99
mod value;
1010

1111
pub use self::error::{
12-
EvalError, EvalResult, EvalErrorKind, AssertMessage, ConstVal, ConstEvalErr, struct_error,
12+
EvalError, EvalResult, EvalErrorKind, AssertMessage, ConstEvalErr, struct_error,
1313
FrameInfo, ConstEvalResult,
1414
};
1515

src/librustc/mir/interpret/value.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22

33
use ty::layout::{Align, HasDataLayout, Size};
44
use ty;
5+
use ty::subst::Substs;
6+
use hir::def_id::DefId;
57

68
use super::{EvalResult, Pointer, PointerArithmetic, Allocation};
79

810
/// Represents a constant value in Rust. ByVal and ScalarPair are optimizations which
911
/// matches Value's optimizations for easy conversions between these two types
10-
#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash)]
12+
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash)]
1113
pub enum ConstValue<'tcx> {
14+
/// Never returned from the `const_eval` query, but the HIR contains these frequently in order
15+
/// to allow HIR creation to happen for everything before needing to be able to run constant
16+
/// evaluation
17+
Unevaluated(DefId, &'tcx Substs<'tcx>),
1218
/// Used only for types with layout::abi::Scalar ABI and ZSTs which use Scalar::undef()
1319
Scalar(Scalar),
1420
/// Used only for types with layout::abi::ScalarPair
@@ -30,6 +36,7 @@ impl<'tcx> ConstValue<'tcx> {
3036
#[inline]
3137
pub fn to_byval_value(&self) -> Option<Value> {
3238
match *self {
39+
ConstValue::Unevaluated(..) |
3340
ConstValue::ByRef(..) => None,
3441
ConstValue::ScalarPair(a, b) => Some(Value::ScalarPair(a, b)),
3542
ConstValue::Scalar(val) => Some(Value::Scalar(val)),
@@ -44,7 +51,8 @@ impl<'tcx> ConstValue<'tcx> {
4451
#[inline]
4552
pub fn to_scalar(&self) -> Option<Scalar> {
4653
match *self {
47-
ConstValue::ByRef(..) => None,
54+
ConstValue::Unevaluated(..) |
55+
ConstValue::ByRef(..) |
4856
ConstValue::ScalarPair(..) => None,
4957
ConstValue::Scalar(val) => Some(val),
5058
}

src/librustc/mir/mod.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -2162,18 +2162,12 @@ impl<'tcx> Debug for Literal<'tcx> {
21622162
}
21632163
}
21642164

2165-
/// Write a `ConstVal` in a way closer to the original source code than the `Debug` output.
2165+
/// Write a `ConstValue` in a way closer to the original source code than the `Debug` output.
21662166
pub fn fmt_const_val<W: Write>(fmt: &mut W, const_val: &ty::Const) -> fmt::Result {
2167-
use mir::interpret::ConstVal;
2168-
match const_val.val {
2169-
ConstVal::Unevaluated(..) => write!(fmt, "{:?}", const_val),
2170-
ConstVal::Value(val) => {
2171-
if let Some(value) = val.to_byval_value() {
2172-
print_miri_value(value, const_val.ty, fmt)
2173-
} else {
2174-
write!(fmt, "{:?}:{}", val, const_val.ty)
2175-
}
2176-
}
2167+
if let Some(value) = const_val.to_byval_value() {
2168+
print_miri_value(value, const_val.ty, fmt)
2169+
} else {
2170+
write!(fmt, "{:?}:{}", const_val.val, const_val.ty)
21772171
}
21782172
}
21792173

src/librustc/traits/project.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use super::util;
2828
use hir::def_id::DefId;
2929
use infer::{InferCtxt, InferOk};
3030
use infer::type_variable::TypeVariableOrigin;
31-
use mir::interpret::ConstVal;
31+
use mir::interpret::ConstValue;
3232
use mir::interpret::{GlobalId};
3333
use rustc_data_structures::snapshot_map::{Snapshot, SnapshotMap};
3434
use syntax::symbol::Symbol;
@@ -426,7 +426,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for AssociatedTypeNormalizer<'a,
426426
}
427427

428428
fn fold_const(&mut self, constant: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
429-
if let ConstVal::Unevaluated(def_id, substs) = constant.val {
429+
if let ConstValue::Unevaluated(def_id, substs) = constant.val {
430430
let tcx = self.selcx.tcx().global_tcx();
431431
if let Some(param_env) = self.tcx().lift_to_global(&self.param_env) {
432432
if substs.needs_infer() || substs.has_skol() {

src/librustc/traits/query/normalize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for QueryNormalizer<'cx, 'gcx, 'tcx
194194
}
195195

196196
fn fold_const(&mut self, constant: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
197-
if let ConstVal::Unevaluated(def_id, substs) = constant.val {
197+
if let ConstValue::Unevaluated(def_id, substs) = constant.val {
198198
let tcx = self.infcx.tcx.global_tcx();
199199
if let Some(param_env) = self.tcx().lift_to_global(&self.param_env) {
200200
if substs.needs_infer() || substs.has_skol() {

src/librustc/ty/flags.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use mir::interpret::ConstVal;
11+
use mir::interpret::ConstValue;
1212
use ty::subst::Substs;
1313
use ty::{self, Ty, TypeFlags, TypeFoldable};
1414

@@ -233,12 +233,9 @@ impl FlagComputation {
233233

234234
fn add_const(&mut self, constant: &ty::Const) {
235235
self.add_ty(constant.ty);
236-
match constant.val {
237-
ConstVal::Value(_) => {}
238-
ConstVal::Unevaluated(_, substs) => {
239-
self.add_flags(TypeFlags::HAS_PROJECTION);
240-
self.add_substs(substs);
241-
}
236+
if let ConstValue::Unevaluated(_, substs) = constant.val {
237+
self.add_flags(TypeFlags::HAS_PROJECTION);
238+
self.add_substs(substs);
242239
}
243240
}
244241

src/librustc/ty/fold.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
//! These methods return true to indicate that the visitor has found what it is looking for
4040
//! and does not need to visit anything else.
4141
42-
use mir::interpret::ConstVal;
42+
use mir::interpret::ConstValue;
4343
use hir::def_id::DefId;
4444
use ty::{self, Binder, Ty, TyCtxt, TypeFlags};
4545

@@ -685,7 +685,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
685685
}
686686

687687
fn visit_const(&mut self, c: &'tcx ty::Const<'tcx>) -> bool {
688-
if let ConstVal::Unevaluated(..) = c.val {
688+
if let ConstValue::Unevaluated(..) = c.val {
689689
let projection_flags = TypeFlags::HAS_NORMALIZABLE_PROJECTION |
690690
TypeFlags::HAS_PROJECTION;
691691
if projection_flags.intersects(self.flags) {

src/librustc/ty/query/config.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use dep_graph::SerializedDepNodeIndex;
1212
use dep_graph::DepNode;
1313
use hir::def_id::{CrateNum, DefId, DefIndex};
14-
use mir::interpret::{GlobalId, ConstValue};
14+
use mir::interpret::GlobalId;
1515
use traits::query::{
1616
CanonicalPredicateGoal, CanonicalProjectionGoal, CanonicalTyGoal, CanonicalTypeOpEqGoal,
1717
CanonicalTypeOpNormalizeGoal, CanonicalTypeOpProvePredicateGoal, CanonicalTypeOpSubtypeGoal,
@@ -191,8 +191,8 @@ impl<'tcx> QueryDescription<'tcx> for queries::super_predicates_of<'tcx> {
191191
}
192192

193193
impl<'tcx> QueryDescription<'tcx> for queries::const_value_to_allocation<'tcx> {
194-
fn describe(_tcx: TyCtxt, (val, ty): (ConstValue<'tcx>, Ty<'tcx>)) -> String {
195-
format!("converting value `{:?}` ({}) to an allocation", val, ty)
194+
fn describe(_tcx: TyCtxt, val: &'tcx ty::Const<'tcx>) -> String {
195+
format!("converting value `{:?}` to an allocation", val)
196196
}
197197
}
198198

src/librustc/ty/query/keys.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl<'tcx> Key for ty::PolyTraitRef<'tcx>{
145145
}
146146
}
147147

148-
impl<'tcx> Key for (mir::interpret::ConstValue<'tcx>, Ty<'tcx>) {
148+
impl<'tcx> Key for &'tcx ty::Const<'tcx> {
149149
fn query_crate(&self) -> CrateNum {
150150
LOCAL_CRATE
151151
}

src/librustc/ty/query/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use middle::exported_symbols::{SymbolExportLevel, ExportedSymbol};
2929
use mir::interpret::ConstEvalResult;
3030
use mir::mono::{CodegenUnit, Stats};
3131
use mir;
32-
use mir::interpret::{GlobalId, Allocation, ConstValue};
32+
use mir::interpret::{GlobalId, Allocation};
3333
use session::{CompileResult, CrateDisambiguator};
3434
use session::config::OutputFilenames;
3535
use traits::{self, Vtable};
@@ -234,7 +234,7 @@ define_queries! { <'tcx>
234234

235235
/// Converts a constant value to an constant allocation
236236
[] fn const_value_to_allocation: const_value_to_allocation(
237-
(ConstValue<'tcx>, Ty<'tcx>)
237+
&'tcx ty::Const<'tcx>
238238
) -> &'tcx Allocation,
239239

240240
[] fn check_match: CheckMatch(DefId)
@@ -570,9 +570,9 @@ fn erase_regions_ty<'tcx>(ty: Ty<'tcx>) -> DepConstructor<'tcx> {
570570
}
571571

572572
fn const_value_to_allocation<'tcx>(
573-
(val, ty): (ConstValue<'tcx>, Ty<'tcx>)
573+
val: &'tcx ty::Const<'tcx>,
574574
) -> DepConstructor<'tcx> {
575-
DepConstructor::ConstValueToAllocation { val, ty }
575+
DepConstructor::ConstValueToAllocation { val }
576576
}
577577

578578
fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {

src/librustc/ty/relate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//! type equality, etc.
1515
1616
use hir::def_id::DefId;
17-
use mir::interpret::ConstVal;
17+
use mir::interpret::ConstValue;
1818
use ty::subst::{Kind, UnpackedKind, Substs};
1919
use ty::{self, Ty, TyCtxt, TypeFoldable};
2020
use ty::error::{ExpectedFound, TypeError};
@@ -474,7 +474,7 @@ pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R,
474474
return Ok(s);
475475
}
476476
match x.val {
477-
ConstVal::Unevaluated(def_id, substs) => {
477+
ConstValue::Unevaluated(def_id, substs) => {
478478
// FIXME(eddyb) get the right param_env.
479479
let param_env = ty::ParamEnv::empty();
480480
match tcx.lift_to_global(&substs) {

src/librustc/ty/structural_impls.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//! hand, though we've recently added some macros (e.g.,
1414
//! `BraceStructLiftImpl!`) to help with the tedium.
1515
16-
use mir::interpret::{ConstVal, ConstEvalErr};
16+
use mir::interpret::{ConstValue, ConstEvalErr};
1717
use ty::{self, Lift, Ty, TyCtxt};
1818
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
1919
use rustc_data_structures::accumulate_vec::AccumulateVec;
@@ -1127,20 +1127,24 @@ EnumTypeFoldableImpl! {
11271127
}
11281128
}
11291129

1130-
impl<'tcx> TypeFoldable<'tcx> for ConstVal<'tcx> {
1130+
impl<'tcx> TypeFoldable<'tcx> for ConstValue<'tcx> {
11311131
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
11321132
match *self {
1133-
ConstVal::Value(v) => ConstVal::Value(v),
1134-
ConstVal::Unevaluated(def_id, substs) => {
1135-
ConstVal::Unevaluated(def_id, substs.fold_with(folder))
1133+
ConstValue::Scalar(v) => ConstValue::Scalar(v),
1134+
ConstValue::ScalarPair(a, b) => ConstValue::ScalarPair(a, b),
1135+
ConstValue::ByRef(alloc, offset) => ConstValue::ByRef(alloc, offset),
1136+
ConstValue::Unevaluated(def_id, substs) => {
1137+
ConstValue::Unevaluated(def_id, substs.fold_with(folder))
11361138
}
11371139
}
11381140
}
11391141

11401142
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
11411143
match *self {
1142-
ConstVal::Value(_) => false,
1143-
ConstVal::Unevaluated(_, substs) => substs.visit_with(visitor),
1144+
ConstValue::Scalar(_) |
1145+
ConstValue::ScalarPair(_, _) |
1146+
ConstValue::ByRef(_, _) => false,
1147+
ConstValue::Unevaluated(_, substs) => substs.visit_with(visitor),
11441148
}
11451149
}
11461150
}

0 commit comments

Comments
 (0)