Skip to content

Commit 7378c25

Browse files
committed
Rename in librustc_mir.
1 parent 028c83c commit 7378c25

File tree

12 files changed

+66
-46
lines changed

12 files changed

+66
-46
lines changed

src/librustc_mir/borrow_check/nll/type_check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc::infer::canonical::QueryRegionConstraints;
2727
use rustc::infer::outlives::env::RegionBoundPairs;
2828
use rustc::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime, NLLRegionVariableOrigin};
2929
use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
30-
use rustc::mir::interpret::{ConstValue, PanicInfo};
30+
use rustc::mir::interpret::PanicInfo;
3131
use rustc::mir::tcx::PlaceTy;
3232
use rustc::mir::visit::{PlaceContext, Visitor, NonMutatingUseContext};
3333
use rustc::mir::*;
@@ -309,7 +309,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
309309
);
310310
}
311311
} else {
312-
if let ConstValue::Unevaluated(def_id, substs) = constant.literal.val {
312+
if let ty::ConstKind::Unevaluated(def_id, substs) = constant.literal.val {
313313
if let Err(terr) = self.cx.fully_perform_op(
314314
location.to_locations(),
315315
ConstraintCategory::Boring,

src/librustc_mir/const_eval.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn op_to_const<'tcx>(
128128
}
129129
},
130130
};
131-
ecx.tcx.mk_const(ty::Const { val, ty: op.layout.ty })
131+
ecx.tcx.mk_const(ty::Const { val: ty::ConstKind::Value(val), ty: op.layout.ty })
132132
}
133133

134134
// Returns a pointer to where the result lives
@@ -519,7 +519,7 @@ pub fn const_caller_location<'tcx>(
519519
intern_const_alloc_recursive(&mut ecx, None, loc_place).unwrap();
520520
let loc_const = ty::Const {
521521
ty: loc_ty,
522-
val: ConstValue::Scalar(loc_place.ptr.into()),
522+
val: ty::ConstKind::Value(ConstValue::Scalar(loc_place.ptr.into())),
523523
};
524524

525525
tcx.mk_const(loc_const)
@@ -580,10 +580,10 @@ fn validate_and_turn_into_const<'tcx>(
580580
if tcx.is_static(def_id) || cid.promoted.is_some() {
581581
let ptr = mplace.ptr.to_ptr()?;
582582
Ok(tcx.mk_const(ty::Const {
583-
val: ConstValue::ByRef {
583+
val: ty::ConstKind::Value(ConstValue::ByRef {
584584
alloc: ecx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id),
585585
offset: ptr.offset,
586-
},
586+
}),
587587
ty: mplace.layout.ty,
588588
}))
589589
} else {

src/librustc_mir/hair/constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ crate fn lit_to_const<'tcx>(
5656
LitKind::Char(c) => ConstValue::Scalar(Scalar::from_char(c)),
5757
LitKind::Err(_) => unreachable!(),
5858
};
59-
Ok(tcx.mk_const(ty::Const { val: lit, ty }))
59+
Ok(tcx.mk_const(ty::Const { val: ty::ConstKind::Value(lit), ty }))
6060
}
6161

6262
fn parse_float<'tcx>(

src/librustc_mir/hair/cx/expr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::hair::cx::to_ref::ToRef;
55
use crate::hair::util::UserAnnotatedTyHelpers;
66
use rustc_index::vec::Idx;
77
use rustc::hir::def::{CtorOf, Res, DefKind, CtorKind};
8-
use rustc::mir::interpret::{GlobalId, ErrorHandled, ConstValue};
8+
use rustc::mir::interpret::{GlobalId, ErrorHandled};
99
use rustc::ty::{self, AdtKind, Ty};
1010
use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow, AutoBorrowMutability, PointerCast};
1111
use rustc::ty::subst::{InternalSubsts, SubstsRef};
@@ -692,7 +692,7 @@ fn make_mirror_unadjusted<'a, 'tcx>(
692692
// and not the beginning of discriminants (which is always `0`)
693693
let substs = InternalSubsts::identity_for_item(cx.tcx(), did);
694694
let lhs = mk_const(cx.tcx().mk_const(ty::Const {
695-
val: ConstValue::Unevaluated(did, substs),
695+
val: ty::ConstKind::Unevaluated(did, substs),
696696
ty: var_ty,
697697
}));
698698
let bin = ExprKind::Binary {
@@ -914,7 +914,7 @@ fn convert_path_expr<'a, 'tcx>(
914914
let local_def_id = cx.tcx.hir().local_def_id(hir_id);
915915
let index = generics.param_def_id_to_index[&local_def_id];
916916
let name = cx.tcx.hir().name(hir_id);
917-
let val = ConstValue::Param(ty::ParamConst::new(index, name));
917+
let val = ty::ConstKind::Param(ty::ParamConst::new(index, name));
918918
ExprKind::Literal {
919919
literal: cx.tcx.mk_const(
920920
ty::Const {
@@ -932,7 +932,7 @@ fn convert_path_expr<'a, 'tcx>(
932932
debug!("convert_path_expr: (const) user_ty={:?}", user_ty);
933933
ExprKind::Literal {
934934
literal: cx.tcx.mk_const(ty::Const {
935-
val: ConstValue::Unevaluated(def_id, substs),
935+
val: ty::ConstKind::Unevaluated(def_id, substs),
936936
ty: cx.tables().node_type(expr.hir_id),
937937
}),
938938
user_ty,

src/librustc_mir/hair/pattern/_match.rs

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,10 @@ impl PatternFolder<'tcx> for LiteralExpander<'tcx> {
313313
(
314314
&ty::Ref(_, rty, _),
315315
&PatKind::Constant {
316-
value: Const { val, ty: ty::TyS { kind: ty::Ref(_, crty, _), .. } },
316+
value: Const {
317+
val: ty::ConstKind::Value(val),
318+
ty: ty::TyS { kind: ty::Ref(_, crty, _), .. }
319+
},
317320
},
318321
) => Pat {
319322
ty: pat.ty,
@@ -324,13 +327,21 @@ impl PatternFolder<'tcx> for LiteralExpander<'tcx> {
324327
span: pat.span,
325328
kind: box PatKind::Constant {
326329
value: self.tcx.mk_const(Const {
327-
val: self.fold_const_value_deref(*val, rty, crty),
330+
val: ty::ConstKind::Value(self.fold_const_value_deref(*val, rty, crty)),
328331
ty: rty,
329332
}),
330333
},
331334
},
332335
},
333336
},
337+
338+
(
339+
&ty::Ref(_, rty, _),
340+
&PatKind::Constant {
341+
value: Const { val, ty: ty::TyS { kind: ty::Ref(_, crty, _), .. } },
342+
},
343+
) => bug!("cannot deref {:#?}, {} -> {}", val, crty, rty),
344+
334345
(_, &PatKind::Binding { subpattern: Some(ref s), .. }) => s.fold_with(self),
335346
_ => pat.super_fold_with(self),
336347
}
@@ -1245,7 +1256,7 @@ impl<'tcx> IntRange<'tcx> {
12451256
) -> Option<IntRange<'tcx>> {
12461257
if let Some((target_size, bias)) = Self::integral_size_and_signed_bias(tcx, value.ty) {
12471258
let ty = value.ty;
1248-
let val = if let ConstValue::Scalar(Scalar::Raw { data, size }) = value.val {
1259+
let val = if let ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw { data, size })) = value.val {
12491260
// For this specific pattern we can skip a lot of effort and go
12501261
// straight to the result, after doing a bit of checking. (We
12511262
// could remove this branch and just use the next branch, which
@@ -1781,7 +1792,19 @@ fn slice_pat_covered_by_const<'tcx>(
17811792
suffix: &[Pat<'tcx>],
17821793
param_env: ty::ParamEnv<'tcx>,
17831794
) -> Result<bool, ErrorReported> {
1784-
let data: &[u8] = match (const_val.val, &const_val.ty.kind) {
1795+
let const_val_val = if let ty::ConstKind::Value(val) = const_val.val {
1796+
val
1797+
} else {
1798+
bug!(
1799+
"slice_pat_covered_by_const: {:#?}, {:#?}, {:#?}, {:#?}",
1800+
const_val,
1801+
prefix,
1802+
slice,
1803+
suffix,
1804+
)
1805+
};
1806+
1807+
let data: &[u8] = match (const_val_val, &const_val.ty.kind) {
17851808
(ConstValue::ByRef { offset, alloc, .. }, ty::Array(t, n)) => {
17861809
assert_eq!(*t, tcx.types.u8);
17871810
let n = n.eval_usize(tcx, param_env);
@@ -2054,7 +2077,8 @@ fn split_grouped_constructors<'p, 'tcx>(
20542077
max_fixed_len =
20552078
cmp::max(max_fixed_len, n.eval_usize(tcx, param_env))
20562079
}
2057-
(ConstValue::Slice { start, end, .. }, ty::Slice(_)) => {
2080+
(ty::ConstKind::Value(ConstValue::Slice { start, end, .. }),
2081+
ty::Slice(_)) => {
20582082
max_fixed_len = cmp::max(max_fixed_len, (end - start) as u64)
20592083
}
20602084
_ => {}
@@ -2253,17 +2277,17 @@ fn specialize_one_pattern<'p, 'a: 'p, 'q: 'p, 'tcx>(
22532277
// is when they are subslices of nonzero slices.
22542278
let (alloc, offset, n, ty) = match value.ty.kind {
22552279
ty::Array(t, n) => match value.val {
2256-
ConstValue::ByRef { offset, alloc, .. } => {
2280+
ty::ConstKind::Value(ConstValue::ByRef { offset, alloc, .. }) => {
22572281
(alloc, offset, n.eval_usize(cx.tcx, cx.param_env), t)
22582282
}
22592283
_ => span_bug!(pat.span, "array pattern is {:?}", value,),
22602284
},
22612285
ty::Slice(t) => {
22622286
match value.val {
2263-
ConstValue::Slice { data, start, end } => {
2287+
ty::ConstKind::Value(ConstValue::Slice { data, start, end }) => {
22642288
(data, Size::from_bytes(start as u64), (end - start) as u64, t)
22652289
}
2266-
ConstValue::ByRef { .. } => {
2290+
ty::ConstKind::Value(ConstValue::ByRef { .. }) => {
22672291
// FIXME(oli-obk): implement `deref` for `ConstValue`
22682292
return None;
22692293
}

src/librustc_mir/hair/pattern/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,9 +1197,10 @@ pub fn compare_const_vals<'tcx>(
11971197

11981198
if let ty::Str = ty.kind {
11991199
match (a.val, b.val) {
1200-
(ConstValue::Slice { .. }, ConstValue::Slice { .. }) => {
1201-
let a_bytes = get_slice_bytes(&tcx, a.val);
1202-
let b_bytes = get_slice_bytes(&tcx, b.val);
1200+
(ty::ConstKind::Value(a_val @ ConstValue::Slice { .. }),
1201+
ty::ConstKind::Value(b_val @ ConstValue::Slice { .. })) => {
1202+
let a_bytes = get_slice_bytes(&tcx, a_val);
1203+
let b_bytes = get_slice_bytes(&tcx, b_val);
12031204
return from_bool(a_bytes == b_bytes);
12041205
}
12051206
_ => (),

src/librustc_mir/interpret/intrinsics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ crate fn eval_nullary_intrinsic<'tcx>(
5454
"type_name" => {
5555
let alloc = type_name::alloc_type_name(tcx, tp_ty);
5656
tcx.mk_const(ty::Const {
57-
val: ConstValue::Slice {
57+
val: ty::ConstKind::Value(ConstValue::Slice {
5858
data: alloc,
5959
start: 0,
6060
end: alloc.len(),
61-
},
61+
}),
6262
ty: tcx.mk_static_str(),
6363
})
6464
},

src/librustc_mir/interpret/operand.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -545,23 +545,27 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
545545
Scalar::Raw { data, size } => Scalar::Raw { data, size },
546546
};
547547
// Early-return cases.
548-
match val.val {
549-
ConstValue::Param(_) =>
548+
let val_val = match val.val {
549+
ty::ConstKind::Param(_) =>
550550
throw_inval!(TooGeneric),
551-
ConstValue::Unevaluated(def_id, substs) => {
551+
ty::ConstKind::Unevaluated(def_id, substs) => {
552552
let instance = self.resolve(def_id, substs)?;
553553
return Ok(OpTy::from(self.const_eval_raw(GlobalId {
554554
instance,
555555
promoted: None,
556556
})?));
557557
}
558-
_ => {}
559-
}
558+
ty::ConstKind::Infer(..) |
559+
ty::ConstKind::Bound(..) |
560+
ty::ConstKind::Placeholder(..) =>
561+
bug!("eval_const_to_op: Unexpected ConstKind {:?}", val),
562+
ty::ConstKind::Value(val_val) => val_val,
563+
};
560564
// Other cases need layout.
561565
let layout = from_known_layout(layout, || {
562566
self.layout_of(val.ty)
563567
})?;
564-
let op = match val.val {
568+
let op = match val_val {
565569
ConstValue::ByRef { alloc, offset } => {
566570
let id = self.tcx.alloc_map.lock().create_memory_alloc(alloc);
567571
// We rely on mutability being set correctly in that allocation to prevent writes
@@ -583,12 +587,6 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
583587
self,
584588
))
585589
}
586-
ConstValue::Param(..) |
587-
ConstValue::Infer(..) |
588-
ConstValue::Bound(..) |
589-
ConstValue::Placeholder(..) |
590-
ConstValue::Unevaluated(..) =>
591-
bug!("eval_const_to_op: Unexpected ConstValue {:?}", val),
592590
};
593591
Ok(OpTy { op, layout })
594592
}

src/librustc_mir/monomorphize/collector.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,15 +1284,15 @@ fn collect_const<'tcx>(
12841284
);
12851285

12861286
match substituted_constant.val {
1287-
ConstValue::Scalar(Scalar::Ptr(ptr)) =>
1287+
ty::ConstKind::Value(ConstValue::Scalar(Scalar::Ptr(ptr))) =>
12881288
collect_miri(tcx, ptr.alloc_id, output),
1289-
ConstValue::Slice { data: alloc, start: _, end: _ } |
1290-
ConstValue::ByRef { alloc, .. } => {
1289+
ty::ConstKind::Value(ConstValue::Slice { data: alloc, start: _, end: _ }) |
1290+
ty::ConstKind::Value(ConstValue::ByRef { alloc, .. }) => {
12911291
for &((), id) in alloc.relocations().values() {
12921292
collect_miri(tcx, id, output);
12931293
}
12941294
}
1295-
ConstValue::Unevaluated(def_id, substs) => {
1295+
ty::ConstKind::Unevaluated(def_id, substs) => {
12961296
let instance = ty::Instance::resolve(tcx,
12971297
param_env,
12981298
def_id,

src/librustc_mir/transform/check_consts/qualifs.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! A copy of the `Qualif` trait in `qualify_consts.rs` that is suitable for the new validator.
22
33
use rustc::mir::*;
4-
use rustc::mir::interpret::ConstValue;
54
use rustc::ty::{self, Ty};
65
use syntax_pos::DUMMY_SP;
76

@@ -118,7 +117,7 @@ pub trait Qualif {
118117
Operand::Move(ref place) => Self::in_place(cx, per_local, place.as_ref()),
119118

120119
Operand::Constant(ref constant) => {
121-
if let ConstValue::Unevaluated(def_id, _) = constant.literal.val {
120+
if let ty::ConstKind::Unevaluated(def_id, _) = constant.literal.val {
122121
// Don't peek inside trait associated constants.
123122
if cx.tcx.trait_of_item(def_id).is_some() {
124123
Self::in_any_value_of_ty(cx, constant.literal.ty)

src/librustc_mir/transform/promote_consts.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
1515
use rustc::hir::def_id::DefId;
1616
use rustc::mir::*;
17-
use rustc::mir::interpret::ConstValue;
1817
use rustc::mir::visit::{PlaceContext, MutatingUseContext, MutVisitor, Visitor};
1918
use rustc::mir::traversal::ReversePostorder;
2019
use rustc::ty::{self, List, TyCtxt, TypeFoldable};
@@ -584,7 +583,7 @@ impl<'tcx> Validator<'_, 'tcx> {
584583
Operand::Move(place) => self.validate_place(place.as_ref()),
585584

586585
Operand::Constant(constant) => {
587-
if let ConstValue::Unevaluated(def_id, _) = constant.literal.val {
586+
if let ty::ConstKind::Unevaluated(def_id, _) = constant.literal.val {
588587
if self.tcx.trait_of_item(def_id).is_some() {
589588
// Don't peek inside trait associated constants.
590589
// (see below what we do for other consts, for now)

src/librustc_mir/transform/qualify_consts.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use rustc::ty::{self, TyCtxt, Ty, TypeFoldable};
1414
use rustc::ty::cast::CastTy;
1515
use rustc::ty::query::Providers;
1616
use rustc::mir::*;
17-
use rustc::mir::interpret::ConstValue;
1817
use rustc::mir::visit::{PlaceContext, Visitor, MutatingUseContext, NonMutatingUseContext};
1918
use rustc::middle::lang_items;
2019
use rustc::session::config::nightly_options;
@@ -251,7 +250,7 @@ trait Qualif {
251250
Operand::Move(ref place) => Self::in_place(cx, place.as_ref()),
252251

253252
Operand::Constant(ref constant) => {
254-
if let ConstValue::Unevaluated(def_id, _) = constant.literal.val {
253+
if let ty::ConstKind::Unevaluated(def_id, _) = constant.literal.val {
255254
// Don't peek inside trait associated constants.
256255
if cx.tcx.trait_of_item(def_id).is_some() {
257256
Self::in_any_value_of_ty(cx, constant.literal.ty).unwrap_or(false)

0 commit comments

Comments
 (0)