-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Overhaul UsePath
#141741
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
Overhaul UsePath
#141741
Conversation
|
Some changes occurred in src/tools/clippy cc @rust-lang/clippy Some changes occurred in match checking cc @Nadrieril |
This comment has been minimized.
This comment has been minimized.
Oh dear... how about: r? @lcnr Not sure? |
This comment has been minimized.
This comment has been minimized.
(I'm the author of the current setup.) |
Ok then: r? @petrochenkov |
Requested reviewer is already assigned to this pull request. Please choose another assignee. |
1 similar comment
Requested reviewer is already assigned to this pull request. Please choose another assignee. |
@@ -347,7 +347,7 @@ pub struct Path<'hir, R = Res> { | |||
} | |||
|
|||
/// Up to three resolutions for type, value and macro namespaces. | |||
pub type UsePath<'hir> = Path<'hir, SmallVec<[Res; 3]>>; |
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.
now the comment doesn't add much information :)
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.
Seems ok as a quick reminder of what PerNS
is.
There are two kinds of list stems
So this
is indeed design.
|
This does make things more "statically typed", but I don't really like this aesthetically. It's not too important though, because HIR imports shouldn't be used for anything load-bearing (except stability checking at the moment), and lints working on them typically do not work fully correctly (they should either work at name resolution time or use So I'd generally classify this as "neutral change, not an improvement". |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Overhaul `UsePath` It currently uses `SmallVec<[Res; 3]>` which is really weird. Details in the individual commits. r? `@petrochenkov`
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (99c6aa3): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
Max RSS (memory usage)Results (primary 0.3%, secondary -0.8%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (secondary 0.5%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: missing data |
Reminder, once the PR becomes ready for a review, use |
I find it much easier to think about in the positive sense.
8e5356c
to
2475522
Compare
I have addressed the specific comments and also added a new commit that streamlines a couple of @bors ready |
r=me after addressing the remaining nits and optionally #141741 (comment). |
`UsePath` contains a `SmallVec<[Res; 3]>`. This holds up to three `Res` results, one per namespace (type, value, or macro). `lower_import_res` takes a `PerNS<Option<Res<NodeId>>>` result and lowers it into the `SmallVec`. This is pretty weird. The input `PerNS` makes it clear which `Res` belongs to which namespace, but the `SmallVec` throws that information away. And code that operates on the `SmallVec` tends to use iteration (or even just grabbing the first entry!) without knowing which namespace the `Res` belongs to. Even weirder! Also, `SmallVec` is an overly flexible type to use here, because it can contain any number of elements (even though it's optimized for 3 in this case). This commit changes `UsePath` so it also contains a `PerNS<Option<Res<HirId>>>`. This type preserves more information and is more self-documenting. The commit also changes a lot of the use sites to access the result for a particular namespace. E.g. if you're looking up a trait, it will be in the `Res` for the type namespace if it's present; it's silly to look in the `Res` for the value namespace or macro namespace. Overall I find the new code much easier to understand. However, some use sites still iterate. These now use `present_items` because that filters out the `None` results. Also, `redundant_pub_crate.rs` gets a bigger change. A `UseKind:ListStem` item gets no `Res` results, which means the old `all` call in `is_not_macro_export` would succeed (because `all` succeeds on an empty iterator) and the `ListStem` would be ignored. This is what we want, but was more by luck than design. The new code detects `ListStem` explicitly. The commit generalizes the name of that function accordingly. Finally, the commit also removes the `use_path` arena, because `PerNS<Option<Res>>` impls `Copy` (unlike `SmallVec`) and it can be allocated in the arena shared by all `Copy` types.
2475522
to
8747ccb
Compare
I addressed the nits. I left the questionable comment behind, I figure it doesn't hurt. @bors r=petrochenkov |
Rollup of 8 pull requests Successful merges: - #140715 (Clarify &mut-methods' docs on sync::OnceLock) - #141677 (Async drop - type instead of async drop fn, fixes #140484) - #141741 (Overhaul `UsePath`) - #141873 (Fixed a typo in `ManuallyDrop`'s doc) - #141876 (Don't declare variables in `ExprKind::Let` in invalid positions) - #141886 (Add missing 2015 edition directives) - #141889 (Add missing `dyn` keywords to tests that do not test for them) - #141891 (Fix borrowck mentioning a name from an external macro we (deliberately) don't save) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #141741 - nnethercote:overhaul-UsePath, r=petrochenkov Overhaul `UsePath` It currently uses `SmallVec<[Res; 3]>` which is really weird. Details in the individual commits. r? `@petrochenkov`
It currently uses
SmallVec<[Res; 3]>
which is really weird. Details in the individual commits.r? @petrochenkov