Skip to content

Commit 099f27b

Browse files
committed
Auto merge of #81440 - tmiasko:always-live-locals, r=matthewjasper
Visit only statements in always live locals No functional changes intended.
2 parents c6bc462 + 5686593 commit 099f27b

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

Diff for: compiler/rustc_mir/src/util/storage.rs

+12-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use rustc_index::bit_set::BitSet;
2-
use rustc_middle::mir::visit::Visitor;
3-
use rustc_middle::mir::{self, Local, Location};
2+
use rustc_middle::mir::{self, Local};
43

54
/// The set of locals in a MIR body that do not have `StorageLive`/`StorageDead` annotations.
65
///
@@ -13,12 +12,18 @@ pub struct AlwaysLiveLocals(BitSet<Local>);
1312

1413
impl AlwaysLiveLocals {
1514
pub fn new(body: &mir::Body<'tcx>) -> Self {
16-
let mut ret = AlwaysLiveLocals(BitSet::new_filled(body.local_decls.len()));
17-
18-
let mut vis = StorageAnnotationVisitor(&mut ret);
19-
vis.visit_body(body);
15+
let mut always_live_locals = AlwaysLiveLocals(BitSet::new_filled(body.local_decls.len()));
16+
17+
for block in body.basic_blocks() {
18+
for statement in &block.statements {
19+
use mir::StatementKind::{StorageDead, StorageLive};
20+
if let StorageLive(l) | StorageDead(l) = statement.kind {
21+
always_live_locals.0.remove(l);
22+
}
23+
}
24+
}
2025

21-
ret
26+
always_live_locals
2227
}
2328

2429
pub fn into_inner(self) -> BitSet<Local> {
@@ -33,15 +38,3 @@ impl std::ops::Deref for AlwaysLiveLocals {
3338
&self.0
3439
}
3540
}
36-
37-
/// Removes locals that have `Storage*` annotations from `AlwaysLiveLocals`.
38-
struct StorageAnnotationVisitor<'a>(&'a mut AlwaysLiveLocals);
39-
40-
impl Visitor<'tcx> for StorageAnnotationVisitor<'_> {
41-
fn visit_statement(&mut self, statement: &mir::Statement<'tcx>, _location: Location) {
42-
use mir::StatementKind::{StorageDead, StorageLive};
43-
if let StorageLive(l) | StorageDead(l) = statement.kind {
44-
(self.0).0.remove(l);
45-
}
46-
}
47-
}

0 commit comments

Comments
 (0)