Skip to content

Commit 1daa912

Browse files
committed
Auto merge of #53825 - oli-obk:beta_backport, r=RalfJung
[beta] const eval perf regression fix backports #52925 (for #52849) and additionally skips hashing on every evaluation step
2 parents 49720ea + 860b257 commit 1daa912

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/librustc_lint/builtin.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -1631,16 +1631,22 @@ fn validate_const<'a, 'tcx>(
16311631

16321632
fn check_const(cx: &LateContext, body_id: hir::BodyId, what: &str) {
16331633
let def_id = cx.tcx.hir.body_owner_def_id(body_id);
1634-
let param_env = cx.tcx.param_env(def_id);
1634+
let is_static = cx.tcx.is_static(def_id).is_some();
1635+
let param_env = if is_static {
1636+
// Use the same param_env as `codegen_static_initializer`, to reuse the cache.
1637+
ty::ParamEnv::reveal_all()
1638+
} else {
1639+
cx.tcx.param_env(def_id)
1640+
};
16351641
let cid = ::rustc::mir::interpret::GlobalId {
16361642
instance: ty::Instance::mono(cx.tcx, def_id),
16371643
promoted: None
16381644
};
16391645
match cx.tcx.const_eval(param_env.and(cid)) {
16401646
Ok(val) => validate_const(cx.tcx, val, param_env, cid, what),
16411647
Err(err) => {
1642-
// errors for statics are already reported directly in the query
1643-
if cx.tcx.is_static(def_id).is_none() {
1648+
// errors for statics are already reported directly in the query, avoid duplicates
1649+
if !is_static {
16441650
let span = cx.tcx.def_span(def_id);
16451651
err.report_as_lint(
16461652
cx.tcx.at(span),

src/librustc_mir/interpret/eval_context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,10 @@ impl<'a, 'mir, 'tcx, M> InfiniteLoopDetector<'a, 'mir, 'tcx, M>
214214
stack: &Vec<Frame<'mir, 'tcx>>,
215215
memory: &Memory<'a, 'mir, 'tcx, M>,
216216
) -> EvalResult<'tcx, ()> {
217-
let snapshot = (machine, stack, memory);
218-
219217
let mut fx = FxHasher::default();
220-
snapshot.hash(&mut fx);
218+
// don't hash the memory, that takes too much time, just compare when you hit a collision
219+
// should be rare enough
220+
(machine, stack).hash(&mut fx);
221221
let hash = fx.finish();
222222

223223
if self.hashes.insert(hash) {

0 commit comments

Comments
 (0)