]> git.lizzy.rs Git - rust.git/commit
Rollup merge of #93064 - Aaron1011:provisional-dep-node, r=michaelwoerister
authorMatthias Krüger <matthias.krueger@famsik.de>
Tue, 25 Jan 2022 04:51:10 +0000 (05:51 +0100)
committerGitHub <noreply@github.com>
Tue, 25 Jan 2022 04:51:10 +0000 (05:51 +0100)
commitcf7041186c047ca329c196d0153abefdccf44d04
tree273f838e4293fffd5617586a6d359f0f7d9eecb7
parent687bb583c85a66eec094e7edb07ca314541f2330
parent02f1a565fee32ac9710b19a73539646d6454b085
Rollup merge of #93064 - Aaron1011:provisional-dep-node, r=michaelwoerister

Properly track `DepNode`s in trait evaluation provisional cache

Fixes #92987

During evaluation of an auto trait predicate, we may encounter a cycle.
This causes us to store the evaluation result in a special 'provisional
cache;. If we later end up determining that the type can legitimately
implement the auto trait despite the cycle, we remove the entry from
the provisional cache, and insert it into the evaluation cache.

Additionally, trait evaluation creates a special anonymous `DepNode`.
All queries invoked during the predicate evaluation are added as
outoging dependency edges from the `DepNode`. This `DepNode` is then
store in the evaluation cache - if a different query ends up reading
from the cache entry, it will also perform a read of the stored
`DepNode`. As a result, the cached evaluation will still end up
(transitively) incurring all of the same dependencies that it would
if it actually performed the uncached evaluation (e.g. a call to
`type_of` to determine constituent types).

Previously, we did not correctly handle the interaction between the
provisional cache and the created `DepNode`. Storing an evaluation
result in the provisional cache would cause us to lose the `DepNode`
created during the evaluation. If we later moved the entry from the
provisional cache to the evaluation cache, we would use the `DepNode`
associated with the evaluation that caused us to 'complete' the cycle,
not the evaluatoon where we first discovered the cycle. As a result,
future reads from the evaluation cache would miss some incremental
compilation dependencies that would have otherwise been added if the
evaluation was *not* cached.

Under the right circumstances, this could lead to us trying to force
a query with a no-longer-existing `DefPathHash`, since we were missing
the (red) dependency edge that would have caused us to bail out before
attempting forcing.

This commit makes the provisional cache store the `DepNode` create
during the provisional evaluation. When we move an entry from the
provisional cache to the evaluation cache, we create a *new* `DepNode`
that has dependencies going to *both* of the evaluation `DepNodes` we
have available. This ensures that cached reads will incur all of
the necessary dependency edges.
compiler/rustc_trait_selection/src/traits/select/mod.rs