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

WIP: Module name resolution #236

Merged
merged 14 commits into from
Nov 21, 2018
Merged

WIP: Module name resolution #236

merged 14 commits into from
Nov 21, 2018

Conversation

matklad
Copy link
Member

@matklad matklad commented Nov 20, 2018

work towards #231

@aochagavia
Copy link
Contributor

Nice work! I didn't have time to tackle this earlier this week, but I enjoyed reading the PR.

@matklad
Copy link
Member Author

matklad commented Nov 21, 2018

Some rough perf numbers:

INFO [ra_analysis::descriptors::module::nameres] item_map: 149.49299ms
INFO [ra_analysis::descriptors::module::nameres] item_map: 56.36107ms
INFO [ra_analysis::descriptors::module::nameres] item_map: 64.422592ms
INFO [ra_analysis::descriptors::module::nameres] item_map: 46.608787ms
INFO [ra_analysis::descriptors::module::nameres] item_map: 66.772202ms
INFO [ra_analysis::descriptors::module::nameres] item_map: 67.200399ms
INFO [ra_analysis::descriptors::module::nameres] item_map: 71.504211ms
INFO [ra_analysis::descriptors::module::nameres] item_map: 55.688357ms
INFO [ra_analysis::descriptors::module::nameres] item_map: 53.92913ms
INFO [ra_analysis::descriptors::module::nameres] item_map: 78.610024ms
INFO [ra_analysis::descriptors::module::nameres] item_map: 52.666113ms

This is for rust-lang/rust repo. Each item_map is roughly a simplified from scratch resolve of all uses. These numbers are pretty existing: there are good enough for completion as is, and there's a ton of room for improvement. Specifically:

  • currently, we basically treat all of rust-lang/rust as a single crate (a single SourceRoot, more specifically). Ideally, we should create a SourceRoot per cargo package. That would allow us to have per-crate invalidation of imports.

  • currently, we store LocalSyntaxPtrs in the data we compute. This is bad, because they change with every edit. Ideally, we should recompute ItemMap only when the user adds/removes items. This can be achieved using a smarter version of LocalSyntaxPtr: instead of storing a pair of offsets, we will store something like "the second struct with name Foo", which should be stable across most edits.

With these two optimizations implemented, I think that such top-down approach to name resolution would be speedy enough even with proper support for globs and macros (:crossed_fingers: )

@aochagavia
Copy link
Contributor

Nice work! Are you planning to add tests as well? This seems quite tricky to get right...

@matklad
Copy link
Member Author

matklad commented Nov 21, 2018

Nice work! Are you planning to add tests as well? This seems quite tricky to get right...

Not in this PR: this is covered by the completion tests atm.

But yeah, we definitely should have nameres specific unit-tests. There's one in this PR for the start. We also should add a test which checks that we don't recompute item_map if user types inside function body.

@matklad
Copy link
Member Author

matklad commented Nov 21, 2018

The main problem is that we've got an ICE...

@matklad
Copy link
Member Author

matklad commented Nov 21, 2018

bors r+

bors bot added a commit that referenced this pull request Nov 21, 2018
236: WIP: Module name resolution r=matklad a=matklad

work towards #231 

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
@bors
Copy link
Contributor

bors bot commented Nov 21, 2018

Build succeeded

@bors bors bot merged commit 5a61b21 into master Nov 21, 2018
@bors bors bot deleted the nameres branch November 21, 2018 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants