Skip to content

Commit 631d767

Browse files
committed
Remove AlwaysLiveLocals wrapper struct
It is just a wrapper around a `BitSet` and doesn't have any functionality of its own.
1 parent 7fe2c4b commit 631d767

File tree

5 files changed

+19
-38
lines changed

5 files changed

+19
-38
lines changed

compiler/rustc_const_eval/src/interpret/eval_context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_middle::ty::layout::{
1515
use rustc_middle::ty::{
1616
self, query::TyCtxtAt, subst::SubstsRef, ParamEnv, Ty, TyCtxt, TypeFoldable,
1717
};
18-
use rustc_mir_dataflow::storage::AlwaysLiveLocals;
18+
use rustc_mir_dataflow::storage::always_live_locals;
1919
use rustc_query_system::ich::StableHashingContext;
2020
use rustc_session::Limit;
2121
use rustc_span::{Pos, Span};
@@ -715,7 +715,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
715715

716716
// Now mark those locals as dead that we do not want to initialize
717717
// Mark locals that use `Storage*` annotations as dead on function entry.
718-
let always_live = AlwaysLiveLocals::new(self.body());
718+
let always_live = always_live_locals(self.body());
719719
for local in locals.indices() {
720720
if !always_live.contains(local) {
721721
locals[local].value = LocalValue::Dead;

compiler/rustc_const_eval/src/transform/validate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_middle::mir::{
1414
use rustc_middle::ty::fold::BottomUpFolder;
1515
use rustc_middle::ty::{self, InstanceDef, ParamEnv, Ty, TyCtxt, TypeFoldable};
1616
use rustc_mir_dataflow::impls::MaybeStorageLive;
17-
use rustc_mir_dataflow::storage::AlwaysLiveLocals;
17+
use rustc_mir_dataflow::storage::always_live_locals;
1818
use rustc_mir_dataflow::{Analysis, ResultsCursor};
1919
use rustc_target::abi::{Size, VariantIdx};
2020

@@ -48,7 +48,7 @@ impl<'tcx> MirPass<'tcx> for Validator {
4848
let param_env = tcx.param_env(def_id);
4949
let mir_phase = self.mir_phase;
5050

51-
let always_live_locals = AlwaysLiveLocals::new(body);
51+
let always_live_locals = always_live_locals(body);
5252
let storage_liveness = MaybeStorageLive::new(always_live_locals)
5353
.into_engine(tcx, body)
5454
.iterate_to_fixpoint()

compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
pub use super::*;
22

3-
use crate::storage::AlwaysLiveLocals;
43
use crate::{CallReturnPlaces, GenKill, Results, ResultsRefCursor};
54
use rustc_middle::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor};
65
use rustc_middle::mir::*;
76
use std::cell::RefCell;
87

98
#[derive(Clone)]
109
pub struct MaybeStorageLive {
11-
always_live_locals: AlwaysLiveLocals,
10+
always_live_locals: BitSet<Local>,
1211
}
1312

1413
impl MaybeStorageLive {
15-
pub fn new(always_live_locals: AlwaysLiveLocals) -> Self {
14+
pub fn new(always_live_locals: BitSet<Local>) -> Self {
1615
MaybeStorageLive { always_live_locals }
1716
}
1817
}

compiler/rustc_mir_dataflow/src/storage.rs

+8-26
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,17 @@ use rustc_middle::mir::{self, Local};
77
//
88
// FIXME: Currently, we need to traverse the entire MIR to compute this. We should instead store it
99
// as a field in the `LocalDecl` for each `Local`.
10-
#[derive(Debug, Clone)]
11-
pub struct AlwaysLiveLocals(BitSet<Local>);
10+
pub fn always_live_locals(body: &mir::Body<'_>) -> BitSet<Local> {
11+
let mut always_live_locals = BitSet::new_filled(body.local_decls.len());
1212

13-
impl AlwaysLiveLocals {
14-
pub fn new(body: &mir::Body<'_>) -> Self {
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-
}
13+
for block in body.basic_blocks() {
14+
for statement in &block.statements {
15+
use mir::StatementKind::{StorageDead, StorageLive};
16+
if let StorageLive(l) | StorageDead(l) = statement.kind {
17+
always_live_locals.remove(l);
2318
}
2419
}
25-
26-
always_live_locals
2720
}
2821

29-
pub fn into_inner(self) -> BitSet<Local> {
30-
self.0
31-
}
32-
}
33-
34-
impl std::ops::Deref for AlwaysLiveLocals {
35-
type Target = BitSet<Local>;
36-
37-
#[inline]
38-
fn deref(&self) -> &Self::Target {
39-
&self.0
40-
}
22+
always_live_locals
4123
}

compiler/rustc_mir_transform/src/generator.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ struct TransformVisitor<'tcx> {
228228
suspension_points: Vec<SuspensionPoint<'tcx>>,
229229

230230
// The set of locals that have no `StorageLive`/`StorageDead` annotations.
231-
always_live_locals: storage::AlwaysLiveLocals,
231+
always_live_locals: BitSet<Local>,
232232

233233
// The original RETURN_PLACE local
234234
new_ret_local: Local,
@@ -450,7 +450,7 @@ struct LivenessInfo {
450450
fn locals_live_across_suspend_points<'tcx>(
451451
tcx: TyCtxt<'tcx>,
452452
body: &Body<'tcx>,
453-
always_live_locals: &storage::AlwaysLiveLocals,
453+
always_live_locals: &BitSet<Local>,
454454
movable: bool,
455455
) -> LivenessInfo {
456456
let body_ref: &Body<'_> = &body;
@@ -615,7 +615,7 @@ impl ops::Deref for GeneratorSavedLocals {
615615
fn compute_storage_conflicts<'mir, 'tcx>(
616616
body: &'mir Body<'tcx>,
617617
saved_locals: &GeneratorSavedLocals,
618-
always_live_locals: storage::AlwaysLiveLocals,
618+
always_live_locals: BitSet<Local>,
619619
requires_storage: rustc_mir_dataflow::Results<'tcx, MaybeRequiresStorage<'mir, 'tcx>>,
620620
) -> BitMatrix<GeneratorSavedLocal, GeneratorSavedLocal> {
621621
assert_eq!(body.local_decls.len(), saved_locals.domain_size());
@@ -625,7 +625,7 @@ fn compute_storage_conflicts<'mir, 'tcx>(
625625

626626
// Locals that are always live or ones that need to be stored across
627627
// suspension points are not eligible for overlap.
628-
let mut ineligible_locals = always_live_locals.into_inner();
628+
let mut ineligible_locals = always_live_locals;
629629
ineligible_locals.intersect(&**saved_locals);
630630

631631
// Compute the storage conflicts for all eligible locals.
@@ -1300,7 +1300,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
13001300
},
13011301
);
13021302

1303-
let always_live_locals = storage::AlwaysLiveLocals::new(&body);
1303+
let always_live_locals = storage::always_live_locals(&body);
13041304

13051305
let liveness_info =
13061306
locals_live_across_suspend_points(tcx, body, &always_live_locals, movable);

0 commit comments

Comments
 (0)