Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate computing crate_hash by hashing metadata #94878

Open
cjgillot opened this issue Mar 12, 2022 · 17 comments
Open

Investigate computing crate_hash by hashing metadata #94878

cjgillot opened this issue Mar 12, 2022 · 17 comments
Labels
E-help-wanted Call for participation: Help is requested to fix this issue. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cjgillot
Copy link
Contributor

cjgillot commented Mar 12, 2022

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

@cjgillot cjgillot added E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. E-help-wanted Call for participation: Help is requested to fix this issue. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. labels Mar 12, 2022
@michaelwoerister
Copy link
Member

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.

@lqd
Copy link
Member

lqd commented Mar 15, 2022

@rustbot claim

@bjorn3
Copy link
Member

bjorn3 commented 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:

tcx.sess.opts.dep_tracking_hash(true).hash_stable(&mut hcx, &mut stable_hasher);

@michaelwoerister
Copy link
Member

Ideally it wouldn't be necessary because the hash includes everything that is accessible to downstream crates, right?

@bjorn3
Copy link
Member

bjorn3 commented 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
Copy link
Member

Yes, but linking is done unconditionally, independent of the crate hash.

@bjorn3
Copy link
Member

bjorn3 commented 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
Copy link
Member

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
Copy link
Member

bjorn3 commented Mar 15, 2022

The crate hash existed long before incremental compilation was introduced afaik.

@bjorn3
Copy link
Member

bjorn3 commented Mar 15, 2022

The SVH has introduced feb 2014 in ec57db0

The goal of this hash is to identify when upstream crates have changed but
downstream crates have not been recompiled.

@lqd
Copy link
Member

lqd commented 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
)

@rustbot rustbot unassigned lqd Apr 22, 2022
@PrestonFrom
Copy link
Contributor

I'm still pretty new, but I'd like to take a stab at this. If it would be more appropriate for something with more experience, though, I'm happy to be un-assigned.

@rustbot claim

@PrestonFrom
Copy link
Contributor

I've gotten very busy all the sudden -- I'm going to unassign myself in case someone has bandwidth to grab this now.

@PrestonFrom PrestonFrom removed their assignment May 11, 2022
@kartva
Copy link
Contributor

kartva commented May 21, 2022

@rustbot claim

@Enselic
Copy link
Member

Enselic commented Mar 16, 2024

Triage: Are you still working on this @DesmondWillowbrook ?

@pierwill
Copy link
Member

pierwill commented Mar 16, 2024 via email

@kartva
Copy link
Contributor

kartva commented Mar 19, 2024

@rustbot release-assignment

@Enselic Enselic added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-help-wanted Call for participation: Help is requested to fix this issue. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

8 participants