Skip to content

Commit

Permalink
Move the dataflow framework to its own crate.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Sep 7, 2021
1 parent 81a600b commit fd9c04f
Show file tree
Hide file tree
Showing 74 changed files with 259 additions and 211 deletions.
31 changes: 26 additions & 5 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3614,6 +3614,7 @@ dependencies = [
"rustc_lexer",
"rustc_middle",
"rustc_mir",
"rustc_mir_dataflow",
"rustc_serialize",
"rustc_session",
"rustc_span",
Expand Down Expand Up @@ -4047,6 +4048,8 @@ version = "0.0.0"
dependencies = [
"bitflags",
"chalk-ir",
"either",
"gsgdt",
"polonius-engine",
"rustc-rayon-core",
"rustc_apfloat",
Expand All @@ -4056,6 +4059,7 @@ dependencies = [
"rustc_data_structures",
"rustc_errors",
"rustc_feature",
"rustc_graphviz",
"rustc_hir",
"rustc_index",
"rustc_macros",
Expand All @@ -4075,25 +4079,21 @@ version = "0.0.0"
dependencies = [
"either",
"gsgdt",
"polonius-engine",
"regex",
"rustc_apfloat",
"rustc_ast",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
"rustc_graphviz",
"rustc_hir",
"rustc_index",
"rustc_infer",
"rustc_macros",
"rustc_middle",
"rustc_serialize",
"rustc_mir_dataflow",
"rustc_session",
"rustc_span",
"rustc_target",
"rustc_trait_selection",
"smallvec",
"tracing",
]

Expand All @@ -4120,6 +4120,26 @@ dependencies = [
"tracing",
]

[[package]]
name = "rustc_mir_dataflow"
version = "0.0.0"
dependencies = [
"polonius-engine",
"regex",
"rustc_ast",
"rustc_data_structures",
"rustc_graphviz",
"rustc_hir",
"rustc_index",
"rustc_middle",
"rustc_serialize",
"rustc_session",
"rustc_span",
"rustc_target",
"smallvec",
"tracing",
]

[[package]]
name = "rustc_mir_transform"
version = "0.0.0"
Expand All @@ -4134,6 +4154,7 @@ dependencies = [
"rustc_index",
"rustc_middle",
"rustc_mir",
"rustc_mir_dataflow",
"rustc_serialize",
"rustc_session",
"rustc_span",
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_borrowck/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ rustc_infer = { path = "../rustc_infer" }
rustc_lexer = { path = "../rustc_lexer" }
rustc_middle = { path = "../rustc_middle" }
rustc_mir = { path = "../rustc_mir" }
rustc_mir_dataflow = { path = "../rustc_mir_dataflow" }
rustc_serialize = { path = "../rustc_serialize" }
rustc_session = { path = "../rustc_session" }
rustc_target = { path = "../rustc_target" }
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/borrow_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_middle::mir::traversal;
use rustc_middle::mir::visit::{MutatingUseContext, NonUseContext, PlaceContext, Visitor};
use rustc_middle::mir::{self, Body, Local, Location};
use rustc_middle::ty::{RegionVid, TyCtxt};
use rustc_mir::dataflow::move_paths::MoveData;
use rustc_mir_dataflow::move_paths::MoveData;
use std::fmt;
use std::ops::Index;

Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_borrowck/src/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use rustc_index::bit_set::BitSet;
use rustc_middle::mir::{self, BasicBlock, Body, Location, Place};
use rustc_middle::ty::RegionVid;
use rustc_middle::ty::TyCtxt;
use rustc_mir::dataflow::impls::{EverInitializedPlaces, MaybeUninitializedPlaces};
use rustc_mir::dataflow::ResultsVisitable;
use rustc_mir::dataflow::{self, fmt::DebugWithContext, GenKill};
use rustc_mir::dataflow::{Analysis, Direction, Results};
use rustc_mir_dataflow::impls::{EverInitializedPlaces, MaybeUninitializedPlaces};
use rustc_mir_dataflow::ResultsVisitable;
use rustc_mir_dataflow::{self, fmt::DebugWithContext, GenKill};
use rustc_mir_dataflow::{Analysis, Direction, Results};
use std::fmt;
use std::iter;

Expand Down Expand Up @@ -323,7 +323,7 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
}
}

impl<'tcx> dataflow::AnalysisDomain<'tcx> for Borrows<'_, 'tcx> {
impl<'tcx> rustc_mir_dataflow::AnalysisDomain<'tcx> for Borrows<'_, 'tcx> {
type Domain = BitSet<BorrowIndex>;

const NAME: &'static str = "borrows";
Expand All @@ -339,7 +339,7 @@ impl<'tcx> dataflow::AnalysisDomain<'tcx> for Borrows<'_, 'tcx> {
}
}

impl<'tcx> dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
type Idx = BorrowIndex;

fn before_statement_effect(
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ use rustc_middle::mir::{
ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, VarBindingForm,
};
use rustc_middle::ty::{self, suggest_constraining_type_param, Ty};
use rustc_mir_dataflow::drop_flag_effects;
use rustc_mir_dataflow::move_paths::{MoveOutIndex, MovePathIndex};
use rustc_span::source_map::DesugaringKind;
use rustc_span::symbol::sym;
use rustc_span::{BytePos, MultiSpan, Span, DUMMY_SP};
use rustc_trait_selection::infer::InferCtxtExt;

use crate::borrowck_errors;
use rustc_mir::dataflow::drop_flag_effects;
use rustc_mir::dataflow::move_paths::{MoveOutIndex, MovePathIndex};

use crate::{
borrow_set::BorrowData, diagnostics::Instance, prefixes::IsPrefixOf,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_middle::mir::{
};
use rustc_middle::ty::print::Print;
use rustc_middle::ty::{self, DefIdTree, Instance, Ty, TyCtxt};
use rustc_mir::dataflow::move_paths::{InitLocation, LookupResult};
use rustc_mir_dataflow::move_paths::{InitLocation, LookupResult};
use rustc_span::{
hygiene::{DesugaringKind, ForLoopLoc},
symbol::sym,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/move_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rustc_errors::{Applicability, DiagnosticBuilder};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_middle::mir::*;
use rustc_middle::ty;
use rustc_mir::dataflow::move_paths::{
use rustc_mir_dataflow::move_paths::{
IllegalMoveOrigin, IllegalMoveOriginKind, LookupResult, MoveError, MovePathIndex,
};
use rustc_span::source_map::DesugaringKind;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/facts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use polonius_engine::Atom;
use rustc_index::vec::Idx;
use rustc_middle::mir::Local;
use rustc_middle::ty::{RegionVid, TyCtxt};
use rustc_mir::dataflow::move_paths::MovePathIndex;
use rustc_mir_dataflow::move_paths::MovePathIndex;
use std::error::Error;
use std::fmt::Debug;
use std::fs::{self, File};
Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ use std::iter;
use std::mem;
use std::rc::Rc;

use rustc_mir::dataflow::impls::{
use rustc_mir_dataflow::impls::{
EverInitializedPlaces, MaybeInitializedPlaces, MaybeUninitializedPlaces,
};
use rustc_mir::dataflow::move_paths::{InitIndex, MoveOutIndex, MovePathIndex};
use rustc_mir::dataflow::move_paths::{InitLocation, LookupResult, MoveData, MoveError};
use rustc_mir::dataflow::Analysis;
use rustc_mir::dataflow::MoveDataParamEnv;
use rustc_mir_dataflow::move_paths::{InitIndex, MoveOutIndex, MovePathIndex};
use rustc_mir_dataflow::move_paths::{InitLocation, LookupResult, MoveData, MoveError};
use rustc_mir_dataflow::Analysis;
use rustc_mir_dataflow::MoveDataParamEnv;

use self::diagnostics::{AccessKind, RegionName};
use self::location::LocationTable;
Expand Down Expand Up @@ -373,7 +373,7 @@ fn do_mir_borrowck<'a, 'tcx>(

mbcx.report_move_errors(move_errors);

rustc_mir::dataflow::visit_results(
rustc_mir_dataflow::visit_results(
&body,
traversal::reverse_postorder(&body).map(|(bb, _)| bb),
&results,
Expand Down Expand Up @@ -615,7 +615,7 @@ struct MirBorrowckCtxt<'cx, 'tcx> {
// 2. loans made in overlapping scopes do not conflict
// 3. assignments do not affect things loaned out as immutable
// 4. moves do not affect things loaned out in any way
impl<'cx, 'tcx> rustc_mir::dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx> {
impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx> {
type FlowState = Flows<'cx, 'tcx>;

fn visit_statement_before_primary_effect(
Expand Down
20 changes: 9 additions & 11 deletions compiler/rustc_borrowck/src/nll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use rustc_data_structures::vec_map::VecMap;
use rustc_errors::Diagnostic;
use rustc_index::vec::IndexVec;
use rustc_infer::infer::InferCtxt;
use rustc_middle::mir::{create_dump_file, dump_enabled, dump_mir, PassWhere};
use rustc_middle::mir::{
BasicBlock, Body, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, Location,
Promoted,
Expand All @@ -17,14 +18,11 @@ use std::path::PathBuf;
use std::rc::Rc;
use std::str::FromStr;

use self::mir_util::PassWhere;
use polonius_engine::{Algorithm, Output};

use rustc_mir::dataflow::impls::MaybeInitializedPlaces;
use rustc_mir::dataflow::move_paths::{InitKind, InitLocation, MoveData};
use rustc_mir::dataflow::ResultsCursor;
use rustc_mir::util as mir_util;
use rustc_mir::util::pretty;
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
use rustc_mir_dataflow::move_paths::{InitKind, InitLocation, MoveData};
use rustc_mir_dataflow::ResultsCursor;

use crate::{
borrow_set::BorrowSet,
Expand Down Expand Up @@ -72,7 +70,7 @@ pub(crate) fn replace_regions_in_mir<'cx, 'tcx>(
// Replace all remaining regions with fresh inference variables.
renumber::renumber_mir(infcx, body, promoted);

mir_util::dump_mir(infcx.tcx, None, "renumber", &0, body, |_, _| Ok(()));
dump_mir(infcx.tcx, None, "renumber", &0, body, |_, _| Ok(()));

universal_regions
}
Expand Down Expand Up @@ -322,11 +320,11 @@ pub(super) fn dump_mir_results<'a, 'tcx>(
regioncx: &RegionInferenceContext<'tcx>,
closure_region_requirements: &Option<ClosureRegionRequirements<'_>>,
) {
if !mir_util::dump_enabled(infcx.tcx, "nll", body.source.def_id()) {
if !dump_enabled(infcx.tcx, "nll", body.source.def_id()) {
return;
}

mir_util::dump_mir(infcx.tcx, None, "nll", &0, body, |pass_where, out| {
dump_mir(infcx.tcx, None, "nll", &0, body, |pass_where, out| {
match pass_where {
// Before the CFG, dump out the values for each region variable.
PassWhere::BeforeCFG => {
Expand Down Expand Up @@ -354,14 +352,14 @@ pub(super) fn dump_mir_results<'a, 'tcx>(
// Also dump the inference graph constraints as a graphviz file.
let _: io::Result<()> = try {
let mut file =
pretty::create_dump_file(infcx.tcx, "regioncx.all.dot", None, "nll", &0, body.source)?;
create_dump_file(infcx.tcx, "regioncx.all.dot", None, "nll", &0, body.source)?;
regioncx.dump_graphviz_raw_constraints(&mut file)?;
};

// Also dump the inference graph constraints as a graphviz file.
let _: io::Result<()> = try {
let mut file =
pretty::create_dump_file(infcx.tcx, "regioncx.scc.dot", None, "nll", &0, body.source)?;
create_dump_file(infcx.tcx, "regioncx.scc.dot", None, "nll", &0, body.source)?;
regioncx.dump_graphviz_scc_constraints(&mut file)?;
};
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_borrowck/src/type_check/liveness/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use rustc_middle::mir::{Body, Local};
use rustc_middle::ty::{RegionVid, TyCtxt};
use std::rc::Rc;

use rustc_mir::dataflow::impls::MaybeInitializedPlaces;
use rustc_mir::dataflow::move_paths::MoveData;
use rustc_mir::dataflow::ResultsCursor;
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
use rustc_mir_dataflow::move_paths::MoveData;
use rustc_mir_dataflow::ResultsCursor;

use crate::{
constraints::OutlivesConstraintSet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::location::{LocationIndex, LocationTable};
use rustc_middle::mir::visit::{MutatingUseContext, PlaceContext, Visitor};
use rustc_middle::mir::{Body, Local, Location, Place};
use rustc_middle::ty::subst::GenericArg;
use rustc_mir::dataflow::move_paths::{LookupResult, MoveData, MovePathIndex};
use rustc_mir_dataflow::move_paths::{LookupResult, MoveData, MovePathIndex};

use super::TypeChecker;

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_borrowck/src/type_check/liveness/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use rustc_trait_selection::traits::query::type_op::outlives::DropckOutlives;
use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput};
use std::rc::Rc;

use rustc_mir::dataflow::impls::MaybeInitializedPlaces;
use rustc_mir::dataflow::move_paths::{HasMoveData, MoveData, MovePathIndex};
use rustc_mir::dataflow::ResultsCursor;
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
use rustc_mir_dataflow::move_paths::{HasMoveData, MoveData, MovePathIndex};
use rustc_mir_dataflow::ResultsCursor;

use crate::{
region_infer::values::{self, PointIndex, RegionValueElements},
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ use rustc_trait_selection::traits::query::type_op::custom::CustomTypeOp;
use rustc_trait_selection::traits::query::Fallible;
use rustc_trait_selection::traits::{self, ObligationCause, PredicateObligations};

use rustc_mir::dataflow::impls::MaybeInitializedPlaces;
use rustc_mir::dataflow::move_paths::MoveData;
use rustc_mir::dataflow::ResultsCursor;
use rustc_mir::transform::{
check_consts::ConstCx, promote_consts::is_const_fn_in_array_repeat_expression,
};
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
use rustc_mir_dataflow::move_paths::MoveData;
use rustc_mir_dataflow::ResultsCursor;

use crate::{
borrow_set::BorrowSet,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub(crate) fn codegen_fn<'tcx>(
let mir = tcx.instance_mir(instance.def);
let _mir_guard = crate::PrintOnPanic(|| {
let mut buf = Vec::new();
rustc_mir::util::write_mir_pretty(tcx, Some(instance.def_id()), &mut buf).unwrap();
rustc_middle::mir::write_mir_pretty(tcx, Some(instance.def_id()), &mut buf).unwrap();
String::from_utf8_lossy(&buf).into_owned()
});

Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_codegen_cranelift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ extern crate rustc_incremental;
extern crate rustc_index;
extern crate rustc_interface;
extern crate rustc_metadata;
extern crate rustc_mir;
extern crate rustc_session;
extern crate rustc_span;
extern crate rustc_target;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_driver/src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use rustc_errors::ErrorReported;
use rustc_hir as hir;
use rustc_hir_pretty as pprust_hir;
use rustc_middle::hir::map as hir_map;
use rustc_middle::mir::{write_mir_graphviz, write_mir_pretty};
use rustc_middle::ty::{self, TyCtxt};
use rustc_mir::util::{write_mir_graphviz, write_mir_pretty};
use rustc_session::config::{Input, PpAstTreeMode, PpHirMode, PpMode, PpSourceMode};
use rustc_session::Session;
use rustc_span::symbol::Ident;
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_middle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ doctest = false
[dependencies]
rustc_arena = { path = "../rustc_arena" }
bitflags = "1.2.1"
either = "1.5.0"
gsgdt = "0.1.2"
tracing = "0.1"
rustc-rayon-core = "0.3.1"
polonius-engine = "0.13.0"
Expand All @@ -21,6 +23,7 @@ rustc_macros = { path = "../rustc_macros" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_query_system = { path = "../rustc_query_system" }
rustc_errors = { path = "../rustc_errors" }
rustc_graphviz = { path = "../rustc_graphviz" }
rustc_index = { path = "../rustc_index" }
rustc_serialize = { path = "../rustc_serialize" }
rustc_ast = { path = "../rustc_ast" }
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_middle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
#![feature(associated_type_defaults)]
#![feature(iter_zip)]
#![feature(thread_local_const_init)]
#![feature(trusted_step)]
#![feature(try_blocks)]
#![feature(try_reserve)]
#![feature(try_reserve_kind)]
#![feature(nonzero_ops)]
Expand Down
File renamed without changes.
Loading

0 comments on commit fd9c04f

Please sign in to comment.