Skip to content

Commit 219b2a0

Browse files
Rollup merge of #133475 - nnethercote:MaybeStorage-improvements, r=lcnr
`MaybeStorage` improvements Minor dataflow improvements. r? `@tmiasko`
2 parents 82622c6 + a602cb6 commit 219b2a0

File tree

9 files changed

+29
-38
lines changed

9 files changed

+29
-38
lines changed

compiler/rustc_const_eval/src/check_consts/check.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ use rustc_middle::span_bug;
1818
use rustc_middle::ty::adjustment::PointerCoercion;
1919
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
2020
use rustc_mir_dataflow::Analysis;
21-
use rustc_mir_dataflow::impls::MaybeStorageLive;
22-
use rustc_mir_dataflow::storage::always_storage_live_locals;
21+
use rustc_mir_dataflow::impls::{MaybeStorageLive, always_storage_live_locals};
2322
use rustc_span::{Span, Symbol, sym};
2423
use rustc_trait_selection::traits::{
2524
Obligation, ObligationCause, ObligationCauseCode, ObligationCtxt,

compiler/rustc_const_eval/src/interpret/stack.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_index::IndexVec;
1010
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
1111
use rustc_middle::ty::{self, Ty, TyCtxt};
1212
use rustc_middle::{bug, mir};
13-
use rustc_mir_dataflow::storage::always_storage_live_locals;
13+
use rustc_mir_dataflow::impls::always_storage_live_locals;
1414
use rustc_span::Span;
1515
use tracing::{info_span, instrument, trace};
1616

compiler/rustc_mir_dataflow/src/impls/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ pub use self::initialized::{
1414
pub use self::liveness::{
1515
MaybeLiveLocals, MaybeTransitiveLiveLocals, TransferFunction as LivenessTransferFunction,
1616
};
17-
pub use self::storage_liveness::{MaybeRequiresStorage, MaybeStorageDead, MaybeStorageLive};
17+
pub use self::storage_liveness::{
18+
MaybeRequiresStorage, MaybeStorageDead, MaybeStorageLive, always_storage_live_locals,
19+
};

compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@ use rustc_middle::mir::*;
77
use super::MaybeBorrowedLocals;
88
use crate::{Analysis, GenKill, ResultsCursor};
99

10+
/// The set of locals in a MIR body that do not have `StorageLive`/`StorageDead` annotations.
11+
///
12+
/// These locals have fixed storage for the duration of the body.
13+
pub fn always_storage_live_locals(body: &Body<'_>) -> BitSet<Local> {
14+
let mut always_live_locals = BitSet::new_filled(body.local_decls.len());
15+
16+
for block in &*body.basic_blocks {
17+
for statement in &block.statements {
18+
if let StatementKind::StorageLive(l) | StatementKind::StorageDead(l) = statement.kind {
19+
always_live_locals.remove(l);
20+
}
21+
}
22+
}
23+
24+
always_live_locals
25+
}
26+
1027
pub struct MaybeStorageLive<'a> {
1128
always_live_locals: Cow<'a, BitSet<Local>>,
1229
}
@@ -28,10 +45,7 @@ impl<'a, 'tcx> Analysis<'tcx> for MaybeStorageLive<'a> {
2845
}
2946

3047
fn initialize_start_block(&self, body: &Body<'tcx>, on_entry: &mut Self::Domain) {
31-
assert_eq!(body.local_decls.len(), self.always_live_locals.domain_size());
32-
for local in self.always_live_locals.iter() {
33-
on_entry.insert(local);
34-
}
48+
on_entry.union(&*self.always_live_locals);
3549

3650
for arg in body.args_iter() {
3751
on_entry.insert(arg);

compiler/rustc_mir_dataflow/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@ pub use self::framework::{
2525
use self::move_paths::MoveData;
2626

2727
pub mod debuginfo;
28-
pub mod drop_flag_effects;
28+
mod drop_flag_effects;
2929
pub mod elaborate_drops;
3030
mod errors;
3131
mod framework;
3232
pub mod impls;
3333
pub mod move_paths;
3434
pub mod points;
3535
pub mod rustc_peek;
36-
pub mod storage;
37-
pub mod un_derefer;
36+
mod un_derefer;
3837
pub mod value_analysis;
3938

4039
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }

compiler/rustc_mir_dataflow/src/storage.rs

-20
This file was deleted.

compiler/rustc_mir_transform/src/coroutine.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ use rustc_middle::ty::{
7070
use rustc_middle::{bug, span_bug};
7171
use rustc_mir_dataflow::impls::{
7272
MaybeBorrowedLocals, MaybeLiveLocals, MaybeRequiresStorage, MaybeStorageLive,
73+
always_storage_live_locals,
7374
};
74-
use rustc_mir_dataflow::storage::always_storage_live_locals;
7575
use rustc_mir_dataflow::{Analysis, Results, ResultsVisitor};
7676
use rustc_span::Span;
7777
use rustc_span::def_id::{DefId, LocalDefId};
@@ -696,8 +696,7 @@ fn locals_live_across_suspend_points<'tcx>(
696696
let loc = Location { block, statement_index: data.statements.len() };
697697

698698
liveness.seek_to_block_end(block);
699-
let mut live_locals: BitSet<_> = BitSet::new_empty(body.local_decls.len());
700-
live_locals.union(liveness.get());
699+
let mut live_locals = liveness.get().clone();
701700

702701
if !movable {
703702
// The `liveness` variable contains the liveness of MIR locals ignoring borrows.

compiler/rustc_mir_transform/src/lint.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use rustc_index::bit_set::BitSet;
99
use rustc_middle::mir::visit::{PlaceContext, Visitor};
1010
use rustc_middle::mir::*;
1111
use rustc_middle::ty::TyCtxt;
12-
use rustc_mir_dataflow::impls::{MaybeStorageDead, MaybeStorageLive};
13-
use rustc_mir_dataflow::storage::always_storage_live_locals;
12+
use rustc_mir_dataflow::impls::{MaybeStorageDead, MaybeStorageLive, always_storage_live_locals};
1413
use rustc_mir_dataflow::{Analysis, ResultsCursor};
1514

1615
pub(super) fn lint_body<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, when: String) {

compiler/rustc_mir_transform/src/ref_prop.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ use rustc_middle::mir::visit::*;
88
use rustc_middle::mir::*;
99
use rustc_middle::ty::TyCtxt;
1010
use rustc_mir_dataflow::Analysis;
11-
use rustc_mir_dataflow::impls::MaybeStorageDead;
12-
use rustc_mir_dataflow::storage::always_storage_live_locals;
11+
use rustc_mir_dataflow::impls::{MaybeStorageDead, always_storage_live_locals};
1312
use tracing::{debug, instrument};
1413

1514
use crate::ssa::{SsaLocals, StorageLiveLocals};

0 commit comments

Comments
 (0)