Skip to content

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

Merged
merged 1 commit into from
Jul 4, 2018

Conversation

nnethercote
Copy link
Contributor

This avoids a bunch of allocations for the bitsets within it,
speeding up a number of NLL benchmarks, the best by 1%.

r? @nikomatsakis

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 28, 2018
Copy link
Contributor

@nikomatsakis nikomatsakis left a 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"

statement_defs_uses.apply(&mut bits);
visitor.defs_uses.clear();
statement.apply(statement_location, &mut visitor);
visitor.defs_uses.apply(&mut bits);
Copy link
Contributor

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?

Copy link
Contributor Author

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+ :)

Copy link
Contributor

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

@nikomatsakis nikomatsakis added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 28, 2018
This avoids a bunch of allocations for the bitsets within it,
speeding up a number of NLL benchmarks, the best by 1%.
@nnethercote nnethercote force-pushed the reuse-DefsUsesVisitor branch from 02d85e2 to b0c7812 Compare July 4, 2018 03:26
@nnethercote
Copy link
Contributor Author

New, super-DRY version.

r? @nikomatsakis

@nikomatsakis
Copy link
Contributor

@bors r+ -- thanks @nnethercote !

@bors
Copy link
Collaborator

bors commented Jul 4, 2018

📌 Commit b0c7812 has been approved by nikomatsakis

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 4, 2018
@bors
Copy link
Collaborator

bors commented Jul 4, 2018

⌛ Testing commit b0c7812 with merge eded1aa...

bors added a commit that referenced this pull request Jul 4, 2018
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
@bors
Copy link
Collaborator

bors commented Jul 4, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing eded1aa to master...

@bors bors merged commit b0c7812 into rust-lang:master Jul 4, 2018
@nnethercote nnethercote deleted the reuse-DefsUsesVisitor branch July 4, 2018 20:36
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants