]> git.lizzy.rs Git - rust.git/commitdiff
Unify the names of const eval queries and their return types
authorOliver Scherer <github35764891676564198441@oli-obk.de>
Thu, 20 Aug 2020 16:55:07 +0000 (18:55 +0200)
committerOliver Scherer <github35764891676564198441@oli-obk.de>
Sat, 19 Sep 2020 08:36:36 +0000 (10:36 +0200)
12 files changed:
compiler/rustc_infer/src/infer/mod.rs
compiler/rustc_middle/src/mir/interpret/error.rs
compiler/rustc_middle/src/mir/interpret/mod.rs
compiler/rustc_middle/src/mir/interpret/queries.rs
compiler/rustc_middle/src/mir/interpret/value.rs
compiler/rustc_middle/src/query/mod.rs
compiler/rustc_middle/src/ty/query/mod.rs
compiler/rustc_mir/src/const_eval/eval_queries.rs
compiler/rustc_mir/src/const_eval/machine.rs
compiler/rustc_mir/src/interpret/eval_context.rs
compiler/rustc_mir/src/interpret/operand.rs
compiler/rustc_mir/src/lib.rs

index 685d2bac94ee37af716ce6b7606dec726b2482e5..2cbdc954e2007cc7c6ea28e5621efa83e60ff210 100644 (file)
@@ -21,7 +21,7 @@
 use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue};
 use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind, ToType};
 use rustc_middle::mir;
-use rustc_middle::mir::interpret::ConstEvalResult;
+use rustc_middle::mir::interpret::EvalToConstValueResult;
 use rustc_middle::traits::select;
 use rustc_middle::ty::error::{ExpectedFound, TypeError, UnconstrainedNumeric};
 use rustc_middle::ty::fold::{TypeFoldable, TypeFolder};
@@ -1542,7 +1542,7 @@ pub fn const_eval_resolve(
         substs: SubstsRef<'tcx>,
         promoted: Option<mir::Promoted>,
         span: Option<Span>,
-    ) -> ConstEvalResult<'tcx> {
+    ) -> EvalToConstValueResult<'tcx> {
         let mut original_values = OriginalQueryValues::default();
         let canonical = self.canonicalize_query(&(param_env, substs), &mut original_values);
 
index 059925088ce1d52d66266574111bfe509ba3dccb..62d02250fe0b1a5ba187684769484dd49ccb490a 100644 (file)
@@ -27,8 +27,8 @@ pub enum ErrorHandled {
     ErrorHandled,
 }
 
-pub type ConstEvalRawResult<'tcx> = Result<RawConst<'tcx>, ErrorHandled>;
-pub type ConstEvalResult<'tcx> = Result<ConstValue<'tcx>, ErrorHandled>;
+pub type EvalToAllocationRawResult<'tcx> = Result<RawConst<'tcx>, ErrorHandled>;
+pub type EvalToConstValueResult<'tcx> = Result<ConstValue<'tcx>, ErrorHandled>;
 
 pub fn struct_error<'tcx>(tcx: TyCtxtAt<'tcx>, msg: &str) -> DiagnosticBuilder<'tcx> {
     struct_span_err!(tcx.sess, tcx.span, E0080, "{}", msg)
index cbc362d934ff8d5c22ff7673fb211e0b4ff5417e..71a99cf95f819bdf4b73929691b1f2c730eea8d4 100644 (file)
@@ -118,9 +118,9 @@ macro_rules! throw_machine_stop {
 use crate::ty::{self, Instance, Ty, TyCtxt};
 
 pub use self::error::{
-    struct_error, CheckInAllocMsg, ConstEvalRawResult, ConstEvalResult, ErrorHandled, InterpError,
-    InterpErrorInfo, InterpResult, InvalidProgramInfo, MachineStopType, ResourceExhaustionInfo,
-    UndefinedBehaviorInfo, UninitBytesAccess, UnsupportedOpInfo,
+    struct_error, CheckInAllocMsg, ErrorHandled, EvalToAllocationRawResult, EvalToConstValueResult,
+    InterpError, InterpErrorInfo, InterpResult, InvalidProgramInfo, MachineStopType,
+    ResourceExhaustionInfo, UndefinedBehaviorInfo, UninitBytesAccess, UnsupportedOpInfo,
 };
 
 pub use self::value::{get_slice_bytes, ConstValue, RawConst, Scalar, ScalarMaybeUninit};
index 20577bdc6bdee06c5d4ab4145fe2ccd07958956a..d545cf6865d29db40b323ffa87d6b6e4584b40bb 100644 (file)
@@ -1,4 +1,4 @@
-use super::{ConstEvalResult, ErrorHandled, GlobalId};
+use super::{ErrorHandled, EvalToConstValueResult, GlobalId};
 
 use crate::mir;
 use crate::ty::subst::{InternalSubsts, SubstsRef};
@@ -10,7 +10,7 @@ impl<'tcx> TyCtxt<'tcx> {
     /// Evaluates a constant without providing any substitutions. This is useful to evaluate consts
     /// that can't take any generic arguments like statics, const items or enum discriminants. If a
     /// generic parameter is used within the constant `ErrorHandled::ToGeneric` will be returned.
-    pub fn const_eval_poly(self, def_id: DefId) -> ConstEvalResult<'tcx> {
+    pub fn const_eval_poly(self, def_id: DefId) -> EvalToConstValueResult<'tcx> {
         // In some situations def_id will have substitutions within scope, but they aren't allowed
         // to be used. So we can't use `Instance::mono`, instead we feed unresolved substitutions
         // into `const_eval` which will return `ErrorHandled::ToGeneric` if any of them are
@@ -38,7 +38,7 @@ pub fn const_eval_resolve(
         substs: SubstsRef<'tcx>,
         promoted: Option<mir::Promoted>,
         span: Option<Span>,
-    ) -> ConstEvalResult<'tcx> {
+    ) -> EvalToConstValueResult<'tcx> {
         match ty::Instance::resolve_opt_const_arg(self, param_env, def, substs) {
             Ok(Some(instance)) => {
                 let cid = GlobalId { instance, promoted };
@@ -54,7 +54,7 @@ pub fn const_eval_instance(
         param_env: ty::ParamEnv<'tcx>,
         instance: ty::Instance<'tcx>,
         span: Option<Span>,
-    ) -> ConstEvalResult<'tcx> {
+    ) -> EvalToConstValueResult<'tcx> {
         self.const_eval_global_id(param_env, GlobalId { instance, promoted: None }, span)
     }
 
@@ -64,14 +64,14 @@ pub fn const_eval_global_id(
         param_env: ty::ParamEnv<'tcx>,
         cid: GlobalId<'tcx>,
         span: Option<Span>,
-    ) -> ConstEvalResult<'tcx> {
+    ) -> EvalToConstValueResult<'tcx> {
         // Const-eval shouldn't depend on lifetimes at all, so we can erase them, which should
         // improve caching of queries.
         let inputs = self.erase_regions(&param_env.and(cid));
         if let Some(span) = span {
-            self.at(span).const_eval_for_ty(inputs)
+            self.at(span).eval_to_const_value(inputs)
         } else {
-            self.const_eval_for_ty(inputs)
+            self.eval_to_const_value(inputs)
         }
     }
 
@@ -94,7 +94,7 @@ fn eval_to_allocation(
         param_env: ty::ParamEnv<'tcx>,
     ) -> Result<&'tcx mir::Allocation, ErrorHandled> {
         trace!("eval_to_allocation: Need to compute {:?}", gid);
-        let raw_const = self.const_eval(param_env.and(gid))?;
+        let raw_const = self.eval_to_allocation_raw(param_env.and(gid))?;
         Ok(self.global_alloc(raw_const.alloc_id).unwrap_memory())
     }
 }
index 7d6ff3eb5c1ccb25c7732403b2e7b7bfffe6025a..930487153c327159ee95f305daf0c94723a9ddb4 100644 (file)
@@ -12,7 +12,7 @@
 
 use super::{sign_extend, truncate, AllocId, Allocation, InterpResult, Pointer, PointerArithmetic};
 
-/// Represents the result of a raw const operation, pre-validation.
+/// Represents the result of const evaluation via the `eval_to_allocation` query.
 #[derive(Clone, HashStable)]
 pub struct RawConst<'tcx> {
     // the value lives here, at offset 0, and that allocation definitely is a `AllocKind::Memory`
index dc89cf3564897bf8a7e43ead42f14304ad004e20..ece9dcf66a3215ac91d7537c1b6593bd76a90acf 100644 (file)
@@ -708,8 +708,10 @@ fn describe_as_module(def_id: LocalDefId, tcx: TyCtxt<'_>) -> String {
 
     Other {
         /// Evaluates a constant and returns the computed allocation.
-        query const_eval(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
-            -> ConstEvalRawResult<'tcx> {
+        ///
+        /// **Do not use this** directly, use the `tcx.eval_static_initializer` wrapper.
+        query eval_to_allocation_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
+            -> EvalToAllocationRawResult<'tcx> {
             desc { |tcx|
                 "const-evaluating `{}`",
                 key.value.display(tcx)
@@ -722,8 +724,8 @@ fn describe_as_module(def_id: LocalDefId, tcx: TyCtxt<'_>) -> String {
         ///
         /// **Do not use this** directly, use one of the following wrappers: `tcx.const_eval_poly`,
         /// `tcx.const_eval_resolve`, `tcx.const_eval_instance`, or `tcx.const_eval_global_id`.
-        query const_eval_for_ty(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
-            -> ConstEvalResult<'tcx> {
+        query eval_to_const_value(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
+            -> EvalToConstValueResult<'tcx> {
             desc { |tcx|
                 "const-evaluating + checking `{}`",
                 key.value.display(tcx)
index ee9b203b151804390860599744f6fafdd88d676c..d3a7412ef14e777c2d58da3879f38373a1b28c62 100644 (file)
@@ -14,7 +14,7 @@
 use crate::middle::stability::{self, DeprecationEntry};
 use crate::mir;
 use crate::mir::interpret::GlobalId;
-use crate::mir::interpret::{ConstEvalRawResult, ConstEvalResult, ConstValue};
+use crate::mir::interpret::{ConstValue, EvalToAllocationRawResult, EvalToConstValueResult};
 use crate::mir::interpret::{LitToConstError, LitToConstInput};
 use crate::mir::mono::CodegenUnit;
 use crate::traits::query::{
index 3b01328df56c080f3bb2f25078e1757743bcee3d..7dae12cf411277d93e4b69a69bb6ccc3f5017d0e 100644 (file)
@@ -200,21 +200,21 @@ fn turn_into_const<'tcx>(
     );
     assert!(
         !is_static || cid.promoted.is_some(),
-        "the `const_eval_for_ty` query should not be used for statics, use `const_eval` instead"
+        "the `eval_to_const_value` query should not be used for statics, use `eval_to_allocation` instead"
     );
     // Turn this into a proper constant.
     op_to_const(&ecx, mplace.into())
 }
 
-pub fn const_eval_for_ty_provider<'tcx>(
+pub fn eval_to_const_value_provider<'tcx>(
     tcx: TyCtxt<'tcx>,
     key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
-) -> ::rustc_middle::mir::interpret::ConstEvalResult<'tcx> {
-    // see comment in const_eval_provider for what we're doing here
+) -> ::rustc_middle::mir::interpret::EvalToConstValueResult<'tcx> {
+    // see comment in const_eval_raw_provider for what we're doing here
     if key.param_env.reveal() == Reveal::All {
         let mut key = key;
         key.param_env = key.param_env.with_user_facing();
-        match tcx.const_eval_for_ty(key) {
+        match tcx.eval_to_const_value(key) {
             // try again with reveal all as requested
             Err(ErrorHandled::TooGeneric) => {}
             // deduplicate calls
@@ -237,13 +237,13 @@ pub fn const_eval_for_ty_provider<'tcx>(
         });
     }
 
-    tcx.const_eval(key).map(|val| turn_into_const(tcx, val, key))
+    tcx.eval_to_allocation_raw(key).map(|val| turn_into_const(tcx, val, key))
 }
 
-pub fn const_eval_provider<'tcx>(
+pub fn eval_to_allocation_raw_provider<'tcx>(
     tcx: TyCtxt<'tcx>,
     key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
-) -> ::rustc_middle::mir::interpret::ConstEvalRawResult<'tcx> {
+) -> ::rustc_middle::mir::interpret::EvalToAllocationRawResult<'tcx> {
     // Because the constant is computed twice (once per value of `Reveal`), we are at risk of
     // reporting the same error twice here. To resolve this, we check whether we can evaluate the
     // constant in the more restrictive `Reveal::UserFacing`, which most likely already was
@@ -255,7 +255,7 @@ pub fn const_eval_provider<'tcx>(
     if key.param_env.reveal() == Reveal::All {
         let mut key = key;
         key.param_env = key.param_env.with_user_facing();
-        match tcx.const_eval(key) {
+        match tcx.eval_to_allocation_raw(key) {
             // try again with reveal all as requested
             Err(ErrorHandled::TooGeneric) => {}
             // deduplicate calls
index 8b0e993f02dc3b04a07589773922eca614ad1a30..73ca7e0d471ca21dadabef1a32b06eec0c8415f4 100644 (file)
@@ -51,7 +51,7 @@ fn try_eval_const_fn_call(
 
         let gid = GlobalId { instance, promoted: None };
 
-        let place = self.const_eval(gid)?;
+        let place = self.eval_to_allocation(gid)?;
 
         self.copy_op(place.into(), dest)?;
 
index ef05d136da17ba5797caff103b715818f766b16f..00d6ffb14eaf265928c9c52dbdcedf33c65cb291 100644 (file)
@@ -875,7 +875,7 @@ pub(super) fn deallocate_local(
         Ok(())
     }
 
-    pub fn const_eval(
+    pub fn eval_to_allocation(
         &self,
         gid: GlobalId<'tcx>,
     ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
@@ -889,7 +889,7 @@ pub fn const_eval(
         } else {
             self.param_env
         };
-        let val = self.tcx.const_eval(param_env.and(gid))?;
+        let val = self.tcx.eval_to_allocation_raw(param_env.and(gid))?;
         self.raw_const_to_mplace(val)
     }
 
index 54c43b518fdddf4e7f0d081e93f6f2dd4bb44260..8c4bb19866e3f94f30f6c7a8173ab0eee47c2c01 100644 (file)
@@ -553,7 +553,7 @@ pub(super) fn eval_operands(
             ty::ConstKind::Error(_) => throw_inval!(TypeckError(ErrorReported)),
             ty::ConstKind::Unevaluated(def, substs, promoted) => {
                 let instance = self.resolve(def.did, substs)?;
-                return Ok(self.const_eval(GlobalId { instance, promoted })?.into());
+                return Ok(self.eval_to_allocation(GlobalId { instance, promoted })?.into());
             }
             ty::ConstKind::Infer(..)
             | ty::ConstKind::Bound(..)
index 07defa2d66d4dbfda2bf47709b2eb30bde49b634..bbbb25117c00c31e61b496872a1c26b41a4ddbd2 100644 (file)
@@ -52,8 +52,8 @@ pub fn provide(providers: &mut Providers) {
     transform::provide(providers);
     monomorphize::partitioning::provide(providers);
     monomorphize::polymorphize::provide(providers);
-    providers.const_eval_for_ty = const_eval::const_eval_for_ty_provider;
-    providers.const_eval = const_eval::const_eval_provider;
+    providers.eval_to_const_value = const_eval::eval_to_const_value_provider;
+    providers.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider;
     providers.const_caller_location = const_eval::const_caller_location;
     providers.destructure_const = |tcx, param_env_and_value| {
         let (param_env, value) = param_env_and_value.into_parts();