Skip to content

[nll] share buffer for liveness::simulate_block #51818

Closed
@nikomatsakis

Description

@nikomatsakis

The simulate_block helper takes the set of live variables at the exit of the block and computes the live variables at each point in the block:

/// Walks backwards through the statements/terminator in the given
/// basic block `block`. At each point within `block`, invokes
/// the callback `op` with the current location and the set of
/// variables that are live on entry to that location.
pub fn simulate_block<'tcx, OP>(&self, mir: &Mir<'tcx>, block: BasicBlock, mut callback: OP)
where
OP: FnMut(Location, &LocalSet),

It works by creating a temporary bitset that contains the final value from the end of the block to start:

// Get a copy of the bits on exit from the block.
let mut bits = self.outs[block].clone();

Rather than re-allocating this buffer, it would be nice to share it across invocations of simulate_block. This makes sense because simulate_block is really only invoked from one place (apart from debugging output), which is the method add_liveness_constraint. That method is invoked from a simple loop over all basic blocks:

https://github.com/rust-lang/rust/blob/master/src/librustc_mir/borrow_check/nll/type_check/liveness.rs#L52-L54

We could therefore have simulate_block take some extra "buffer" parameter (which would be stored on the stack and passed to add_liveness_constraint).

According to recent profiles, this fn accounts for about 2% of MIR borrowck, though, so this may not be worth it. Still, we're at the point where "every little bit helps!"

Metadata

Metadata

Assignees

Labels

NLL-performantWorking towards the "performance is good" goalT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions