Skip to content

Commit

Permalink
Rollup merge of #130297 - nnethercote:dataflow-cleanups, r=cjgillot
Browse files Browse the repository at this point in the history
Dataflow cleanups

r? `@cjgillot`
  • Loading branch information
matthiaskrgr authored Sep 13, 2024
2 parents 778f6fb + bb943f9 commit c5e0f9a
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 167 deletions.
23 changes: 11 additions & 12 deletions compiler/rustc_borrowck/src/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -23,34 +23,33 @@ 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));
}

fn reconstruct_before_statement_effect(
&mut self,
state: &mut Self::FlowState,
state: &mut Self::Domain,
stmt: &mir::Statement<'tcx>,
loc: Location,
) {
Expand All @@ -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,
) {
Expand All @@ -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,
) {
Expand All @@ -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,
) {
Expand Down
Loading

0 comments on commit c5e0f9a

Please sign in to comment.