Allow to feed a value in another query's cache and remove `WithOptConstParam` by...
source link: https://github.com/rust-lang/rust/pull/96840
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Conversation
Contributor
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 casetype_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 thantype_of
) -> we verify that the saved value and the re-computed value oftype_of
have the same hash;type_of
is red, thentypeck
is red -> it's the caller responsibility to ensuretypeck
is recomputed beforetype_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.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK