s/ConstantSource/ConstantKind/
This commit is contained in:
parent
11ddd22510
commit
c30c1be1e6
@ -40,8 +40,8 @@ pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, '_>) -> bool {
|
||||
let mut all_constants_ok = true;
|
||||
for constant in &fx.mir.required_consts {
|
||||
let const_ = match fx.monomorphize(constant.literal) {
|
||||
ConstantSource::Ty(ct) => ct,
|
||||
ConstantSource::Val(..) => continue,
|
||||
ConstantKind::Ty(ct) => ct,
|
||||
ConstantKind::Val(..) => continue,
|
||||
};
|
||||
match const_.val {
|
||||
ConstKind::Value(_) => {}
|
||||
@ -117,8 +117,8 @@ pub(crate) fn codegen_constant<'tcx>(
|
||||
constant: &Constant<'tcx>,
|
||||
) -> CValue<'tcx> {
|
||||
let const_ = match fx.monomorphize(constant.literal) {
|
||||
ConstantSource::Ty(ct) => ct,
|
||||
ConstantSource::Val(val, ty) => return codegen_const_value(fx, val, ty),
|
||||
ConstantKind::Ty(ct) => ct,
|
||||
ConstantKind::Val(val, ty) => return codegen_const_value(fx, val, ty),
|
||||
};
|
||||
let const_val = match const_.val {
|
||||
ConstKind::Value(const_val) => const_val,
|
||||
@ -427,10 +427,10 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
|
||||
match operand {
|
||||
Operand::Copy(_) | Operand::Move(_) => None,
|
||||
Operand::Constant(const_) => match const_.literal {
|
||||
ConstantSource::Ty(const_) => {
|
||||
ConstantKind::Ty(const_) => {
|
||||
fx.monomorphize(const_).eval(fx.tcx, ParamEnv::reveal_all()).val.try_to_value()
|
||||
}
|
||||
ConstantSource::Val(val, _) => Some(val),
|
||||
ConstantKind::Val(val, _) => Some(val),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -26,8 +26,8 @@ pub fn eval_mir_constant(
|
||||
) -> Result<ConstValue<'tcx>, ErrorHandled> {
|
||||
let ct = self.monomorphize(constant.literal);
|
||||
let ct = match ct {
|
||||
mir::ConstantSource::Ty(ct) => ct,
|
||||
mir::ConstantSource::Val(val, _) => return Ok(val),
|
||||
mir::ConstantKind::Ty(ct) => ct,
|
||||
mir::ConstantKind::Val(val, _) => return Ok(val),
|
||||
};
|
||||
match ct.val {
|
||||
ty::ConstKind::Unevaluated(def, substs, promoted) => self
|
||||
|
@ -381,14 +381,6 @@ pub fn assert_bits(self, target_size: Size) -> u128 {
|
||||
self.to_bits(target_size).expect("expected Raw bits but got a Pointer")
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn to_int(self) -> InterpResult<'tcx, ScalarInt> {
|
||||
match self {
|
||||
Scalar::Ptr(_) => throw_unsup!(ReadPointerAsBytes),
|
||||
Scalar::Int(int) => Ok(int),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn assert_int(self) -> ScalarInt {
|
||||
self.to_int().expect("expected an int but got an abstract pointer")
|
||||
|
@ -2033,7 +2033,7 @@ pub fn function_handle(
|
||||
Operand::Constant(box Constant {
|
||||
span,
|
||||
user_ty: None,
|
||||
literal: ConstantSource::Ty(ty::Const::zero_sized(tcx, ty)),
|
||||
literal: ConstantKind::Ty(ty::Const::zero_sized(tcx, ty)),
|
||||
})
|
||||
}
|
||||
|
||||
@ -2064,7 +2064,7 @@ pub fn const_from_scalar(
|
||||
Operand::Constant(box Constant {
|
||||
span,
|
||||
user_ty: None,
|
||||
literal: ConstantSource::Val(val.into(), ty),
|
||||
literal: ConstantKind::Val(val.into(), ty),
|
||||
})
|
||||
}
|
||||
|
||||
@ -2406,11 +2406,11 @@ pub struct Constant<'tcx> {
|
||||
/// Needed for NLL to impose user-given type constraints.
|
||||
pub user_ty: Option<UserTypeAnnotationIndex>,
|
||||
|
||||
pub literal: ConstantSource<'tcx>,
|
||||
pub literal: ConstantKind<'tcx>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, PartialOrd, TyEncodable, TyDecodable, Hash, HashStable, Debug)]
|
||||
pub enum ConstantSource<'tcx> {
|
||||
pub enum ConstantKind<'tcx> {
|
||||
/// This constant came from the type system
|
||||
Ty(&'tcx ty::Const<'tcx>),
|
||||
/// This constant cannot go back into the type system, as it represents
|
||||
@ -2436,33 +2436,33 @@ pub fn ty(&self) -> Ty<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&'tcx ty::Const<'tcx>> for ConstantSource<'tcx> {
|
||||
impl From<&'tcx ty::Const<'tcx>> for ConstantKind<'tcx> {
|
||||
fn from(ct: &'tcx ty::Const<'tcx>) -> Self {
|
||||
Self::Ty(ct)
|
||||
}
|
||||
}
|
||||
|
||||
impl ConstantSource<'tcx> {
|
||||
impl ConstantKind<'tcx> {
|
||||
/// Returns `None` if the constant is not trivially safe for use in the type system.
|
||||
pub fn const_for_ty(&self) -> Option<&'tcx ty::Const<'tcx>> {
|
||||
match self {
|
||||
ConstantSource::Ty(c) => Some(c),
|
||||
ConstantSource::Val(..) => None,
|
||||
ConstantKind::Ty(c) => Some(c),
|
||||
ConstantKind::Val(..) => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ty(&self) -> Ty<'tcx> {
|
||||
match self {
|
||||
ConstantSource::Ty(c) => c.ty,
|
||||
ConstantSource::Val(_, ty) => ty,
|
||||
ConstantKind::Ty(c) => c.ty,
|
||||
ConstantKind::Val(_, ty) => ty,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn try_to_value(self) -> Option<interpret::ConstValue<'tcx>> {
|
||||
match self {
|
||||
ConstantSource::Ty(c) => c.val.try_to_value(),
|
||||
ConstantSource::Val(val, _) => Some(val),
|
||||
ConstantKind::Ty(c) => c.val.try_to_value(),
|
||||
ConstantKind::Val(val, _) => Some(val),
|
||||
}
|
||||
}
|
||||
|
||||
@ -2709,8 +2709,8 @@ fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
|
||||
_ => write!(fmt, "const ")?,
|
||||
}
|
||||
match self.literal {
|
||||
ConstantSource::Ty(c) => pretty_print_const(c, fmt, true),
|
||||
ConstantSource::Val(val, ty) => pretty_print_const_value(val, ty, fmt, true),
|
||||
ConstantKind::Ty(c) => pretty_print_const(c, fmt, true),
|
||||
ConstantKind::Val(val, ty) => pretty_print_const_value(val, ty, fmt, true),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -347,18 +347,18 @@ fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ConstantSource<'tcx> {
|
||||
impl<'tcx> TypeFoldable<'tcx> for ConstantKind<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
match self {
|
||||
ConstantSource::Ty(c) => ConstantSource::Ty(c.fold_with(folder)),
|
||||
ConstantSource::Val(v, t) => ConstantSource::Val(v, t.fold_with(folder)),
|
||||
ConstantKind::Ty(c) => ConstantKind::Ty(c.fold_with(folder)),
|
||||
ConstantKind::Val(v, t) => ConstantKind::Val(v, t.fold_with(folder)),
|
||||
}
|
||||
}
|
||||
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
||||
match *self {
|
||||
ConstantSource::Ty(c) => c.visit_with(visitor),
|
||||
ConstantSource::Val(_, t) => t.visit_with(visitor),
|
||||
ConstantKind::Ty(c) => c.visit_with(visitor),
|
||||
ConstantKind::Val(_, t) => t.visit_with(visitor),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -872,8 +872,8 @@ fn super_constant(&mut self,
|
||||
self.visit_span(span);
|
||||
drop(user_ty); // no visit method for this
|
||||
match literal {
|
||||
ConstantSource::Ty(ct) => self.visit_const(ct, location),
|
||||
ConstantSource::Val(_, t) => self.visit_ty(t, TyContext::Location(location)),
|
||||
ConstantKind::Ty(ct) => self.visit_const(ct, location),
|
||||
ConstantKind::Val(_, t) => self.visit_ty(t, TyContext::Location(location)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -315,7 +315,7 @@ fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) {
|
||||
} else {
|
||||
let tcx = self.tcx();
|
||||
let maybe_uneval = match constant.literal {
|
||||
ConstantSource::Ty(ct) => match ct.val {
|
||||
ConstantKind::Ty(ct) => match ct.val {
|
||||
ty::ConstKind::Unevaluated(def, substs, promoted) => {
|
||||
Some((def, substs, promoted))
|
||||
}
|
||||
|
@ -573,12 +573,12 @@ pub(super) fn eval_operands(
|
||||
|
||||
crate fn mir_const_to_op(
|
||||
&self,
|
||||
val: &mir::ConstantSource<'tcx>,
|
||||
val: &mir::ConstantKind<'tcx>,
|
||||
layout: Option<TyAndLayout<'tcx>>,
|
||||
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
|
||||
match val {
|
||||
mir::ConstantSource::Ty(ct) => self.const_to_op(ct, layout),
|
||||
mir::ConstantSource::Val(val, ty) => self.const_val_to_op(*val, ty, None),
|
||||
mir::ConstantKind::Ty(ct) => self.const_to_op(ct, layout),
|
||||
mir::ConstantKind::Val(val, ty) => self.const_val_to_op(*val, ty, None),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,9 +13,9 @@
|
||||
MutVisitor, MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor,
|
||||
};
|
||||
use rustc_middle::mir::{
|
||||
AssertKind, BasicBlock, BinOp, Body, ClearCrossCrate, Constant, ConstantSource, Local,
|
||||
LocalDecl, LocalKind, Location, Operand, Place, Rvalue, SourceInfo, SourceScope,
|
||||
SourceScopeData, Statement, StatementKind, Terminator, TerminatorKind, UnOp, RETURN_PLACE,
|
||||
AssertKind, BasicBlock, BinOp, Body, ClearCrossCrate, Constant, ConstantKind, Local, LocalDecl,
|
||||
LocalKind, Location, Operand, Place, Rvalue, SourceInfo, SourceScope, SourceScopeData,
|
||||
Statement, StatementKind, Terminator, TerminatorKind, UnOp, RETURN_PLACE,
|
||||
};
|
||||
use rustc_middle::ty::layout::{HasTyCtxt, LayoutError, TyAndLayout};
|
||||
use rustc_middle::ty::subst::{InternalSubsts, Subst};
|
||||
@ -489,14 +489,14 @@ fn eval_constant(&mut self, c: &Constant<'tcx>, source_info: SourceInfo) -> Opti
|
||||
let err = ConstEvalErr::new(&self.ecx, error, Some(c.span));
|
||||
if let Some(lint_root) = self.lint_root(source_info) {
|
||||
let lint_only = match c.literal {
|
||||
ConstantSource::Ty(ct) => match ct.val {
|
||||
ConstantKind::Ty(ct) => match ct.val {
|
||||
// Promoteds must lint and not error as the user didn't ask for them
|
||||
ConstKind::Unevaluated(_, _, Some(_)) => true,
|
||||
// Out of backwards compatibility we cannot report hard errors in unused
|
||||
// generic functions using associated constants of the generic parameters.
|
||||
_ => c.literal.needs_subst(),
|
||||
},
|
||||
ConstantSource::Val(_, ty) => ty.needs_subst(),
|
||||
ConstantKind::Val(_, ty) => ty.needs_subst(),
|
||||
};
|
||||
if lint_only {
|
||||
// Out of backwards compatibility we cannot report hard errors in unused
|
||||
@ -818,7 +818,7 @@ fn replace_with_const(
|
||||
) {
|
||||
if let Rvalue::Use(Operand::Constant(c)) = rval {
|
||||
match c.literal {
|
||||
ConstantSource::Ty(c) if matches!(c.val, ConstKind::Unevaluated(..)) => {}
|
||||
ConstantKind::Ty(c) if matches!(c.val, ConstKind::Unevaluated(..)) => {}
|
||||
_ => {
|
||||
trace!("skipping replace of Rvalue::Use({:?} because it is already a const", c);
|
||||
return;
|
||||
|
@ -450,8 +450,8 @@ fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) {
|
||||
self.push(&format!("+ user_ty: {:?}", user_ty));
|
||||
}
|
||||
match literal {
|
||||
ConstantSource::Ty(literal) => self.push(&format!("+ literal: {:?}", literal)),
|
||||
ConstantSource::Val(val, ty) => {
|
||||
ConstantKind::Ty(literal) => self.push(&format!("+ literal: {:?}", literal)),
|
||||
ConstantKind::Val(val, ty) => {
|
||||
self.push(&format!("+ literal: {:?}, {}", val, ty))
|
||||
}
|
||||
}
|
||||
|
@ -378,8 +378,8 @@ fn operand_to_node(
|
||||
Ok(self.locals[local])
|
||||
}
|
||||
mir::Operand::Constant(ct) => match ct.literal {
|
||||
mir::ConstantSource::Ty(ct) => Ok(self.add_node(Node::Leaf(ct), span)),
|
||||
mir::ConstantSource::Val(..) => self.error(Some(span), "unsupported constant")?,
|
||||
mir::ConstantKind::Ty(ct) => Ok(self.add_node(Node::Leaf(ct), span)),
|
||||
mir::ConstantKind::Val(..) => self.error(Some(span), "unsupported constant")?,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user