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

Make re-export collection deterministic #65043

Merged
merged 2 commits into from
Oct 6, 2019

Conversation

Aaron1011
Copy link
Member

@Aaron1011 Aaron1011 commented Oct 3, 2019

Fixes #65036

Previously, we were using an FxHashMap to collect module re-exports.
However, re-exports end up getting serialized into crate metadata, which
means that metadata generation was non-deterministic. This resulted in
spurious error messages changes (e.g. PR #64906) due to pretty-printing
implicitly depending on the order of re-exports when computing the
proper path to show to the user.

See #65042 for a long-term strategy to detect this kind of issue

@rust-highfive
Copy link
Collaborator

r? @petrochenkov

(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 Oct 3, 2019
@Aaron1011
Copy link
Member Author

r? @Centril

@rust-highfive rust-highfive assigned Centril and unassigned petrochenkov Oct 3, 2019
@Centril
Copy link
Contributor

Centril commented Oct 3, 2019

Looks good but r? @petrochenkov should really review this since resolve is their wheelhouse. :)

@Mark-Simulacrum
Copy link
Member

I think we usually deal with this via collection into a Vec and sorting just before metadata serialization; that might be a better approach here?

@jonas-schievink
Copy link
Contributor

Fixes #65043

Did you mean "Fixes #65036"?

@Centril
Copy link
Contributor

Centril commented Oct 3, 2019

I personally feel that IndexMap is a more reliable by-construction approach that takes care of every iteration site so you don't have to care about all of them. Maybe when we get the wrapper for FxHashMap we should use that instead.

@Aaron1011
Copy link
Member Author

@jonas-schievink: Thanks, fixed

@Mark-Simulacrum
Copy link
Member

We do have a StableMap in the data structures crate as of a recent PR, so maybe using that here would be better. It does not expose iteration order at all (lacking those methods entirely).

But again, I'm fine landing this in the mean time. An indexmap seems like a reasonable answer too.

@matthewjasper
Copy link
Contributor

Stable map looks unsuitable since Idents don't implement Ord.

@petrochenkov
Copy link
Contributor

I think we usually deal with this via collection into a Vec and sorting just before metadata serialization

That was my first reaction too.
Changing Resolutions, which are used for a thousand other things beside serializing reexports, is such an unproportionally heavy hammer for fixing this.

We actually have a method for visiting resolutions in a stable fashion (fn for_each_child_stable) which is already used in diagnostic reporting with the same purpose.

@petrochenkov petrochenkov 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 Oct 3, 2019
@petrochenkov
Copy link
Contributor

petrochenkov commented Oct 3, 2019

@bors try @rust-timer queue

@bors
Copy link
Contributor

bors commented Oct 3, 2019

⌛ Trying commit 2c9bf5f9320945e4fc29927e8de60dd2fad8172f with merge 9f13bf7d334cc30a5fbe83d0309ccf107c0d512e...

@Centril

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Oct 3, 2019

⌛ Trying commit 2c9bf5f9320945e4fc29927e8de60dd2fad8172f with merge 0e298d5daf4f422edf242c37161329ee79515942...

@petrochenkov
Copy link
Contributor

petrochenkov commented Oct 3, 2019

I personally feel that IndexMap is a more reliable by-construction approach

Actually, I'm not sure that the insertion order itself is stable for the resolutions, if it's not, then IndexMap maintaining it won't matter much.

@Centril
Copy link
Contributor

Centril commented Oct 3, 2019

Interesting. I'm pretty happy I reassigned this PR. :)

@bors
Copy link
Contributor

bors commented Oct 3, 2019

☀️ Try build successful - checks-azure
Build commit: 0e298d5daf4f422edf242c37161329ee79515942 (0e298d5daf4f422edf242c37161329ee79515942)

@rust-timer
Copy link
Collaborator

Queued 0e298d5daf4f422edf242c37161329ee79515942 with parent 032a53a, future comparison URL.

@bjorn3
Copy link
Member

bjorn3 commented Oct 4, 2019

I personally feel that IndexMap is a more reliable by-construction approach

Actually, I'm not sure that the insertion order itself is stable for the resolutions, if it's not, then IndexMap maintaining it won't matter much.

We have StableMap since #64131. It works the same as FxHashMap, but you can't iterate it, you have to use .into_sorted_vec() instead.

@Aaron1011
Copy link
Member Author

@petrochenkov: This looks like a wash performance wise - a few minor speedups and a few minor slowdowns. I suspect that much of it is just noise.

@petrochenkov
Copy link
Contributor

Yeah, I just wanted to check what performance impact IndexMap can have, sorry for all this noise.
I still think using for_each_child_stable in finalize_resolutions_in is a preferable solution.

@Aaron1011
Copy link
Member Author

Aaron1011 commented Oct 4, 2019

@petrochenkov: All other things being equal, I think it's better to reduce the amount of non-determinism in the compiler. This issue was a pain to track down, and I'm worried that it might crop up again if we're relying on every caller using for_each_child_stable whenever they need to iterate over to it.

@petrochenkov
Copy link
Contributor

Let's check whether IndexMap provides what we need or not - #65117.

@petrochenkov
Copy link
Contributor

Looks like resolutions are added in stable order, so we can use an IndexMap.

@Aaron1011
Could you remove for_each_child_stable in this PR then, and replace its uses with for_each_child.
(Replacing other iterations through resolutions would also be nice, the use of for_each_child looks a bit cleaner in all cases.)

Previously, we were using an `FxHashMap` to collect module re-exports.
However, re-exports end up getting serialized into crate metadata, which
means that metadata generation was non-deterministic. This resulted in
spurious error messages changes (e.g. PR rust-lang#64906) due to pretty-printing
implicitly depending on the order of re-exports when computing the
proper path to show to the user.

See rust-lang#65042 for a long-term strategy to detect this kind of issue
@Aaron1011
Copy link
Member Author

@petrochenkov Updated

Now that `Resolutions` has a deterministic iteration order, it's no
longer necessary to sort its entries before iterating over them
@petrochenkov
Copy link
Contributor

Thanks!
@bors r+

@bors
Copy link
Contributor

bors commented Oct 5, 2019

📌 Commit add0a42 has been approved by petrochenkov

@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 Oct 5, 2019
@bors
Copy link
Contributor

bors commented Oct 6, 2019

⌛ Testing commit add0a42 with merge 0358617...

bors added a commit that referenced this pull request Oct 6, 2019
…nkov

Make re-export collection deterministic

Fixes #65036

Previously, we were using an `FxHashMap` to collect module re-exports.
However, re-exports end up getting serialized into crate metadata, which
means that metadata generation was non-deterministic. This resulted in
spurious error messages changes (e.g. PR #64906) due to pretty-printing
implicitly depending on the order of re-exports when computing the
proper path to show to the user.

See #65042 for a long-term strategy to detect this kind of issue
@bors
Copy link
Contributor

bors commented Oct 6, 2019

☀️ Test successful - checks-azure
Approved by: petrochenkov
Pushing 0358617 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Oct 6, 2019
@bors bors merged commit add0a42 into rust-lang:master Oct 6, 2019
@Aaron1011 Aaron1011 deleted the fix/reexport-determinism branch October 6, 2019 17:04
@RalfJung
Copy link
Member

RalfJung commented Oct 9, 2019

Previously, we were using an FxHashMap to collect module re-exports.
However, re-exports end up getting serialized into crate metadata, which
means that metadata generation was non-deterministic.

Clarification to avoid spreading this myth further: FxHashMap is deterministic. However, inserting a new element can surprisingly affect the entire iteration order. Also see #63713 (comment).

@Aaron1011
Copy link
Member Author

@RalfJung: I meant 'non-deterministic with respect to platforms' - that is, the crate metadata order wouldn't look the same across different platforms. Sorry for the confusion.

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.

Intermittent failure in src/test/ui/reify-intrinsic.stderr