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

Add TRACKED_NO_CRATE_HASH and use it for --remap-path-prefix #84233

Merged
merged 5 commits into from
Apr 29, 2021

Conversation

jyn514
Copy link
Member

@jyn514 jyn514 commented Apr 15, 2021

In #48162, --remap-path-prefix was changed to be untracked by incremental compilation so that .rlibs built with and without it would be bitwise identical. Since --remap-path-prefix is used for reproducible builds, it's important that it doesn't change the output rlib.

Unfortunately, that broke incremental recompilation because we no longer rebuilt the rlib when --remap-path-prefix changed. To avoid that, but still make sure the output is bitwise identical, this PR adds a new TRACKED_NO_CRATE_HASH mode for CLI options. This invalidates the incremental cache, without adding the option to the crate hash embedded in the rlib.

  • Add TRACKED_NO_CRATE_HASH and cbeuw's SUBSTRUCT idea
  • Refactor the unit tests to ensure non_default_option isn't the default, which found a couple bugs.
  • Refactor the tests to have less boilerplate
  • Remove real_rust_source_base_dir from Session so it's only hashed once

I verified locally that this fixes #66955.

r? @Aaron1011 (feel free to reassign)

@jyn514 jyn514 added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-incr-comp Area: Incremental compilation labels Apr 15, 2021
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 15, 2021
@Aaron1011
Copy link
Member

@jyn514: Can you add a test to compiler/rustc_interface/src/tests.rs to ensure that the option stays tracked?

@rust-log-analyzer

This comment has been minimized.

@jyn514
Copy link
Member Author

jyn514 commented Apr 16, 2021

@jyn514: Can you add a test to compiler/rustc_interface/src/tests.rs to ensure that the option stays tracked?

Done, and I also tested that non_default_option isn't the default, which found a couple bugs.

@jyn514
Copy link
Member Author

jyn514 commented Apr 16, 2021

Hmm, the test in reproducible-builds seems wrong? Presumably the .rlib is different because it's now hashing the --remap-path-prefix argument. Is there a reason it tests the .rlib specifically instead of some binary compiled using it?

@jyn514
Copy link
Member Author

jyn514 commented Apr 16, 2021

Actually I wonder if the issue is that tracked options make it all the way to .rlibs? I would expect them to only be stored in the incremental cache, not in any outputs.

@rust-log-analyzer

This comment has been minimized.

@jyn514
Copy link
Member Author

jyn514 commented Apr 16, 2021

Hmm, it looks like this was intentionally changed in #48162 ? @michaelwoerister do you have suggestions for invalidating the cache when this changes without also changing the output .rlib?

@Aaron1011 Aaron1011 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 16, 2021
@michaelwoerister
Copy link
Member

This is on my todo list. It does not look like a trivial problem.

@jyn514 jyn514 assigned michaelwoerister and unassigned Aaron1011 Apr 21, 2021
@jyn514 jyn514 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 21, 2021
@michaelwoerister
Copy link
Member

michaelwoerister commented Apr 23, 2021

It looks like we can't make the option [TRACKED] in its current form (because that would break reproducible builds) but #83813 will probably introduce a new form of tracking that should solve this problem.

@jyn514
Copy link
Member Author

jyn514 commented Apr 26, 2021

This is waiting on me to implement #83813 (comment).

@jyn514 jyn514 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 26, 2021
@jyn514
Copy link
Member Author

jyn514 commented Apr 26, 2021

If you pull the body of the [TRACKED] branch in hash_option!() out into a function, it should be straightforward to add a [TRACKED_NO_CRATE_HASH] branch. You could then add a include_no_crate_hash_options parameter to dep_tracking_hash(). That way we won't have to change how things work in the dep-graph -- just pass true there and false in hir::map::index_hir().

@michaelwoerister hmm, there's also a impl dep_tracking::DepTrackingHash for Options - should that include the hash or not? Or should I remove that impl so everyone calling this has to chose explicitly?

@jyn514
Copy link
Member Author

jyn514 commented Apr 26, 2021

should I remove that impl so everyone calling this has to chose explicitly?

I tried this and it doesn't work because sub_hashes.insert uses a trait object:

error[E0277]: the trait bound `options::DebuggingOptions: DepTrackingHash` is not satisfied
   --> compiler/rustc_session/src/options.rs:65:34
    |
49  | / macro_rules! top_level_options {
50  | |     (pub struct Options { $(
51  | |         $opt:ident : $t:ty [$dep_tracking_marker:ident $($warn_val:expr, $warn_text:expr)*],
52  | |     )* } ) => (
...   |
65  | |                                  &self.$opt,
    | |                                  ^^^^^^^^^^ the trait `DepTrackingHash` is not implemented for `options::DebuggingOptions`
...   |
79  | |     );
80  | | }
    | |_- in this expansion of `top_level_options!`
...
99  | / top_level_options!(
100 | |     pub struct Options {
101 | |         // The crate config requested for the session, which may be combined
102 | |         // with additional crate configurations during the compile process.
...   |
171 | |     }
172 | | );
    | |__- in this macro invocation
    |
    = note: required for the cast to the object type `dyn DepTrackingHash`

Maybe I should add include_no_crate_hash: bool to the trait itself?

@rust-log-analyzer

This comment has been minimized.

@cbeuw
Copy link
Contributor

cbeuw commented Apr 26, 2021

For reference, this is what I did when I tried to implement it: #83813 (comment) 39ebceb

There probably is a better way though

@jyn514
Copy link
Member Author

jyn514 commented Apr 26, 2021

Adding this argument to the trait's method doesn't make sense because it'll also affect all individual types implementing it.

Hmm, why do you say that? What if you want to add a TRACKED_NO_CRATE_HASH option to a substruct?

@bors bors added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 29, 2021
@jyn514 jyn514 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 29, 2021
@michaelwoerister
Copy link
Member

@bors rollup=never

This makes the comments show up in the generated docs.

- Fix markdown formatting
@jyn514
Copy link
Member Author

jyn514 commented Apr 29, 2021

@bors r=michaelwoerister (I just changed the formatting of some of the docs, nothing related to incremental itself)

@bors
Copy link
Contributor

bors commented Apr 29, 2021

📌 Commit 5a692a7 has been approved by michaelwoerister

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 29, 2021
@bors
Copy link
Contributor

bors commented Apr 29, 2021

⌛ Testing commit 5a692a7 with merge 814a560...

@bors
Copy link
Contributor

bors commented Apr 29, 2021

☀️ Test successful - checks-actions
Approved by: michaelwoerister
Pushing 814a560 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 29, 2021
@bors bors merged commit 814a560 into rust-lang:master Apr 29, 2021
@rustbot rustbot added this to the 1.53.0 milestone Apr 29, 2021
@jyn514 jyn514 deleted the track-path-prefix branch April 29, 2021 17:49
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 5, 2021
Implement DepTrackingHash for `Option` through blanket impls instead of macros

This avoids having to add a new macro call for both the `Option` and the type itself.

Noticed this while working on rust-lang#84233.
r? `@Aaron1011`
tmp_buf = crate::filesearch::get_or_default_sysroot();
&tmp_buf
}
};
Copy link
Member

@RalfJung RalfJung Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Computing the sysroot here is a problem as it means when the config driver callback changes the sysroot, that does not properly get taken into account.

This PR moved real_rust_source_base_dir from after the config callback to before, which is not good. Config should not contain "derived" values, only the input as provided by the user.

I'm trying to fix this in #122993 but I have no idea about all this "tracked" stuff, so I don't know if what I do makes any sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-incr-comp Area: Incremental compilation merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

remap-path-prefix will not re-compile properly in dev build
9 participants