summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_mir_dataflow
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_mir_dataflow')
-rw-r--r--compiler/rustc_mir_dataflow/src/drop_flag_effects.rs97
-rw-r--r--compiler/rustc_mir_dataflow/src/elaborate_drops.rs14
-rw-r--r--compiler/rustc_mir_dataflow/src/framework/direction.rs6
-rw-r--r--compiler/rustc_mir_dataflow/src/framework/fmt.rs4
-rw-r--r--compiler/rustc_mir_dataflow/src/framework/graphviz.rs18
-rw-r--r--compiler/rustc_mir_dataflow/src/framework/lattice.rs2
-rw-r--r--compiler/rustc_mir_dataflow/src/impls/liveness.rs4
-rw-r--r--compiler/rustc_mir_dataflow/src/impls/mod.rs2
-rw-r--r--compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs13
-rw-r--r--compiler/rustc_mir_dataflow/src/move_paths/mod.rs21
-rw-r--r--compiler/rustc_mir_dataflow/src/value_analysis.rs4
11 files changed, 90 insertions, 95 deletions
diff --git a/compiler/rustc_mir_dataflow/src/drop_flag_effects.rs b/compiler/rustc_mir_dataflow/src/drop_flag_effects.rs
index f102872cd..3224e13f7 100644
--- a/compiler/rustc_mir_dataflow/src/drop_flag_effects.rs
+++ b/compiler/rustc_mir_dataflow/src/drop_flag_effects.rs
@@ -29,56 +29,6 @@ where
None
}
-/// When enumerating the child fragments of a path, don't recurse into
-/// paths (1.) past arrays, slices, and pointers, nor (2.) into a type
-/// that implements `Drop`.
-///
-/// Places behind references or arrays are not tracked by elaboration
-/// and are always assumed to be initialized when accessible. As
-/// references and indexes can be reseated, trying to track them can
-/// only lead to trouble.
-///
-/// Places behind ADT's with a Drop impl are not tracked by
-/// elaboration since they can never have a drop-flag state that
-/// differs from that of the parent with the Drop impl.
-///
-/// In both cases, the contents can only be accessed if and only if
-/// their parents are initialized. This implies for example that there
-/// is no need to maintain separate drop flags to track such state.
-//
-// FIXME: we have to do something for moving slice patterns.
-fn place_contents_drop_state_cannot_differ<'tcx>(
- tcx: TyCtxt<'tcx>,
- body: &Body<'tcx>,
- place: mir::Place<'tcx>,
-) -> bool {
- let ty = place.ty(body, tcx).ty;
- match ty.kind() {
- ty::Array(..) => {
- debug!(
- "place_contents_drop_state_cannot_differ place: {:?} ty: {:?} => false",
- place, ty
- );
- false
- }
- ty::Slice(..) | ty::Ref(..) | ty::RawPtr(..) => {
- debug!(
- "place_contents_drop_state_cannot_differ place: {:?} ty: {:?} refd => true",
- place, ty
- );
- true
- }
- ty::Adt(def, _) if (def.has_dtor(tcx) && !def.is_box()) || def.is_union() => {
- debug!(
- "place_contents_drop_state_cannot_differ place: {:?} ty: {:?} Drop => true",
- place, ty
- );
- true
- }
- _ => false,
- }
-}
-
pub fn on_lookup_result_bits<'tcx, F>(
tcx: TyCtxt<'tcx>,
body: &Body<'tcx>,
@@ -105,13 +55,58 @@ pub fn on_all_children_bits<'tcx, F>(
) where
F: FnMut(MovePathIndex),
{
+ #[inline]
fn is_terminal_path<'tcx>(
tcx: TyCtxt<'tcx>,
body: &Body<'tcx>,
move_data: &MoveData<'tcx>,
path: MovePathIndex,
) -> bool {
- place_contents_drop_state_cannot_differ(tcx, body, move_data.move_paths[path].place)
+ let place = move_data.move_paths[path].place;
+
+ // When enumerating the child fragments of a path, don't recurse into
+ // paths (1.) past arrays, slices, and pointers, nor (2.) into a type
+ // that implements `Drop`.
+ //
+ // Places behind references or arrays are not tracked by elaboration
+ // and are always assumed to be initialized when accessible. As
+ // references and indexes can be reseated, trying to track them can
+ // only lead to trouble.
+ //
+ // Places behind ADT's with a Drop impl are not tracked by
+ // elaboration since they can never have a drop-flag state that
+ // differs from that of the parent with the Drop impl.
+ //
+ // In both cases, the contents can only be accessed if and only if
+ // their parents are initialized. This implies for example that there
+ // is no need to maintain separate drop flags to track such state.
+ //
+ // FIXME: we have to do something for moving slice patterns.
+ let ty = place.ty(body, tcx).ty;
+ match ty.kind() {
+ ty::Adt(def, _) if (def.has_dtor(tcx) && !def.is_box()) || def.is_union() => {
+ debug!(
+ "place_contents_drop_state_cannot_differ place: {:?} ty: {:?} Drop => true",
+ place, ty
+ );
+ true
+ }
+ ty::Array(..) => {
+ debug!(
+ "place_contents_drop_state_cannot_differ place: {:?} ty: {:?} => false",
+ place, ty
+ );
+ false
+ }
+ ty::Slice(..) | ty::Ref(..) | ty::RawPtr(..) => {
+ debug!(
+ "place_contents_drop_state_cannot_differ place: {:?} ty: {:?} refd => true",
+ place, ty
+ );
+ true
+ }
+ _ => false,
+ }
}
fn on_all_children_bits<'tcx, F>(
diff --git a/compiler/rustc_mir_dataflow/src/elaborate_drops.rs b/compiler/rustc_mir_dataflow/src/elaborate_drops.rs
index ce87a1916..7836ae2e7 100644
--- a/compiler/rustc_mir_dataflow/src/elaborate_drops.rs
+++ b/compiler/rustc_mir_dataflow/src/elaborate_drops.rs
@@ -596,7 +596,6 @@ where
source_info: self.source_info,
kind: TerminatorKind::SwitchInt {
discr: Operand::Move(discr),
- switch_ty: discr_ty,
targets: SwitchTargets::new(
values.iter().copied().zip(blocks.iter().copied()),
*blocks.last().unwrap(),
@@ -615,7 +614,6 @@ where
let drop_trait = tcx.require_lang_item(LangItem::Drop, None);
let drop_fn = tcx.associated_item_def_ids(drop_trait)[0];
let ty = self.place_ty(self.place);
- let substs = tcx.mk_substs_trait(ty, []);
let ref_ty =
tcx.mk_ref(tcx.lifetimes.re_erased, ty::TypeAndMut { ty, mutbl: hir::Mutability::Mut });
@@ -633,7 +631,12 @@ where
)],
terminator: Some(Terminator {
kind: TerminatorKind::Call {
- func: Operand::function_handle(tcx, drop_fn, substs, self.source_info.span),
+ func: Operand::function_handle(
+ tcx,
+ drop_fn,
+ [ty.into()],
+ self.source_info.span,
+ ),
args: vec![Operand::Move(Place::from(ref_place))],
destination: unit_temp,
target: Some(succ),
@@ -716,7 +719,7 @@ where
is_cleanup: unwind.is_cleanup(),
terminator: Some(Terminator {
source_info: self.source_info,
- kind: TerminatorKind::if_(tcx, move_(can_go), succ, drop_block),
+ kind: TerminatorKind::if_(move_(can_go), succ, drop_block),
}),
};
let loop_block = self.elaborator.patch().new_block(loop_block);
@@ -781,7 +784,6 @@ where
source_info: self.source_info,
kind: TerminatorKind::SwitchInt {
discr: move_(elem_size),
- switch_ty: tcx.types.usize,
targets: SwitchTargets::static_if(
0,
self.drop_loop_pair(ety, false, len),
@@ -1021,7 +1023,7 @@ where
DropStyle::Static => on_set,
DropStyle::Conditional | DropStyle::Open => {
let flag = self.elaborator.get_drop_flag(self.path).unwrap();
- let term = TerminatorKind::if_(self.tcx(), flag, on_set, on_unset);
+ let term = TerminatorKind::if_(flag, on_set, on_unset);
self.new_block(unwind, term)
}
}
diff --git a/compiler/rustc_mir_dataflow/src/framework/direction.rs b/compiler/rustc_mir_dataflow/src/framework/direction.rs
index 5c77f3ea3..077a21fc8 100644
--- a/compiler/rustc_mir_dataflow/src/framework/direction.rs
+++ b/compiler/rustc_mir_dataflow/src/framework/direction.rs
@@ -261,7 +261,7 @@ impl Direction for Backward {
propagate(pred, &tmp);
}
- mir::TerminatorKind::SwitchInt { targets: _, ref discr, switch_ty: _ } => {
+ mir::TerminatorKind::SwitchInt { targets: _, ref discr } => {
let mut applier = BackwardSwitchIntEdgeEffectsApplier {
body,
pred,
@@ -287,7 +287,7 @@ impl Direction for Backward {
| mir::TerminatorKind::InlineAsm { cleanup: Some(unwind), .. }
if unwind == bb =>
{
- if dead_unwinds.map_or(true, |dead| !dead.contains(bb)) {
+ if dead_unwinds.map_or(true, |dead| !dead.contains(pred)) {
propagate(pred, exit_state);
}
}
@@ -577,7 +577,7 @@ impl Direction for Forward {
}
}
- SwitchInt { ref targets, ref discr, switch_ty: _ } => {
+ SwitchInt { ref targets, ref discr } => {
let mut applier = ForwardSwitchIntEdgeEffectsApplier {
exit_state,
targets,
diff --git a/compiler/rustc_mir_dataflow/src/framework/fmt.rs b/compiler/rustc_mir_dataflow/src/framework/fmt.rs
index 209e6f7ac..490be166a 100644
--- a/compiler/rustc_mir_dataflow/src/framework/fmt.rs
+++ b/compiler/rustc_mir_dataflow/src/framework/fmt.rs
@@ -143,7 +143,7 @@ where
", "
};
- write!(f, "{}", delim)?;
+ write!(f, "{delim}")?;
idx.fmt_with(ctxt, f)?;
first = false;
}
@@ -164,7 +164,7 @@ where
", "
};
- write!(f, "{}", delim)?;
+ write!(f, "{delim}")?;
idx.fmt_with(ctxt, f)?;
first = false;
}
diff --git a/compiler/rustc_mir_dataflow/src/framework/graphviz.rs b/compiler/rustc_mir_dataflow/src/framework/graphviz.rs
index c9d5601f2..96c42894b 100644
--- a/compiler/rustc_mir_dataflow/src/framework/graphviz.rs
+++ b/compiler/rustc_mir_dataflow/src/framework/graphviz.rs
@@ -71,7 +71,7 @@ where
fn graph_id(&self) -> dot::Id<'_> {
let name = graphviz_safe_def_name(self.body.source.def_id());
- dot::Id::new(format!("graph_for_def_id_{}", name)).unwrap()
+ dot::Id::new(format!("graph_for_def_id_{name}")).unwrap()
}
fn node_id(&self, n: &Self::Node) -> dot::Id<'_> {
@@ -190,7 +190,7 @@ where
" cellpadding=\"3\"",
" sides=\"rb\"",
);
- write!(w, r#"<table{fmt}>"#, fmt = table_fmt)?;
+ write!(w, r#"<table{table_fmt}>"#)?;
// A + B: Block header
match self.style {
@@ -372,7 +372,7 @@ where
write!(w, concat!("<tr>", r#"<td colspan="2" {fmt}>MIR</td>"#,), fmt = fmt,)?;
for name in state_column_names {
- write!(w, "<td {fmt}>{name}</td>", fmt = fmt, name = name)?;
+ write!(w, "<td {fmt}>{name}</td>")?;
}
write!(w, "</tr>")
@@ -394,18 +394,18 @@ where
};
for (i, statement) in body[block].statements.iter().enumerate() {
- let statement_str = format!("{:?}", statement);
- let index_str = format!("{}", i);
+ let statement_str = format!("{statement:?}");
+ let index_str = format!("{i}");
let after = next_in_dataflow_order(&mut afters);
let before = befores.as_mut().map(next_in_dataflow_order);
self.write_row(w, &index_str, &statement_str, |_this, w, fmt| {
if let Some(before) = before {
- write!(w, r#"<td {fmt} align="left">{diff}</td>"#, fmt = fmt, diff = before)?;
+ write!(w, r#"<td {fmt} align="left">{before}</td>"#)?;
}
- write!(w, r#"<td {fmt} align="left">{diff}</td>"#, fmt = fmt, diff = after)
+ write!(w, r#"<td {fmt} align="left">{after}</td>"#)
})?;
}
@@ -421,10 +421,10 @@ where
self.write_row(w, "T", &terminator_str, |_this, w, fmt| {
if let Some(before) = before {
- write!(w, r#"<td {fmt} align="left">{diff}</td>"#, fmt = fmt, diff = before)?;
+ write!(w, r#"<td {fmt} align="left">{before}</td>"#)?;
}
- write!(w, r#"<td {fmt} align="left">{diff}</td>"#, fmt = fmt, diff = after)
+ write!(w, r#"<td {fmt} align="left">{after}</td>"#)
})
}
diff --git a/compiler/rustc_mir_dataflow/src/framework/lattice.rs b/compiler/rustc_mir_dataflow/src/framework/lattice.rs
index f0e75c53e..8fdac7b2c 100644
--- a/compiler/rustc_mir_dataflow/src/framework/lattice.rs
+++ b/compiler/rustc_mir_dataflow/src/framework/lattice.rs
@@ -26,7 +26,7 @@
//! ## `PartialOrd`
//!
//! Given that they represent partially ordered sets, you may be surprised that [`JoinSemiLattice`]
-//! and [`MeetSemiLattice`] do not have [`PartialOrd`][std::cmp::PartialOrd] as a supertrait. This
+//! and [`MeetSemiLattice`] do not have [`PartialOrd`] as a supertrait. This
//! is because most standard library types use lexicographic ordering instead of set inclusion for
//! their `PartialOrd` impl. Since we do not actually need to compare lattice elements to run a
//! dataflow analysis, there's no need for a newtype wrapper with a custom `PartialOrd` impl. The
diff --git a/compiler/rustc_mir_dataflow/src/impls/liveness.rs b/compiler/rustc_mir_dataflow/src/impls/liveness.rs
index 3e08a8799..923dc16c1 100644
--- a/compiler/rustc_mir_dataflow/src/impls/liveness.rs
+++ b/compiler/rustc_mir_dataflow/src/impls/liveness.rs
@@ -149,7 +149,7 @@ enum DefUse {
}
impl DefUse {
- fn apply<'tcx>(trans: &mut impl GenKill<Local>, place: Place<'tcx>, context: PlaceContext) {
+ fn apply(trans: &mut impl GenKill<Local>, place: Place<'_>, context: PlaceContext) {
match DefUse::for_place(place, context) {
Some(DefUse::Def) => trans.kill(place.local),
Some(DefUse::Use) => trans.gen(place.local),
@@ -157,7 +157,7 @@ impl DefUse {
}
}
- fn for_place<'tcx>(place: Place<'tcx>, context: PlaceContext) -> Option<DefUse> {
+ fn for_place(place: Place<'_>, context: PlaceContext) -> Option<DefUse> {
match context {
PlaceContext::NonUse(_) => None,
diff --git a/compiler/rustc_mir_dataflow/src/impls/mod.rs b/compiler/rustc_mir_dataflow/src/impls/mod.rs
index bc31ec42b..4b5324e20 100644
--- a/compiler/rustc_mir_dataflow/src/impls/mod.rs
+++ b/compiler/rustc_mir_dataflow/src/impls/mod.rs
@@ -750,7 +750,7 @@ where
/// Calls `f` for each mutable borrow or raw reference in the program.
///
-/// This DOES NOT call `f` for a shared borrow of a type with interior mutability. That's okay for
+/// This DOES NOT call `f` for a shared borrow of a type with interior mutability. That's okay for
/// initializedness, because we cannot move from an `UnsafeCell` (outside of `core::cell`), but
/// other analyses will likely need to check for `!Freeze`.
fn for_each_mut_borrow<'tcx>(
diff --git a/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs b/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs
index 18760b6c6..8d379b90a 100644
--- a/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs
+++ b/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs
@@ -3,20 +3,21 @@ pub use super::*;
use crate::{CallReturnPlaces, GenKill, Results, ResultsRefCursor};
use rustc_middle::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor};
use rustc_middle::mir::*;
+use std::borrow::Cow;
use std::cell::RefCell;
#[derive(Clone)]
-pub struct MaybeStorageLive {
- always_live_locals: BitSet<Local>,
+pub struct MaybeStorageLive<'a> {
+ always_live_locals: Cow<'a, BitSet<Local>>,
}
-impl MaybeStorageLive {
- pub fn new(always_live_locals: BitSet<Local>) -> Self {
+impl<'a> MaybeStorageLive<'a> {
+ pub fn new(always_live_locals: Cow<'a, BitSet<Local>>) -> Self {
MaybeStorageLive { always_live_locals }
}
}
-impl<'tcx> crate::AnalysisDomain<'tcx> for MaybeStorageLive {
+impl<'tcx, 'a> crate::AnalysisDomain<'tcx> for MaybeStorageLive<'a> {
type Domain = BitSet<Local>;
const NAME: &'static str = "maybe_storage_live";
@@ -38,7 +39,7 @@ impl<'tcx> crate::AnalysisDomain<'tcx> for MaybeStorageLive {
}
}
-impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeStorageLive {
+impl<'tcx, 'a> crate::GenKillAnalysis<'tcx> for MaybeStorageLive<'a> {
type Idx = Local;
fn statement_effect(
diff --git a/compiler/rustc_mir_dataflow/src/move_paths/mod.rs b/compiler/rustc_mir_dataflow/src/move_paths/mod.rs
index b36e268cf..5f22a418d 100644
--- a/compiler/rustc_mir_dataflow/src/move_paths/mod.rs
+++ b/compiler/rustc_mir_dataflow/src/move_paths/mod.rs
@@ -14,9 +14,8 @@ use self::abs_domain::{AbstractElem, Lift};
mod abs_domain;
rustc_index::newtype_index! {
- pub struct MovePathIndex {
- DEBUG_FORMAT = "mp{}"
- }
+ #[debug_format = "mp{}"]
+ pub struct MovePathIndex {}
}
impl polonius_engine::Atom for MovePathIndex {
@@ -26,15 +25,13 @@ impl polonius_engine::Atom for MovePathIndex {
}
rustc_index::newtype_index! {
- pub struct MoveOutIndex {
- DEBUG_FORMAT = "mo{}"
- }
+ #[debug_format = "mo{}"]
+ pub struct MoveOutIndex {}
}
rustc_index::newtype_index! {
- pub struct InitIndex {
- DEBUG_FORMAT = "in{}"
- }
+ #[debug_format = "in{}"]
+ pub struct InitIndex {}
}
impl MoveOutIndex {
@@ -132,13 +129,13 @@ impl<'tcx> fmt::Debug for MovePath<'tcx> {
fn fmt(&self, w: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(w, "MovePath {{")?;
if let Some(parent) = self.parent {
- write!(w, " parent: {:?},", parent)?;
+ write!(w, " parent: {parent:?},")?;
}
if let Some(first_child) = self.first_child {
- write!(w, " first_child: {:?},", first_child)?;
+ write!(w, " first_child: {first_child:?},")?;
}
if let Some(next_sibling) = self.next_sibling {
- write!(w, " next_sibling: {:?}", next_sibling)?;
+ write!(w, " next_sibling: {next_sibling:?}")?;
}
write!(w, " place: {:?} }}", self.place)
}
diff --git a/compiler/rustc_mir_dataflow/src/value_analysis.rs b/compiler/rustc_mir_dataflow/src/value_analysis.rs
index 7df011422..0522c6579 100644
--- a/compiler/rustc_mir_dataflow/src/value_analysis.rs
+++ b/compiler/rustc_mir_dataflow/src/value_analysis.rs
@@ -823,7 +823,7 @@ fn iter_fields<'tcx>(
}
/// Returns all locals with projections that have their reference or address taken.
-fn excluded_locals<'tcx>(body: &Body<'tcx>) -> IndexVec<Local, bool> {
+fn excluded_locals(body: &Body<'_>) -> IndexVec<Local, bool> {
struct Collector {
result: IndexVec<Local, bool>,
}
@@ -920,7 +920,7 @@ fn debug_with_context<V: Debug + Eq>(
) -> std::fmt::Result {
for (local, place) in map.locals.iter_enumerated() {
if let Some(place) = place {
- debug_with_context_rec(*place, &format!("{:?}", local), new, old, map, f)?;
+ debug_with_context_rec(*place, &format!("{local:?}"), new, old, map, f)?;
}
}
Ok(())