summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_mir_dataflow
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:06:37 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:06:37 +0000
commit246f239d9f40f633160f0c18f87a20922d4e77bb (patch)
tree5a88572663584b3d4d28e5a20e10abab1be40884 /compiler/rustc_mir_dataflow
parentReleasing progress-linux version 1.64.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-246f239d9f40f633160f0c18f87a20922d4e77bb.tar.xz
rustc-246f239d9f40f633160f0c18f87a20922d4e77bb.zip
Merging debian version 1.65.0+dfsg1-2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_mir_dataflow')
-rw-r--r--compiler/rustc_mir_dataflow/Cargo.toml3
-rw-r--r--compiler/rustc_mir_dataflow/src/errors.rs71
-rw-r--r--compiler/rustc_mir_dataflow/src/framework/engine.rs22
-rw-r--r--compiler/rustc_mir_dataflow/src/framework/graphviz.rs4
-rw-r--r--compiler/rustc_mir_dataflow/src/framework/mod.rs3
-rw-r--r--compiler/rustc_mir_dataflow/src/framework/tests.rs10
-rw-r--r--compiler/rustc_mir_dataflow/src/impls/liveness.rs107
-rw-r--r--compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs2
-rw-r--r--compiler/rustc_mir_dataflow/src/lib.rs5
-rw-r--r--compiler/rustc_mir_dataflow/src/move_paths/builder.rs4
-rw-r--r--compiler/rustc_mir_dataflow/src/move_paths/mod.rs2
-rw-r--r--compiler/rustc_mir_dataflow/src/rustc_peek.rs30
-rw-r--r--compiler/rustc_mir_dataflow/src/storage.rs2
13 files changed, 181 insertions, 84 deletions
diff --git a/compiler/rustc_mir_dataflow/Cargo.toml b/compiler/rustc_mir_dataflow/Cargo.toml
index baf9735fb..385e9ba74 100644
--- a/compiler/rustc_mir_dataflow/Cargo.toml
+++ b/compiler/rustc_mir_dataflow/Cargo.toml
@@ -13,10 +13,13 @@ smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
tracing = "0.1"
rustc_ast = { path = "../rustc_ast" }
rustc_data_structures = { path = "../rustc_data_structures" }
+rustc_errors = { path = "../rustc_errors" }
rustc_graphviz = { path = "../rustc_graphviz" }
rustc_hir = { path = "../rustc_hir" }
rustc_index = { path = "../rustc_index" }
+rustc_macros = { path = "../rustc_macros" }
rustc_middle = { path = "../rustc_middle" }
rustc_serialize = { path = "../rustc_serialize" }
+rustc_session = { path = "../rustc_session" }
rustc_target = { path = "../rustc_target" }
rustc_span = { path = "../rustc_span" }
diff --git a/compiler/rustc_mir_dataflow/src/errors.rs b/compiler/rustc_mir_dataflow/src/errors.rs
new file mode 100644
index 000000000..cc1425787
--- /dev/null
+++ b/compiler/rustc_mir_dataflow/src/errors.rs
@@ -0,0 +1,71 @@
+use rustc_macros::SessionDiagnostic;
+use rustc_span::{Span, Symbol};
+
+#[derive(SessionDiagnostic)]
+#[diag(mir_dataflow::path_must_end_in_filename)]
+pub(crate) struct PathMustEndInFilename {
+ #[primary_span]
+ pub span: Span,
+}
+
+#[derive(SessionDiagnostic)]
+#[diag(mir_dataflow::unknown_formatter)]
+pub(crate) struct UnknownFormatter {
+ #[primary_span]
+ pub span: Span,
+}
+
+#[derive(SessionDiagnostic)]
+#[diag(mir_dataflow::duplicate_values_for)]
+pub(crate) struct DuplicateValuesFor {
+ #[primary_span]
+ pub span: Span,
+ pub name: Symbol,
+}
+
+#[derive(SessionDiagnostic)]
+#[diag(mir_dataflow::requires_an_argument)]
+pub(crate) struct RequiresAnArgument {
+ #[primary_span]
+ pub span: Span,
+ pub name: Symbol,
+}
+
+#[derive(SessionDiagnostic)]
+#[diag(mir_dataflow::stop_after_dataflow_ended_compilation)]
+pub(crate) struct StopAfterDataFlowEndedCompilation;
+
+#[derive(SessionDiagnostic)]
+#[diag(mir_dataflow::peek_must_be_place_or_ref_place)]
+pub(crate) struct PeekMustBePlaceOrRefPlace {
+ #[primary_span]
+ pub span: Span,
+}
+
+#[derive(SessionDiagnostic)]
+#[diag(mir_dataflow::peek_must_be_not_temporary)]
+pub(crate) struct PeekMustBeNotTemporary {
+ #[primary_span]
+ pub span: Span,
+}
+
+#[derive(SessionDiagnostic)]
+#[diag(mir_dataflow::peek_bit_not_set)]
+pub(crate) struct PeekBitNotSet {
+ #[primary_span]
+ pub span: Span,
+}
+
+#[derive(SessionDiagnostic)]
+#[diag(mir_dataflow::peek_argument_not_a_local)]
+pub(crate) struct PeekArgumentNotALocal {
+ #[primary_span]
+ pub span: Span,
+}
+
+#[derive(SessionDiagnostic)]
+#[diag(mir_dataflow::peek_argument_untracked)]
+pub(crate) struct PeekArgumentUntracked {
+ #[primary_span]
+ pub span: Span,
+}
diff --git a/compiler/rustc_mir_dataflow/src/framework/engine.rs b/compiler/rustc_mir_dataflow/src/framework/engine.rs
index f374658ce..bc75645e7 100644
--- a/compiler/rustc_mir_dataflow/src/framework/engine.rs
+++ b/compiler/rustc_mir_dataflow/src/framework/engine.rs
@@ -1,5 +1,8 @@
//! A solver for dataflow problems.
+use crate::errors::{
+ DuplicateValuesFor, PathMustEndInFilename, RequiresAnArgument, UnknownFormatter,
+};
use crate::framework::BitSetExt;
use std::ffi::OsString;
@@ -108,9 +111,9 @@ where
// Otherwise, compute and store the cumulative transfer function for each block.
let identity = GenKillSet::identity(analysis.bottom_value(body).domain_size());
- let mut trans_for_block = IndexVec::from_elem(identity, body.basic_blocks());
+ let mut trans_for_block = IndexVec::from_elem(identity, &body.basic_blocks);
- for (block, block_data) in body.basic_blocks().iter_enumerated() {
+ for (block, block_data) in body.basic_blocks.iter_enumerated() {
let trans = &mut trans_for_block[block];
A::Direction::gen_kill_effects_in_block(&analysis, trans, block, block_data);
}
@@ -144,7 +147,7 @@ where
apply_trans_for_block: Option<Box<dyn Fn(BasicBlock, &mut A::Domain)>>,
) -> Self {
let bottom_value = analysis.bottom_value(body);
- let mut entry_sets = IndexVec::from_elem(bottom_value.clone(), body.basic_blocks());
+ let mut entry_sets = IndexVec::from_elem(bottom_value.clone(), &body.basic_blocks);
analysis.initialize_start_block(body, &mut entry_sets[mir::START_BLOCK]);
if A::Direction::IS_BACKWARD && entry_sets[mir::START_BLOCK] != bottom_value {
@@ -197,8 +200,7 @@ where
..
} = self;
- let mut dirty_queue: WorkQueue<BasicBlock> =
- WorkQueue::with_none(body.basic_blocks().len());
+ let mut dirty_queue: WorkQueue<BasicBlock> = WorkQueue::with_none(body.basic_blocks.len());
if A::Direction::IS_FORWARD {
for (bb, _) in traversal::reverse_postorder(body) {
@@ -347,7 +349,7 @@ impl RustcMirAttrs {
match path.file_name() {
Some(_) => Ok(path),
None => {
- tcx.sess.span_err(attr.span(), "path must end in a filename");
+ tcx.sess.emit_err(PathMustEndInFilename { span: attr.span() });
Err(())
}
}
@@ -356,7 +358,7 @@ impl RustcMirAttrs {
Self::set_field(&mut ret.formatter, tcx, &attr, |s| match s {
sym::gen_kill | sym::two_phase => Ok(s),
_ => {
- tcx.sess.span_err(attr.span(), "unknown formatter");
+ tcx.sess.emit_err(UnknownFormatter { span: attr.span() });
Err(())
}
})
@@ -377,8 +379,7 @@ impl RustcMirAttrs {
mapper: impl FnOnce(Symbol) -> Result<T, ()>,
) -> Result<(), ()> {
if field.is_some() {
- tcx.sess
- .span_err(attr.span(), &format!("duplicate values for `{}`", attr.name_or_empty()));
+ tcx.sess.emit_err(DuplicateValuesFor { span: attr.span(), name: attr.name_or_empty() });
return Err(());
}
@@ -387,8 +388,7 @@ impl RustcMirAttrs {
*field = Some(mapper(s)?);
Ok(())
} else {
- tcx.sess
- .span_err(attr.span(), &format!("`{}` requires an argument", attr.name_or_empty()));
+ tcx.sess.emit_err(RequiresAnArgument { span: attr.span(), name: attr.name_or_empty() });
Err(())
}
}
diff --git a/compiler/rustc_mir_dataflow/src/framework/graphviz.rs b/compiler/rustc_mir_dataflow/src/framework/graphviz.rs
index c94198c56..579fe68a1 100644
--- a/compiler/rustc_mir_dataflow/src/framework/graphviz.rs
+++ b/compiler/rustc_mir_dataflow/src/framework/graphviz.rs
@@ -108,12 +108,12 @@ where
type Edge = CfgEdge;
fn nodes(&self) -> dot::Nodes<'_, Self::Node> {
- self.body.basic_blocks().indices().collect::<Vec<_>>().into()
+ self.body.basic_blocks.indices().collect::<Vec<_>>().into()
}
fn edges(&self) -> dot::Edges<'_, Self::Edge> {
self.body
- .basic_blocks()
+ .basic_blocks
.indices()
.flat_map(|bb| dataflow_successors(self.body, bb))
.collect::<Vec<_>>()
diff --git a/compiler/rustc_mir_dataflow/src/framework/mod.rs b/compiler/rustc_mir_dataflow/src/framework/mod.rs
index f9fd6c9c5..d9aff94fe 100644
--- a/compiler/rustc_mir_dataflow/src/framework/mod.rs
+++ b/compiler/rustc_mir_dataflow/src/framework/mod.rs
@@ -256,6 +256,7 @@ pub trait Analysis<'tcx>: AnalysisDomain<'tcx> {
/// .iterate_to_fixpoint()
/// .into_results_cursor(body);
/// ```
+ #[inline]
fn into_engine<'mir>(
self,
tcx: TyCtxt<'tcx>,
@@ -413,7 +414,7 @@ where
}
/* Extension methods */
-
+ #[inline]
fn into_engine<'mir>(
self,
tcx: TyCtxt<'tcx>,
diff --git a/compiler/rustc_mir_dataflow/src/framework/tests.rs b/compiler/rustc_mir_dataflow/src/framework/tests.rs
index d9461fd3a..17102454a 100644
--- a/compiler/rustc_mir_dataflow/src/framework/tests.rs
+++ b/compiler/rustc_mir_dataflow/src/framework/tests.rs
@@ -100,9 +100,9 @@ impl<D: Direction> MockAnalysis<'_, D> {
fn mock_entry_sets(&self) -> IndexVec<BasicBlock, BitSet<usize>> {
let empty = self.bottom_value(self.body);
- let mut ret = IndexVec::from_elem(empty, &self.body.basic_blocks());
+ let mut ret = IndexVec::from_elem(empty, &self.body.basic_blocks);
- for (bb, _) in self.body.basic_blocks().iter_enumerated() {
+ for (bb, _) in self.body.basic_blocks.iter_enumerated() {
ret[bb] = self.mock_entry_set(bb);
}
@@ -169,7 +169,7 @@ impl<'tcx, D: Direction> AnalysisDomain<'tcx> for MockAnalysis<'tcx, D> {
const NAME: &'static str = "mock";
fn bottom_value(&self, body: &mir::Body<'tcx>) -> Self::Domain {
- BitSet::new_empty(Self::BASIC_BLOCK_OFFSET + body.basic_blocks().len())
+ BitSet::new_empty(Self::BASIC_BLOCK_OFFSET + body.basic_blocks.len())
}
fn initialize_start_block(&self, _: &mir::Body<'tcx>, _: &mut Self::Domain) {
@@ -271,9 +271,7 @@ fn test_cursor<D: Direction>(analysis: MockAnalysis<'_, D>) {
cursor.allow_unreachable();
let every_target = || {
- body.basic_blocks()
- .iter_enumerated()
- .flat_map(|(bb, _)| SeekTarget::iter_in_block(body, bb))
+ body.basic_blocks.iter_enumerated().flat_map(|(bb, _)| SeekTarget::iter_in_block(body, bb))
};
let mut seek_to_target = |targ| {
diff --git a/compiler/rustc_mir_dataflow/src/impls/liveness.rs b/compiler/rustc_mir_dataflow/src/impls/liveness.rs
index 21132eb99..3e08a8799 100644
--- a/compiler/rustc_mir_dataflow/src/impls/liveness.rs
+++ b/compiler/rustc_mir_dataflow/src/impls/liveness.rs
@@ -23,12 +23,6 @@ use crate::{Analysis, AnalysisDomain, Backward, CallReturnPlaces, GenKill, GenKi
/// [liveness]: https://en.wikipedia.org/wiki/Live_variable_analysis
pub struct MaybeLiveLocals;
-impl MaybeLiveLocals {
- fn transfer_function<'a, T>(&self, trans: &'a mut T) -> TransferFunction<'a, T> {
- TransferFunction(trans)
- }
-}
-
impl<'tcx> AnalysisDomain<'tcx> for MaybeLiveLocals {
type Domain = ChunkedBitSet<Local>;
type Direction = Backward;
@@ -54,7 +48,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeLiveLocals {
statement: &mir::Statement<'tcx>,
location: Location,
) {
- self.transfer_function(trans).visit_statement(statement, location);
+ TransferFunction(trans).visit_statement(statement, location);
}
fn terminator_effect(
@@ -63,7 +57,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeLiveLocals {
terminator: &mir::Terminator<'tcx>,
location: Location,
) {
- self.transfer_function(trans).visit_terminator(terminator, location);
+ TransferFunction(trans).visit_terminator(terminator, location);
}
fn call_return_effect(
@@ -85,9 +79,11 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeLiveLocals {
_resume_block: mir::BasicBlock,
resume_place: mir::Place<'tcx>,
) {
- if let Some(local) = resume_place.as_local() {
- trans.kill(local);
- }
+ YieldResumeEffect(trans).visit_place(
+ &resume_place,
+ PlaceContext::MutatingUse(MutatingUseContext::Yield),
+ Location::START,
+ )
}
}
@@ -98,28 +94,51 @@ where
T: GenKill<Local>,
{
fn visit_place(&mut self, place: &mir::Place<'tcx>, context: PlaceContext, location: Location) {
- let local = place.local;
-
- // We purposefully do not call `super_place` here to avoid calling `visit_local` for this
- // place with one of the `Projection` variants of `PlaceContext`.
- self.visit_projection(place.as_ref(), context, location);
+ if let PlaceContext::MutatingUse(MutatingUseContext::Yield) = context {
+ // The resume place is evaluated and assigned to only after generator resumes, so its
+ // effect is handled separately in `yield_resume_effect`.
+ return;
+ }
match DefUse::for_place(*place, context) {
- Some(DefUse::Def) => self.0.kill(local),
- Some(DefUse::Use) => self.0.gen(local),
+ Some(DefUse::Def) => {
+ if let PlaceContext::MutatingUse(
+ MutatingUseContext::Call | MutatingUseContext::AsmOutput,
+ ) = context
+ {
+ // For the associated terminators, this is only a `Def` when the terminator returns
+ // "successfully." As such, we handle this case separately in `call_return_effect`
+ // above. However, if the place looks like `*_5`, this is still unconditionally a use of
+ // `_5`.
+ } else {
+ self.0.kill(place.local);
+ }
+ }
+ Some(DefUse::Use) => self.0.gen(place.local),
None => {}
}
+
+ self.visit_projection(place.as_ref(), context, location);
}
fn visit_local(&mut self, local: Local, context: PlaceContext, _: Location) {
- // Because we do not call `super_place` above, `visit_local` is only called for locals that
- // do not appear as part of a `Place` in the MIR. This handles cases like the implicit use
- // of the return place in a `Return` terminator or the index in an `Index` projection.
- match DefUse::for_place(local.into(), context) {
- Some(DefUse::Def) => self.0.kill(local),
- Some(DefUse::Use) => self.0.gen(local),
- None => {}
- }
+ DefUse::apply(self.0, local.into(), context);
+ }
+}
+
+struct YieldResumeEffect<'a, T>(&'a mut T);
+
+impl<'tcx, T> Visitor<'tcx> for YieldResumeEffect<'_, T>
+where
+ T: GenKill<Local>,
+{
+ fn visit_place(&mut self, place: &mir::Place<'tcx>, context: PlaceContext, location: Location) {
+ DefUse::apply(self.0, *place, context);
+ self.visit_projection(place.as_ref(), context, location);
+ }
+
+ fn visit_local(&mut self, local: Local, context: PlaceContext, _: Location) {
+ DefUse::apply(self.0, local.into(), context);
}
}
@@ -130,11 +149,25 @@ enum DefUse {
}
impl DefUse {
+ fn apply<'tcx>(trans: &mut impl GenKill<Local>, place: Place<'tcx>, context: PlaceContext) {
+ match DefUse::for_place(place, context) {
+ Some(DefUse::Def) => trans.kill(place.local),
+ Some(DefUse::Use) => trans.gen(place.local),
+ None => {}
+ }
+ }
+
fn for_place<'tcx>(place: Place<'tcx>, context: PlaceContext) -> Option<DefUse> {
match context {
PlaceContext::NonUse(_) => None,
- PlaceContext::MutatingUse(MutatingUseContext::Store | MutatingUseContext::Deinit) => {
+ PlaceContext::MutatingUse(
+ MutatingUseContext::Call
+ | MutatingUseContext::Yield
+ | MutatingUseContext::AsmOutput
+ | MutatingUseContext::Store
+ | MutatingUseContext::Deinit,
+ ) => {
if place.is_indirect() {
// Treat derefs as a use of the base local. `*p = 4` is not a def of `p` but a
// use.
@@ -152,16 +185,6 @@ impl DefUse {
place.is_indirect().then_some(DefUse::Use)
}
- // For the associated terminators, this is only a `Def` when the terminator returns
- // "successfully." As such, we handle this case separately in `call_return_effect`
- // above. However, if the place looks like `*_5`, this is still unconditionally a use of
- // `_5`.
- PlaceContext::MutatingUse(
- MutatingUseContext::Call
- | MutatingUseContext::Yield
- | MutatingUseContext::AsmOutput,
- ) => place.is_indirect().then_some(DefUse::Use),
-
// All other contexts are uses...
PlaceContext::MutatingUse(
MutatingUseContext::AddressOf
@@ -247,7 +270,7 @@ impl<'a, 'tcx> Analysis<'tcx> for MaybeTransitiveLiveLocals<'a> {
| StatementKind::Retag(..)
| StatementKind::AscribeUserType(..)
| StatementKind::Coverage(..)
- | StatementKind::CopyNonOverlapping(..)
+ | StatementKind::Intrinsic(..)
| StatementKind::Nop => None,
};
if let Some(destination) = destination {
@@ -290,8 +313,10 @@ impl<'a, 'tcx> Analysis<'tcx> for MaybeTransitiveLiveLocals<'a> {
_resume_block: mir::BasicBlock,
resume_place: mir::Place<'tcx>,
) {
- if let Some(local) = resume_place.as_local() {
- trans.remove(local);
- }
+ YieldResumeEffect(trans).visit_place(
+ &resume_place,
+ PlaceContext::MutatingUse(MutatingUseContext::Yield),
+ Location::START,
+ )
}
}
diff --git a/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs b/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs
index f6b5af90a..18760b6c6 100644
--- a/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs
+++ b/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs
@@ -142,7 +142,7 @@ impl<'mir, 'tcx> crate::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'mir, 'tc
| StatementKind::FakeRead(..)
| StatementKind::Nop
| StatementKind::Retag(..)
- | StatementKind::CopyNonOverlapping(..)
+ | StatementKind::Intrinsic(..)
| StatementKind::StorageLive(..) => {}
}
}
diff --git a/compiler/rustc_mir_dataflow/src/lib.rs b/compiler/rustc_mir_dataflow/src/lib.rs
index 5793a286b..b45c32ee9 100644
--- a/compiler/rustc_mir_dataflow/src/lib.rs
+++ b/compiler/rustc_mir_dataflow/src/lib.rs
@@ -1,12 +1,14 @@
#![feature(associated_type_defaults)]
#![feature(box_patterns)]
#![feature(exact_size_is_empty)]
-#![feature(let_else)]
+#![cfg_attr(bootstrap, feature(let_else))]
#![feature(min_specialization)]
#![feature(once_cell)]
#![feature(stmt_expr_attributes)]
#![feature(trusted_step)]
#![recursion_limit = "256"]
+#![deny(rustc::untranslatable_diagnostic)]
+#![deny(rustc::diagnostic_outside_of_impl)]
#[macro_use]
extern crate tracing;
@@ -33,6 +35,7 @@ use self::move_paths::MoveData;
pub mod drop_flag_effects;
pub mod elaborate_drops;
+mod errors;
mod framework;
pub mod impls;
pub mod move_paths;
diff --git a/compiler/rustc_mir_dataflow/src/move_paths/builder.rs b/compiler/rustc_mir_dataflow/src/move_paths/builder.rs
index 116e5c1f3..f46fd118b 100644
--- a/compiler/rustc_mir_dataflow/src/move_paths/builder.rs
+++ b/compiler/rustc_mir_dataflow/src/move_paths/builder.rs
@@ -243,7 +243,7 @@ pub(super) fn gather_moves<'tcx>(
builder.gather_args();
- for (bb, block) in body.basic_blocks().iter_enumerated() {
+ for (bb, block) in body.basic_blocks.iter_enumerated() {
for (i, stmt) in block.statements.iter().enumerate() {
let source = Location { block: bb, statement_index: i };
builder.gather_statement(source, stmt);
@@ -330,7 +330,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
StatementKind::Retag { .. }
| StatementKind::AscribeUserType(..)
| StatementKind::Coverage(..)
- | StatementKind::CopyNonOverlapping(..)
+ | StatementKind::Intrinsic(..)
| StatementKind::Nop => {}
}
}
diff --git a/compiler/rustc_mir_dataflow/src/move_paths/mod.rs b/compiler/rustc_mir_dataflow/src/move_paths/mod.rs
index a951c5b0b..b36e268cf 100644
--- a/compiler/rustc_mir_dataflow/src/move_paths/mod.rs
+++ b/compiler/rustc_mir_dataflow/src/move_paths/mod.rs
@@ -217,7 +217,7 @@ where
fn new(body: &Body<'_>) -> Self {
LocationMap {
map: body
- .basic_blocks()
+ .basic_blocks
.iter()
.map(|block| vec![T::default(); block.statements.len() + 1])
.collect(),
diff --git a/compiler/rustc_mir_dataflow/src/rustc_peek.rs b/compiler/rustc_mir_dataflow/src/rustc_peek.rs
index f2471f37a..7cae68efb 100644
--- a/compiler/rustc_mir_dataflow/src/rustc_peek.rs
+++ b/compiler/rustc_mir_dataflow/src/rustc_peek.rs
@@ -6,6 +6,10 @@ use rustc_middle::mir::MirPass;
use rustc_middle::mir::{self, Body, Local, Location};
use rustc_middle::ty::{self, Ty, TyCtxt};
+use crate::errors::{
+ PeekArgumentNotALocal, PeekArgumentUntracked, PeekBitNotSet, PeekMustBeNotTemporary,
+ PeekMustBePlaceOrRefPlace, StopAfterDataFlowEndedCompilation,
+};
use crate::framework::BitSetExt;
use crate::impls::{
DefinitelyInitializedPlaces, MaybeInitializedPlaces, MaybeLiveLocals, MaybeUninitializedPlaces,
@@ -64,7 +68,7 @@ impl<'tcx> MirPass<'tcx> for SanityCheck {
}
if has_rustc_mir_with(tcx, def_id, sym::stop_after_dataflow).is_some() {
- tcx.sess.fatal("stop_after_dataflow ended compilation");
+ tcx.sess.emit_fatal(StopAfterDataFlowEndedCompilation);
}
}
}
@@ -97,7 +101,7 @@ pub fn sanity_check_via_rustc_peek<'tcx, A>(
let mut cursor = ResultsCursor::new(body, results);
- let peek_calls = body.basic_blocks().iter_enumerated().filter_map(|(bb, block_data)| {
+ let peek_calls = body.basic_blocks.iter_enumerated().filter_map(|(bb, block_data)| {
PeekCall::from_terminator(tcx, block_data.terminator()).map(|call| (bb, block_data, call))
});
@@ -133,9 +137,7 @@ pub fn sanity_check_via_rustc_peek<'tcx, A>(
}
_ => {
- let msg = "rustc_peek: argument expression \
- must be either `place` or `&place`";
- tcx.sess.span_err(call.span, msg);
+ tcx.sess.emit_err(PeekMustBePlaceOrRefPlace { span: call.span });
}
}
}
@@ -204,18 +206,12 @@ impl PeekCall {
if let Some(local) = place.as_local() {
local
} else {
- tcx.sess.diagnostic().span_err(
- span,
- "dataflow::sanity_check cannot feed a non-temp to rustc_peek.",
- );
+ tcx.sess.emit_err(PeekMustBeNotTemporary { span });
return None;
}
}
_ => {
- tcx.sess.diagnostic().span_err(
- span,
- "dataflow::sanity_check cannot feed a non-temp to rustc_peek.",
- );
+ tcx.sess.emit_err(PeekMustBeNotTemporary { span });
return None;
}
};
@@ -255,12 +251,12 @@ where
let bit_state = flow_state.contains(peek_mpi);
debug!("rustc_peek({:?} = &{:?}) bit_state: {}", call.arg, place, bit_state);
if !bit_state {
- tcx.sess.span_err(call.span, "rustc_peek: bit not set");
+ tcx.sess.emit_err(PeekBitNotSet { span: call.span });
}
}
LookupResult::Parent(..) => {
- tcx.sess.span_err(call.span, "rustc_peek: argument untracked");
+ tcx.sess.emit_err(PeekArgumentUntracked { span: call.span });
}
}
}
@@ -276,12 +272,12 @@ impl<'tcx> RustcPeekAt<'tcx> for MaybeLiveLocals {
) {
info!(?place, "peek_at");
let Some(local) = place.as_local() else {
- tcx.sess.span_err(call.span, "rustc_peek: argument was not a local");
+ tcx.sess.emit_err(PeekArgumentNotALocal { span: call.span });
return;
};
if !flow_state.contains(local) {
- tcx.sess.span_err(call.span, "rustc_peek: bit not set");
+ tcx.sess.emit_err(PeekBitNotSet { span: call.span });
}
}
}
diff --git a/compiler/rustc_mir_dataflow/src/storage.rs b/compiler/rustc_mir_dataflow/src/storage.rs
index c909648ea..e5a0e1d31 100644
--- a/compiler/rustc_mir_dataflow/src/storage.rs
+++ b/compiler/rustc_mir_dataflow/src/storage.rs
@@ -7,7 +7,7 @@ use rustc_middle::mir::{self, Local};
pub fn always_storage_live_locals(body: &mir::Body<'_>) -> BitSet<Local> {
let mut always_live_locals = BitSet::new_filled(body.local_decls.len());
- for block in body.basic_blocks() {
+ for block in &*body.basic_blocks {
for statement in &block.statements {
use mir::StatementKind::{StorageDead, StorageLive};
if let StorageLive(l) | StorageDead(l) = statement.kind {