-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
suggesting for traits do not search the "prelude crates" #55613
Conversation
As of submitting this, there's currently an issue with one of the suggestions improved by this PR, see this thread on Zulip. |
This comment has been minimized.
This comment has been minimized.
dec517d
to
07dd6b0
Compare
This comment has been minimized.
This comment has been minimized.
07dd6b0
to
2a52973
Compare
This comment has been minimized.
This comment has been minimized.
Ping from triage @davidtwco: It looks like your PR failed on travis. |
Thanks @TimNN - currently awaiting some further instruction on Zulip for this otherwise I'd be all over fixing the Travis failure! |
Ping from triage. Thanks for the update, @davidtwco. I'll mark this PR as blocked for now. |
This comment has been minimized.
This comment has been minimized.
2a52973
to
57fc3fc
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
57fc3fc
to
e03d25f
Compare
This comment has been minimized.
This comment has been minimized.
e03d25f
to
a76a58a
Compare
Managed to solve the issue that was blocking this PR, it should be ready for review. However, solving this issue required making the |
This comment has been minimized.
This comment has been minimized.
a76a58a
to
3810b51
Compare
This comment has been minimized.
This comment has been minimized.
3810b51
to
87af306
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
argh looks like I failed to finish my review, posting partial comments here
src/librustc/ty/context.rs
Outdated
@@ -1268,7 +1268,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { | |||
} | |||
|
|||
pub fn crates(self) -> Lrc<Vec<CrateNum>> { | |||
self.all_crate_nums(LOCAL_CRATE) | |||
Lrc::new(self.cstore.crates_untracked()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is creating a new vector each time, perhaps change the return type to Vec<..>
? Also, I worry a bit about the incremental computation side of this. It feels like we should be very careful using a method named untracked
=) it may be that the method name is outdated though or that the setup needs to be adjusted. I would expect us to be tracking the set of prelude names as part of the incremental state
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed the last commit so it also updates the return type of this as it is a new Vec<..>
each time.
The reason that I changed this was because after speculatively loading a new crate for the purpose of diagnostics, the result of the crates
query wouldn't change. This was fine for the purposes of adding a note like this:
= note: the following trait defines an item `extern_baz`, perhaps you need to implement it:
candidate #1: `baz::BazTrait`
But when adding a note like that below, it didn't work:
help: the following trait is implemented but not in scope, perhaps add a `use` for it:
|
LL | use baz::BazTrait;
This is because the larger check that worked out whether this was appropriate to suggest called the crates
query in a few places and the missing speculatively-loaded crates would cause the logic to always consider a trait from a speculatively-loaded trait unsuitable.
As I understand it, it isn't possible to invalidate the cache of the crates
query after speculatively-loading crates (see this message from @eddyb).
The crates
query just iterates over self.metas
in the cstore
and so will only ever contain the crates that exist when it was first invoked and then cached. I wrote some more detail here about my investigation into why only the first case got a suggestion, @oli-obk then suggested stopping the crates
function from being a query.
Something about the @michaelwoerister, maybe you have an opinion about whether this will work out? The problem is that the I feel like there's a sort of "leak" happening here of information. There is shared mutable state (the set of loaded crates) and somehow it's not quite being tracked. (In practice, it's probably harmless, but still...). Not sure the best way to model this. |
We discussed this some on Zulip -- the consensus was that indeed there is a problem with incremental here. The question was whether we can find a solution that doesn't require changing the crates query, perhaps by giving less precise suggestions? |
I've experimented with adding a maximal query that loads all crates and returns all crate nums and then tried using that in the handful of places I previously identified would be needed to get the suggestion to show up - but I wasn't able to get this working and it was causing some ICEs. Further, some of the code that would need to use this query would be invoked even when there isn't a error - effectively loading all crates all the time. If we undo the most recent commit then we lose the suggestion in the below snippet: However, we do keep the suggestion in this case: If that's acceptable then it might be worthwhile landing that and follow-up if we can think of a way to do this that doesn't modify the crates query. |
@davidtwco I don't quite understand what the difference is between the case where you get a suggestion and the one where you don't. However, one thing I wanted to ask: right now, we do some amount of trait selection in order to figure out if the trait is implemented and hence just needs to be imported or whether the trait needs to be implemented. Personally, I usually find this distinction kind of annoying and useless, but it's perhaps because I know Rust well. I essentially just want a list of the traits that feature the method: often, if it is not implemented already, I want to implement it. If we were not trying to figure out whether the trait was implemented, but we were merely looking to see if it featured the given method, do you think that would still trigger the ICE-prone code paths? |
@nikomatsakis In the case where we do error, all that happpens is that we look at all suggestible traits (which is produced with the speculatively loaded crate numbers manually included) and then check for an appropriate associated item - whatever is involved in doing this doesn't involve loading the crates (and would therefore also need the speculatively loaded crate numbers): In the case where we won't error, we end up with the trait (always originating from the ...which ends up at... ...which ends up at (sorry, I got lazy writing descriptions of the call stack)... ...which ends up at... ...which ends up at... ...which ends up at... ...which ends up at (phew, I'm glad I took notes) ... ...which ends up at... ...which ends up at... ...which ends up at... ...and that call to
I don't believe so. |
This comment has been minimized.
This comment has been minimized.
c546dc4
to
2ed7860
Compare
This comment has been minimized.
This comment has been minimized.
2ed7860
to
2c834d5
Compare
This comment has been minimized.
This comment has been minimized.
This commit adds some helpful logging statements to help work out what is going on.
This commit adds a query that can be used to load crates in later phases of the compiler for the purpose of diagnostics.
This commit updates the `all_traits` query to speculatively load all crates that have an `--extern` flag for the purpose of diagnostics.
This commit renames the `all_traits` query to `all_suggestible_traits` to better highlight that it is intended for diagnostic/error reporting purposes. This was already the case, as highlighted by a doc comment on the function as it existed previously.
This commit stops `crates` from being a query so that it will always execute. This is required as speculative loading of crates for diagnostic purposes will add new crate numbers that `crates` would not include when cached.
2c834d5
to
17a6b1f
Compare
☔ The latest upstream changes (presumably #58728) made this pull request unmergeable. Please resolve the merge conflicts. |
I’m going to close this - the minor diagnostic improvements that this PR would bring (should the unresolved questions about the implementation be resolved) aren’t worth the increased complexity required. |
Fixes #54618.
r? @nikomatsakis
cc @eddyb