Skip to content
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

Reuse the `DefsUsesVisitor` in `simulate_block()`. #51870

Merged
merged 1 commit into from Jul 4, 2018

Conversation

Projects
None yet
4 participants
@nnethercote
Copy link
Contributor

nnethercote commented 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%.

r? @nikomatsakis

@nikomatsakis
Copy link
Contributor

nikomatsakis left a comment

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);

This comment has been minimized.

Copy link
@nikomatsakis

nikomatsakis Jun 28, 2018

Contributor

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?

This comment has been minimized.

Copy link
@nnethercote

nnethercote Jun 28, 2018

Author Contributor

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

This comment has been minimized.

Copy link
@nikomatsakis

nikomatsakis Jun 29, 2018

Contributor

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

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%.

@nnethercote nnethercote force-pushed the nnethercote:reuse-DefsUsesVisitor branch from 02d85e2 to b0c7812 Jul 4, 2018

@nnethercote

This comment has been minimized.

Copy link
Contributor Author

nnethercote commented Jul 4, 2018

New, super-DRY version.

r? @nikomatsakis

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Jul 4, 2018

@bors r+ -- thanks @nnethercote !

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jul 4, 2018

📌 Commit b0c7812 has been approved by nikomatsakis

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jul 4, 2018

⌛️ Testing commit b0c7812 with merge eded1aa...

bors added a commit that referenced this pull request Jul 4, 2018

Auto merge of #51870 - nnethercote:reuse-DefsUsesVisitor, r=nikomatsakis
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

This comment has been minimized.

Copy link
Contributor

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

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details

@nnethercote nnethercote deleted the nnethercote:reuse-DefsUsesVisitor branch Jul 4, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.