Skip to content

Commit 76a24ac

Browse files
committed
Auto merge of rust-lang#121387 - oli-obk:eager_const_failures_regression, r=<try>
Avoid some unnecessary query invocations. Specifically this inlines `const_eval_poly` and avoids computing the generic params, the param env, normalizing the param env and erasing lifetimes on everything. should fix the perf regression from rust-lang#121087
2 parents 026b3b8 + 0df64c5 commit 76a24ac

File tree

1 file changed

+7
-1
lines changed
  • compiler/rustc_hir_analysis/src

1 file changed

+7
-1
lines changed

compiler/rustc_hir_analysis/src/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ mod variance;
101101
use rustc_errors::ErrorGuaranteed;
102102
use rustc_hir as hir;
103103
use rustc_middle::middle;
104+
use rustc_middle::mir::interpret::GlobalId;
104105
use rustc_middle::query::Providers;
105106
use rustc_middle::ty::{self, Ty, TyCtxt};
106107
use rustc_middle::util;
@@ -204,7 +205,12 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
204205
let def_kind = tcx.def_kind(item_def_id);
205206
match def_kind {
206207
DefKind::Static(_) => tcx.ensure().eval_static_initializer(item_def_id),
207-
DefKind::Const => tcx.ensure().const_eval_poly(item_def_id.into()),
208+
DefKind::Const if tcx.generics_of(item_def_id).params.is_empty() => {
209+
let instance = ty::Instance::new(item_def_id.into(), ty::GenericArgs::empty());
210+
let cid = GlobalId { instance, promoted: None };
211+
let param_env = ty::ParamEnv::reveal_all();
212+
tcx.ensure().eval_to_const_value_raw(param_env.and(cid));
213+
}
208214
_ => (),
209215
}
210216
});

0 commit comments

Comments
 (0)