Rename in librustc_mir.
This commit is contained in:
parent
028c83cdf6
commit
7378c25f25
@ -27,7 +27,7 @@
|
||||
use rustc::infer::outlives::env::RegionBoundPairs;
|
||||
use rustc::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime, NLLRegionVariableOrigin};
|
||||
use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||
use rustc::mir::interpret::{ConstValue, PanicInfo};
|
||||
use rustc::mir::interpret::PanicInfo;
|
||||
use rustc::mir::tcx::PlaceTy;
|
||||
use rustc::mir::visit::{PlaceContext, Visitor, NonMutatingUseContext};
|
||||
use rustc::mir::*;
|
||||
@ -309,7 +309,7 @@ fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) {
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if let ConstValue::Unevaluated(def_id, substs) = constant.literal.val {
|
||||
if let ty::ConstKind::Unevaluated(def_id, substs) = constant.literal.val {
|
||||
if let Err(terr) = self.cx.fully_perform_op(
|
||||
location.to_locations(),
|
||||
ConstraintCategory::Boring,
|
||||
|
@ -128,7 +128,7 @@ fn op_to_const<'tcx>(
|
||||
}
|
||||
},
|
||||
};
|
||||
ecx.tcx.mk_const(ty::Const { val, ty: op.layout.ty })
|
||||
ecx.tcx.mk_const(ty::Const { val: ty::ConstKind::Value(val), ty: op.layout.ty })
|
||||
}
|
||||
|
||||
// Returns a pointer to where the result lives
|
||||
@ -519,7 +519,7 @@ pub fn const_caller_location<'tcx>(
|
||||
intern_const_alloc_recursive(&mut ecx, None, loc_place).unwrap();
|
||||
let loc_const = ty::Const {
|
||||
ty: loc_ty,
|
||||
val: ConstValue::Scalar(loc_place.ptr.into()),
|
||||
val: ty::ConstKind::Value(ConstValue::Scalar(loc_place.ptr.into())),
|
||||
};
|
||||
|
||||
tcx.mk_const(loc_const)
|
||||
@ -580,10 +580,10 @@ fn validate_and_turn_into_const<'tcx>(
|
||||
if tcx.is_static(def_id) || cid.promoted.is_some() {
|
||||
let ptr = mplace.ptr.to_ptr()?;
|
||||
Ok(tcx.mk_const(ty::Const {
|
||||
val: ConstValue::ByRef {
|
||||
val: ty::ConstKind::Value(ConstValue::ByRef {
|
||||
alloc: ecx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id),
|
||||
offset: ptr.offset,
|
||||
},
|
||||
}),
|
||||
ty: mplace.layout.ty,
|
||||
}))
|
||||
} else {
|
||||
|
@ -56,7 +56,7 @@
|
||||
LitKind::Char(c) => ConstValue::Scalar(Scalar::from_char(c)),
|
||||
LitKind::Err(_) => unreachable!(),
|
||||
};
|
||||
Ok(tcx.mk_const(ty::Const { val: lit, ty }))
|
||||
Ok(tcx.mk_const(ty::Const { val: ty::ConstKind::Value(lit), ty }))
|
||||
}
|
||||
|
||||
fn parse_float<'tcx>(
|
||||
|
@ -5,7 +5,7 @@
|
||||
use crate::hair::util::UserAnnotatedTyHelpers;
|
||||
use rustc_index::vec::Idx;
|
||||
use rustc::hir::def::{CtorOf, Res, DefKind, CtorKind};
|
||||
use rustc::mir::interpret::{GlobalId, ErrorHandled, ConstValue};
|
||||
use rustc::mir::interpret::{GlobalId, ErrorHandled};
|
||||
use rustc::ty::{self, AdtKind, Ty};
|
||||
use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow, AutoBorrowMutability, PointerCast};
|
||||
use rustc::ty::subst::{InternalSubsts, SubstsRef};
|
||||
@ -692,7 +692,7 @@ fn make_mirror_unadjusted<'a, 'tcx>(
|
||||
// and not the beginning of discriminants (which is always `0`)
|
||||
let substs = InternalSubsts::identity_for_item(cx.tcx(), did);
|
||||
let lhs = mk_const(cx.tcx().mk_const(ty::Const {
|
||||
val: ConstValue::Unevaluated(did, substs),
|
||||
val: ty::ConstKind::Unevaluated(did, substs),
|
||||
ty: var_ty,
|
||||
}));
|
||||
let bin = ExprKind::Binary {
|
||||
@ -914,7 +914,7 @@ fn convert_path_expr<'a, 'tcx>(
|
||||
let local_def_id = cx.tcx.hir().local_def_id(hir_id);
|
||||
let index = generics.param_def_id_to_index[&local_def_id];
|
||||
let name = cx.tcx.hir().name(hir_id);
|
||||
let val = ConstValue::Param(ty::ParamConst::new(index, name));
|
||||
let val = ty::ConstKind::Param(ty::ParamConst::new(index, name));
|
||||
ExprKind::Literal {
|
||||
literal: cx.tcx.mk_const(
|
||||
ty::Const {
|
||||
@ -932,7 +932,7 @@ fn convert_path_expr<'a, 'tcx>(
|
||||
debug!("convert_path_expr: (const) user_ty={:?}", user_ty);
|
||||
ExprKind::Literal {
|
||||
literal: cx.tcx.mk_const(ty::Const {
|
||||
val: ConstValue::Unevaluated(def_id, substs),
|
||||
val: ty::ConstKind::Unevaluated(def_id, substs),
|
||||
ty: cx.tables().node_type(expr.hir_id),
|
||||
}),
|
||||
user_ty,
|
||||
|
@ -313,7 +313,10 @@ fn fold_pattern(&mut self, pat: &Pat<'tcx>) -> Pat<'tcx> {
|
||||
(
|
||||
&ty::Ref(_, rty, _),
|
||||
&PatKind::Constant {
|
||||
value: Const { val, ty: ty::TyS { kind: ty::Ref(_, crty, _), .. } },
|
||||
value: Const {
|
||||
val: ty::ConstKind::Value(val),
|
||||
ty: ty::TyS { kind: ty::Ref(_, crty, _), .. }
|
||||
},
|
||||
},
|
||||
) => Pat {
|
||||
ty: pat.ty,
|
||||
@ -324,13 +327,21 @@ fn fold_pattern(&mut self, pat: &Pat<'tcx>) -> Pat<'tcx> {
|
||||
span: pat.span,
|
||||
kind: box PatKind::Constant {
|
||||
value: self.tcx.mk_const(Const {
|
||||
val: self.fold_const_value_deref(*val, rty, crty),
|
||||
val: ty::ConstKind::Value(self.fold_const_value_deref(*val, rty, crty)),
|
||||
ty: rty,
|
||||
}),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
(
|
||||
&ty::Ref(_, rty, _),
|
||||
&PatKind::Constant {
|
||||
value: Const { val, ty: ty::TyS { kind: ty::Ref(_, crty, _), .. } },
|
||||
},
|
||||
) => bug!("cannot deref {:#?}, {} -> {}", val, crty, rty),
|
||||
|
||||
(_, &PatKind::Binding { subpattern: Some(ref s), .. }) => s.fold_with(self),
|
||||
_ => pat.super_fold_with(self),
|
||||
}
|
||||
@ -1245,7 +1256,7 @@ fn from_const(
|
||||
) -> Option<IntRange<'tcx>> {
|
||||
if let Some((target_size, bias)) = Self::integral_size_and_signed_bias(tcx, value.ty) {
|
||||
let ty = value.ty;
|
||||
let val = if let ConstValue::Scalar(Scalar::Raw { data, size }) = value.val {
|
||||
let val = if let ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw { data, size })) = value.val {
|
||||
// For this specific pattern we can skip a lot of effort and go
|
||||
// straight to the result, after doing a bit of checking. (We
|
||||
// could remove this branch and just use the next branch, which
|
||||
@ -1781,7 +1792,19 @@ fn slice_pat_covered_by_const<'tcx>(
|
||||
suffix: &[Pat<'tcx>],
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
) -> Result<bool, ErrorReported> {
|
||||
let data: &[u8] = match (const_val.val, &const_val.ty.kind) {
|
||||
let const_val_val = if let ty::ConstKind::Value(val) = const_val.val {
|
||||
val
|
||||
} else {
|
||||
bug!(
|
||||
"slice_pat_covered_by_const: {:#?}, {:#?}, {:#?}, {:#?}",
|
||||
const_val,
|
||||
prefix,
|
||||
slice,
|
||||
suffix,
|
||||
)
|
||||
};
|
||||
|
||||
let data: &[u8] = match (const_val_val, &const_val.ty.kind) {
|
||||
(ConstValue::ByRef { offset, alloc, .. }, ty::Array(t, n)) => {
|
||||
assert_eq!(*t, tcx.types.u8);
|
||||
let n = n.eval_usize(tcx, param_env);
|
||||
@ -2054,7 +2077,8 @@ fn range_borders(r: IntRange<'_>) -> impl Iterator<Item = Border> {
|
||||
max_fixed_len =
|
||||
cmp::max(max_fixed_len, n.eval_usize(tcx, param_env))
|
||||
}
|
||||
(ConstValue::Slice { start, end, .. }, ty::Slice(_)) => {
|
||||
(ty::ConstKind::Value(ConstValue::Slice { start, end, .. }),
|
||||
ty::Slice(_)) => {
|
||||
max_fixed_len = cmp::max(max_fixed_len, (end - start) as u64)
|
||||
}
|
||||
_ => {}
|
||||
@ -2253,17 +2277,17 @@ fn specialize_one_pattern<'p, 'a: 'p, 'q: 'p, 'tcx>(
|
||||
// is when they are subslices of nonzero slices.
|
||||
let (alloc, offset, n, ty) = match value.ty.kind {
|
||||
ty::Array(t, n) => match value.val {
|
||||
ConstValue::ByRef { offset, alloc, .. } => {
|
||||
ty::ConstKind::Value(ConstValue::ByRef { offset, alloc, .. }) => {
|
||||
(alloc, offset, n.eval_usize(cx.tcx, cx.param_env), t)
|
||||
}
|
||||
_ => span_bug!(pat.span, "array pattern is {:?}", value,),
|
||||
},
|
||||
ty::Slice(t) => {
|
||||
match value.val {
|
||||
ConstValue::Slice { data, start, end } => {
|
||||
ty::ConstKind::Value(ConstValue::Slice { data, start, end }) => {
|
||||
(data, Size::from_bytes(start as u64), (end - start) as u64, t)
|
||||
}
|
||||
ConstValue::ByRef { .. } => {
|
||||
ty::ConstKind::Value(ConstValue::ByRef { .. }) => {
|
||||
// FIXME(oli-obk): implement `deref` for `ConstValue`
|
||||
return None;
|
||||
}
|
||||
|
@ -1197,9 +1197,10 @@ pub fn compare_const_vals<'tcx>(
|
||||
|
||||
if let ty::Str = ty.kind {
|
||||
match (a.val, b.val) {
|
||||
(ConstValue::Slice { .. }, ConstValue::Slice { .. }) => {
|
||||
let a_bytes = get_slice_bytes(&tcx, a.val);
|
||||
let b_bytes = get_slice_bytes(&tcx, b.val);
|
||||
(ty::ConstKind::Value(a_val @ ConstValue::Slice { .. }),
|
||||
ty::ConstKind::Value(b_val @ ConstValue::Slice { .. })) => {
|
||||
let a_bytes = get_slice_bytes(&tcx, a_val);
|
||||
let b_bytes = get_slice_bytes(&tcx, b_val);
|
||||
return from_bool(a_bytes == b_bytes);
|
||||
}
|
||||
_ => (),
|
||||
|
@ -54,11 +54,11 @@ fn numeric_intrinsic<'tcx, Tag>(
|
||||
"type_name" => {
|
||||
let alloc = type_name::alloc_type_name(tcx, tp_ty);
|
||||
tcx.mk_const(ty::Const {
|
||||
val: ConstValue::Slice {
|
||||
val: ty::ConstKind::Value(ConstValue::Slice {
|
||||
data: alloc,
|
||||
start: 0,
|
||||
end: alloc.len(),
|
||||
},
|
||||
}),
|
||||
ty: tcx.mk_static_str(),
|
||||
})
|
||||
},
|
||||
|
@ -545,23 +545,27 @@ pub(super) fn eval_operands(
|
||||
Scalar::Raw { data, size } => Scalar::Raw { data, size },
|
||||
};
|
||||
// Early-return cases.
|
||||
match val.val {
|
||||
ConstValue::Param(_) =>
|
||||
let val_val = match val.val {
|
||||
ty::ConstKind::Param(_) =>
|
||||
throw_inval!(TooGeneric),
|
||||
ConstValue::Unevaluated(def_id, substs) => {
|
||||
ty::ConstKind::Unevaluated(def_id, substs) => {
|
||||
let instance = self.resolve(def_id, substs)?;
|
||||
return Ok(OpTy::from(self.const_eval_raw(GlobalId {
|
||||
instance,
|
||||
promoted: None,
|
||||
})?));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
ty::ConstKind::Infer(..) |
|
||||
ty::ConstKind::Bound(..) |
|
||||
ty::ConstKind::Placeholder(..) =>
|
||||
bug!("eval_const_to_op: Unexpected ConstKind {:?}", val),
|
||||
ty::ConstKind::Value(val_val) => val_val,
|
||||
};
|
||||
// Other cases need layout.
|
||||
let layout = from_known_layout(layout, || {
|
||||
self.layout_of(val.ty)
|
||||
})?;
|
||||
let op = match val.val {
|
||||
let op = match val_val {
|
||||
ConstValue::ByRef { alloc, offset } => {
|
||||
let id = self.tcx.alloc_map.lock().create_memory_alloc(alloc);
|
||||
// We rely on mutability being set correctly in that allocation to prevent writes
|
||||
@ -583,12 +587,6 @@ pub(super) fn eval_operands(
|
||||
self,
|
||||
))
|
||||
}
|
||||
ConstValue::Param(..) |
|
||||
ConstValue::Infer(..) |
|
||||
ConstValue::Bound(..) |
|
||||
ConstValue::Placeholder(..) |
|
||||
ConstValue::Unevaluated(..) =>
|
||||
bug!("eval_const_to_op: Unexpected ConstValue {:?}", val),
|
||||
};
|
||||
Ok(OpTy { op, layout })
|
||||
}
|
||||
|
@ -1284,15 +1284,15 @@ fn collect_const<'tcx>(
|
||||
);
|
||||
|
||||
match substituted_constant.val {
|
||||
ConstValue::Scalar(Scalar::Ptr(ptr)) =>
|
||||
ty::ConstKind::Value(ConstValue::Scalar(Scalar::Ptr(ptr))) =>
|
||||
collect_miri(tcx, ptr.alloc_id, output),
|
||||
ConstValue::Slice { data: alloc, start: _, end: _ } |
|
||||
ConstValue::ByRef { alloc, .. } => {
|
||||
ty::ConstKind::Value(ConstValue::Slice { data: alloc, start: _, end: _ }) |
|
||||
ty::ConstKind::Value(ConstValue::ByRef { alloc, .. }) => {
|
||||
for &((), id) in alloc.relocations().values() {
|
||||
collect_miri(tcx, id, output);
|
||||
}
|
||||
}
|
||||
ConstValue::Unevaluated(def_id, substs) => {
|
||||
ty::ConstKind::Unevaluated(def_id, substs) => {
|
||||
let instance = ty::Instance::resolve(tcx,
|
||||
param_env,
|
||||
def_id,
|
||||
|
@ -1,7 +1,6 @@
|
||||
//! A copy of the `Qualif` trait in `qualify_consts.rs` that is suitable for the new validator.
|
||||
|
||||
use rustc::mir::*;
|
||||
use rustc::mir::interpret::ConstValue;
|
||||
use rustc::ty::{self, Ty};
|
||||
use syntax_pos::DUMMY_SP;
|
||||
|
||||
@ -118,7 +117,7 @@ fn in_operand(
|
||||
Operand::Move(ref place) => Self::in_place(cx, per_local, place.as_ref()),
|
||||
|
||||
Operand::Constant(ref constant) => {
|
||||
if let ConstValue::Unevaluated(def_id, _) = constant.literal.val {
|
||||
if let ty::ConstKind::Unevaluated(def_id, _) = constant.literal.val {
|
||||
// Don't peek inside trait associated constants.
|
||||
if cx.tcx.trait_of_item(def_id).is_some() {
|
||||
Self::in_any_value_of_ty(cx, constant.literal.ty)
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::mir::*;
|
||||
use rustc::mir::interpret::ConstValue;
|
||||
use rustc::mir::visit::{PlaceContext, MutatingUseContext, MutVisitor, Visitor};
|
||||
use rustc::mir::traversal::ReversePostorder;
|
||||
use rustc::ty::{self, List, TyCtxt, TypeFoldable};
|
||||
@ -584,7 +583,7 @@ fn validate_operand(&self, operand: &Operand<'tcx>) -> Result<(), Unpromotable>
|
||||
Operand::Move(place) => self.validate_place(place.as_ref()),
|
||||
|
||||
Operand::Constant(constant) => {
|
||||
if let ConstValue::Unevaluated(def_id, _) = constant.literal.val {
|
||||
if let ty::ConstKind::Unevaluated(def_id, _) = constant.literal.val {
|
||||
if self.tcx.trait_of_item(def_id).is_some() {
|
||||
// Don't peek inside trait associated constants.
|
||||
// (see below what we do for other consts, for now)
|
||||
|
@ -14,7 +14,6 @@
|
||||
use rustc::ty::cast::CastTy;
|
||||
use rustc::ty::query::Providers;
|
||||
use rustc::mir::*;
|
||||
use rustc::mir::interpret::ConstValue;
|
||||
use rustc::mir::visit::{PlaceContext, Visitor, MutatingUseContext, NonMutatingUseContext};
|
||||
use rustc::middle::lang_items;
|
||||
use rustc::session::config::nightly_options;
|
||||
@ -251,7 +250,7 @@ fn in_operand(cx: &ConstCx<'_, 'tcx>, operand: &Operand<'tcx>) -> bool {
|
||||
Operand::Move(ref place) => Self::in_place(cx, place.as_ref()),
|
||||
|
||||
Operand::Constant(ref constant) => {
|
||||
if let ConstValue::Unevaluated(def_id, _) = constant.literal.val {
|
||||
if let ty::ConstKind::Unevaluated(def_id, _) = constant.literal.val {
|
||||
// Don't peek inside trait associated constants.
|
||||
if cx.tcx.trait_of_item(def_id).is_some() {
|
||||
Self::in_any_value_of_ty(cx, constant.literal.ty).unwrap_or(false)
|
||||
|
Loading…
Reference in New Issue
Block a user