1
Fork 0

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

View file

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

View file

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

View file

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

View file

@ -544,15 +544,15 @@ where
A: Analysis<'tcx>, A: Analysis<'tcx>,
A::Domain: DebugWithContext<A>, 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 { if A::Direction::IS_FORWARD {
self.prev_state.clone_from(state); 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 { if A::Direction::IS_BACKWARD {
self.prev_state.clone_from(state); self.prev_state.clone_from(state);
} }
@ -561,7 +561,7 @@ where
fn visit_statement_before_primary_effect( fn visit_statement_before_primary_effect(
&mut self, &mut self,
results: &mut Results<'tcx, A>, results: &mut Results<'tcx, A>,
state: &Self::FlowState, state: &Self::Domain,
_statement: &mir::Statement<'tcx>, _statement: &mir::Statement<'tcx>,
_location: Location, _location: Location,
) { ) {
@ -574,7 +574,7 @@ where
fn visit_statement_after_primary_effect( fn visit_statement_after_primary_effect(
&mut self, &mut self,
results: &mut Results<'tcx, A>, results: &mut Results<'tcx, A>,
state: &Self::FlowState, state: &Self::Domain,
_statement: &mir::Statement<'tcx>, _statement: &mir::Statement<'tcx>,
_location: Location, _location: Location,
) { ) {
@ -585,7 +585,7 @@ where
fn visit_terminator_before_primary_effect( fn visit_terminator_before_primary_effect(
&mut self, &mut self,
results: &mut Results<'tcx, A>, results: &mut Results<'tcx, A>,
state: &Self::FlowState, state: &Self::Domain,
_terminator: &mir::Terminator<'tcx>, _terminator: &mir::Terminator<'tcx>,
_location: Location, _location: Location,
) { ) {
@ -598,7 +598,7 @@ where
fn visit_terminator_after_primary_effect( fn visit_terminator_after_primary_effect(
&mut self, &mut self,
results: &mut Results<'tcx, A>, results: &mut Results<'tcx, A>,
state: &Self::FlowState, state: &Self::Domain,
_terminator: &mir::Terminator<'tcx>, _terminator: &mir::Terminator<'tcx>,
_location: Location, _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 /// Calls the corresponding method in `ResultsVisitor` for every location in a `mir::Body` with the
/// dataflow state at that location. /// 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>, body: &'mir mir::Body<'tcx>,
blocks: impl IntoIterator<Item = BasicBlock>, blocks: impl IntoIterator<Item = BasicBlock>,
results: &mut R, results: &mut R,
vis: &mut impl ResultsVisitor<'mir, 'tcx, R, FlowState = F>, vis: &mut impl ResultsVisitor<'mir, 'tcx, R, Domain = D>,
) where ) 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)] #[cfg(debug_assertions)]
let reachable_blocks = mir::traversal::reachable_as_bitset(body); 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 /// A visitor over the results of an `Analysis`. The type parameter `R` is the results type being
/// visited. /// visited.
pub trait ResultsVisitor<'mir, 'tcx, R> { 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 /// Called with the `before_statement_effect` of the given statement applied to `state` but not
/// its `statement_effect`. /// its `statement_effect`.
fn visit_statement_before_primary_effect( fn visit_statement_before_primary_effect(
&mut self, &mut self,
_results: &mut R, _results: &mut R,
_state: &Self::FlowState, _state: &Self::Domain,
_statement: &'mir mir::Statement<'tcx>, _statement: &'mir mir::Statement<'tcx>,
_location: Location, _location: Location,
) { ) {
@ -49,7 +49,7 @@ pub trait ResultsVisitor<'mir, 'tcx, R> {
fn visit_statement_after_primary_effect( fn visit_statement_after_primary_effect(
&mut self, &mut self,
_results: &mut R, _results: &mut R,
_state: &Self::FlowState, _state: &Self::Domain,
_statement: &'mir mir::Statement<'tcx>, _statement: &'mir mir::Statement<'tcx>,
_location: Location, _location: Location,
) { ) {
@ -60,7 +60,7 @@ pub trait ResultsVisitor<'mir, 'tcx, R> {
fn visit_terminator_before_primary_effect( fn visit_terminator_before_primary_effect(
&mut self, &mut self,
_results: &mut R, _results: &mut R,
_state: &Self::FlowState, _state: &Self::Domain,
_terminator: &'mir mir::Terminator<'tcx>, _terminator: &'mir mir::Terminator<'tcx>,
_location: Location, _location: Location,
) { ) {
@ -73,13 +73,13 @@ pub trait ResultsVisitor<'mir, 'tcx, R> {
fn visit_terminator_after_primary_effect( fn visit_terminator_after_primary_effect(
&mut self, &mut self,
_results: &mut R, _results: &mut R,
_state: &Self::FlowState, _state: &Self::Domain,
_terminator: &'mir mir::Terminator<'tcx>, _terminator: &'mir mir::Terminator<'tcx>,
_location: Location, _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`. /// Things that can be visited by a `ResultsVisitor`.
@ -88,40 +88,40 @@ pub trait ResultsVisitor<'mir, 'tcx, R> {
/// simultaneously. /// simultaneously.
pub trait ResultsVisitable<'tcx> { pub trait ResultsVisitable<'tcx> {
type Direction: Direction; 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`. /// 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( fn reconstruct_before_statement_effect(
&mut self, &mut self,
state: &mut Self::FlowState, state: &mut Self::Domain,
statement: &mir::Statement<'tcx>, statement: &mir::Statement<'tcx>,
location: Location, location: Location,
); );
fn reconstruct_statement_effect( fn reconstruct_statement_effect(
&mut self, &mut self,
state: &mut Self::FlowState, state: &mut Self::Domain,
statement: &mir::Statement<'tcx>, statement: &mir::Statement<'tcx>,
location: Location, location: Location,
); );
fn reconstruct_before_terminator_effect( fn reconstruct_before_terminator_effect(
&mut self, &mut self,
state: &mut Self::FlowState, state: &mut Self::Domain,
terminator: &mir::Terminator<'tcx>, terminator: &mir::Terminator<'tcx>,
location: Location, location: Location,
); );
fn reconstruct_terminator_effect( fn reconstruct_terminator_effect(
&mut self, &mut self,
state: &mut Self::FlowState, state: &mut Self::Domain,
terminator: &mir::Terminator<'tcx>, terminator: &mir::Terminator<'tcx>,
location: Location, location: Location,
); );
@ -131,21 +131,20 @@ impl<'tcx, A> ResultsVisitable<'tcx> for Results<'tcx, A>
where where
A: Analysis<'tcx>, A: Analysis<'tcx>,
{ {
type FlowState = A::Domain; type Domain = A::Domain;
type Direction = A::Direction; 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) 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)); state.clone_from(self.entry_set_for_block(block));
} }
fn reconstruct_before_statement_effect( fn reconstruct_before_statement_effect(
&mut self, &mut self,
state: &mut Self::FlowState, state: &mut Self::Domain,
stmt: &mir::Statement<'tcx>, stmt: &mir::Statement<'tcx>,
loc: Location, loc: Location,
) { ) {
@ -154,7 +153,7 @@ where
fn reconstruct_statement_effect( fn reconstruct_statement_effect(
&mut self, &mut self,
state: &mut Self::FlowState, state: &mut Self::Domain,
stmt: &mir::Statement<'tcx>, stmt: &mir::Statement<'tcx>,
loc: Location, loc: Location,
) { ) {
@ -163,7 +162,7 @@ where
fn reconstruct_before_terminator_effect( fn reconstruct_before_terminator_effect(
&mut self, &mut self,
state: &mut Self::FlowState, state: &mut Self::Domain,
term: &mir::Terminator<'tcx>, term: &mir::Terminator<'tcx>,
loc: Location, loc: Location,
) { ) {
@ -172,7 +171,7 @@ where
fn reconstruct_terminator_effect( fn reconstruct_terminator_effect(
&mut self, &mut self,
state: &mut Self::FlowState, state: &mut Self::Domain,
term: &mir::Terminator<'tcx>, term: &mir::Terminator<'tcx>,
loc: Location, loc: Location,
) { ) {

View file

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

View file

@ -229,7 +229,7 @@ trait RustcPeekAt<'tcx>: Analysis<'tcx> {
&self, &self,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
place: mir::Place<'tcx>, place: mir::Place<'tcx>,
flow_state: &Self::Domain, state: &Self::Domain,
call: PeekCall, call: PeekCall,
); );
} }
@ -243,12 +243,12 @@ where
&self, &self,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
place: mir::Place<'tcx>, place: mir::Place<'tcx>,
flow_state: &Self::Domain, state: &Self::Domain,
call: PeekCall, call: PeekCall,
) { ) {
match self.move_data().rev_lookup.find(place.as_ref()) { match self.move_data().rev_lookup.find(place.as_ref()) {
LookupResult::Exact(peek_mpi) => { 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); debug!("rustc_peek({:?} = &{:?}) bit_state: {}", call.arg, place, bit_state);
if !bit_state { if !bit_state {
tcx.dcx().emit_err(PeekBitNotSet { span: call.span }); tcx.dcx().emit_err(PeekBitNotSet { span: call.span });
@ -267,7 +267,7 @@ impl<'tcx> RustcPeekAt<'tcx> for MaybeLiveLocals {
&self, &self,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
place: mir::Place<'tcx>, place: mir::Place<'tcx>,
flow_state: &BitSet<Local>, state: &BitSet<Local>,
call: PeekCall, call: PeekCall,
) { ) {
info!(?place, "peek_at"); info!(?place, "peek_at");
@ -276,7 +276,7 @@ impl<'tcx> RustcPeekAt<'tcx> for MaybeLiveLocals {
return; return;
}; };
if !flow_state.contains(local) { if !state.contains(local) {
tcx.dcx().emit_err(PeekBitNotSet { span: call.span }); 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> impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
for StorageConflictVisitor<'a, 'tcx> for StorageConflictVisitor<'a, 'tcx>
{ {
type FlowState = BitSet<Local>; type Domain = BitSet<Local>;
fn visit_statement_before_primary_effect( fn visit_statement_before_primary_effect(
&mut self, &mut self,
_results: &mut R, _results: &mut R,
state: &Self::FlowState, state: &Self::Domain,
_statement: &'a Statement<'tcx>, _statement: &'a Statement<'tcx>,
loc: Location, loc: Location,
) { ) {
@ -900,7 +900,7 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
fn visit_terminator_before_primary_effect( fn visit_terminator_before_primary_effect(
&mut self, &mut self,
_results: &mut R, _results: &mut R,
state: &Self::FlowState, state: &Self::Domain,
_terminator: &'a Terminator<'tcx>, _terminator: &'a Terminator<'tcx>,
loc: Location, loc: Location,
) { ) {
@ -909,13 +909,13 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
} }
impl StorageConflictVisitor<'_, '_> { 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. // Ignore unreachable blocks.
if let TerminatorKind::Unreachable = self.body.basic_blocks[loc.block].terminator().kind { if let TerminatorKind::Unreachable = self.body.basic_blocks[loc.block].terminator().kind {
return; return;
} }
self.eligible_storage_live.clone_from(flow_state); self.eligible_storage_live.clone_from(state);
self.eligible_storage_live.intersect(&**self.saved_locals); self.eligible_storage_live.intersect(&**self.saved_locals);
for local in self.eligible_storage_live.iter() { 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>>>> ResultsVisitor<'mir, 'tcx, Results<'tcx, ValueAnalysisWrapper<ConstAnalysis<'_, 'tcx>>>>
for Collector<'tcx, '_> for Collector<'tcx, '_>
{ {
type FlowState = State<FlatSet<Scalar>>; type Domain = State<FlatSet<Scalar>>;
#[instrument(level = "trace", skip(self, results, statement))] #[instrument(level = "trace", skip(self, results, statement))]
fn visit_statement_before_primary_effect( fn visit_statement_before_primary_effect(
&mut self, &mut self,
results: &mut Results<'tcx, ValueAnalysisWrapper<ConstAnalysis<'_, 'tcx>>>, results: &mut Results<'tcx, ValueAnalysisWrapper<ConstAnalysis<'_, 'tcx>>>,
state: &Self::FlowState, state: &Self::Domain,
statement: &'mir Statement<'tcx>, statement: &'mir Statement<'tcx>,
location: Location, location: Location,
) { ) {
@ -751,7 +751,7 @@ impl<'mir, 'tcx>
fn visit_statement_after_primary_effect( fn visit_statement_after_primary_effect(
&mut self, &mut self,
results: &mut Results<'tcx, ValueAnalysisWrapper<ConstAnalysis<'_, 'tcx>>>, results: &mut Results<'tcx, ValueAnalysisWrapper<ConstAnalysis<'_, 'tcx>>>,
state: &Self::FlowState, state: &Self::Domain,
statement: &'mir Statement<'tcx>, statement: &'mir Statement<'tcx>,
location: Location, location: Location,
) { ) {
@ -776,7 +776,7 @@ impl<'mir, 'tcx>
fn visit_terminator_before_primary_effect( fn visit_terminator_before_primary_effect(
&mut self, &mut self,
results: &mut Results<'tcx, ValueAnalysisWrapper<ConstAnalysis<'_, 'tcx>>>, results: &mut Results<'tcx, ValueAnalysisWrapper<ConstAnalysis<'_, 'tcx>>>,
state: &Self::FlowState, state: &Self::Domain,
terminator: &'mir Terminator<'tcx>, terminator: &'mir Terminator<'tcx>,
location: Location, location: Location,
) { ) {