Skip to content

Commit 84bab31

Browse files
committed
Auto merge of #96840 - cjgillot:query-feed, r=oli-obk
Allow to feed a value in another query's cache and remove `WithOptConstParam` I used it to remove `WithOptConstParam` queries, as an example. The idea is that a query (here `typeck(function)`) can write into another query's cache (here `type_of(anon const)`). The dependency node for `type_of` would depend on all the current dependencies of `typeck`. There is still an issue with cycles: if `type_of(anon const)` is accessed before `typeck(function)`, we will still have the usual cycle. The way around this issue is to `ensure` that `typeck(function)` is called before accessing `type_of(anon const)`. When replayed, we may the following cases: - `typeck` is green, in that case `type_of` is green too, and all is right; - `type_of` is green, `typeck` may still be marked as red (it depends on strictly more things than `type_of`) -> we verify that the saved value and the re-computed value of `type_of` have the same hash; - `type_of` is red, then `typeck` is red -> it's the caller responsibility to ensure `typeck` is recomputed *before* `type_of`. As `anon consts` have their own `DefPathData`, it's not possible to have the def-id of the anon-const point to something outside the original function, but the general case may have to be resolved before using this device more broadly. There is an open question about loading from the on-disk cache. If `typeck` is loaded from the on-disk cache, the side-effect does not happen. The regular `type_of` implementation can go and fetch the correct value from the decoded `typeck` results, and the dep-graph will check that the hashes match, but I'm not sure we want to rely on this behaviour. I specifically allowed to feed the value to `type_of` from inside a call to `type_of`. In that case, the dep-graph will check that the fingerprints of both values match. This implementation is still very sensitive to cycles, and requires that we call `typeck(function)` before `typeck(anon const)`. The reason is that `typeck(anon const)` calls `type_of(anon const)`, which calls `typeck(function)`, which feeds `type_of(anon const)`, and needs to build the MIR so needs `typeck(anon const)`. The latter call would not cycle, since `type_of(anon const)` has been set, but I'd rather not remove the cycle check.
2 parents e8197b1 + 8ead58c commit 84bab31

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

clippy_lints/src/non_copy_const.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,9 @@ fn is_value_unfrozen_poly<'tcx>(cx: &LateContext<'tcx>, body_id: BodyId, ty: Ty<
196196
fn is_value_unfrozen_expr<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId, def_id: DefId, ty: Ty<'tcx>) -> bool {
197197
let substs = cx.typeck_results().node_substs(hir_id);
198198

199-
let result = cx.tcx.const_eval_resolve(
200-
cx.param_env,
201-
mir::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs),
202-
None,
203-
);
199+
let result = cx
200+
.tcx
201+
.const_eval_resolve(cx.param_env, mir::UnevaluatedConst::new(def_id, substs), None);
204202
is_value_unfrozen_raw(cx, result, ty)
205203
}
206204

clippy_utils/src/consts.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -450,11 +450,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
450450
let result = self
451451
.lcx
452452
.tcx
453-
.const_eval_resolve(
454-
self.param_env,
455-
mir::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs),
456-
None,
457-
)
453+
.const_eval_resolve(self.param_env, mir::UnevaluatedConst::new(def_id, substs), None)
458454
.ok()
459455
.map(|val| rustc_middle::mir::ConstantKind::from_value(val, ty))?;
460456
let result = miri_to_const(self.lcx.tcx, result);

0 commit comments

Comments
 (0)