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

resolve: Try to fix instability in import suggestions #43552

Merged
merged 1 commit into from
Aug 1, 2017

Conversation

petrochenkov
Copy link
Contributor

cc #42033

lookup_import_candidates walks module graph in DFS order and skips modules that were already visited (which is correct because there can be cycles).
However it means that if we visited std::prelude::v1::Result::Ok first, we will never visit std::result::Result::Ok because Result will be skipped as already visited (note: enums are also modules here), and otherwise, if we visited std::result::Result::Ok first, we will never get to std::prelude::v1::Result::Ok.
What child module of std (prelude or result) we will visit first, depends on randomized hashing, so we have instability in diagnostics.

With this patch modules' children are visited in stable order in lookup_import_candidates, this should fix the issue, but let's see what Travis will say.

r? @oli-obk

@oli-obk
Copy link
Contributor

oli-obk commented Jul 30, 2017

Even if this becomes deterministic by these changes, I dislike the results:

+   = help: there is an enum variant `std::result::Result::Ok`, try using `std::result::Result`?
+   = help: there is an enum variant `std::prelude::v1::Option::Some`, try using `std::prelude::v1::Option`?

Result shows up in the real path while Option shows up in the reexport in the prelude.

I still think that it's impossible to produce nice diagnostics with paths during resolve and that we should be caching them until resolve is finished and report them then

@petrochenkov
Copy link
Contributor Author

petrochenkov commented Jul 30, 2017

I don't see how delaying will help here.
These particular diagnostics are reported during the second stage of resolve when all import resolution is done and all definitions are available. Fully completing resolution will not add any new information useful here.

The problem with prelude paths is that reexports are shown in candidates as well as true definitions. The intent of the original PR was to filter out the reexports, however the implementation doesn't work correctly and nothing outside of the current crate is considered a reexport and filtered out.
fn each_child_of_item and friends should preserve the export/non-export distinction and provide it to resolve so it can filter away reexports properly.
This is an orthogonal issue though and it doesn't block migration of compile-fail tests to UI testing.

@oli-obk
Copy link
Contributor

oli-obk commented Jul 31, 2017

Makes sense. Implementation Lgtm.

You'll need a reviewer to sign off the PR though.

@petrochenkov
Copy link
Contributor Author

r? @jseyfried

@carols10cents carols10cents added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 31, 2017
@jseyfried
Copy link
Contributor

@bors r+

@carols10cents
Copy link
Member

@bors r=jseyfried

@bors
Copy link
Contributor

bors commented Jul 31, 2017

📌 Commit a6993d6 has been approved by jseyfried

@bors
Copy link
Contributor

bors commented Aug 1, 2017

⌛ Testing commit a6993d6 with merge ca764ee39451f96aa9db27b392b6d1b1974676c3...

@bors
Copy link
Contributor

bors commented Aug 1, 2017

💔 Test failed - status-travis

@alexcrichton
Copy link
Member

@bors: retry

@bors
Copy link
Contributor

bors commented Aug 1, 2017

⌛ Testing commit a6993d6 with merge 6e8452e...

bors added a commit that referenced this pull request Aug 1, 2017
resolve: Try to fix instability in import suggestions

cc #42033

`lookup_import_candidates` walks module graph in DFS order and skips modules that were already visited (which is correct because there can be cycles).
However it means that if we visited `std::prelude::v1::Result::Ok` first, we will never visit `std::result::Result::Ok` because `Result` will be skipped as already visited (note: enums are also modules here), and otherwise, if we visited `std::result::Result::Ok` first, we will never get to `std::prelude::v1::Result::Ok`.
What child module of `std` (`prelude` or `result`) we will visit first, depends on randomized hashing, so we have instability in diagnostics.

With this patch modules' children are visited in stable order in `lookup_import_candidates`, this should fix the issue, but let's see what Travis will say.

r? @oli-obk
@bors
Copy link
Contributor

bors commented Aug 1, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: jseyfried
Pushing 6e8452e to master...

@bors bors merged commit a6993d6 into rust-lang:master Aug 1, 2017
@petrochenkov petrochenkov deleted the instab branch August 26, 2017 00:19
@jyn514 jyn514 added A-resolve Area: Name resolution T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-resolve Area: Name resolution S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

7 participants