Rename `FlowState` as `Domain`.

Because that's what it is; no point having a different name for it.
This commit is contained in:
Nicholas Nethercote 2024-09-13 16:27:24 +10:00
parent 55c9f96265
commit bb943f93ff
10 changed files with 160 additions and 163 deletions

View File

@ -9,7 +9,7 @@ use rustc_middle::mir::{
use rustc_middle::ty::{RegionVid, TyCtxt};
use rustc_mir_dataflow::fmt::DebugWithContext;
use rustc_mir_dataflow::impls::{EverInitializedPlaces, MaybeUninitializedPlaces};
use rustc_mir_dataflow::{Analysis, AnalysisDomain, GenKill, Results, ResultsVisitable};
use rustc_mir_dataflow::{Analysis, AnalysisDomain, Forward, GenKill, Results, ResultsVisitable};
use tracing::debug;
use crate::{places_conflict, BorrowSet, PlaceConflictBias, PlaceExt, RegionInferenceContext};
@ -23,26 +23,25 @@ pub(crate) struct BorrowckResults<'a, 'tcx> {
/// The transient state of the dataflow analyses used by the borrow checker.
#[derive(Debug)]
pub(crate) struct BorrowckFlowState<'a, 'tcx> {
pub(crate) struct BorrowckDomain<'a, 'tcx> {
pub(crate) borrows: <Borrows<'a, 'tcx> as AnalysisDomain<'tcx>>::Domain,
pub(crate) uninits: <MaybeUninitializedPlaces<'a, 'tcx> as AnalysisDomain<'tcx>>::Domain,
pub(crate) ever_inits: <EverInitializedPlaces<'a, 'tcx> as AnalysisDomain<'tcx>>::Domain,
}
impl<'a, 'tcx> ResultsVisitable<'tcx> for BorrowckResults<'a, 'tcx> {
// All three analyses are forward, but we have to use just one here.
type Direction = <Borrows<'a, 'tcx> as AnalysisDomain<'tcx>>::Direction;
type FlowState = BorrowckFlowState<'a, 'tcx>;
type Direction = Forward;
type Domain = BorrowckDomain<'a, 'tcx>;
fn new_flow_state(&self, body: &mir::Body<'tcx>) -> Self::FlowState {
BorrowckFlowState {
fn bottom_value(&self, body: &mir::Body<'tcx>) -> Self::Domain {
BorrowckDomain {
borrows: self.borrows.analysis.bottom_value(body),
uninits: self.uninits.analysis.bottom_value(body),
ever_inits: self.ever_inits.analysis.bottom_value(body),
}
}
fn reset_to_block_entry(&self, state: &mut Self::FlowState, block: BasicBlock) {
fn reset_to_block_entry(&self, state: &mut Self::Domain, block: BasicBlock) {
state.borrows.clone_from(self.borrows.entry_set_for_block(block));
state.uninits.clone_from(self.uninits.entry_set_for_block(block));
state.ever_inits.clone_from(self.ever_inits.entry_set_for_block(block));
@ -50,7 +49,7 @@ impl<'a, 'tcx> ResultsVisitable<'tcx> for BorrowckResults<'a, 'tcx> {
fn reconstruct_before_statement_effect(
&mut self,
state: &mut Self::FlowState,
state: &mut Self::Domain,
stmt: &mir::Statement<'tcx>,
loc: Location,
) {
@ -61,7 +60,7 @@ impl<'a, 'tcx> ResultsVisitable<'tcx> for BorrowckResults<'a, 'tcx> {
fn reconstruct_statement_effect(
&mut self,
state: &mut Self::FlowState,
state: &mut Self::Domain,
stmt: &mir::Statement<'tcx>,
loc: Location,
) {
@ -72,7 +71,7 @@ impl<'a, 'tcx> ResultsVisitable<'tcx> for BorrowckResults<'a, 'tcx> {
fn reconstruct_before_terminator_effect(
&mut self,
state: &mut Self::FlowState,
state: &mut Self::Domain,
term: &mir::Terminator<'tcx>,
loc: Location,
) {
@ -83,7 +82,7 @@ impl<'a, 'tcx> ResultsVisitable<'tcx> for BorrowckResults<'a, 'tcx> {
fn reconstruct_terminator_effect(
&mut self,
state: &mut Self::FlowState,
state: &mut Self::Domain,
term: &mir::Terminator<'tcx>,
loc: Location,
) {

View File

@ -83,7 +83,7 @@ mod util;
pub mod consumers;
use borrow_set::{BorrowData, BorrowSet};
use dataflow::{BorrowIndex, BorrowckFlowState as Flows, BorrowckResults, Borrows};
use dataflow::{BorrowIndex, BorrowckDomain, BorrowckResults, Borrows};
use nll::PoloniusOutput;
use place_ext::PlaceExt;
use places_conflict::{places_conflict, PlaceConflictBias};
@ -602,25 +602,25 @@ struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
for MirBorrowckCtxt<'a, '_, 'tcx>
{
type FlowState = Flows<'a, 'tcx>;
type Domain = BorrowckDomain<'a, 'tcx>;
fn visit_statement_before_primary_effect(
&mut self,
_results: &mut R,
flow_state: &Flows<'a, 'tcx>,
state: &BorrowckDomain<'a, 'tcx>,
stmt: &'a Statement<'tcx>,
location: Location,
) {
debug!("MirBorrowckCtxt::process_statement({:?}, {:?}): {:?}", location, stmt, flow_state);
debug!("MirBorrowckCtxt::process_statement({:?}, {:?}): {:?}", location, stmt, state);
let span = stmt.source_info.span;
self.check_activations(location, span, flow_state);
self.check_activations(location, span, state);
match &stmt.kind {
StatementKind::Assign(box (lhs, rhs)) => {
self.consume_rvalue(location, (rhs, span), flow_state);
self.consume_rvalue(location, (rhs, span), state);
self.mutate_place(location, (*lhs, span), Shallow(None), flow_state);
self.mutate_place(location, (*lhs, span), Shallow(None), state);
}
StatementKind::FakeRead(box (_, place)) => {
// Read for match doesn't access any memory and is used to
@ -637,11 +637,11 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
location,
InitializationRequiringAction::Use,
(place.as_ref(), span),
flow_state,
state,
);
}
StatementKind::Intrinsic(box kind) => match kind {
NonDivergingIntrinsic::Assume(op) => self.consume_operand(location, (op, span), flow_state),
NonDivergingIntrinsic::Assume(op) => self.consume_operand(location, (op, span), state),
NonDivergingIntrinsic::CopyNonOverlapping(..) => span_bug!(
span,
"Unexpected CopyNonOverlapping, should only appear after lower_intrinsics",
@ -662,7 +662,7 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
(Place::from(*local), span),
(Shallow(None), Write(WriteKind::StorageDeadOrDrop)),
LocalMutationIsAllowed::Yes,
flow_state,
state,
);
}
StatementKind::Nop
@ -677,18 +677,18 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
fn visit_terminator_before_primary_effect(
&mut self,
_results: &mut R,
flow_state: &Flows<'a, 'tcx>,
state: &BorrowckDomain<'a, 'tcx>,
term: &'a Terminator<'tcx>,
loc: Location,
) {
debug!("MirBorrowckCtxt::process_terminator({:?}, {:?}): {:?}", loc, term, flow_state);
debug!("MirBorrowckCtxt::process_terminator({:?}, {:?}): {:?}", loc, term, state);
let span = term.source_info.span;
self.check_activations(loc, span, flow_state);
self.check_activations(loc, span, state);
match &term.kind {
TerminatorKind::SwitchInt { discr, targets: _ } => {
self.consume_operand(loc, (discr, span), flow_state);
self.consume_operand(loc, (discr, span), state);
}
TerminatorKind::Drop { place, target: _, unwind: _, replace } => {
debug!(
@ -704,7 +704,7 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
(*place, span),
(AccessDepth::Drop, Write(write_kind)),
LocalMutationIsAllowed::Yes,
flow_state,
state,
);
}
TerminatorKind::Call {
@ -716,29 +716,29 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
call_source: _,
fn_span: _,
} => {
self.consume_operand(loc, (func, span), flow_state);
self.consume_operand(loc, (func, span), state);
for arg in args {
self.consume_operand(loc, (&arg.node, arg.span), flow_state);
self.consume_operand(loc, (&arg.node, arg.span), state);
}
self.mutate_place(loc, (*destination, span), Deep, flow_state);
self.mutate_place(loc, (*destination, span), Deep, state);
}
TerminatorKind::TailCall { func, args, fn_span: _ } => {
self.consume_operand(loc, (func, span), flow_state);
self.consume_operand(loc, (func, span), state);
for arg in args {
self.consume_operand(loc, (&arg.node, arg.span), flow_state);
self.consume_operand(loc, (&arg.node, arg.span), state);
}
}
TerminatorKind::Assert { cond, expected: _, msg, target: _, unwind: _ } => {
self.consume_operand(loc, (cond, span), flow_state);
self.consume_operand(loc, (cond, span), state);
if let AssertKind::BoundsCheck { len, index } = &**msg {
self.consume_operand(loc, (len, span), flow_state);
self.consume_operand(loc, (index, span), flow_state);
self.consume_operand(loc, (len, span), state);
self.consume_operand(loc, (index, span), state);
}
}
TerminatorKind::Yield { value, resume: _, resume_arg, drop: _ } => {
self.consume_operand(loc, (value, span), flow_state);
self.mutate_place(loc, (*resume_arg, span), Deep, flow_state);
self.consume_operand(loc, (value, span), state);
self.mutate_place(loc, (*resume_arg, span), Deep, state);
}
TerminatorKind::InlineAsm {
@ -752,22 +752,17 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
for op in operands {
match op {
InlineAsmOperand::In { reg: _, value } => {
self.consume_operand(loc, (value, span), flow_state);
self.consume_operand(loc, (value, span), state);
}
InlineAsmOperand::Out { reg: _, late: _, place, .. } => {
if let Some(place) = place {
self.mutate_place(loc, (*place, span), Shallow(None), flow_state);
self.mutate_place(loc, (*place, span), Shallow(None), state);
}
}
InlineAsmOperand::InOut { reg: _, late: _, in_value, out_place } => {
self.consume_operand(loc, (in_value, span), flow_state);
self.consume_operand(loc, (in_value, span), state);
if let &Some(out_place) = out_place {
self.mutate_place(
loc,
(out_place, span),
Shallow(None),
flow_state,
);
self.mutate_place(loc, (out_place, span), Shallow(None), state);
}
}
InlineAsmOperand::Const { value: _ }
@ -794,7 +789,7 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
fn visit_terminator_after_primary_effect(
&mut self,
_results: &mut R,
flow_state: &Flows<'a, 'tcx>,
state: &BorrowckDomain<'a, 'tcx>,
term: &'a Terminator<'tcx>,
loc: Location,
) {
@ -805,7 +800,7 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
if self.movable_coroutine {
// Look for any active borrows to locals
let borrow_set = self.borrow_set.clone();
for i in flow_state.borrows.iter() {
for i in state.borrows.iter() {
let borrow = &borrow_set[i];
self.check_for_local_borrow(borrow, span);
}
@ -821,7 +816,7 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
// StorageDead, but we don't always emit those (notably on unwind paths),
// so this "extra check" serves as a kind of backup.
let borrow_set = self.borrow_set.clone();
for i in flow_state.borrows.iter() {
for i in state.borrows.iter() {
let borrow = &borrow_set[i];
self.check_for_invalidation_at_exit(loc, borrow, span);
}
@ -989,7 +984,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
place_span: (Place<'tcx>, Span),
kind: (AccessDepth, ReadOrWrite),
is_local_mutation_allowed: LocalMutationIsAllowed,
flow_state: &Flows<'a, 'tcx>,
state: &BorrowckDomain<'a, 'tcx>,
) {
let (sd, rw) = kind;
@ -1020,11 +1015,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
place_span,
rw,
is_local_mutation_allowed,
flow_state,
state,
location,
);
let conflict_error =
self.check_access_for_conflict(location, place_span, sd, rw, flow_state);
let conflict_error = self.check_access_for_conflict(location, place_span, sd, rw, state);
if conflict_error || mutability_error {
debug!("access_place: logging error place_span=`{:?}` kind=`{:?}`", place_span, kind);
@ -1032,14 +1026,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
}
}
#[instrument(level = "debug", skip(self, flow_state))]
#[instrument(level = "debug", skip(self, state))]
fn check_access_for_conflict(
&mut self,
location: Location,
place_span: (Place<'tcx>, Span),
sd: AccessDepth,
rw: ReadOrWrite,
flow_state: &Flows<'a, 'tcx>,
state: &BorrowckDomain<'a, 'tcx>,
) -> bool {
let mut error_reported = false;
let borrow_set = Rc::clone(&self.borrow_set);
@ -1054,7 +1048,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
}
&polonius_output
} else {
&flow_state.borrows
&state.borrows
};
each_borrow_involving_path(
@ -1180,17 +1174,17 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
location: Location,
place_span: (Place<'tcx>, Span),
kind: AccessDepth,
flow_state: &Flows<'a, 'tcx>,
state: &BorrowckDomain<'a, 'tcx>,
) {
// Write of P[i] or *P requires P init'd.
self.check_if_assigned_path_is_moved(location, place_span, flow_state);
self.check_if_assigned_path_is_moved(location, place_span, state);
self.access_place(
location,
place_span,
(kind, Write(WriteKind::Mutate)),
LocalMutationIsAllowed::No,
flow_state,
state,
);
}
@ -1198,7 +1192,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
&mut self,
location: Location,
(rvalue, span): (&'a Rvalue<'tcx>, Span),
flow_state: &Flows<'a, 'tcx>,
state: &BorrowckDomain<'a, 'tcx>,
) {
match rvalue {
&Rvalue::Ref(_ /*rgn*/, bk, place) => {
@ -1224,7 +1218,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
(place, span),
access_kind,
LocalMutationIsAllowed::No,
flow_state,
state,
);
let action = if bk == BorrowKind::Fake(FakeBorrowKind::Shallow) {
@ -1237,7 +1231,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
location,
action,
(place.as_ref(), span),
flow_state,
state,
);
}
@ -1257,14 +1251,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
(place, span),
access_kind,
LocalMutationIsAllowed::No,
flow_state,
state,
);
self.check_if_path_or_subpath_is_moved(
location,
InitializationRequiringAction::Borrow,
(place.as_ref(), span),
flow_state,
state,
);
}
@ -1275,7 +1269,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
| Rvalue::UnaryOp(_ /*un_op*/, operand)
| Rvalue::Cast(_ /*cast_kind*/, operand, _ /*ty*/)
| Rvalue::ShallowInitBox(operand, _ /*ty*/) => {
self.consume_operand(location, (operand, span), flow_state)
self.consume_operand(location, (operand, span), state)
}
&Rvalue::CopyForDeref(place) => {
@ -1284,7 +1278,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
(place, span),
(Deep, Read(ReadKind::Copy)),
LocalMutationIsAllowed::No,
flow_state,
state,
);
// Finally, check if path was already moved.
@ -1292,7 +1286,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
location,
InitializationRequiringAction::Use,
(place.as_ref(), span),
flow_state,
state,
);
}
@ -1307,19 +1301,19 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
(place, span),
(Shallow(af), Read(ReadKind::Copy)),
LocalMutationIsAllowed::No,
flow_state,
state,
);
self.check_if_path_or_subpath_is_moved(
location,
InitializationRequiringAction::Use,
(place.as_ref(), span),
flow_state,
state,
);
}
Rvalue::BinaryOp(_bin_op, box (operand1, operand2)) => {
self.consume_operand(location, (operand1, span), flow_state);
self.consume_operand(location, (operand2, span), flow_state);
self.consume_operand(location, (operand1, span), state);
self.consume_operand(location, (operand2, span), state);
}
Rvalue::NullaryOp(_op, _ty) => {
@ -1349,7 +1343,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
}
for operand in operands {
self.consume_operand(location, (operand, span), flow_state);
self.consume_operand(location, (operand, span), state);
}
}
}
@ -1456,7 +1450,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
&mut self,
location: Location,
(operand, span): (&'a Operand<'tcx>, Span),
flow_state: &Flows<'a, 'tcx>,
state: &BorrowckDomain<'a, 'tcx>,
) {
match *operand {
Operand::Copy(place) => {
@ -1467,7 +1461,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
(place, span),
(Deep, Read(ReadKind::Copy)),
LocalMutationIsAllowed::No,
flow_state,
state,
);
// Finally, check if path was already moved.
@ -1475,7 +1469,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
location,
InitializationRequiringAction::Use,
(place.as_ref(), span),
flow_state,
state,
);
}
Operand::Move(place) => {
@ -1488,7 +1482,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
(place, span),
(Deep, Write(WriteKind::Move)),
LocalMutationIsAllowed::Yes,
flow_state,
state,
);
// Finally, check if path was already moved.
@ -1496,7 +1490,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
location,
InitializationRequiringAction::Use,
(place.as_ref(), span),
flow_state,
state,
);
}
Operand::Constant(_) => {}
@ -1576,7 +1570,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
}
}
fn check_activations(&mut self, location: Location, span: Span, flow_state: &Flows<'a, 'tcx>) {
fn check_activations(
&mut self,
location: Location,
span: Span,
state: &BorrowckDomain<'a, 'tcx>,
) {
// Two-phase borrow support: For each activation that is newly
// generated at this statement, check if it interferes with
// another borrow.
@ -1595,7 +1594,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
(borrow.borrowed_place, span),
(Deep, Activation(WriteKind::MutableBorrow(borrow.kind), borrow_index)),
LocalMutationIsAllowed::No,
flow_state,
state,
);
// We do not need to call `check_if_path_or_subpath_is_moved`
// again, as we already called it when we made the
@ -1739,9 +1738,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
location: Location,
desired_action: InitializationRequiringAction,
place_span: (PlaceRef<'tcx>, Span),
flow_state: &Flows<'a, 'tcx>,
state: &BorrowckDomain<'a, 'tcx>,
) {
let maybe_uninits = &flow_state.uninits;
let maybe_uninits = &state.uninits;
// Bad scenarios:
//
@ -1844,9 +1843,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
location: Location,
desired_action: InitializationRequiringAction,
place_span: (PlaceRef<'tcx>, Span),
flow_state: &Flows<'a, 'tcx>,
state: &BorrowckDomain<'a, 'tcx>,
) {
let maybe_uninits = &flow_state.uninits;
let maybe_uninits = &state.uninits;
// Bad scenarios:
//
@ -1863,7 +1862,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
// must have been initialized for the use to be sound.
// 6. Move of `a.b.c` then reinit of `a.b.c.d`, use of `a.b.c.d`
self.check_if_full_path_is_moved(location, desired_action, place_span, flow_state);
self.check_if_full_path_is_moved(location, desired_action, place_span, state);
if let Some((place_base, ProjectionElem::Subslice { from, to, from_end: false })) =
place_span.0.last_projection()
@ -1943,7 +1942,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
&mut self,
location: Location,
(place, span): (Place<'tcx>, Span),
flow_state: &Flows<'a, 'tcx>,
state: &BorrowckDomain<'a, 'tcx>,
) {
debug!("check_if_assigned_path_is_moved place: {:?}", place);
@ -1965,7 +1964,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
ProjectionElem::Deref => {
self.check_if_full_path_is_moved(
location, InitializationRequiringAction::Use,
(place_base, span), flow_state);
(place_base, span), state);
// (base initialized; no need to
// recur further)
break;
@ -1985,7 +1984,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
ty::Adt(def, _) if def.has_dtor(tcx) => {
self.check_if_path_or_subpath_is_moved(
location, InitializationRequiringAction::Assignment,
(place_base, span), flow_state);
(place_base, span), state);
// (base initialized; no need to
// recur further)
@ -1995,7 +1994,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
// Once `let s; s.x = V; read(s.x);`,
// is allowed, remove this match arm.
ty::Adt(..) | ty::Tuple(..) => {
check_parent_of_field(self, location, place_base, span, flow_state);
check_parent_of_field(self, location, place_base, span, state);
}
_ => {}
@ -2009,7 +2008,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
location: Location,
base: PlaceRef<'tcx>,
span: Span,
flow_state: &Flows<'a, 'tcx>,
state: &BorrowckDomain<'a, 'tcx>,
) {
// rust-lang/rust#21232: Until Rust allows reads from the
// initialized parts of partially initialized structs, we
@ -2042,7 +2041,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
// Shallow so that we'll stop at any dereference; we'll
// report errors about issues with such bases elsewhere.
let maybe_uninits = &flow_state.uninits;
let maybe_uninits = &state.uninits;
// Find the shortest uninitialized prefix you can reach
// without going over a Deref.
@ -2100,7 +2099,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
(place, span): (Place<'tcx>, Span),
kind: ReadOrWrite,
is_local_mutation_allowed: LocalMutationIsAllowed,
flow_state: &Flows<'a, 'tcx>,
state: &BorrowckDomain<'a, 'tcx>,
location: Location,
) -> bool {
debug!(
@ -2124,7 +2123,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
};
match self.is_mutable(place.as_ref(), is_local_mutation_allowed) {
Ok(root_place) => {
self.add_used_mut(root_place, flow_state);
self.add_used_mut(root_place, state);
return false;
}
Err(place_err) => {
@ -2136,7 +2135,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
Reservation(WriteKind::Mutate) | Write(WriteKind::Mutate) => {
match self.is_mutable(place.as_ref(), is_local_mutation_allowed) {
Ok(root_place) => {
self.add_used_mut(root_place, flow_state);
self.add_used_mut(root_place, state);
return false;
}
Err(place_err) => {
@ -2194,7 +2193,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
// partial initialization, do not complain about mutability
// errors except for actual mutation (as opposed to an attempt
// to do a partial initialization).
let previously_initialized = self.is_local_ever_initialized(place.local, flow_state);
let previously_initialized = self.is_local_ever_initialized(place.local, state);
// at this point, we have set up the error reporting state.
if let Some(init_index) = previously_initialized {
@ -2216,22 +2215,22 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
fn is_local_ever_initialized(
&self,
local: Local,
flow_state: &Flows<'a, 'tcx>,
state: &BorrowckDomain<'a, 'tcx>,
) -> Option<InitIndex> {
let mpi = self.move_data.rev_lookup.find_local(local)?;
let ii = &self.move_data.init_path_map[mpi];
ii.into_iter().find(|&&index| flow_state.ever_inits.contains(index)).copied()
ii.into_iter().find(|&&index| state.ever_inits.contains(index)).copied()
}
/// Adds the place into the used mutable variables set
fn add_used_mut(&mut self, root_place: RootPlace<'tcx>, flow_state: &Flows<'a, 'tcx>) {
fn add_used_mut(&mut self, root_place: RootPlace<'tcx>, state: &BorrowckDomain<'a, 'tcx>) {
match root_place {
RootPlace { place_local: local, place_projection: [], is_local_mutation_allowed } => {
// If the local may have been initialized, and it is now currently being
// mutated, then it is justified to be annotated with the `mut`
// keyword, since the mutation may be a possible reassignment.
if is_local_mutation_allowed != LocalMutationIsAllowed::Yes
&& self.is_local_ever_initialized(local, flow_state).is_some()
&& self.is_local_ever_initialized(local, state).is_some()
{
self.used_mut.insert(local);
}

View File

@ -42,14 +42,14 @@ pub trait Direction {
) where
A: GenKillAnalysis<'tcx>;
fn visit_results_in_block<'mir, 'tcx, F, R>(
state: &mut F,
fn visit_results_in_block<'mir, 'tcx, D, R>(
state: &mut D,
block: BasicBlock,
block_data: &'mir mir::BasicBlockData<'tcx>,
results: &mut R,
vis: &mut impl ResultsVisitor<'mir, 'tcx, R, FlowState = F>,
vis: &mut impl ResultsVisitor<'mir, 'tcx, R, Domain = D>,
) where
R: ResultsVisitable<'tcx, FlowState = F>;
R: ResultsVisitable<'tcx, Domain = D>;
fn join_state_into_successors_of<'tcx, A>(
analysis: &mut A,
@ -186,14 +186,14 @@ impl Direction for Backward {
analysis.apply_statement_effect(state, statement, location);
}
fn visit_results_in_block<'mir, 'tcx, F, R>(
state: &mut F,
fn visit_results_in_block<'mir, 'tcx, D, R>(
state: &mut D,
block: BasicBlock,
block_data: &'mir mir::BasicBlockData<'tcx>,
results: &mut R,
vis: &mut impl ResultsVisitor<'mir, 'tcx, R, FlowState = F>,
vis: &mut impl ResultsVisitor<'mir, 'tcx, R, Domain = D>,
) where
R: ResultsVisitable<'tcx, FlowState = F>,
R: ResultsVisitable<'tcx, Domain = D>,
{
results.reset_to_block_entry(state, block);
@ -444,9 +444,9 @@ impl Direction for Forward {
block: BasicBlock,
block_data: &'mir mir::BasicBlockData<'tcx>,
results: &mut R,
vis: &mut impl ResultsVisitor<'mir, 'tcx, R, FlowState = F>,
vis: &mut impl ResultsVisitor<'mir, 'tcx, R, Domain = F>,
) where
R: ResultsVisitable<'tcx, FlowState = F>,
R: ResultsVisitable<'tcx, Domain = F>,
{
results.reset_to_block_entry(state, block);

View File

@ -57,7 +57,7 @@ where
&mut self,
body: &'mir mir::Body<'tcx>,
blocks: impl IntoIterator<Item = BasicBlock>,
vis: &mut impl ResultsVisitor<'mir, 'tcx, Self, FlowState = A::Domain>,
vis: &mut impl ResultsVisitor<'mir, 'tcx, Self, Domain = A::Domain>,
) {
visit_results(body, blocks, self, vis)
}
@ -65,7 +65,7 @@ where
pub fn visit_reachable_with<'mir>(
&mut self,
body: &'mir mir::Body<'tcx>,
vis: &mut impl ResultsVisitor<'mir, 'tcx, Self, FlowState = A::Domain>,
vis: &mut impl ResultsVisitor<'mir, 'tcx, Self, Domain = A::Domain>,
) {
let blocks = mir::traversal::reachable(body);
visit_results(body, blocks.map(|(bb, _)| bb), self, vis)

View File

@ -544,15 +544,15 @@ where
A: Analysis<'tcx>,
A::Domain: DebugWithContext<A>,
{
type FlowState = A::Domain;
type Domain = A::Domain;
fn visit_block_start(&mut self, state: &Self::FlowState) {
fn visit_block_start(&mut self, state: &Self::Domain) {
if A::Direction::IS_FORWARD {
self.prev_state.clone_from(state);
}
}
fn visit_block_end(&mut self, state: &Self::FlowState) {
fn visit_block_end(&mut self, state: &Self::Domain) {
if A::Direction::IS_BACKWARD {
self.prev_state.clone_from(state);
}
@ -561,7 +561,7 @@ where
fn visit_statement_before_primary_effect(
&mut self,
results: &mut Results<'tcx, A>,
state: &Self::FlowState,
state: &Self::Domain,
_statement: &mir::Statement<'tcx>,
_location: Location,
) {
@ -574,7 +574,7 @@ where
fn visit_statement_after_primary_effect(
&mut self,
results: &mut Results<'tcx, A>,
state: &Self::FlowState,
state: &Self::Domain,
_statement: &mir::Statement<'tcx>,
_location: Location,
) {
@ -585,7 +585,7 @@ where
fn visit_terminator_before_primary_effect(
&mut self,
results: &mut Results<'tcx, A>,
state: &Self::FlowState,
state: &Self::Domain,
_terminator: &mir::Terminator<'tcx>,
_location: Location,
) {
@ -598,7 +598,7 @@ where
fn visit_terminator_after_primary_effect(
&mut self,
results: &mut Results<'tcx, A>,
state: &Self::FlowState,
state: &Self::Domain,
_terminator: &mir::Terminator<'tcx>,
_location: Location,
) {

View File

@ -4,15 +4,15 @@ use super::{Analysis, Direction, Results};
/// Calls the corresponding method in `ResultsVisitor` for every location in a `mir::Body` with the
/// dataflow state at that location.
pub fn visit_results<'mir, 'tcx, F, R>(
pub fn visit_results<'mir, 'tcx, D, R>(
body: &'mir mir::Body<'tcx>,
blocks: impl IntoIterator<Item = BasicBlock>,
results: &mut R,
vis: &mut impl ResultsVisitor<'mir, 'tcx, R, FlowState = F>,
vis: &mut impl ResultsVisitor<'mir, 'tcx, R, Domain = D>,
) where
R: ResultsVisitable<'tcx, FlowState = F>,
R: ResultsVisitable<'tcx, Domain = D>,
{
let mut state = results.new_flow_state(body);
let mut state = results.bottom_value(body);
#[cfg(debug_assertions)]
let reachable_blocks = mir::traversal::reachable_as_bitset(body);
@ -29,16 +29,16 @@ pub fn visit_results<'mir, 'tcx, F, R>(
/// A visitor over the results of an `Analysis`. The type parameter `R` is the results type being
/// visited.
pub trait ResultsVisitor<'mir, 'tcx, R> {
type FlowState;
type Domain;
fn visit_block_start(&mut self, _state: &Self::FlowState) {}
fn visit_block_start(&mut self, _state: &Self::Domain) {}
/// Called with the `before_statement_effect` of the given statement applied to `state` but not
/// its `statement_effect`.
fn visit_statement_before_primary_effect(
&mut self,
_results: &mut R,
_state: &Self::FlowState,
_state: &Self::Domain,
_statement: &'mir mir::Statement<'tcx>,
_location: Location,
) {
@ -49,7 +49,7 @@ pub trait ResultsVisitor<'mir, 'tcx, R> {
fn visit_statement_after_primary_effect(
&mut self,
_results: &mut R,
_state: &Self::FlowState,
_state: &Self::Domain,
_statement: &'mir mir::Statement<'tcx>,
_location: Location,
) {
@ -60,7 +60,7 @@ pub trait ResultsVisitor<'mir, 'tcx, R> {
fn visit_terminator_before_primary_effect(
&mut self,
_results: &mut R,
_state: &Self::FlowState,
_state: &Self::Domain,
_terminator: &'mir mir::Terminator<'tcx>,
_location: Location,
) {
@ -73,13 +73,13 @@ pub trait ResultsVisitor<'mir, 'tcx, R> {
fn visit_terminator_after_primary_effect(
&mut self,
_results: &mut R,
_state: &Self::FlowState,
_state: &Self::Domain,
_terminator: &'mir mir::Terminator<'tcx>,
_location: Location,
) {
}
fn visit_block_end(&mut self, _state: &Self::FlowState) {}
fn visit_block_end(&mut self, _state: &Self::Domain) {}
}
/// Things that can be visited by a `ResultsVisitor`.
@ -88,40 +88,40 @@ pub trait ResultsVisitor<'mir, 'tcx, R> {
/// simultaneously.
pub trait ResultsVisitable<'tcx> {
type Direction: Direction;
type FlowState;
type Domain;
/// Creates an empty `FlowState` to hold the transient state for these dataflow results.
/// Creates an empty `Domain` to hold the transient state for these dataflow results.
///
/// The value of the newly created `FlowState` will be overwritten by `reset_to_block_entry`
/// The value of the newly created `Domain` will be overwritten by `reset_to_block_entry`
/// before it can be observed by a `ResultsVisitor`.
fn new_flow_state(&self, body: &mir::Body<'tcx>) -> Self::FlowState;
fn bottom_value(&self, body: &mir::Body<'tcx>) -> Self::Domain;
fn reset_to_block_entry(&self, state: &mut Self::FlowState, block: BasicBlock);
fn reset_to_block_entry(&self, state: &mut Self::Domain, block: BasicBlock);
fn reconstruct_before_statement_effect(
&mut self,
state: &mut Self::FlowState,
state: &mut Self::Domain,
statement: &mir::Statement<'tcx>,
location: Location,
);
fn reconstruct_statement_effect(
&mut self,
state: &mut Self::FlowState,
state: &mut Self::Domain,
statement: &mir::Statement<'tcx>,
location: Location,
);
fn reconstruct_before_terminator_effect(
&mut self,
state: &mut Self::FlowState,
state: &mut Self::Domain,
terminator: &mir::Terminator<'tcx>,
location: Location,
);
fn reconstruct_terminator_effect(
&mut self,
state: &mut Self::FlowState,
state: &mut Self::Domain,
terminator: &mir::Terminator<'tcx>,
location: Location,
);
@ -131,21 +131,20 @@ impl<'tcx, A> ResultsVisitable<'tcx> for Results<'tcx, A>
where
A: Analysis<'tcx>,
{
type FlowState = A::Domain;
type Domain = A::Domain;
type Direction = A::Direction;
fn new_flow_state(&self, body: &mir::Body<'tcx>) -> Self::FlowState {
fn bottom_value(&self, body: &mir::Body<'tcx>) -> Self::Domain {
self.analysis.bottom_value(body)
}
fn reset_to_block_entry(&self, state: &mut Self::FlowState, block: BasicBlock) {
fn reset_to_block_entry(&self, state: &mut Self::Domain, block: BasicBlock) {
state.clone_from(self.entry_set_for_block(block));
}
fn reconstruct_before_statement_effect(
&mut self,
state: &mut Self::FlowState,
state: &mut Self::Domain,
stmt: &mir::Statement<'tcx>,
loc: Location,
) {
@ -154,7 +153,7 @@ where
fn reconstruct_statement_effect(
&mut self,
state: &mut Self::FlowState,
state: &mut Self::Domain,
stmt: &mir::Statement<'tcx>,
loc: Location,
) {
@ -163,7 +162,7 @@ where
fn reconstruct_before_terminator_effect(
&mut self,
state: &mut Self::FlowState,
state: &mut Self::Domain,
term: &mir::Terminator<'tcx>,
loc: Location,
) {
@ -172,7 +171,7 @@ where
fn reconstruct_terminator_effect(
&mut self,
state: &mut Self::FlowState,
state: &mut Self::Domain,
term: &mir::Terminator<'tcx>,
loc: Location,
) {

View File

@ -102,7 +102,7 @@ pub fn save_as_intervals<'tcx, N, R>(
) -> SparseIntervalMatrix<N, PointIndex>
where
N: Idx,
R: ResultsVisitable<'tcx, FlowState = BitSet<N>>,
R: ResultsVisitable<'tcx, Domain = BitSet<N>>,
{
let values = SparseIntervalMatrix::new(elements.num_points());
let mut visitor = Visitor { elements, values };
@ -124,12 +124,12 @@ impl<'mir, 'tcx, R, N> ResultsVisitor<'mir, 'tcx, R> for Visitor<'_, N>
where
N: Idx,
{
type FlowState = BitSet<N>;
type Domain = BitSet<N>;
fn visit_statement_after_primary_effect(
&mut self,
_results: &mut R,
state: &Self::FlowState,
state: &Self::Domain,
_statement: &'mir mir::Statement<'tcx>,
location: Location,
) {
@ -143,7 +143,7 @@ where
fn visit_terminator_after_primary_effect(
&mut self,
_results: &mut R,
state: &Self::FlowState,
state: &Self::Domain,
_terminator: &'mir mir::Terminator<'tcx>,
location: Location,
) {

View File

@ -229,7 +229,7 @@ trait RustcPeekAt<'tcx>: Analysis<'tcx> {
&self,
tcx: TyCtxt<'tcx>,
place: mir::Place<'tcx>,
flow_state: &Self::Domain,
state: &Self::Domain,
call: PeekCall,
);
}
@ -243,12 +243,12 @@ where
&self,
tcx: TyCtxt<'tcx>,
place: mir::Place<'tcx>,
flow_state: &Self::Domain,
state: &Self::Domain,
call: PeekCall,
) {
match self.move_data().rev_lookup.find(place.as_ref()) {
LookupResult::Exact(peek_mpi) => {
let bit_state = flow_state.contains(peek_mpi);
let bit_state = state.contains(peek_mpi);
debug!("rustc_peek({:?} = &{:?}) bit_state: {}", call.arg, place, bit_state);
if !bit_state {
tcx.dcx().emit_err(PeekBitNotSet { span: call.span });
@ -267,7 +267,7 @@ impl<'tcx> RustcPeekAt<'tcx> for MaybeLiveLocals {
&self,
tcx: TyCtxt<'tcx>,
place: mir::Place<'tcx>,
flow_state: &BitSet<Local>,
state: &BitSet<Local>,
call: PeekCall,
) {
info!(?place, "peek_at");
@ -276,7 +276,7 @@ impl<'tcx> RustcPeekAt<'tcx> for MaybeLiveLocals {
return;
};
if !flow_state.contains(local) {
if !state.contains(local) {
tcx.dcx().emit_err(PeekBitNotSet { span: call.span });
}
}

View File

@ -885,12 +885,12 @@ struct StorageConflictVisitor<'a, 'tcx> {
impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
for StorageConflictVisitor<'a, 'tcx>
{
type FlowState = BitSet<Local>;
type Domain = BitSet<Local>;
fn visit_statement_before_primary_effect(
&mut self,
_results: &mut R,
state: &Self::FlowState,
state: &Self::Domain,
_statement: &'a Statement<'tcx>,
loc: Location,
) {
@ -900,7 +900,7 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
fn visit_terminator_before_primary_effect(
&mut self,
_results: &mut R,
state: &Self::FlowState,
state: &Self::Domain,
_terminator: &'a Terminator<'tcx>,
loc: Location,
) {
@ -909,13 +909,13 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
}
impl StorageConflictVisitor<'_, '_> {
fn apply_state(&mut self, flow_state: &BitSet<Local>, loc: Location) {
fn apply_state(&mut self, state: &BitSet<Local>, loc: Location) {
// Ignore unreachable blocks.
if let TerminatorKind::Unreachable = self.body.basic_blocks[loc.block].terminator().kind {
return;
}
self.eligible_storage_live.clone_from(flow_state);
self.eligible_storage_live.clone_from(state);
self.eligible_storage_live.intersect(&**self.saved_locals);
for local in self.eligible_storage_live.iter() {

View File

@ -723,13 +723,13 @@ impl<'mir, 'tcx>
ResultsVisitor<'mir, 'tcx, Results<'tcx, ValueAnalysisWrapper<ConstAnalysis<'_, 'tcx>>>>
for Collector<'tcx, '_>
{
type FlowState = State<FlatSet<Scalar>>;
type Domain = State<FlatSet<Scalar>>;
#[instrument(level = "trace", skip(self, results, statement))]
fn visit_statement_before_primary_effect(
&mut self,
results: &mut Results<'tcx, ValueAnalysisWrapper<ConstAnalysis<'_, 'tcx>>>,
state: &Self::FlowState,
state: &Self::Domain,
statement: &'mir Statement<'tcx>,
location: Location,
) {
@ -751,7 +751,7 @@ impl<'mir, 'tcx>
fn visit_statement_after_primary_effect(
&mut self,
results: &mut Results<'tcx, ValueAnalysisWrapper<ConstAnalysis<'_, 'tcx>>>,
state: &Self::FlowState,
state: &Self::Domain,
statement: &'mir Statement<'tcx>,
location: Location,
) {
@ -776,7 +776,7 @@ impl<'mir, 'tcx>
fn visit_terminator_before_primary_effect(
&mut self,
results: &mut Results<'tcx, ValueAnalysisWrapper<ConstAnalysis<'_, 'tcx>>>,
state: &Self::FlowState,
state: &Self::Domain,
terminator: &'mir Terminator<'tcx>,
location: Location,
) {