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

@nnethercote
Copy link
Contributor

@nnethercote 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

Copy link
Contributor

@nikomatsakis 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.

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

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

@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

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
Copy link
Contributor Author

@nnethercote nnethercote commented Jul 4, 2018

New, super-DRY version.

r? @nikomatsakis

@nikomatsakis
Copy link
Contributor

@nikomatsakis nikomatsakis commented Jul 4, 2018

@bors r+ -- thanks @nnethercote !

@bors
Copy link
Contributor

@bors bors commented Jul 4, 2018

📌 Commit b0c7812 has been approved by nikomatsakis

@bors
Copy link
Contributor

@bors 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
Contributor

@bors 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
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
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.