-
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
Cleanup resolve #55144
Cleanup resolve #55144
Conversation
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
src/librustc_resolve/lib.rs
Outdated
} | ||
self.ribs[ValueNS].pop(); | ||
let valuens_len = self.ribs[ValueNS].len(); | ||
self.ribs[ValueNS].truncate(valuens_len - num_macro_definition_ribs - 1); |
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.
hm, why is this offset by 1 but the next one not?
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.
This preserves the existing logic; self.ribs[ValueNS]
was popped once more after the loop.
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.
Please, keep the old obvious logic (pop
s are symmetric with pushes above), unless you have benchmarks.
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.
@petrochenkov truncating is faster - the more elements to pop
, the faster it becomes.
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 know that it's faster, I meant that it doesn't matter that it's faster, because the speed up is unnoticeable in the general picture. In this case readability/simplicity is very much preferable.
(By benchmarks I mean e.g. benchmark showing that this specific code is hot and takes a significant percent of resolve time.)
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.
Unfortunately I don't have a Linux rig to do perf runs :/. I can revert to the original code if you don't think this piece of code is hot enough.
src/librustc_resolve/macros.rs
Outdated
@@ -277,11 +275,12 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> { | |||
if traits.is_empty() { | |||
attrs.remove(i); | |||
} else { | |||
let mut tokens = Vec::new(); | |||
let mut tokens = Vec::with_capacity(traits.len().saturating_sub(1)); |
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.
No real need for the saturating_sub here since we've already checked if traits is empty (it's not)
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'd say there's no real need to pollute code with reserves/capacities unless there are benchmarks.
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.
(Also, this specific code is being removed in #54271.)
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.
@petrochenkov push loops with specified capacity are always faster than with an empty Vec
.
src/librustc_resolve/macros.rs
Outdated
@@ -931,7 +930,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { | |||
}.or_else(|| { | |||
let names = self.builtin_macros.iter().chain(self.macro_use_prelude.iter()) | |||
.filter_map(|(name, binding)| { | |||
if binding.macro_kind() == Some(kind) { Some(name) } else { None } | |||
if binding.macro_kind().is_some() { Some(name) } else { None } |
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.
This is plausibly a change in behavior?
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.
Whoops, I misread it as an if let
; this might be the reason behind the error (I'll check on my testing rig before updating).
Please, keep |
src/librustc_resolve/lib.rs
Outdated
).collect(); | ||
if fake_self.contains(&item_str) | ||
); | ||
if fake_self.any(|ident| ident == *item_str) |
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 think you can just use ["this", "my"].contains(&*item_str.as_str())
here.
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.
Almost; ["this", "my"].contains(&&*item_str.as_str())
.
eef2fe9
to
89c20b7
Compare
@petrochenkov I fixed the test error (it was the one I expected), rolled back |
Thanks! |
📌 Commit 89c20b7 has been approved by |
Cleanup resolve - improve/remove allocations - `truncate` instead of `pop`ping in a loop - improve common patterns
Cleanup resolve - improve/remove allocations - `truncate` instead of `pop`ping in a loop - improve common patterns
Rollup of 7 pull requests Successful merges: - #54300 (Updated RELEASES.md for 1.30.0) - #55013 ([NLL] Propagate bounds from generators) - #55071 (Fix ICE and report a human readable error) - #55144 (Cleanup resolve) - #55166 (Don't warn about parentheses on `match (return)`) - #55169 (Add a `copysign` function to f32 and f64) - #55178 (Stabilize slice::chunks_exact(), chunks_exact_mut(), rchunks(), rchunks_mut(), rchunks_exact(), rchunks_exact_mut())
truncate
instead ofpop
ping in a loop