From c30c1be1e69a0cf37855b611fa0921e41e04016f Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 15 Mar 2021 11:23:44 +0000 Subject: [PATCH] s/ConstantSource/ConstantKind/ --- .../rustc_codegen_cranelift/src/constant.rs | 12 ++++---- .../rustc_codegen_ssa/src/mir/constant.rs | 4 +-- .../rustc_middle/src/mir/interpret/value.rs | 8 ------ compiler/rustc_middle/src/mir/mod.rs | 28 +++++++++---------- .../rustc_middle/src/mir/type_foldable.rs | 10 +++---- compiler/rustc_middle/src/mir/visit.rs | 4 +-- .../src/borrow_check/type_check/mod.rs | 2 +- compiler/rustc_mir/src/interpret/operand.rs | 6 ++-- .../rustc_mir/src/transform/const_prop.rs | 12 ++++---- compiler/rustc_mir/src/util/pretty.rs | 4 +-- .../src/traits/const_evaluatable.rs | 4 +-- 11 files changed, 43 insertions(+), 51 deletions(-) diff --git a/compiler/rustc_codegen_cranelift/src/constant.rs b/compiler/rustc_codegen_cranelift/src/constant.rs index 23ad5267c56..9d93370b7d0 100644 --- a/compiler/rustc_codegen_cranelift/src/constant.rs +++ b/compiler/rustc_codegen_cranelift/src/constant.rs @@ -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), }, } } diff --git a/compiler/rustc_codegen_ssa/src/mir/constant.rs b/compiler/rustc_codegen_ssa/src/mir/constant.rs index d73e2325a8b..aa41acc3578 100644 --- a/compiler/rustc_codegen_ssa/src/mir/constant.rs +++ b/compiler/rustc_codegen_ssa/src/mir/constant.rs @@ -26,8 +26,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { ) -> Result, 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 diff --git a/compiler/rustc_middle/src/mir/interpret/value.rs b/compiler/rustc_middle/src/mir/interpret/value.rs index 515aabd59bc..44810a9b2e6 100644 --- a/compiler/rustc_middle/src/mir/interpret/value.rs +++ b/compiler/rustc_middle/src/mir/interpret/value.rs @@ -381,14 +381,6 @@ impl<'tcx, Tag> Scalar { 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") diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 481d02fccf5..0ba0429b4e2 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -2033,7 +2033,7 @@ impl<'tcx> Operand<'tcx> { 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 @@ impl<'tcx> Operand<'tcx> { 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, - 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 @@ impl Constant<'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> { 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 @@ impl<'tcx> Display for Constant<'tcx> { _ => 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), } } } diff --git a/compiler/rustc_middle/src/mir/type_foldable.rs b/compiler/rustc_middle/src/mir/type_foldable.rs index 44bedd75553..cb599277270 100644 --- a/compiler/rustc_middle/src/mir/type_foldable.rs +++ b/compiler/rustc_middle/src/mir/type_foldable.rs @@ -347,18 +347,18 @@ impl<'tcx> TypeFoldable<'tcx> for Constant<'tcx> { } } -impl<'tcx> TypeFoldable<'tcx> for ConstantSource<'tcx> { +impl<'tcx> TypeFoldable<'tcx> for ConstantKind<'tcx> { fn super_fold_with>(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>(&self, visitor: &mut V) -> ControlFlow { 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), } } } diff --git a/compiler/rustc_middle/src/mir/visit.rs b/compiler/rustc_middle/src/mir/visit.rs index 9015e771864..be248ccabda 100644 --- a/compiler/rustc_middle/src/mir/visit.rs +++ b/compiler/rustc_middle/src/mir/visit.rs @@ -872,8 +872,8 @@ macro_rules! make_mir_visitor { 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)), } } diff --git a/compiler/rustc_mir/src/borrow_check/type_check/mod.rs b/compiler/rustc_mir/src/borrow_check/type_check/mod.rs index d744db064b6..cce1549cb29 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/mod.rs +++ b/compiler/rustc_mir/src/borrow_check/type_check/mod.rs @@ -315,7 +315,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> { } 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)) } diff --git a/compiler/rustc_mir/src/interpret/operand.rs b/compiler/rustc_mir/src/interpret/operand.rs index 69ab2abaf27..28933493a21 100644 --- a/compiler/rustc_mir/src/interpret/operand.rs +++ b/compiler/rustc_mir/src/interpret/operand.rs @@ -573,12 +573,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { crate fn mir_const_to_op( &self, - val: &mir::ConstantSource<'tcx>, + val: &mir::ConstantKind<'tcx>, layout: Option>, ) -> 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), } } diff --git a/compiler/rustc_mir/src/transform/const_prop.rs b/compiler/rustc_mir/src/transform/const_prop.rs index 0d5c8953bc6..cc8669d9705 100644 --- a/compiler/rustc_mir/src/transform/const_prop.rs +++ b/compiler/rustc_mir/src/transform/const_prop.rs @@ -13,9 +13,9 @@ use rustc_middle::mir::visit::{ 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 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { 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 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { ) { 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; diff --git a/compiler/rustc_mir/src/util/pretty.rs b/compiler/rustc_mir/src/util/pretty.rs index 8e38a87a8f4..1bf010ffca7 100644 --- a/compiler/rustc_mir/src/util/pretty.rs +++ b/compiler/rustc_mir/src/util/pretty.rs @@ -450,8 +450,8 @@ impl Visitor<'tcx> for ExtraComments<'tcx> { 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)) } } diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index 5ace45e4c7c..670527fb3f0 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -378,8 +378,8 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> { 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")?, }, } }