You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Investigate computing crate_hash by hashing metadata #94878
E-help-wantedCall for participation: Help is requested to fix this issue.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
The crate_hash query is used to detect is metadata has changed before attempting to decode more complex information from it.
Until now, this crate hash has been computed manually using HIR.
Computing it while encoding metadata itself may be more robust and exhaustive.
General instructions:
add a StableHasher and a StableHashingContext in rustc_metadata::rmeta::encoder::EncodeContext;
double all accesses to the embedded opaque encoder by a call to hash_stable with the same data;
manually reimplement encoding and hashing for special datatypes (CrateNum, DefId, LocalDefId...);
remove the implementation of the crate_hash query in rustc_middle::hir::map, and reimplement it from the just-encoded metadata;
evaluate effect on performance.
Please reach out on zulip if more details are required.
cc @michaelwoerister
I think this is very promising. I would suggest to entirely remove the local version of the crate_hash query. That should make things easier to implement.
The crate metadata is missing the session configuration with which the crate has been compiled. This means that eg changing optimization level probably won't change crate metadata. It probably needs to change the crate hash though. Including tcx.sess.opts.dep_tracking_hash(true) should be enough:
The object files are accessible to downstream crates (they are linked into the final artifact after all), but they depend on both the crate metadata and the compilation session options.
I think it isn't too far fetched that cargo or other build systems will use the crate hash in the far future instead of mtime or hashing the entire file.
I don't know. In my opinion the crate hash is an internal implementation detail of the incremental compilation system that's only there to optimize a common code path there. I wouldn't recommend any outside tooling to rely on it.
(I've begun looking at this already, but I've unfortunately realized that I won't have time to work on this soon enough.
Since it's both short-to-try and has mentorship available from michael and camille, it should be a good opportunity for a new contributor, rather than waiting on me and taking this opportunity away from someone who's interested.
I have no strong opinion and am willing to do whatever the local norm is. I have been leaving it open out of paranoia that we'll find a critical bug and need to roll back and retry.
E-help-wantedCall for participation: Help is requested to fix this issue.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
Activity
michaelwoerister commentedon Mar 15, 2022
I think this is very promising. I would suggest to entirely remove the local version of the
crate_hashquery. That should make things easier to implement.lqd commentedon Mar 15, 2022
@rustbot claim
bjorn3 commentedon Mar 15, 2022
The crate metadata is missing the session configuration with which the crate has been compiled. This means that eg changing optimization level probably won't change crate metadata. It probably needs to change the crate hash though. Including
tcx.sess.opts.dep_tracking_hash(true)should be enough:rust/compiler/rustc_middle/src/hir/map/mod.rs
Line 1135 in 4e82f35
michaelwoerister commentedon Mar 15, 2022
Ideally it wouldn't be necessary because the hash includes everything that is accessible to downstream crates, right?
bjorn3 commentedon Mar 15, 2022
The object files are accessible to downstream crates (they are linked into the final artifact after all), but they depend on both the crate metadata and the compilation session options.
michaelwoerister commentedon Mar 15, 2022
Yes, but linking is done unconditionally, independent of the crate hash.
bjorn3 commentedon Mar 15, 2022
I think it isn't too far fetched that cargo or other build systems will use the crate hash in the far future instead of mtime or hashing the entire file.
michaelwoerister commentedon Mar 15, 2022
I don't know. In my opinion the crate hash is an internal implementation detail of the incremental compilation system that's only there to optimize a common code path there. I wouldn't recommend any outside tooling to rely on it.
bjorn3 commentedon Mar 15, 2022
The crate hash existed long before incremental compilation was introduced afaik.
bjorn3 commentedon Mar 15, 2022
The SVH has introduced feb 2014 in ec57db0
lqd commentedon Apr 22, 2022
(I've begun looking at this already, but I've unfortunately realized that I won't have time to work on this soon enough.
Since it's both short-to-try and has mentorship available from michael and camille, it should be a good opportunity for a new contributor, rather than waiting on me and taking this opportunity away from someone who's interested.
@rustbot release-assignment
)
30 remaining items
Auto merge of #154724 - Daniel-B-Smith:smithdb3/fix-94878, r=oli-obk
Auto merge of #154724 - Daniel-B-Smith:smithdb3/fix-94878, r=<try>
Auto merge of #154724 - Daniel-B-Smith:smithdb3/fix-94878, r=oli-obk
Kobzol commentedon Sep 27, 2026
Should this be closed, now that #154724 has landed?
Rollup merge of rust-lang#163455 - Daniel-B-Smith:smithdb3/163426, r=…
Rollup merge of rust-lang#163455 - Daniel-B-Smith:smithdb3/163426, r=…
Rollup merge of rust-lang#163455 - Daniel-B-Smith:smithdb3/163426, r=…
Rollup merge of rust-lang#163455 - Daniel-B-Smith:smithdb3/163426, r=…
Rollup merge of rust-lang#163455 - Daniel-B-Smith:smithdb3/163426, r=…
Unrolled build for #163455 in rollup 163583
Rollup merge of #163455 - Daniel-B-Smith:smithdb3/163426, r=bjorn3
Rollup merge of #163455 - Daniel-B-Smith:smithdb3/163426, r=bjorn3
Daniel-B-Smith commentedon Oct 16, 2026
I have no strong opinion and am willing to do whatever the local norm is. I have been leaving it open out of paranoia that we'll find a critical bug and need to roll back and retry.
Kobzol commentedon Oct 16, 2026
In that case it can be reopened. I think that we can close this now. Great work on this!