Make sure to record deps from cached task in new solver on first run · rust-lang/rust@988f28d (original) (raw)

File tree

4 files changed

lines changed

4 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -302,7 +302,11 @@ impl<D: Deps> DepGraph {
302 302 OP: FnOnce() -> R,
303 303 {
304 304 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 +}
306 310 None => (op(), self.next_virtual_depnode_index()),
307 311 }
308 312 }
@@ -397,7 +401,16 @@ impl<D: Deps> DepGraphData {
397 401
398 402 /// Executes something within an "anonymous" task, that is, a task the
399 403 /// `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>(
401 414 &self,
402 415 cx: Tcx,
403 416 dep_kind: DepKind,
Original file line number Diff line number Diff line change
@@ -520,9 +520,11 @@ where
520 520 let (result, dep_node_index) =
521 521 qcx.start_query(job_id, query.depth_limit(), Some(&diagnostics), |
522 522 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 + |
527 +);
526 528 }
527 529
528 530 // `to_dep_node` is expensive for some `DepKind`s.
Original file line number Diff line number Diff line change
@@ -1400,10 +1400,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1400 1400 where
1401 1401 OP: FnOnce(&mut Self) -> R,
1402 1402 {
1403 -let (result, dep_node) =
1404 -self.tcx().dep_graph.with_anon_task(self.tcx(), dep_kinds::TraitSelect, |
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, |
1407 1404 }
1408 1405
1409 1406 /// filter_impls filters candidates that have a positive impl for a negative
Original file line number Diff line number Diff line change
@@ -511,7 +511,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph {
511 511
512 512 // This is for global caching, so we properly track query dependencies.
513 513 // 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
515 515 // not tracked by the cache key and from outside of this anon task, it
516 516 // must not be added to the global cache. Notably, this is the case for
517 517 // trait solver cycles participants.