-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
rustc: return iterators from Terminator(Kind)::successors(_mut). #50278
Conversation
bcff042
to
fed7cef
Compare
Is this supposed to bring any measurable improvements? |
src/librustc/mir/mod.rs
Outdated
@@ -1952,7 +1951,8 @@ impl<'tcx> ControlFlowGraph for Mir<'tcx> { | |||
fn successors<'graph>(&'graph self, node: Self::Node) | |||
-> <Self as GraphSuccessors<'graph>>::Iter | |||
{ | |||
self.basic_blocks[node].terminator().successors().into_owned().into_iter() | |||
self.basic_blocks[node].terminator().successors() | |||
.cloned().collect::<Vec<_>>().into_iter() |
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.
Do we need the .collect().into_iter()
?
I think the answer is "that would require us to not use impl Iterator
, but rather the concrete type for successors
- or otherwise implement impl Trait
in impls". The concrete type is not that ugly I think.
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.
We could have the concrete type in an exported type
to emulate typeof
.
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 agree, we could have Successors
and SuccessorsMut
. I'll make the change next week.
src/librustc/mir/traversal.rs
Outdated
@@ -127,7 +127,7 @@ impl<'a, 'tcx> Postorder<'a, 'tcx> { | |||
if let Some(ref term) = data.terminator { | |||
po.visited.insert(root.index()); | |||
|
|||
let succs = term.successors().into_owned().into_iter(); | |||
let succs = term.successors().cloned().collect::<Vec<_>>().into_iter(); |
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.
Same
src/librustc/mir/traversal.rs
Outdated
@@ -197,7 +197,7 @@ impl<'a, 'tcx> Postorder<'a, 'tcx> { | |||
|
|||
if self.visited.insert(bb.index()) { | |||
if let Some(ref term) = self.mir[bb].terminator { | |||
let succs = term.successors().into_owned().into_iter(); | |||
let succs = term.successors().cloned().collect::<Vec<_>>().into_iter(); |
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.
Same
Not even that for |
I was looking at this because the allocations done by I tried changing the return type to a SmallVec with 8 elements. This successfully avoided the allocation in >99.9% of the cases, but resulted in negligible speedups. For example, for inflate the total number of allocations dropped by 5% but the instruction count only dropped by 0.1%. Overall, it probably won't make a difference to speed, but it does reduce allocations and so can't hurt. It also makes the code of |
r=me with arielb1's suggestion |
@bors r=nikomatsakis |
📌 Commit f0f26b8 has been approved by |
rustc: return iterators from Terminator(Kind)::successors(_mut). Minor cleanup (and potentially speedup) prompted by @nnethercote's `SmallVec` experiments. This PR assumes `.count()` and `.nth(i)` on `iter::Chain<option::IntoIter, slice::Iter(Mut)>` are `O(1)`, but otherwise all of the uses appear to immediately iterate through the successors. r? @nikomatsakis
☀️ Test successful - status-appveyor, status-travis |
Minor cleanup (and potentially speedup) prompted by @nnethercote's
SmallVec
experiments.This PR assumes
.count()
and.nth(i)
oniter::Chain<option::IntoIter, slice::Iter(Mut)>
areO(1)
, but otherwise all of the uses appear to immediately iterate through the successors.r? @nikomatsakis