about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Schneider <github35764891676564198441@oli-obk.de>2018-09-03 17:09:24 +0200
committerOliver Scherer <github35764891676564198441@oli-obk.de>2018-10-25 16:47:35 +0200
commitd736197bc2040d1b76e91567ae09f1eb35f3a28c (patch)
treeafe156dc6f0def0ae4504f606e67dda97dc8a5db
parentb4ee38ede3d6a3418103336cecdb8bd08db8e5ab (diff)
downloadrust-d736197bc2040d1b76e91567ae09f1eb35f3a28c.tar.gz
rust-d736197bc2040d1b76e91567ae09f1eb35f3a28c.zip
Explain the `Reveal::UserFacing` deduplication trick
-rw-r--r--src/librustc_mir/const_eval.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs
index 861d0b2f7e1..f105df304f4 100644
--- a/src/librustc_mir/const_eval.rs
+++ b/src/librustc_mir/const_eval.rs
@@ -577,6 +577,7 @@ pub fn const_eval_provider<'a, 'tcx>(
     tcx: TyCtxt<'a, 'tcx, 'tcx>,
     key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
 ) -> ::rustc::mir::interpret::ConstEvalResult<'tcx> {
+    // see comment in const_eval_provider for what we're doing here
     if key.param_env.reveal == Reveal::All {
         let mut key = key.clone();
         key.param_env.reveal = Reveal::UserFacing;
@@ -596,6 +597,12 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
     tcx: TyCtxt<'a, 'tcx, 'tcx>,
     key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
 ) -> ::rustc::mir::interpret::ConstEvalResult<'tcx> {
+    // so we do a small trick here. We check whether we can evaluate the constant in the more
+    // restrictive `Reveal::UserFacing`, which most likely already was computed. In a large
+    // percentage of constants that will already have succeeded. Only associated constants of
+    // generic functions will fail due to not enough monomorphization information being available
+
+    // in case we fail in the `UserFacing` variant, we just do the real computation.
     if key.param_env.reveal == Reveal::All {
         let mut key = key.clone();
         key.param_env.reveal = Reveal::UserFacing;