Skip to content

Commit f77f4d5

Browse files
committed
Auto merge of #107542 - compiler-errors:param-envs-with-inference-vars-are-cursed, r=jackh726
Don't call `with_reveal_all_normalized` in const-eval when `param_env` has inference vars in it **what:** This slightly shifts the order of operations from an existing hack: https://github.com/rust-lang/rust/blob/5b6ed253c42a69b93e7447fb0874a89ab6bc1cfb/compiler/rustc_middle/src/ty/consts/kind.rs#L225-L230 in order to avoid calling a tcx query (`TyCtxt::reveal_opaque_types_in_bounds`, via `ParamEnv::with_reveal_all_normalized`) when a param-env has inference variables in it. **why:** This allows us to enable fingerprinting of query keys/values outside of incr-comp in deubg mode, to make sure we catch other places where we're passing infer vars and other bad things into query keys. Currently that (bbf3383) crashes because we introduce inference vars into a param-env in the blanket-impl finder in rustdoc 😓 https://github.com/rust-lang/rust/blob/5b6ed253c42a69b93e7447fb0874a89ab6bc1cfb/src/librustdoc/clean/blanket_impl.rs#L43 See the CI failure here: https://github.com/rust-lang/rust/actions/runs/4058194838/jobs/6984834619
2 parents 4507fda + 789e828 commit f77f4d5

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

compiler/rustc_middle/src/ty/consts/kind.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -217,23 +217,21 @@ impl<'tcx> ConstKind<'tcx> {
217217
// Note that we erase regions *before* calling `with_reveal_all_normalized`,
218218
// so that we don't try to invoke this query with
219219
// any region variables.
220-
let param_env_and = tcx
221-
.erase_regions(param_env)
222-
.with_reveal_all_normalized(tcx)
223-
.and(tcx.erase_regions(unevaluated));
224220

225221
// HACK(eddyb) when the query key would contain inference variables,
226222
// attempt using identity substs and `ParamEnv` instead, that will succeed
227223
// when the expression doesn't depend on any parameters.
228224
// FIXME(eddyb, skinny121) pass `InferCtxt` into here when it's available, so that
229225
// we can call `infcx.const_eval_resolve` which handles inference variables.
230-
let param_env_and = if param_env_and.needs_infer() {
226+
let param_env_and = if (param_env, unevaluated).has_non_region_infer() {
231227
tcx.param_env(unevaluated.def.did).and(ty::UnevaluatedConst {
232228
def: unevaluated.def,
233229
substs: InternalSubsts::identity_for_item(tcx, unevaluated.def.did),
234230
})
235231
} else {
236-
param_env_and
232+
tcx.erase_regions(param_env)
233+
.with_reveal_all_normalized(tcx)
234+
.and(tcx.erase_regions(unevaluated))
237235
};
238236

239237
// FIXME(eddyb) maybe the `const_eval_*` methods should take

compiler/rustc_query_system/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#![feature(hash_raw_entry)]
44
#![feature(min_specialization)]
55
#![feature(extern_types)]
6+
#![feature(let_chains)]
67
#![allow(rustc::potential_query_instability)]
78
#![deny(rustc::untranslatable_diagnostic)]
89
#![deny(rustc::diagnostic_outside_of_impl)]

compiler/rustc_query_system/src/query/plumbing.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! generate the actual methods on tcx which find and execute the provider,
33
//! manage the caches, and so forth.
44
5-
use crate::dep_graph::{DepContext, DepKind, DepNode, DepNodeIndex};
5+
use crate::dep_graph::{DepContext, DepKind, DepNode, DepNodeIndex, DepNodeParams};
66
use crate::ich::StableHashingContext;
77
use crate::query::caches::QueryCache;
88
use crate::query::job::{report_cycle, QueryInfo, QueryJob, QueryJobId, QueryJobInfo};
@@ -408,10 +408,27 @@ where
408408

409409
// Fast path for when incr. comp. is off.
410410
if !dep_graph.is_fully_enabled() {
411+
// Fingerprint the key, just to assert that it doesn't
412+
// have anything we don't consider hashable
413+
if cfg!(debug_assertions) {
414+
let _ = key.to_fingerprint(*qcx.dep_context());
415+
}
416+
411417
let prof_timer = qcx.dep_context().profiler().query_provider();
412418
let result = qcx.start_query(job_id, Q::DEPTH_LIMIT, None, || Q::compute(qcx, key));
413419
let dep_node_index = dep_graph.next_virtual_depnode_index();
414420
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
421+
422+
// Similarly, fingerprint the result to assert that
423+
// it doesn't have anything not considered hashable.
424+
if cfg!(debug_assertions)
425+
&& let Some(hash_result) = Q::HASH_RESULT
426+
{
427+
qcx.dep_context().with_stable_hashing_context(|mut hcx| {
428+
hash_result(&mut hcx, &result);
429+
});
430+
}
431+
415432
return (result, dep_node_index);
416433
}
417434

0 commit comments

Comments
 (0)