-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Handle partial resolve cases #2466
Conversation
I wonder how this looks performance-wise. My gut feeling is that we'll need something more involved here, like tracking unresovled types/values/macros separatelly, as well as remembering name resolution results for prefixes (instead of resolving each path from the start every time). |
Hm, another easy optimization we can do is to mark paths which are rooted at external crates as |
Good idea. I added some easy optimizations:
I understand the name resolution prefixes one (I would recommend adding general path cache in DefCollector in another PR), but why should we tracks unresolved types/values/macros separately ? |
cf661d0
to
c23353d
Compare
Hm, I feel uneasy about this change, for two reasons:
It might be a good idea to check, how this work list is setup in |
Well, these changes can of course be rejected because I don't have a general idea how to solve this problem and trying out to see what code will work. :)
Sure, and you are right. TLDR: here are an over simplifer version of how rustc do (pseudo code): fn resolve_imports() {
while old_unresolved_imports.len() != unresolved_imports.len() {
for item in old_unresolved_imports {
let res = resolve_item(item);
if res == RESOLVED {
unresolved_imports.push(item);
} else {
resolved_imports.push(item)
}
}
};
}
fn passes() {
// Expand macro pass
loop {
resolve_imports();
if resolve_and_expand_macros() == REACH_FIX_POINT {
break;
}
}
unresolved_imports.extends(resolved_imports);
resolve_imports();
} Details An import item is added in add_import_directive, the namespace is stored in While the expanding loop start at After all expansions loop ends, for each crate, |
Thanks for this overview @edwin0cheng , it's really helpful! So I think this are the main diff with our current mode:
Notably, it still maintains a single list of unresolved imports! From the points above, I think we probably should start here with a solid foundation for
I am out of steam for today to be able to concretely describe the next steps here, but I feel a set of pre-requsites is:
|
8c6c8fc
to
6663a5a
Compare
6663a5a
to
51f4fb4
Compare
I rebased and made some changes:
|
This looks great now! bors r+ |
2466: Handle partial resolve cases r=matklad a=edwin0cheng Another try to fix #2443 : We resolve all imports every time in `DefCollector::collect` loop even it is resolved previously. This is because other unresolved imports and macros will bring in another `PerNs`, so we can only assume that it has been partially resolved. Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
bors retry |
Already running a review |
Build succeeded
|
…then later in the algorithm another namespace is added The import is flagged as "indeterminate", and previously it was re-resolved, but only at the end of name resolution, when it's already too late for anything that depends on it. This issue was tried to fix in rust-lang#2466, but it was not fixed fully.
…then later in the algorithm another namespace is added The import is flagged as "indeterminate", and previously it was re-resolved, but only at the end of name resolution, when it's already too late for anything that depends on it. This issue was tried to fix in rust-lang#2466, but it was not fixed fully.
fix: Fix name resolution when an import is resolved to some namespace and then later in the algorithm another namespace is added The import is flagged as "indeterminate", and previously it was re-resolved, but only at the end of name resolution, when it's already too late for anything that depends on it. This issue was tried to fix in #2466, but it was not fixed fully. That PR is also why IDE features did work: the import at the end was resolved correctly, so IDE features that re-resolved the macro path resolved it correctly. I was concerned about the performance of this, but this doesn't seem to regress `analysis-stats .`, so I guess it's fine to land this. I have no idea about the incremental perf however and I don't know how to measure that, although when typing in `zbus` (including creating a new function, which should recompute the def map) completion was fast enough. I didn't check what rustc does, so maybe it does something more performant, like keeping track of only possibly problematic imports. Fixes #18138. Probably fixes #17630.
…then later in the algorithm another namespace is added The import is flagged as "indeterminate", and previously it was re-resolved, but only at the end of name resolution, when it's already too late for anything that depends on it. This issue was tried to fix in rust-lang/rust-analyzer#2466, but it was not fixed fully.
fix: Fix name resolution when an import is resolved to some namespace and then later in the algorithm another namespace is added The import is flagged as "indeterminate", and previously it was re-resolved, but only at the end of name resolution, when it's already too late for anything that depends on it. This issue was tried to fix in rust-lang/rust-analyzer#2466, but it was not fixed fully. That PR is also why IDE features did work: the import at the end was resolved correctly, so IDE features that re-resolved the macro path resolved it correctly. I was concerned about the performance of this, but this doesn't seem to regress `analysis-stats .`, so I guess it's fine to land this. I have no idea about the incremental perf however and I don't know how to measure that, although when typing in `zbus` (including creating a new function, which should recompute the def map) completion was fast enough. I didn't check what rustc does, so maybe it does something more performant, like keeping track of only possibly problematic imports. Fixes rust-lang#18138. Probably fixes rust-lang#17630.
Another try to fix #2443 :
We resolve all imports every time in
DefCollector::collect
loop even it is resolved previously.This is because other unresolved imports and macros will bring in another
PerNs
, so we can only assume that it has been partially resolved.