Skip to content

Commit 5a0a5e6

Browse files
committed
Auto merge of #133828 - compiler-errors:incr-sad, r=lcnr
Make sure to record deps from cached task in new solver on first run We weren't actually performing a read of the dep node in `with_cached_task` in the new solver, which meant that all queries that computed a goal for the first time were just not recording the query dependencies that we call in that query. In the incremental test, the typeck query for `fn poll` isn't being marked red even tho it's invalidated due to its writeback results changing. This happens b/c we normalize `Self::Error` into `Error`, which should call `type_of` which is a red query (since `ty::Adt` contains an `AdtDef`, and that `AdtDef`'s stable hash changes since it's ). However, since we weren't tracking deps in that normalize query, the typeck result was remaining green, and we were trying to decode a def id that no longer exists (the field that got removed). r? lcnr
2 parents acabb52 + 988f28d commit 5a0a5e6

File tree

5 files changed

+47
-10
lines changed

5 files changed

+47
-10
lines changed

compiler/rustc_query_system/src/dep_graph/graph.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,11 @@ impl<D: Deps> DepGraph<D> {
302302
OP: FnOnce() -> R,
303303
{
304304
match self.data() {
305-
Some(data) => data.with_anon_task(cx, dep_kind, op),
305+
Some(data) => {
306+
let (result, index) = data.with_anon_task_inner(cx, dep_kind, op);
307+
self.read_index(index);
308+
(result, index)
309+
}
306310
None => (op(), self.next_virtual_depnode_index()),
307311
}
308312
}
@@ -397,7 +401,16 @@ impl<D: Deps> DepGraphData<D> {
397401

398402
/// Executes something within an "anonymous" task, that is, a task the
399403
/// `DepNode` of which is determined by the list of inputs it read from.
400-
pub(crate) fn with_anon_task<Tcx: DepContext<Deps = D>, OP, R>(
404+
///
405+
/// NOTE: this does not actually count as a read of the DepNode here.
406+
/// Using the result of this task without reading the DepNode will result
407+
/// in untracked dependencies which may lead to ICEs as nodes are
408+
/// incorrectly marked green.
409+
///
410+
/// FIXME: This could perhaps return a `WithDepNode` to ensure that the
411+
/// user of this function actually performs the read; we'll have to see
412+
/// how to make that work with `anon` in `execute_job_incr`, though.
413+
pub(crate) fn with_anon_task_inner<Tcx: DepContext<Deps = D>, OP, R>(
401414
&self,
402415
cx: Tcx,
403416
dep_kind: DepKind,

compiler/rustc_query_system/src/query/plumbing.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,11 @@ where
520520
let (result, dep_node_index) =
521521
qcx.start_query(job_id, query.depth_limit(), Some(&diagnostics), || {
522522
if query.anon() {
523-
return dep_graph_data.with_anon_task(*qcx.dep_context(), query.dep_kind(), || {
524-
query.compute(qcx, key)
525-
});
523+
return dep_graph_data.with_anon_task_inner(
524+
*qcx.dep_context(),
525+
query.dep_kind(),
526+
|| query.compute(qcx, key),
527+
);
526528
}
527529

528530
// `to_dep_node` is expensive for some `DepKind`s.

compiler/rustc_trait_selection/src/traits/select/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1400,10 +1400,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
14001400
where
14011401
OP: FnOnce(&mut Self) -> R,
14021402
{
1403-
let (result, dep_node) =
1404-
self.tcx().dep_graph.with_anon_task(self.tcx(), dep_kinds::TraitSelect, || op(self));
1405-
self.tcx().dep_graph.read_index(dep_node);
1406-
(result, dep_node)
1403+
self.tcx().dep_graph.with_anon_task(self.tcx(), dep_kinds::TraitSelect, || op(self))
14071404
}
14081405

14091406
/// filter_impls filters candidates that have a positive impl for a negative

compiler/rustc_type_ir/src/search_graph/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
511511

512512
// This is for global caching, so we properly track query dependencies.
513513
// Everything that affects the `result` should be performed within this
514-
// `with_anon_task` closure. If computing this goal depends on something
514+
// `with_cached_task` closure. If computing this goal depends on something
515515
// not tracked by the cache key and from outside of this anon task, it
516516
// must not be added to the global cache. Notably, this is the case for
517517
// trait solver cycles participants.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//@ revisions: cfail1 cfail2
2+
3+
//@ compile-flags: -Znext-solver
4+
//@ check-pass
5+
6+
pub trait Future {
7+
type Error;
8+
fn poll() -> Self::Error;
9+
}
10+
11+
struct S;
12+
impl Future for S {
13+
type Error = Error;
14+
fn poll() -> Self::Error {
15+
todo!()
16+
}
17+
}
18+
19+
#[cfg(cfail1)]
20+
pub struct Error(());
21+
22+
#[cfg(cfail2)]
23+
pub struct Error();
24+
25+
fn main() {}

0 commit comments

Comments
 (0)