Skip to content

Commit d736197

Browse files
committed
Explain the Reveal::UserFacing deduplication trick
1 parent b4ee38e commit d736197

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/librustc_mir/const_eval.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ pub fn const_eval_provider<'a, 'tcx>(
577577
tcx: TyCtxt<'a, 'tcx, 'tcx>,
578578
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
579579
) -> ::rustc::mir::interpret::ConstEvalResult<'tcx> {
580+
// see comment in const_eval_provider for what we're doing here
580581
if key.param_env.reveal == Reveal::All {
581582
let mut key = key.clone();
582583
key.param_env.reveal = Reveal::UserFacing;
@@ -596,6 +597,12 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
596597
tcx: TyCtxt<'a, 'tcx, 'tcx>,
597598
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
598599
) -> ::rustc::mir::interpret::ConstEvalResult<'tcx> {
600+
// so we do a small trick here. We check whether we can evaluate the constant in the more
601+
// restrictive `Reveal::UserFacing`, which most likely already was computed. In a large
602+
// percentage of constants that will already have succeeded. Only associated constants of
603+
// generic functions will fail due to not enough monomorphization information being available
604+
605+
// in case we fail in the `UserFacing` variant, we just do the real computation.
599606
if key.param_env.reveal == Reveal::All {
600607
let mut key = key.clone();
601608
key.param_env.reveal = Reveal::UserFacing;

0 commit comments

Comments
 (0)