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

Don't sort a Vec before computing its DepTrackingHash #85702

Merged
merged 1 commit into from
May 31, 2021

Conversation

Aaron1011
Copy link
Member

Previously, we sorted the vec prior to hashing, making the hash
independent of the original (command-line argument) order. However, the
original vec was still always kept in the original order, so we were
relying on the rest of the compiler always working with it in an
'order-independent' way.

This assumption was not being upheld by the native_libraries query -
the order of the entires in its result depends on the order of entries
in Options.libs. This lead to an 'unstable fingerprint' ICE when the
-l arguments were re-ordered.

This PR removes the sorting logic entirely. Re-ordering command-line
arguments (without adding/removing/changing any arguments) seems like a
really niche use case, and correctly optimizing for it would require
additional work. By always hashing arguments in their original order, we
can entirely avoid a cause of 'unstable fingerprint' errors.

@rust-highfive
Copy link
Collaborator

r? @matthewjasper

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 26, 2021
@Mark-Simulacrum
Copy link
Member

@bors rollup=never - could be perf sensitive, in theory, though somewhat unlikely

@rust-log-analyzer

This comment has been minimized.

Previously, we sorted the vec prior to hashing, making the hash
independent of the original (command-line argument) order. However, the
original vec was still always kept in the original order, so we were
relying on the rest of the compiler always working with it in an
'order-independent' way.

This assumption was not being upheld by the `native_libraries` query -
the order of the entires in its result depends on the order of entries
in `Options.libs`. This lead to an 'unstable fingerprint' ICE when the
`-l` arguments were re-ordered.

This PR removes the sorting logic entirely. Re-ordering command-line
arguments (without adding/removing/changing any arguments) seems like a
really niche use case, and correctly optimizing for it would require
additional work. By always hashing arguments in their original order, we
can entirely avoid a cause of 'unstable fingerprint' errors.
@jyn514
Copy link
Member

jyn514 commented May 26, 2021

cc #84234

@michaelwoerister
Copy link
Member

Thanks for the PR, @Aaron1011! This looks good to me -- but I don't quite understand how the regression test works? Can you add a comment explaining it? Otherwise feel free to r=me.

@estebank
Copy link
Contributor

@michaelwoerister the test gets run twice with different flag order. On the second execution, whichever it might be, it would ICE+panic and the test would fail.

@michaelwoerister
Copy link
Member

Right, but the first invocation of the test has to pass. Otherwise we'll start with an empty cache for the second run and won't be able to observe the crash.

@estebank
Copy link
Contributor

@michaelwoerister I don't think link errors affect the cache, but I could be wrong.

@michaelwoerister
Copy link
Member

That's possible. I'm not sure. I would not want to rely on it in a regression test though.

@Aaron1011
Copy link
Member Author

The cache does get populated when there's a link error - I reproduced the ICE with this test on master. Using nonexistent libraries makes the test smaller, since we don't need to compile an actual native library.

@michaelwoerister
Copy link
Member

I'm a bit worried that this might change at some point in the future and then the test would silently become ineffective. Is there a way to make the test fail if the second run starts with an empty cache? Like adding one of the existing incr. comp. test attributes? Not really because we expect the cache to be cleared already during dep-graph loading, right? Maybe that would be worth adding another test attribute or -Z option though.

I'll leave it up to you, @Aaron1011! If you decide to merge the test as it is I want to at least open an issue.

@Aaron1011
Copy link
Member Author

@michaelwoerister Note that in this case, we will end up with an empty cache, since the commandline arg hash will be changed by the re-ordering of the link arguments. However, we will still attempt to load the old incremental data, and discover the mismatch when we do.

It would be good to have a flag to assert this - I'll open an issue.

@Aaron1011
Copy link
Member Author

@michaelwoerister: I've opened #85864 to track adding a new debugging flag to assert the correct state of the incr cache.

@bors r=michaelwoerister

@bors
Copy link
Contributor

bors commented May 31, 2021

📌 Commit 605513a 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-review Status: Awaiting review from the assignee but also interested parties. labels May 31, 2021
@bors
Copy link
Contributor

bors commented May 31, 2021

⌛ Testing commit 605513a with merge 657bc01...

@bors
Copy link
Contributor

bors commented May 31, 2021

☀️ Test successful - checks-actions
Approved by: michaelwoerister
Pushing 657bc01 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 31, 2021
@bors bors merged commit 657bc01 into rust-lang:master May 31, 2021
@rustbot rustbot added this to the 1.54.0 milestone May 31, 2021
@michaelwoerister
Copy link
Member

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants