-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
omit record_accesses
function when collecting MonoItem
s
#97168
Conversation
r? @cjgillot (rust-highfive has picked a reviewer for you, use r? to override) |
IIUC, the point was to avoid calling |
It makes sense! Sorry for mistaking the meaning of this FIXME earlier. I have made the corresponding changes. |
fn record_accesses<'a>( | ||
&mut self, | ||
source: MonoItem<'tcx>, | ||
new_targets: impl Iterator<Item = &'a (Spanned<MonoItem<'tcx>>, bool)> + ExactSizeIterator, |
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 can take a simple slice, no need to be more general than necessary.
for (i, (target, inline)) in new_targets.iter().enumerate() { | ||
self.targets.push(*target); | ||
if *inline { | ||
for (i, target) in new_targets.enumerate() { |
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 prefer destructuring the tuple, the intent is clearer.
.into_iter() | ||
.filter_map(|root| root.node.is_instantiable(tcx).then_some(root.node)) | ||
.filter_map(|root| root.0.node.is_instantiable(tcx).then_some(root.0.node)) |
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.
Can we destructure the tuple here?
output.extend(methods); | ||
.map(|item| { | ||
let item = create_fn_mono_item(tcx, item, source); | ||
let inlined = if is_root { |
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.
Where does this logic come from?
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.
Judging inlining does seem a little out of place here. I added the extend method to the MonoItems so it looks more reasonable
@@ -226,6 +225,24 @@ pub struct InliningMap<'tcx> { | |||
inlines: GrowableBitSet<usize>, | |||
} | |||
|
|||
struct MonoItems<'tcx> { |
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.
Could you document this struct and its fields?
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.
sure
collect_items_rec(tcx, neighbour, visited, recursion_depths, recursion_limit, inlining_map); | ||
inlining_map.lock_mut().record_accesses(starting_point.node, neighbors.items.iter()); | ||
|
||
for neighbour in neighbors.items { |
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 destructure the tuple here too.
Thanks for reviewing! I made the corresponding changes and it looks clearer |
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.
Thanks @SparrowLii! Looking good.
Two nits, and then r=me.
} else { | ||
item.node.instantiation_mode(self.tcx) == InstantiationMode::LocalCopy | ||
}; | ||
self.items.push((item, inlined)); |
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 function can be implemented as self.extend([item])
.
struct MonoItems<'tcx> { | ||
// Whether the collecting start from the root. The mono | ||
// items will not be inlined if so. | ||
is_root: bool, |
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 comment is not accurate. The questions is whether we need to compute instantiation_mode
, not about inlining.
Proposed redaction: "When collecting from the root, we do not need to compute whether items will need to be inlined."
Should this be named compute_inlining
?
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.
Thanks! Such a comment is indeed more accurate
@bors r=cjgillot |
@SparrowLii: 🔑 Insufficient privileges: Not in reviewers |
@cjgillot It seems that we need you to r+ here |
@bors r+ |
📌 Commit 480e603 has been approved by |
☀️ Test successful - checks-actions |
Finished benchmarking commit (1ab9893): comparison url. Instruction count
Max RSS (memory usage)Results
CyclesResults
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression Footnotes |
PR rust-lang#97168 was created to address this comment in `record_accesses`: // We collect this into a `SmallVec` to avoid calling `is_inlining_candidate` in the lock. // FIXME: Call `is_inlining_candidate` when pushing to `neighbors` in `collect_items_rec` // instead to avoid creating this `SmallVec`. It removed the need for the `SmallVec` (a good thing) by introducing `MonoItems`, which introduced some additional complexity (a bad thing). However, the reason the `SmallVec` was being used in the first place -- "to avoid calling `is_inlining_candidate` in the lock" -- isn't necessary, as far as I can tell. Perhaps it was at one point. So this commit just moves what is left of the call to `is_inlining_candidate` -- a call the innocuous `instantiation_mode` -- inside the lock. This avoids the complexity of `MonoItems` sometimes computing inlining data and sometimes not.
This PR fixes the FIXME in the impl of
record_accesses
function.[Edit] We can call
instantiation_mode
when push theMonoItem
intoneighbors
. This avoids extra local variablesaccesses: SmallVec<[_; 128]>