From b6cb9b6d655a300955de1249bfc30ca0bfd1f70b Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 1 Aug 2018 00:25:46 +0200 Subject: [PATCH 1/3] check_const: use the same ParamEnv as codegen for statics --- src/librustc_lint/builtin.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 95da9ffe3a540..c419637059b4c 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1631,7 +1631,12 @@ fn validate_const<'a, 'tcx>( fn check_const(cx: &LateContext, body_id: hir::BodyId, what: &str) { let def_id = cx.tcx.hir.body_owner_def_id(body_id); - let param_env = cx.tcx.param_env(def_id); + let is_static = cx.tcx.is_static(def_id).is_some(); + let param_env = if is_static { + ty::ParamEnv::reveal_all() + } else { + cx.tcx.param_env(def_id) + }; let cid = ::rustc::mir::interpret::GlobalId { instance: ty::Instance::mono(cx.tcx, def_id), promoted: None @@ -1639,8 +1644,8 @@ fn check_const(cx: &LateContext, body_id: hir::BodyId, what: &str) { match cx.tcx.const_eval(param_env.and(cid)) { Ok(val) => validate_const(cx.tcx, val, param_env, cid, what), Err(err) => { - // errors for statics are already reported directly in the query - if cx.tcx.is_static(def_id).is_none() { + // errors for statics are already reported directly in the query, avoid duplicates + if !is_static { let span = cx.tcx.def_span(def_id); err.report_as_lint( cx.tcx.at(span), From 4a895585d8940efa85bae9acb6acc195166c361e Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 1 Aug 2018 08:39:30 +0200 Subject: [PATCH 2/3] add comment --- src/librustc_lint/builtin.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index c419637059b4c..9dd6bd594b7e9 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1633,6 +1633,7 @@ fn check_const(cx: &LateContext, body_id: hir::BodyId, what: &str) { let def_id = cx.tcx.hir.body_owner_def_id(body_id); let is_static = cx.tcx.is_static(def_id).is_some(); let param_env = if is_static { + // Use the same param_env as `codegen_static_initializer`, to reuse the cache. ty::ParamEnv::reveal_all() } else { cx.tcx.param_env(def_id) From 860b257178f5d9f13f574ca6143780df9e30330f Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Thu, 30 Aug 2018 16:38:35 +0200 Subject: [PATCH 3/3] Don't hash the ctfe memory --- src/librustc_mir/interpret/eval_context.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index c6c1a1d1ebb22..8c071ff7234ec 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -214,10 +214,10 @@ impl<'a, 'mir, 'tcx, M> InfiniteLoopDetector<'a, 'mir, 'tcx, M> stack: &Vec>, memory: &Memory<'a, 'mir, 'tcx, M>, ) -> EvalResult<'tcx, ()> { - let snapshot = (machine, stack, memory); - let mut fx = FxHasher::default(); - snapshot.hash(&mut fx); + // don't hash the memory, that takes too much time, just compare when you hit a collision + // should be rare enough + (machine, stack).hash(&mut fx); let hash = fx.finish(); if self.hashes.insert(hash) {