-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Reuse the DefsUsesVisitor
in simulate_block()
.
#51870
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
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.
Looks good, left a "cleanup nit"
src/librustc_mir/util/liveness.rs
Outdated
statement_defs_uses.apply(&mut bits); | ||
visitor.defs_uses.clear(); | ||
statement.apply(statement_location, &mut visitor); | ||
visitor.defs_uses.apply(&mut bits); |
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.
Hmm. It'd be nice to encapsulate the "clear, apply, etc" logic into some helper so as to make this more obvious. Since we only want to clear the bits before each statement, though, perhaps some setup like this would be good:
impl DefsUseVisitor {
fn clear_then_update_bits(&mut self, location: Location, value: &impl MirVisitable<'tcx>, bits: &mut LocalSet) {
self.clear();
self.update_bits(location, value, bits);
}
/// Update `bits` with the affects of `value`. We should always visit in reverse order.
/// This method assumes that we have not visited anything before; if you have, use `clear_and_update_bits`.
fn update_bits(&mut self, location: Location, value: &impl MirVisitable<'tcx>, bits: &mut LocalSet) {
value.apply(location, self);
self.defs_uses.apply(bits);
}
}
What do you 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.
TBH, think it's less clear, and it's more code, and those factors outweigh the benefit of not repeating. But I'll do it if that's what is necessary for an r+ :)
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.
Yes, it would please me — not necessarily those exact names and setup, but some kind of method that groups together the logical operation that is occuring here ("clear flag, do visit, apply the result"), and ideally some comments about what the heck is going on.
-- Your capricious reviewer
This avoids a bunch of allocations for the bitsets within it, speeding up a number of NLL benchmarks, the best by 1%.
02d85e2
to
b0c7812
Compare
New, super-DRY version. |
@bors r+ -- thanks @nnethercote ! |
📌 Commit b0c7812 has been approved by |
Reuse the `DefsUsesVisitor` in `simulate_block()`. This avoids a bunch of allocations for the bitsets within it, speeding up a number of NLL benchmarks, the best by 1%. r? @nikomatsakis
☀️ Test successful - status-appveyor, status-travis |
This avoids a bunch of allocations for the bitsets within it,
speeding up a number of NLL benchmarks, the best by 1%.
r? @nikomatsakis