From fd9c04fe32d3b7700d600ae1be72d5758ffd66ff Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 5 Jan 2021 19:53:07 +0100 Subject: [PATCH] Move the dataflow framework to its own crate. --- Cargo.lock | 31 +++++++++++--- compiler/rustc_borrowck/Cargo.toml | 1 + compiler/rustc_borrowck/src/borrow_set.rs | 2 +- compiler/rustc_borrowck/src/dataflow.rs | 12 +++--- .../src/diagnostics/conflict_errors.rs | 4 +- .../rustc_borrowck/src/diagnostics/mod.rs | 2 +- .../src/diagnostics/move_errors.rs | 2 +- compiler/rustc_borrowck/src/facts.rs | 2 +- compiler/rustc_borrowck/src/lib.rs | 14 +++---- compiler/rustc_borrowck/src/nll.rs | 20 +++++----- .../src/type_check/liveness/mod.rs | 6 +-- .../src/type_check/liveness/polonius.rs | 2 +- .../src/type_check/liveness/trace.rs | 6 +-- compiler/rustc_borrowck/src/type_check/mod.rs | 6 +-- compiler/rustc_codegen_cranelift/src/base.rs | 2 +- compiler/rustc_codegen_cranelift/src/lib.rs | 1 - compiler/rustc_driver/src/pretty.rs | 2 +- compiler/rustc_middle/Cargo.toml | 3 ++ compiler/rustc_middle/src/lib.rs | 2 + .../src/mir}/generic_graph.rs | 0 .../src/mir}/generic_graphviz.rs | 0 .../util => rustc_middle/src/mir}/graphviz.rs | 0 compiler/rustc_middle/src/mir/mod.rs | 28 +++++++++++++ .../util => rustc_middle/src/mir}/patch.rs | 0 .../util => rustc_middle/src/mir}/pretty.rs | 0 .../util => rustc_middle/src/mir}/spanview.rs | 0 compiler/rustc_mir/Cargo.toml | 6 +-- .../rustc_mir/src/const_eval/eval_queries.rs | 2 +- .../rustc_mir/src/interpret/eval_context.rs | 2 +- compiler/rustc_mir/src/interpret/memory.rs | 4 +- compiler/rustc_mir/src/lib.rs | 4 -- .../src/transform/check_consts/check.rs | 8 ++-- .../src/transform/check_consts/resolver.rs | 5 +-- compiler/rustc_mir/src/transform/mod.rs | 23 +---------- compiler/rustc_mir/src/transform/validate.rs | 7 ++-- compiler/rustc_mir/src/util/mod.rs | 12 ------ compiler/rustc_mir_dataflow/Cargo.toml | 24 +++++++++++ .../src}/drop_flag_effects.rs | 2 +- .../src}/elaborate_drops.rs | 2 +- .../src}/framework/cursor.rs | 0 .../src}/framework/direction.rs | 0 .../src}/framework/engine.rs | 2 +- .../src}/framework/fmt.rs | 8 ++-- .../src}/framework/graphviz.rs | 2 +- .../src}/framework/lattice.rs | 0 .../src}/framework/mod.rs | 0 .../src}/framework/tests.rs | 0 .../src}/framework/visitor.rs | 0 .../src}/impls/borrowed_locals.rs | 4 +- .../src}/impls/init_locals.rs | 6 +-- .../src}/impls/liveness.rs | 2 +- .../src}/impls/mod.rs | 21 +++++----- .../src}/impls/storage_liveness.rs | 12 +++--- .../mod.rs => rustc_mir_dataflow/src/lib.rs} | 21 ++++++++++ .../src}/move_paths/abs_domain.rs | 0 .../src}/move_paths/builder.rs | 0 .../src}/move_paths/mod.rs | 0 .../src}/rustc_peek.rs | 14 +++---- .../src}/storage.rs | 0 compiler/rustc_mir_transform/Cargo.toml | 1 + .../src/add_moves_for_packed_drops.rs | 2 +- .../rustc_mir_transform/src/coverage/debug.rs | 10 ++--- .../rustc_mir_transform/src/coverage/mod.rs | 4 +- .../rustc_mir_transform/src/coverage/spans.rs | 4 +- compiler/rustc_mir_transform/src/dest_prop.rs | 10 ++--- compiler/rustc_mir_transform/src/dump_mir.rs | 15 ++----- .../src/early_otherwise_branch.rs | 2 +- .../src/elaborate_drops.rs | 40 ++++++++++--------- compiler/rustc_mir_transform/src/generator.rs | 20 +++++----- compiler/rustc_mir_transform/src/lib.rs | 4 +- .../src/remove_noop_landing_pads.rs | 2 +- compiler/rustc_mir_transform/src/shim.rs | 6 +-- src/tools/clippy/clippy_lints/src/lib.rs | 2 +- .../clippy_lints/src/redundant_clone.rs | 7 +++- 74 files changed, 259 insertions(+), 211 deletions(-) rename compiler/{rustc_mir/src/util => rustc_middle/src/mir}/generic_graph.rs (100%) rename compiler/{rustc_mir/src/util => rustc_middle/src/mir}/generic_graphviz.rs (100%) rename compiler/{rustc_mir/src/util => rustc_middle/src/mir}/graphviz.rs (100%) rename compiler/{rustc_mir/src/util => rustc_middle/src/mir}/patch.rs (100%) rename compiler/{rustc_mir/src/util => rustc_middle/src/mir}/pretty.rs (100%) rename compiler/{rustc_mir/src/util => rustc_middle/src/mir}/spanview.rs (100%) create mode 100644 compiler/rustc_mir_dataflow/Cargo.toml rename compiler/{rustc_mir/src/dataflow => rustc_mir_dataflow/src}/drop_flag_effects.rs (99%) rename compiler/{rustc_mir/src/util => rustc_mir_dataflow/src}/elaborate_drops.rs (99%) rename compiler/{rustc_mir/src/dataflow => rustc_mir_dataflow/src}/framework/cursor.rs (100%) rename compiler/{rustc_mir/src/dataflow => rustc_mir_dataflow/src}/framework/direction.rs (100%) rename compiler/{rustc_mir/src/dataflow => rustc_mir_dataflow/src}/framework/engine.rs (99%) rename compiler/{rustc_mir/src/dataflow => rustc_mir_dataflow/src}/framework/fmt.rs (94%) rename compiler/{rustc_mir/src/dataflow => rustc_mir_dataflow/src}/framework/graphviz.rs (99%) rename compiler/{rustc_mir/src/dataflow => rustc_mir_dataflow/src}/framework/lattice.rs (100%) rename compiler/{rustc_mir/src/dataflow => rustc_mir_dataflow/src}/framework/mod.rs (100%) rename compiler/{rustc_mir/src/dataflow => rustc_mir_dataflow/src}/framework/tests.rs (100%) rename compiler/{rustc_mir/src/dataflow => rustc_mir_dataflow/src}/framework/visitor.rs (100%) rename compiler/{rustc_mir/src/dataflow => rustc_mir_dataflow/src}/impls/borrowed_locals.rs (99%) rename compiler/{rustc_mir/src/dataflow => rustc_mir_dataflow/src}/impls/init_locals.rs (95%) rename compiler/{rustc_mir/src/dataflow => rustc_mir_dataflow/src}/impls/liveness.rs (98%) rename compiler/{rustc_mir/src/dataflow => rustc_mir_dataflow/src}/impls/mod.rs (98%) rename compiler/{rustc_mir/src/dataflow => rustc_mir_dataflow/src}/impls/storage_liveness.rs (96%) rename compiler/{rustc_mir/src/dataflow/mod.rs => rustc_mir_dataflow/src/lib.rs} (74%) rename compiler/{rustc_mir/src/dataflow => rustc_mir_dataflow/src}/move_paths/abs_domain.rs (100%) rename compiler/{rustc_mir/src/dataflow => rustc_mir_dataflow/src}/move_paths/builder.rs (100%) rename compiler/{rustc_mir/src/dataflow => rustc_mir_dataflow/src}/move_paths/mod.rs (100%) rename compiler/{rustc_mir/src/transform => rustc_mir_dataflow/src}/rustc_peek.rs (96%) rename compiler/{rustc_mir/src/util => rustc_mir_dataflow/src}/storage.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 841fc608476..ab9126fb5f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3614,6 +3614,7 @@ dependencies = [ "rustc_lexer", "rustc_middle", "rustc_mir", + "rustc_mir_dataflow", "rustc_serialize", "rustc_session", "rustc_span", @@ -4047,6 +4048,8 @@ version = "0.0.0" dependencies = [ "bitflags", "chalk-ir", + "either", + "gsgdt", "polonius-engine", "rustc-rayon-core", "rustc_apfloat", @@ -4056,6 +4059,7 @@ dependencies = [ "rustc_data_structures", "rustc_errors", "rustc_feature", + "rustc_graphviz", "rustc_hir", "rustc_index", "rustc_macros", @@ -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", ] @@ -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" @@ -4134,6 +4154,7 @@ dependencies = [ "rustc_index", "rustc_middle", "rustc_mir", + "rustc_mir_dataflow", "rustc_serialize", "rustc_session", "rustc_span", diff --git a/compiler/rustc_borrowck/Cargo.toml b/compiler/rustc_borrowck/Cargo.toml index e919c2cbc4f..11b3ec28d45 100644 --- a/compiler/rustc_borrowck/Cargo.toml +++ b/compiler/rustc_borrowck/Cargo.toml @@ -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" } diff --git a/compiler/rustc_borrowck/src/borrow_set.rs b/compiler/rustc_borrowck/src/borrow_set.rs index eb4d815bfc3..ee2ce1d3f74 100644 --- a/compiler/rustc_borrowck/src/borrow_set.rs +++ b/compiler/rustc_borrowck/src/borrow_set.rs @@ -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; diff --git a/compiler/rustc_borrowck/src/dataflow.rs b/compiler/rustc_borrowck/src/dataflow.rs index cb440b2cbb9..1e660ece908 100644 --- a/compiler/rustc_borrowck/src/dataflow.rs +++ b/compiler/rustc_borrowck/src/dataflow.rs @@ -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; @@ -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; const NAME: &'static str = "borrows"; @@ -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( diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 8f6181f410d..758a660525d 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -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, diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs index 980894d6b4d..cc09db0e3dc 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -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, diff --git a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs index dd4886312da..3c114084586 100644 --- a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs @@ -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; diff --git a/compiler/rustc_borrowck/src/facts.rs b/compiler/rustc_borrowck/src/facts.rs index ed3f846e4ad..86b719bdfa0 100644 --- a/compiler/rustc_borrowck/src/facts.rs +++ b/compiler/rustc_borrowck/src/facts.rs @@ -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}; diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 9fe3d79e4ed..c1aa4df9924 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -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; @@ -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, @@ -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( diff --git a/compiler/rustc_borrowck/src/nll.rs b/compiler/rustc_borrowck/src/nll.rs index d40990d4676..8b2c0362261 100644 --- a/compiler/rustc_borrowck/src/nll.rs +++ b/compiler/rustc_borrowck/src/nll.rs @@ -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, @@ -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, @@ -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 } @@ -322,11 +320,11 @@ pub(super) fn dump_mir_results<'a, 'tcx>( regioncx: &RegionInferenceContext<'tcx>, closure_region_requirements: &Option>, ) { - 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 => { @@ -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)?; }; } diff --git a/compiler/rustc_borrowck/src/type_check/liveness/mod.rs b/compiler/rustc_borrowck/src/type_check/liveness/mod.rs index 265c14bb286..1e712354d6a 100644 --- a/compiler/rustc_borrowck/src/type_check/liveness/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/mod.rs @@ -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, diff --git a/compiler/rustc_borrowck/src/type_check/liveness/polonius.rs b/compiler/rustc_borrowck/src/type_check/liveness/polonius.rs index 7c087d38eb7..79ab8b713f9 100644 --- a/compiler/rustc_borrowck/src/type_check/liveness/polonius.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/polonius.rs @@ -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; diff --git a/compiler/rustc_borrowck/src/type_check/liveness/trace.rs b/compiler/rustc_borrowck/src/type_check/liveness/trace.rs index c7d776bfde0..1671c7c627e 100644 --- a/compiler/rustc_borrowck/src/type_check/liveness/trace.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/trace.rs @@ -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}, diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 63075d066a6..19224ca43dd 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -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, diff --git a/compiler/rustc_codegen_cranelift/src/base.rs b/compiler/rustc_codegen_cranelift/src/base.rs index e99a227a3a6..46a7485e4ef 100644 --- a/compiler/rustc_codegen_cranelift/src/base.rs +++ b/compiler/rustc_codegen_cranelift/src/base.rs @@ -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() }); diff --git a/compiler/rustc_codegen_cranelift/src/lib.rs b/compiler/rustc_codegen_cranelift/src/lib.rs index 2e5e8f683cd..87193e3ef53 100644 --- a/compiler/rustc_codegen_cranelift/src/lib.rs +++ b/compiler/rustc_codegen_cranelift/src/lib.rs @@ -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; diff --git a/compiler/rustc_driver/src/pretty.rs b/compiler/rustc_driver/src/pretty.rs index 579ba43b6d8..a25cc000443 100644 --- a/compiler/rustc_driver/src/pretty.rs +++ b/compiler/rustc_driver/src/pretty.rs @@ -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; diff --git a/compiler/rustc_middle/Cargo.toml b/compiler/rustc_middle/Cargo.toml index 2403ce2d24f..68b83fccc85 100644 --- a/compiler/rustc_middle/Cargo.toml +++ b/compiler/rustc_middle/Cargo.toml @@ -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" @@ -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" } diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index 6868be50f1d..c7c26cf5990 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -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)] diff --git a/compiler/rustc_mir/src/util/generic_graph.rs b/compiler/rustc_middle/src/mir/generic_graph.rs similarity index 100% rename from compiler/rustc_mir/src/util/generic_graph.rs rename to compiler/rustc_middle/src/mir/generic_graph.rs diff --git a/compiler/rustc_mir/src/util/generic_graphviz.rs b/compiler/rustc_middle/src/mir/generic_graphviz.rs similarity index 100% rename from compiler/rustc_mir/src/util/generic_graphviz.rs rename to compiler/rustc_middle/src/mir/generic_graphviz.rs diff --git a/compiler/rustc_mir/src/util/graphviz.rs b/compiler/rustc_middle/src/mir/graphviz.rs similarity index 100% rename from compiler/rustc_mir/src/util/graphviz.rs rename to compiler/rustc_middle/src/mir/graphviz.rs diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 83f6e79d5fc..ef2154b31f4 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -42,11 +42,17 @@ pub use self::query::*; pub mod abstract_const; pub mod coverage; +mod generic_graph; +pub mod generic_graphviz; mod graph_cyclic_cache; +pub mod graphviz; pub mod interpret; pub mod mono; +pub mod patch; mod predecessors; +pub mod pretty; mod query; +pub mod spanview; pub mod tcx; pub mod terminator; pub use terminator::*; @@ -54,6 +60,12 @@ pub mod traversal; mod type_foldable; pub mod visit; +pub use self::generic_graph::graphviz_safe_def_name; +pub use self::graphviz::write_mir_graphviz; +pub use self::pretty::{ + create_dump_file, display_allocation, dump_enabled, dump_mir, write_mir_pretty, PassWhere, +}; + /// Types for locals pub type LocalDecls<'tcx> = IndexVec>; @@ -75,6 +87,22 @@ impl<'tcx> HasLocalDecls<'tcx> for Body<'tcx> { } } +/// A streamlined trait that you can implement to create a pass; the +/// pass will be named after the type, and it will consist of a main +/// loop that goes over each available MIR and applies `run_pass`. +pub trait MirPass<'tcx> { + fn name(&self) -> Cow<'_, str> { + let name = std::any::type_name::(); + if let Some(tail) = name.rfind(':') { + Cow::from(&name[tail + 1..]) + } else { + Cow::from(name) + } + } + + fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>); +} + /// The various "big phases" that MIR goes through. /// /// These phases all describe dialects of MIR. Since all MIR uses the same datastructures, the diff --git a/compiler/rustc_mir/src/util/patch.rs b/compiler/rustc_middle/src/mir/patch.rs similarity index 100% rename from compiler/rustc_mir/src/util/patch.rs rename to compiler/rustc_middle/src/mir/patch.rs diff --git a/compiler/rustc_mir/src/util/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs similarity index 100% rename from compiler/rustc_mir/src/util/pretty.rs rename to compiler/rustc_middle/src/mir/pretty.rs diff --git a/compiler/rustc_mir/src/util/spanview.rs b/compiler/rustc_middle/src/mir/spanview.rs similarity index 100% rename from compiler/rustc_mir/src/util/spanview.rs rename to compiler/rustc_middle/src/mir/spanview.rs diff --git a/compiler/rustc_mir/Cargo.toml b/compiler/rustc_mir/Cargo.toml index 0207d9c012e..b187b716199 100644 --- a/compiler/rustc_mir/Cargo.toml +++ b/compiler/rustc_mir/Cargo.toml @@ -9,22 +9,18 @@ doctest = false [dependencies] either = "1.5.0" gsgdt = "0.1.2" -polonius-engine = "0.13.0" -regex = "1" -smallvec = { version = "1.0", features = ["union", "may_dangle"] } tracing = "0.1" rustc_apfloat = { path = "../rustc_apfloat" } rustc_ast = { path = "../rustc_ast" } rustc_attr = { path = "../rustc_attr" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } -rustc_graphviz = { path = "../rustc_graphviz" } rustc_hir = { path = "../rustc_hir" } rustc_index = { path = "../rustc_index" } rustc_infer = { path = "../rustc_infer" } rustc_macros = { path = "../rustc_macros" } rustc_middle = { path = "../rustc_middle" } -rustc_serialize = { path = "../rustc_serialize" } +rustc_mir_dataflow = { path = "../rustc_mir_dataflow" } rustc_session = { path = "../rustc_session" } rustc_target = { path = "../rustc_target" } rustc_trait_selection = { path = "../rustc_trait_selection" } diff --git a/compiler/rustc_mir/src/const_eval/eval_queries.rs b/compiler/rustc_mir/src/const_eval/eval_queries.rs index 3e8a93e08c2..171fc45ea46 100644 --- a/compiler/rustc_mir/src/const_eval/eval_queries.rs +++ b/compiler/rustc_mir/src/const_eval/eval_queries.rs @@ -5,12 +5,12 @@ use crate::interpret::{ Immediate, InternKind, InterpCx, InterpResult, MPlaceTy, MemoryKind, OpTy, RefTracking, Scalar, ScalarMaybeUninit, StackPopCleanup, }; -use crate::util::pretty::display_allocation; use rustc_errors::ErrorReported; use rustc_hir::def::DefKind; use rustc_middle::mir; use rustc_middle::mir::interpret::ErrorHandled; +use rustc_middle::mir::pretty::display_allocation; use rustc_middle::traits::Reveal; use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::print::with_no_trimmed_paths; diff --git a/compiler/rustc_mir/src/interpret/eval_context.rs b/compiler/rustc_mir/src/interpret/eval_context.rs index 05502d8b21f..0521443533b 100644 --- a/compiler/rustc_mir/src/interpret/eval_context.rs +++ b/compiler/rustc_mir/src/interpret/eval_context.rs @@ -12,6 +12,7 @@ use rustc_middle::ty::layout::{self, LayoutError, LayoutOf, LayoutOfHelpers, TyA use rustc_middle::ty::{ self, query::TyCtxtAt, subst::SubstsRef, ParamEnv, Ty, TyCtxt, TypeFoldable, }; +use rustc_mir_dataflow::storage::AlwaysLiveLocals; use rustc_session::Limit; use rustc_span::{Pos, Span}; use rustc_target::abi::{Align, HasDataLayout, Size, TargetDataLayout}; @@ -22,7 +23,6 @@ use super::{ ScalarMaybeUninit, StackPopJump, }; use crate::transform::validate::equal_up_to_regions; -use crate::util::storage::AlwaysLiveLocals; pub struct InterpCx<'mir, 'tcx, M: Machine<'mir, 'tcx>> { /// Stores the `Machine` instance. diff --git a/compiler/rustc_mir/src/interpret/memory.rs b/compiler/rustc_mir/src/interpret/memory.rs index 4d13274a120..b8b6ff93753 100644 --- a/compiler/rustc_mir/src/interpret/memory.rs +++ b/compiler/rustc_mir/src/interpret/memory.rs @@ -15,6 +15,7 @@ use std::ptr; use rustc_ast::Mutability; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_middle::mir::display_allocation; use rustc_middle::ty::{Instance, ParamEnv, TyCtxt}; use rustc_target::abi::{Align, HasDataLayout, Size, TargetDataLayout}; @@ -23,7 +24,6 @@ use super::{ InterpResult, Machine, MayLeak, Pointer, PointerArithmetic, Provenance, Scalar, ScalarMaybeUninit, }; -use crate::util::pretty; #[derive(Debug, PartialEq, Copy, Clone)] pub enum MemoryKind { @@ -851,7 +851,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> std::fmt::Debug for DumpAllocs<'a, for alloc_id in alloc.relocations().values().map(|tag| tag.get_alloc_id()) { allocs_to_print.push_back(alloc_id); } - write!(fmt, "{}", pretty::display_allocation(tcx, alloc)) + write!(fmt, "{}", display_allocation(tcx, alloc)) } let mut allocs_to_print: VecDeque<_> = self.allocs.iter().copied().collect(); diff --git a/compiler/rustc_mir/src/lib.rs b/compiler/rustc_mir/src/lib.rs index fa1f27daa80..c24c9a9b5ee 100644 --- a/compiler/rustc_mir/src/lib.rs +++ b/compiler/rustc_mir/src/lib.rs @@ -6,7 +6,6 @@ Rust MIR: a lowered representation of Rust. #![feature(assert_matches)] #![cfg_attr(bootstrap, feature(bindings_after_at))] -#![feature(associated_type_defaults)] #![feature(bool_to_option)] #![feature(box_patterns)] #![feature(control_flow_enum)] @@ -19,9 +18,7 @@ Rust MIR: a lowered representation of Rust. #![feature(min_specialization)] #![feature(slice_ptr_get)] #![feature(option_get_or_insert_default)] -#![feature(once_cell)] #![feature(never_type)] -#![feature(stmt_expr_attributes)] #![feature(trait_alias)] #![feature(trusted_len)] #![feature(trusted_step)] @@ -33,7 +30,6 @@ extern crate tracing; extern crate rustc_middle; pub mod const_eval; -pub mod dataflow; pub mod interpret; pub mod transform; pub mod util; diff --git a/compiler/rustc_mir/src/transform/check_consts/check.rs b/compiler/rustc_mir/src/transform/check_consts/check.rs index 0c381276823..d02b4286c17 100644 --- a/compiler/rustc_mir/src/transform/check_consts/check.rs +++ b/compiler/rustc_mir/src/transform/check_consts/check.rs @@ -12,6 +12,8 @@ use rustc_middle::ty::cast::CastTy; use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts}; use rustc_middle::ty::{self, adjustment::PointerCast, Instance, InstanceDef, Ty, TyCtxt}; use rustc_middle::ty::{Binder, TraitPredicate, TraitRef}; +use rustc_mir_dataflow::impls::MaybeMutBorrowedLocals; +use rustc_mir_dataflow::{self, Analysis}; use rustc_span::{sym, Span, Symbol}; use rustc_trait_selection::traits::error_reporting::InferCtxtExt; use rustc_trait_selection::traits::{self, SelectionContext, TraitEngine}; @@ -24,17 +26,15 @@ use super::qualifs::{self, CustomEq, HasMutInterior, NeedsDrop}; use super::resolver::FlowSensitiveAnalysis; use super::{is_lang_panic_fn, ConstCx, Qualif}; use crate::const_eval::is_unstable_const_fn; -use crate::dataflow::impls::MaybeMutBorrowedLocals; -use crate::dataflow::{self, Analysis}; // We are using `MaybeMutBorrowedLocals` as a proxy for whether an item may have been mutated // through a pointer prior to the given point. This is okay even though `MaybeMutBorrowedLocals` // kills locals upon `StorageDead` because a local will never be used after a `StorageDead`. type IndirectlyMutableResults<'mir, 'tcx> = - dataflow::ResultsCursor<'mir, 'tcx, MaybeMutBorrowedLocals<'mir, 'tcx>>; + rustc_mir_dataflow::ResultsCursor<'mir, 'tcx, MaybeMutBorrowedLocals<'mir, 'tcx>>; type QualifResults<'mir, 'tcx, Q> = - dataflow::ResultsCursor<'mir, 'tcx, FlowSensitiveAnalysis<'mir, 'mir, 'tcx, Q>>; + rustc_mir_dataflow::ResultsCursor<'mir, 'tcx, FlowSensitiveAnalysis<'mir, 'mir, 'tcx, Q>>; #[derive(Default)] pub struct Qualifs<'mir, 'tcx> { diff --git a/compiler/rustc_mir/src/transform/check_consts/resolver.rs b/compiler/rustc_mir/src/transform/check_consts/resolver.rs index a00301952b3..8e1b69a1d74 100644 --- a/compiler/rustc_mir/src/transform/check_consts/resolver.rs +++ b/compiler/rustc_mir/src/transform/check_consts/resolver.rs @@ -9,7 +9,6 @@ use rustc_middle::mir::{self, BasicBlock, Local, Location}; use std::marker::PhantomData; use super::{qualifs, ConstCx, Qualif}; -use crate::dataflow; /// A `Visitor` that propagates qualifs between locals. This defines the transfer function of /// `FlowSensitiveAnalysis`. @@ -165,7 +164,7 @@ where } } -impl dataflow::AnalysisDomain<'tcx> for FlowSensitiveAnalysis<'_, '_, 'tcx, Q> +impl rustc_mir_dataflow::AnalysisDomain<'tcx> for FlowSensitiveAnalysis<'_, '_, 'tcx, Q> where Q: Qualif, { @@ -182,7 +181,7 @@ where } } -impl dataflow::Analysis<'tcx> for FlowSensitiveAnalysis<'_, '_, 'tcx, Q> +impl rustc_mir_dataflow::Analysis<'tcx> for FlowSensitiveAnalysis<'_, '_, 'tcx, Q> where Q: Qualif, { diff --git a/compiler/rustc_mir/src/transform/mod.rs b/compiler/rustc_mir/src/transform/mod.rs index abf43dd1d23..38c28f34934 100644 --- a/compiler/rustc_mir/src/transform/mod.rs +++ b/compiler/rustc_mir/src/transform/mod.rs @@ -1,26 +1,5 @@ -use rustc_middle::mir::Body; -use rustc_middle::ty::TyCtxt; -use std::borrow::Cow; - pub mod check_consts; pub mod promote_consts; -pub mod rustc_peek; pub mod validate; -/// Generates a default name for the pass based on the name of the -/// type `T`. -pub fn default_name() -> Cow<'static, str> { - let name = std::any::type_name::(); - if let Some(tail) = name.rfind(':') { Cow::from(&name[tail + 1..]) } else { Cow::from(name) } -} - -/// A streamlined trait that you can implement to create a pass; the -/// pass will be named after the type, and it will consist of a main -/// loop that goes over each available MIR and applies `run_pass`. -pub trait MirPass<'tcx> { - fn name(&self) -> Cow<'_, str> { - default_name::() - } - - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>); -} +pub use rustc_middle::mir::MirPass; diff --git a/compiler/rustc_mir/src/transform/validate.rs b/compiler/rustc_mir/src/transform/validate.rs index 835789069bb..40a32a76c94 100644 --- a/compiler/rustc_mir/src/transform/validate.rs +++ b/compiler/rustc_mir/src/transform/validate.rs @@ -1,9 +1,5 @@ //! Validates the MIR to ensure that invariants are upheld. -use crate::dataflow::impls::MaybeStorageLive; -use crate::dataflow::{Analysis, ResultsCursor}; -use crate::util::storage::AlwaysLiveLocals; - use super::MirPass; use rustc_index::bit_set::BitSet; use rustc_infer::infer::TyCtxtInferExt; @@ -17,6 +13,9 @@ use rustc_middle::mir::{ }; use rustc_middle::ty::fold::BottomUpFolder; use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt, TypeFoldable}; +use rustc_mir_dataflow::impls::MaybeStorageLive; +use rustc_mir_dataflow::storage::AlwaysLiveLocals; +use rustc_mir_dataflow::{Analysis, ResultsCursor}; use rustc_target::abi::Size; #[derive(Copy, Clone, Debug)] diff --git a/compiler/rustc_mir/src/util/mod.rs b/compiler/rustc_mir/src/util/mod.rs index 741c1e6b2c6..4a406f8bfd0 100644 --- a/compiler/rustc_mir/src/util/mod.rs +++ b/compiler/rustc_mir/src/util/mod.rs @@ -1,20 +1,8 @@ pub mod aggregate; -pub mod elaborate_drops; -pub mod patch; -pub mod storage; - mod alignment; pub mod collect_writes; mod find_self_call; -mod generic_graph; -pub mod generic_graphviz; -mod graphviz; -pub mod pretty; -pub mod spanview; pub use self::aggregate::expand_aggregate; pub use self::alignment::is_disaligned; pub use self::find_self_call::find_self_call; -pub use self::generic_graph::graphviz_safe_def_name; -pub use self::graphviz::write_mir_graphviz; -pub use self::pretty::{dump_enabled, dump_mir, write_mir_fn, write_mir_pretty, PassWhere}; diff --git a/compiler/rustc_mir_dataflow/Cargo.toml b/compiler/rustc_mir_dataflow/Cargo.toml new file mode 100644 index 00000000000..adc3882f843 --- /dev/null +++ b/compiler/rustc_mir_dataflow/Cargo.toml @@ -0,0 +1,24 @@ +[package] +authors = ["The Rust Project Developers"] +name = "rustc_mir_dataflow" +version = "0.0.0" +edition = "2018" + +[lib] +doctest = false + +[dependencies] +polonius-engine = "0.13.0" +regex = "1" +smallvec = { version = "1.6.1", features = ["union", "may_dangle"] } +tracing = "0.1" +rustc_ast = { path = "../rustc_ast" } +rustc_data_structures = { path = "../rustc_data_structures" } +rustc_graphviz = { path = "../rustc_graphviz" } +rustc_hir = { path = "../rustc_hir" } +rustc_index = { path = "../rustc_index" } +rustc_middle = { path = "../rustc_middle" } +rustc_serialize = { path = "../rustc_serialize" } +rustc_session = { path = "../rustc_session" } +rustc_target = { path = "../rustc_target" } +rustc_span = { path = "../rustc_span" } diff --git a/compiler/rustc_mir/src/dataflow/drop_flag_effects.rs b/compiler/rustc_mir_dataflow/src/drop_flag_effects.rs similarity index 99% rename from compiler/rustc_mir/src/dataflow/drop_flag_effects.rs rename to compiler/rustc_mir_dataflow/src/drop_flag_effects.rs index fa449a23688..e2269562b3d 100644 --- a/compiler/rustc_mir/src/dataflow/drop_flag_effects.rs +++ b/compiler/rustc_mir_dataflow/src/drop_flag_effects.rs @@ -1,4 +1,4 @@ -use crate::util::elaborate_drops::DropFlagState; +use crate::elaborate_drops::DropFlagState; use rustc_middle::mir::{self, Body, Location}; use rustc_middle::ty::{self, TyCtxt}; use rustc_target::abi::VariantIdx; diff --git a/compiler/rustc_mir/src/util/elaborate_drops.rs b/compiler/rustc_mir_dataflow/src/elaborate_drops.rs similarity index 99% rename from compiler/rustc_mir/src/util/elaborate_drops.rs rename to compiler/rustc_mir_dataflow/src/elaborate_drops.rs index 50756fc15fb..7607ccc3aba 100644 --- a/compiler/rustc_mir/src/util/elaborate_drops.rs +++ b/compiler/rustc_mir_dataflow/src/elaborate_drops.rs @@ -1,7 +1,7 @@ -use crate::util::patch::MirPatch; use rustc_hir as hir; use rustc_hir::lang_items::LangItem; use rustc_index::vec::Idx; +use rustc_middle::mir::patch::MirPatch; use rustc_middle::mir::*; use rustc_middle::traits::Reveal; use rustc_middle::ty::subst::SubstsRef; diff --git a/compiler/rustc_mir/src/dataflow/framework/cursor.rs b/compiler/rustc_mir_dataflow/src/framework/cursor.rs similarity index 100% rename from compiler/rustc_mir/src/dataflow/framework/cursor.rs rename to compiler/rustc_mir_dataflow/src/framework/cursor.rs diff --git a/compiler/rustc_mir/src/dataflow/framework/direction.rs b/compiler/rustc_mir_dataflow/src/framework/direction.rs similarity index 100% rename from compiler/rustc_mir/src/dataflow/framework/direction.rs rename to compiler/rustc_mir_dataflow/src/framework/direction.rs diff --git a/compiler/rustc_mir/src/dataflow/framework/engine.rs b/compiler/rustc_mir_dataflow/src/framework/engine.rs similarity index 99% rename from compiler/rustc_mir/src/dataflow/framework/engine.rs rename to compiler/rustc_mir_dataflow/src/framework/engine.rs index 7ff7c860591..804abc3b42b 100644 --- a/compiler/rustc_mir/src/dataflow/framework/engine.rs +++ b/compiler/rustc_mir_dataflow/src/framework/engine.rs @@ -11,6 +11,7 @@ use rustc_hir::def_id::DefId; use rustc_index::bit_set::BitSet; use rustc_index::vec::{Idx, IndexVec}; use rustc_middle::mir::{self, traversal, BasicBlock}; +use rustc_middle::mir::{create_dump_file, dump_enabled}; use rustc_middle::ty::TyCtxt; use rustc_span::symbol::{sym, Symbol}; @@ -20,7 +21,6 @@ use super::{ visit_results, Analysis, Direction, GenKill, GenKillAnalysis, GenKillSet, JoinSemiLattice, ResultsCursor, ResultsVisitor, }; -use crate::util::pretty::{create_dump_file, dump_enabled}; /// A dataflow analysis that has converged to fixpoint. pub struct Results<'tcx, A> diff --git a/compiler/rustc_mir/src/dataflow/framework/fmt.rs b/compiler/rustc_mir_dataflow/src/framework/fmt.rs similarity index 94% rename from compiler/rustc_mir/src/dataflow/framework/fmt.rs rename to compiler/rustc_mir_dataflow/src/framework/fmt.rs index 35115ca9db7..1d1553bbbd9 100644 --- a/compiler/rustc_mir/src/dataflow/framework/fmt.rs +++ b/compiler/rustc_mir_dataflow/src/framework/fmt.rs @@ -147,18 +147,18 @@ where } impl DebugWithContext for rustc_middle::mir::Local {} -impl DebugWithContext for crate::dataflow::move_paths::InitIndex {} +impl DebugWithContext for crate::move_paths::InitIndex {} -impl<'tcx, C> DebugWithContext for crate::dataflow::move_paths::MovePathIndex +impl<'tcx, C> DebugWithContext for crate::move_paths::MovePathIndex where - C: crate::dataflow::move_paths::HasMoveData<'tcx>, + C: crate::move_paths::HasMoveData<'tcx>, { fn fmt_with(&self, ctxt: &C, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", ctxt.move_data().move_paths[*self]) } } -impl DebugWithContext for crate::dataflow::lattice::Dual +impl DebugWithContext for crate::lattice::Dual where T: DebugWithContext, { diff --git a/compiler/rustc_mir/src/dataflow/framework/graphviz.rs b/compiler/rustc_mir_dataflow/src/framework/graphviz.rs similarity index 99% rename from compiler/rustc_mir/src/dataflow/framework/graphviz.rs rename to compiler/rustc_mir_dataflow/src/framework/graphviz.rs index 4e54257a1cb..a370f8e40f9 100644 --- a/compiler/rustc_mir/src/dataflow/framework/graphviz.rs +++ b/compiler/rustc_mir_dataflow/src/framework/graphviz.rs @@ -6,11 +6,11 @@ use std::{io, ops, str}; use regex::Regex; use rustc_graphviz as dot; +use rustc_middle::mir::graphviz_safe_def_name; use rustc_middle::mir::{self, BasicBlock, Body, Location}; use super::fmt::{DebugDiffWithAdapter, DebugWithAdapter, DebugWithContext}; use super::{Analysis, Direction, Results, ResultsRefCursor, ResultsVisitor}; -use crate::util::graphviz_safe_def_name; #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum OutputStyle { diff --git a/compiler/rustc_mir/src/dataflow/framework/lattice.rs b/compiler/rustc_mir_dataflow/src/framework/lattice.rs similarity index 100% rename from compiler/rustc_mir/src/dataflow/framework/lattice.rs rename to compiler/rustc_mir_dataflow/src/framework/lattice.rs diff --git a/compiler/rustc_mir/src/dataflow/framework/mod.rs b/compiler/rustc_mir_dataflow/src/framework/mod.rs similarity index 100% rename from compiler/rustc_mir/src/dataflow/framework/mod.rs rename to compiler/rustc_mir_dataflow/src/framework/mod.rs diff --git a/compiler/rustc_mir/src/dataflow/framework/tests.rs b/compiler/rustc_mir_dataflow/src/framework/tests.rs similarity index 100% rename from compiler/rustc_mir/src/dataflow/framework/tests.rs rename to compiler/rustc_mir_dataflow/src/framework/tests.rs diff --git a/compiler/rustc_mir/src/dataflow/framework/visitor.rs b/compiler/rustc_mir_dataflow/src/framework/visitor.rs similarity index 100% rename from compiler/rustc_mir/src/dataflow/framework/visitor.rs rename to compiler/rustc_mir_dataflow/src/framework/visitor.rs diff --git a/compiler/rustc_mir/src/dataflow/impls/borrowed_locals.rs b/compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs similarity index 99% rename from compiler/rustc_mir/src/dataflow/impls/borrowed_locals.rs rename to compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs index 65e04ed6831..81d84f80ad4 100644 --- a/compiler/rustc_mir/src/dataflow/impls/borrowed_locals.rs +++ b/compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs @@ -1,6 +1,6 @@ -pub use super::*; +use super::*; -use crate::dataflow::{AnalysisDomain, GenKill, GenKillAnalysis}; +use crate::{AnalysisDomain, GenKill, GenKillAnalysis}; use rustc_middle::mir::visit::Visitor; use rustc_middle::mir::*; use rustc_middle::ty::{ParamEnv, TyCtxt}; diff --git a/compiler/rustc_mir/src/dataflow/impls/init_locals.rs b/compiler/rustc_mir_dataflow/src/impls/init_locals.rs similarity index 95% rename from compiler/rustc_mir/src/dataflow/impls/init_locals.rs rename to compiler/rustc_mir_dataflow/src/impls/init_locals.rs index bb7292cd033..07570e764f5 100644 --- a/compiler/rustc_mir/src/dataflow/impls/init_locals.rs +++ b/compiler/rustc_mir_dataflow/src/impls/init_locals.rs @@ -2,7 +2,7 @@ //! //! A local will be maybe initialized if *any* projections of that local might be initialized. -use crate::dataflow::{self, GenKill}; +use crate::GenKill; use rustc_index::bit_set::BitSet; use rustc_middle::mir::visit::{PlaceContext, Visitor}; @@ -10,7 +10,7 @@ use rustc_middle::mir::{self, BasicBlock, Local, Location}; pub struct MaybeInitializedLocals; -impl dataflow::AnalysisDomain<'tcx> for MaybeInitializedLocals { +impl crate::AnalysisDomain<'tcx> for MaybeInitializedLocals { type Domain = BitSet; const NAME: &'static str = "maybe_init_locals"; @@ -28,7 +28,7 @@ impl dataflow::AnalysisDomain<'tcx> for MaybeInitializedLocals { } } -impl dataflow::GenKillAnalysis<'tcx> for MaybeInitializedLocals { +impl crate::GenKillAnalysis<'tcx> for MaybeInitializedLocals { type Idx = Local; fn statement_effect( diff --git a/compiler/rustc_mir/src/dataflow/impls/liveness.rs b/compiler/rustc_mir_dataflow/src/impls/liveness.rs similarity index 98% rename from compiler/rustc_mir/src/dataflow/impls/liveness.rs rename to compiler/rustc_mir_dataflow/src/impls/liveness.rs index 2d20f0d9547..0039d3188d5 100644 --- a/compiler/rustc_mir/src/dataflow/impls/liveness.rs +++ b/compiler/rustc_mir_dataflow/src/impls/liveness.rs @@ -2,7 +2,7 @@ use rustc_index::bit_set::BitSet; use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::{self, Local, Location}; -use crate::dataflow::{AnalysisDomain, Backward, GenKill, GenKillAnalysis}; +use crate::{AnalysisDomain, Backward, GenKill, GenKillAnalysis}; /// A [live-variable dataflow analysis][liveness]. /// diff --git a/compiler/rustc_mir/src/dataflow/impls/mod.rs b/compiler/rustc_mir_dataflow/src/impls/mod.rs similarity index 98% rename from compiler/rustc_mir/src/dataflow/impls/mod.rs rename to compiler/rustc_mir_dataflow/src/impls/mod.rs index 020a7b188fd..771ad90af28 100644 --- a/compiler/rustc_mir/src/dataflow/impls/mod.rs +++ b/compiler/rustc_mir_dataflow/src/impls/mod.rs @@ -7,18 +7,15 @@ use rustc_index::vec::Idx; use rustc_middle::mir::{self, Body, Location}; use rustc_middle::ty::{self, TyCtxt}; -use super::MoveDataParamEnv; - -use crate::util::elaborate_drops::DropFlagState; - -use super::move_paths::{HasMoveData, InitIndex, InitKind, MoveData, MovePathIndex}; -use super::{lattice, AnalysisDomain, GenKill, GenKillAnalysis}; - -use super::drop_flag_effects_for_function_entry; -use super::drop_flag_effects_for_location; -use super::on_lookup_result_bits; -use crate::dataflow::drop_flag_effects; -use crate::dataflow::framework::SwitchIntEdgeEffects; +use crate::drop_flag_effects; +use crate::drop_flag_effects_for_function_entry; +use crate::drop_flag_effects_for_location; +use crate::elaborate_drops::DropFlagState; +use crate::framework::SwitchIntEdgeEffects; +use crate::move_paths::{HasMoveData, InitIndex, InitKind, MoveData, MovePathIndex}; +use crate::on_lookup_result_bits; +use crate::MoveDataParamEnv; +use crate::{lattice, AnalysisDomain, GenKill, GenKillAnalysis}; mod borrowed_locals; mod init_locals; diff --git a/compiler/rustc_mir/src/dataflow/impls/storage_liveness.rs b/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs similarity index 96% rename from compiler/rustc_mir/src/dataflow/impls/storage_liveness.rs rename to compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs index 792664597fd..b468e50b391 100644 --- a/compiler/rustc_mir/src/dataflow/impls/storage_liveness.rs +++ b/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs @@ -1,7 +1,7 @@ pub use super::*; -use crate::dataflow::{self, GenKill, Results, ResultsRefCursor}; -use crate::util::storage::AlwaysLiveLocals; +use crate::storage::AlwaysLiveLocals; +use crate::{GenKill, Results, ResultsRefCursor}; use rustc_middle::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::*; use std::cell::RefCell; @@ -17,7 +17,7 @@ impl MaybeStorageLive { } } -impl dataflow::AnalysisDomain<'tcx> for MaybeStorageLive { +impl crate::AnalysisDomain<'tcx> for MaybeStorageLive { type Domain = BitSet; const NAME: &'static str = "maybe_storage_live"; @@ -39,7 +39,7 @@ impl dataflow::AnalysisDomain<'tcx> for MaybeStorageLive { } } -impl dataflow::GenKillAnalysis<'tcx> for MaybeStorageLive { +impl crate::GenKillAnalysis<'tcx> for MaybeStorageLive { type Idx = Local; fn statement_effect( @@ -97,7 +97,7 @@ impl<'mir, 'tcx> MaybeRequiresStorage<'mir, 'tcx> { } } -impl<'mir, 'tcx> dataflow::AnalysisDomain<'tcx> for MaybeRequiresStorage<'mir, 'tcx> { +impl<'mir, 'tcx> crate::AnalysisDomain<'tcx> for MaybeRequiresStorage<'mir, 'tcx> { type Domain = BitSet; const NAME: &'static str = "requires_storage"; @@ -116,7 +116,7 @@ impl<'mir, 'tcx> dataflow::AnalysisDomain<'tcx> for MaybeRequiresStorage<'mir, ' } } -impl<'mir, 'tcx> dataflow::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'mir, 'tcx> { +impl<'mir, 'tcx> crate::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'mir, 'tcx> { type Idx = Local; fn before_statement_effect( diff --git a/compiler/rustc_mir/src/dataflow/mod.rs b/compiler/rustc_mir_dataflow/src/lib.rs similarity index 74% rename from compiler/rustc_mir/src/dataflow/mod.rs rename to compiler/rustc_mir_dataflow/src/lib.rs index f388d41d317..282ea8db1bb 100644 --- a/compiler/rustc_mir/src/dataflow/mod.rs +++ b/compiler/rustc_mir_dataflow/src/lib.rs @@ -1,3 +1,21 @@ +#![feature(associated_type_defaults)] +#![feature(bool_to_option)] +#![feature(box_patterns)] +#![feature(box_syntax)] +#![feature(const_panic)] +#![feature(exact_size_is_empty)] +#![feature(in_band_lifetimes)] +#![feature(iter_zip)] +#![feature(min_specialization)] +#![feature(once_cell)] +#![feature(stmt_expr_attributes)] +#![feature(trusted_step)] + +#[macro_use] +extern crate tracing; +#[macro_use] +extern crate rustc_middle; + use rustc_ast::{self as ast, MetaItem}; use rustc_middle::ty; use rustc_session::Session; @@ -17,9 +35,12 @@ pub use self::framework::{ use self::move_paths::MoveData; pub mod drop_flag_effects; +pub mod elaborate_drops; mod framework; pub mod impls; pub mod move_paths; +pub mod rustc_peek; +pub mod storage; pub(crate) mod indexes { pub(crate) use super::move_paths::MovePathIndex; diff --git a/compiler/rustc_mir/src/dataflow/move_paths/abs_domain.rs b/compiler/rustc_mir_dataflow/src/move_paths/abs_domain.rs similarity index 100% rename from compiler/rustc_mir/src/dataflow/move_paths/abs_domain.rs rename to compiler/rustc_mir_dataflow/src/move_paths/abs_domain.rs diff --git a/compiler/rustc_mir/src/dataflow/move_paths/builder.rs b/compiler/rustc_mir_dataflow/src/move_paths/builder.rs similarity index 100% rename from compiler/rustc_mir/src/dataflow/move_paths/builder.rs rename to compiler/rustc_mir_dataflow/src/move_paths/builder.rs diff --git a/compiler/rustc_mir/src/dataflow/move_paths/mod.rs b/compiler/rustc_mir_dataflow/src/move_paths/mod.rs similarity index 100% rename from compiler/rustc_mir/src/dataflow/move_paths/mod.rs rename to compiler/rustc_mir_dataflow/src/move_paths/mod.rs diff --git a/compiler/rustc_mir/src/transform/rustc_peek.rs b/compiler/rustc_mir_dataflow/src/rustc_peek.rs similarity index 96% rename from compiler/rustc_mir/src/transform/rustc_peek.rs rename to compiler/rustc_mir_dataflow/src/rustc_peek.rs index f4a1b0ddba5..29ffed99344 100644 --- a/compiler/rustc_mir/src/transform/rustc_peek.rs +++ b/compiler/rustc_mir_dataflow/src/rustc_peek.rs @@ -5,25 +5,25 @@ use rustc_span::symbol::sym; use rustc_span::Span; use rustc_target::spec::abi::Abi; -use crate::transform::MirPass; use rustc_index::bit_set::BitSet; +use rustc_middle::mir::MirPass; use rustc_middle::mir::{self, Body, Local, Location}; use rustc_middle::ty::{self, Ty, TyCtxt}; -use crate::dataflow::impls::{ +use crate::impls::{ DefinitelyInitializedPlaces, MaybeInitializedPlaces, MaybeLiveLocals, MaybeMutBorrowedLocals, MaybeUninitializedPlaces, }; -use crate::dataflow::move_paths::{HasMoveData, MoveData}; -use crate::dataflow::move_paths::{LookupResult, MovePathIndex}; -use crate::dataflow::MoveDataParamEnv; -use crate::dataflow::{Analysis, JoinSemiLattice, Results, ResultsCursor}; +use crate::move_paths::{HasMoveData, MoveData}; +use crate::move_paths::{LookupResult, MovePathIndex}; +use crate::MoveDataParamEnv; +use crate::{Analysis, JoinSemiLattice, Results, ResultsCursor}; pub struct SanityCheck; impl<'tcx> MirPass<'tcx> for SanityCheck { fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { - use crate::dataflow::has_rustc_mir_with; + use crate::has_rustc_mir_with; let def_id = body.source.def_id(); if !tcx.has_attr(def_id, sym::rustc_mir) { debug!("skipping rustc_peek::SanityCheck on {}", tcx.def_path_str(def_id)); diff --git a/compiler/rustc_mir/src/util/storage.rs b/compiler/rustc_mir_dataflow/src/storage.rs similarity index 100% rename from compiler/rustc_mir/src/util/storage.rs rename to compiler/rustc_mir_dataflow/src/storage.rs diff --git a/compiler/rustc_mir_transform/Cargo.toml b/compiler/rustc_mir_transform/Cargo.toml index cba3ab5176e..bc0f69d190c 100644 --- a/compiler/rustc_mir_transform/Cargo.toml +++ b/compiler/rustc_mir_transform/Cargo.toml @@ -19,6 +19,7 @@ rustc_hir = { path = "../rustc_hir" } rustc_index = { path = "../rustc_index" } 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" } diff --git a/compiler/rustc_mir_transform/src/add_moves_for_packed_drops.rs b/compiler/rustc_mir_transform/src/add_moves_for_packed_drops.rs index c48d0c8b8f2..9eaf2b6a211 100644 --- a/compiler/rustc_mir_transform/src/add_moves_for_packed_drops.rs +++ b/compiler/rustc_mir_transform/src/add_moves_for_packed_drops.rs @@ -2,8 +2,8 @@ use rustc_middle::mir::*; use rustc_middle::ty::TyCtxt; use crate::util; -use crate::util::patch::MirPatch; use crate::MirPass; +use rustc_middle::mir::patch::MirPatch; // This pass moves values being dropped that are within a packed // struct to a separate local before dropping them, to ensure that diff --git a/compiler/rustc_mir_transform/src/coverage/debug.rs b/compiler/rustc_mir_transform/src/coverage/debug.rs index 9de2f4a5f84..513a85b5913 100644 --- a/compiler/rustc_mir_transform/src/coverage/debug.rs +++ b/compiler/rustc_mir_transform/src/coverage/debug.rs @@ -111,9 +111,9 @@ use super::graph::{BasicCoverageBlock, BasicCoverageBlockData, CoverageGraph}; use super::spans::CoverageSpan; -use crate::util::generic_graphviz::GraphvizWriter; -use crate::util::pretty; -use crate::util::spanview::{self, SpanViewable}; +use rustc_middle::mir::create_dump_file; +use rustc_middle::mir::generic_graphviz::GraphvizWriter; +use rustc_middle::mir::spanview::{self, SpanViewable}; use rustc_data_structures::fx::FxHashMap; use rustc_middle::mir::coverage::*; @@ -641,7 +641,7 @@ pub(super) fn dump_coverage_spanview( let def_id = mir_source.def_id(); let span_viewables = span_viewables(tcx, mir_body, basic_coverage_blocks, &coverage_spans); - let mut file = pretty::create_dump_file(tcx, "html", None, pass_name, &0, mir_source) + let mut file = create_dump_file(tcx, "html", None, pass_name, &0, mir_source) .expect("Unexpected error creating MIR spanview HTML file"); let crate_name = tcx.crate_name(def_id.krate); let item_name = tcx.def_path(def_id).to_filename_friendly_no_crate(); @@ -743,7 +743,7 @@ pub(super) fn dump_coverage_graphviz( .join("\n ") )); } - let mut file = pretty::create_dump_file(tcx, "dot", None, pass_name, &0, mir_source) + let mut file = create_dump_file(tcx, "dot", None, pass_name, &0, mir_source) .expect("Unexpected error creating BasicCoverageBlock graphviz DOT file"); graphviz_writer .write_graphviz(tcx, &mut file) diff --git a/compiler/rustc_mir_transform/src/coverage/mod.rs b/compiler/rustc_mir_transform/src/coverage/mod.rs index f7f01915021..6043606c379 100644 --- a/compiler/rustc_mir_transform/src/coverage/mod.rs +++ b/compiler/rustc_mir_transform/src/coverage/mod.rs @@ -12,7 +12,6 @@ use counters::CoverageCounters; use graph::{BasicCoverageBlock, BasicCoverageBlockData, CoverageGraph}; use spans::{CoverageSpan, CoverageSpans}; -use crate::util::pretty; use crate::MirPass; use rustc_data_structures::fingerprint::Fingerprint; @@ -25,6 +24,7 @@ use rustc_middle::hir::map::blocks::FnLikeNode; use rustc_middle::ich::StableHashingContext; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::mir::coverage::*; +use rustc_middle::mir::dump_enabled; use rustc_middle::mir::{ self, BasicBlock, BasicBlockData, Coverage, SourceInfo, Statement, StatementKind, Terminator, TerminatorKind, @@ -159,7 +159,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> { let mut graphviz_data = debug::GraphvizData::new(); let mut debug_used_expressions = debug::UsedExpressions::new(); - let dump_mir = pretty::dump_enabled(tcx, self.pass_name, def_id); + let dump_mir = dump_enabled(tcx, self.pass_name, def_id); let dump_graphviz = dump_mir && tcx.sess.opts.debugging_opts.dump_mir_graphviz; let dump_spanview = dump_mir && tcx.sess.opts.debugging_opts.dump_mir_spanview.is_some(); diff --git a/compiler/rustc_mir_transform/src/coverage/spans.rs b/compiler/rustc_mir_transform/src/coverage/spans.rs index 08cc87ccc34..2ea2e06029d 100644 --- a/compiler/rustc_mir_transform/src/coverage/spans.rs +++ b/compiler/rustc_mir_transform/src/coverage/spans.rs @@ -1,15 +1,13 @@ use super::debug::term_type; use super::graph::{BasicCoverageBlock, BasicCoverageBlockData, CoverageGraph, START_BCB}; -use crate::util::spanview::source_range_no_file; - use rustc_data_structures::graph::WithNumNodes; +use rustc_middle::mir::spanview::source_range_no_file; use rustc_middle::mir::{ self, AggregateKind, BasicBlock, FakeReadCause, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, }; use rustc_middle::ty::TyCtxt; - use rustc_span::source_map::original_sp; use rustc_span::{BytePos, ExpnKind, MacroKind, Span, Symbol}; diff --git a/compiler/rustc_mir_transform/src/dest_prop.rs b/compiler/rustc_mir_transform/src/dest_prop.rs index ec9279ff00c..dd95f001423 100644 --- a/compiler/rustc_mir_transform/src/dest_prop.rs +++ b/compiler/rustc_mir_transform/src/dest_prop.rs @@ -96,10 +96,7 @@ //! [previous attempt]: https://github.com/rust-lang/rust/pull/47954 //! [subsequent approach]: https://github.com/rust-lang/rust/pull/71003 -use crate::{ - util::{dump_mir, PassWhere}, - MirPass, -}; +use crate::MirPass; use itertools::Itertools; use rustc_data_structures::unify::{InPlaceUnificationTable, UnifyKey}; use rustc_index::{ @@ -108,13 +105,14 @@ use rustc_index::{ }; use rustc_middle::mir::tcx::PlaceTy; use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor}; +use rustc_middle::mir::{dump_mir, PassWhere}; use rustc_middle::mir::{ traversal, Body, InlineAsmOperand, Local, LocalKind, Location, Operand, Place, PlaceElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, }; use rustc_middle::ty::TyCtxt; -use rustc_mir::dataflow::impls::{MaybeInitializedLocals, MaybeLiveLocals}; -use rustc_mir::dataflow::Analysis; +use rustc_mir_dataflow::impls::{MaybeInitializedLocals, MaybeLiveLocals}; +use rustc_mir_dataflow::Analysis; // Empirical measurements have resulted in some observations: // - Running on a body with a single block and 500 locals takes barely any time diff --git a/compiler/rustc_mir_transform/src/dump_mir.rs b/compiler/rustc_mir_transform/src/dump_mir.rs index 753948dacb3..2a24e1ea8d7 100644 --- a/compiler/rustc_mir_transform/src/dump_mir.rs +++ b/compiler/rustc_mir_transform/src/dump_mir.rs @@ -5,9 +5,9 @@ use std::fmt; use std::fs::File; use std::io; -use crate::util as mir_util; use crate::MirPass; use rustc_middle::mir::Body; +use rustc_middle::mir::{dump_enabled, dump_mir, write_mir_pretty}; use rustc_middle::ty::TyCtxt; use rustc_session::config::{OutputFilenames, OutputType}; @@ -39,21 +39,14 @@ pub fn on_mir_pass<'tcx>( body: &Body<'tcx>, is_after: bool, ) { - if mir_util::dump_enabled(tcx, pass_name, body.source.def_id()) { - mir_util::dump_mir( - tcx, - Some(pass_num), - pass_name, - &Disambiguator { is_after }, - body, - |_, _| Ok(()), - ); + if dump_enabled(tcx, pass_name, body.source.def_id()) { + dump_mir(tcx, Some(pass_num), pass_name, &Disambiguator { is_after }, body, |_, _| Ok(())); } } pub fn emit_mir(tcx: TyCtxt<'_>, outputs: &OutputFilenames) -> io::Result<()> { let path = outputs.path(OutputType::Mir); let mut f = io::BufWriter::new(File::create(&path)?); - mir_util::write_mir_pretty(tcx, None, &mut f)?; + write_mir_pretty(tcx, None, &mut f)?; Ok(()) } diff --git a/compiler/rustc_mir_transform/src/early_otherwise_branch.rs b/compiler/rustc_mir_transform/src/early_otherwise_branch.rs index 01d0c10eddc..d7f1ad7f696 100644 --- a/compiler/rustc_mir_transform/src/early_otherwise_branch.rs +++ b/compiler/rustc_mir_transform/src/early_otherwise_branch.rs @@ -1,4 +1,4 @@ -use crate::{util::patch::MirPatch, MirPass}; +use rustc_middle::mir::patch::MirPatch; use rustc_middle::mir::*; use rustc_middle::ty::{Ty, TyCtxt}; use std::fmt::Debug; diff --git a/compiler/rustc_mir_transform/src/elaborate_drops.rs b/compiler/rustc_mir_transform/src/elaborate_drops.rs index 5ed13a0268d..b9a48197a35 100644 --- a/compiler/rustc_mir_transform/src/elaborate_drops.rs +++ b/compiler/rustc_mir_transform/src/elaborate_drops.rs @@ -1,18 +1,17 @@ -use crate::util::elaborate_drops::{elaborate_drop, DropFlagState, Unwind}; -use crate::util::elaborate_drops::{DropElaborator, DropFlagMode, DropStyle}; -use crate::util::patch::MirPatch; use crate::MirPass; use rustc_data_structures::fx::FxHashMap; use rustc_index::bit_set::BitSet; +use rustc_middle::mir::patch::MirPatch; use rustc_middle::mir::*; use rustc_middle::ty::{self, TyCtxt}; -use rustc_mir::dataflow; -use rustc_mir::dataflow::impls::{MaybeInitializedPlaces, MaybeUninitializedPlaces}; -use rustc_mir::dataflow::move_paths::{LookupResult, MoveData, MovePathIndex}; -use rustc_mir::dataflow::on_lookup_result_bits; -use rustc_mir::dataflow::MoveDataParamEnv; -use rustc_mir::dataflow::{on_all_children_bits, on_all_drop_children_bits}; -use rustc_mir::dataflow::{Analysis, ResultsCursor}; +use rustc_mir_dataflow::elaborate_drops::{elaborate_drop, DropFlagState, Unwind}; +use rustc_mir_dataflow::elaborate_drops::{DropElaborator, DropFlagMode, DropStyle}; +use rustc_mir_dataflow::impls::{MaybeInitializedPlaces, MaybeUninitializedPlaces}; +use rustc_mir_dataflow::move_paths::{LookupResult, MoveData, MovePathIndex}; +use rustc_mir_dataflow::on_lookup_result_bits; +use rustc_mir_dataflow::MoveDataParamEnv; +use rustc_mir_dataflow::{on_all_children_bits, on_all_drop_children_bits}; +use rustc_mir_dataflow::{Analysis, ResultsCursor}; use rustc_span::Span; use rustc_target::abi::VariantIdx; use std::fmt; @@ -214,14 +213,14 @@ impl<'a, 'b, 'tcx> DropElaborator<'a, 'tcx> for Elaborator<'a, 'b, 'tcx> { } fn field_subpath(&self, path: Self::Path, field: Field) -> Option { - dataflow::move_path_children_matching(self.ctxt.move_data(), path, |e| match e { + rustc_mir_dataflow::move_path_children_matching(self.ctxt.move_data(), path, |e| match e { ProjectionElem::Field(idx, _) => idx == field, _ => false, }) } fn array_subpath(&self, path: Self::Path, index: u64, size: u64) -> Option { - dataflow::move_path_children_matching(self.ctxt.move_data(), path, |e| match e { + rustc_mir_dataflow::move_path_children_matching(self.ctxt.move_data(), path, |e| match e { ProjectionElem::ConstantIndex { offset, min_length, from_end } => { debug_assert!(size == min_length, "min_length should be exact for arrays"); assert!(!from_end, "from_end should not be used for array element ConstantIndex"); @@ -232,13 +231,13 @@ impl<'a, 'b, 'tcx> DropElaborator<'a, 'tcx> for Elaborator<'a, 'b, 'tcx> { } fn deref_subpath(&self, path: Self::Path) -> Option { - dataflow::move_path_children_matching(self.ctxt.move_data(), path, |e| { + rustc_mir_dataflow::move_path_children_matching(self.ctxt.move_data(), path, |e| { e == ProjectionElem::Deref }) } fn downcast_subpath(&self, path: Self::Path, variant: VariantIdx) -> Option { - dataflow::move_path_children_matching(self.ctxt.move_data(), path, |e| match e { + rustc_mir_dataflow::move_path_children_matching(self.ctxt.move_data(), path, |e| match e { ProjectionElem::Downcast(_, idx) => idx == variant, _ => false, }) @@ -513,9 +512,14 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> { fn drop_flags_for_args(&mut self) { let loc = Location::START; - dataflow::drop_flag_effects_for_function_entry(self.tcx, self.body, self.env, |path, ds| { - self.set_drop_flag(loc, path, ds); - }) + rustc_mir_dataflow::drop_flag_effects_for_function_entry( + self.tcx, + self.body, + self.env, + |path, ds| { + self.set_drop_flag(loc, path, ds); + }, + ) } fn drop_flags_for_locs(&mut self) { @@ -556,7 +560,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> { } } let loc = Location { block: bb, statement_index: i }; - dataflow::drop_flag_effects_for_location( + rustc_mir_dataflow::drop_flag_effects_for_location( self.tcx, self.body, self.env, diff --git a/compiler/rustc_mir_transform/src/generator.rs b/compiler/rustc_mir_transform/src/generator.rs index f2486b58aac..06366b6fc31 100644 --- a/compiler/rustc_mir_transform/src/generator.rs +++ b/compiler/rustc_mir_transform/src/generator.rs @@ -50,24 +50,24 @@ //! Otherwise it drops all the values in scope at the last suspension point. use crate::simplify; -use crate::util::dump_mir; use crate::util::expand_aggregate; -use crate::util::storage; use crate::MirPass; use rustc_data_structures::fx::FxHashMap; use rustc_hir as hir; use rustc_hir::lang_items::LangItem; use rustc_index::bit_set::{BitMatrix, BitSet}; use rustc_index::vec::{Idx, IndexVec}; +use rustc_middle::mir::dump_mir; use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor}; use rustc_middle::mir::*; use rustc_middle::ty::subst::{Subst, SubstsRef}; use rustc_middle::ty::GeneratorSubsts; use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt}; -use rustc_mir::dataflow::impls::{ +use rustc_mir_dataflow::impls::{ MaybeBorrowedLocals, MaybeLiveLocals, MaybeRequiresStorage, MaybeStorageLive, }; -use rustc_mir::dataflow::{self, Analysis}; +use rustc_mir_dataflow::storage; +use rustc_mir_dataflow::{self, Analysis}; use rustc_target::abi::VariantIdx; use rustc_target::spec::PanicStrategy; use std::{iter, ops}; @@ -468,7 +468,7 @@ fn locals_live_across_suspend_points( .iterate_to_fixpoint(); let mut borrowed_locals_cursor = - dataflow::ResultsCursor::new(body_ref, &borrowed_locals_results); + rustc_mir_dataflow::ResultsCursor::new(body_ref, &borrowed_locals_results); // Calculate the MIR locals that we actually need to keep storage around // for. @@ -476,7 +476,7 @@ fn locals_live_across_suspend_points( .into_engine(tcx, body_ref) .iterate_to_fixpoint(); let mut requires_storage_cursor = - dataflow::ResultsCursor::new(body_ref, &requires_storage_results); + rustc_mir_dataflow::ResultsCursor::new(body_ref, &requires_storage_results); // Calculate the liveness of MIR locals ignoring borrows. let mut liveness = MaybeLiveLocals @@ -616,7 +616,7 @@ fn compute_storage_conflicts( body: &'mir Body<'tcx>, saved_locals: &GeneratorSavedLocals, always_live_locals: storage::AlwaysLiveLocals, - requires_storage: dataflow::Results<'tcx, MaybeRequiresStorage<'mir, 'tcx>>, + requires_storage: rustc_mir_dataflow::Results<'tcx, MaybeRequiresStorage<'mir, 'tcx>>, ) -> BitMatrix { assert_eq!(body.local_decls.len(), saved_locals.domain_size()); @@ -671,7 +671,7 @@ struct StorageConflictVisitor<'mir, 'tcx, 's> { local_conflicts: BitMatrix, } -impl dataflow::ResultsVisitor<'mir, 'tcx> for StorageConflictVisitor<'mir, 'tcx, '_> { +impl rustc_mir_dataflow::ResultsVisitor<'mir, 'tcx> for StorageConflictVisitor<'mir, 'tcx, '_> { type FlowState = BitSet; fn visit_statement_before_primary_effect( @@ -865,8 +865,8 @@ fn insert_switch<'tcx>( fn elaborate_generator_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { use crate::shim::DropShimElaborator; - use crate::util::elaborate_drops::{elaborate_drop, Unwind}; - use crate::util::patch::MirPatch; + use rustc_middle::mir::patch::MirPatch; + use rustc_mir_dataflow::elaborate_drops::{elaborate_drop, Unwind}; // Note that `elaborate_drops` only drops the upvars of a generator, and // this is ok because `open_drop` can only be reached within that own diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index 93f0a7f3d04..2c8bdf4a207 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -75,9 +75,9 @@ mod unreachable_prop; use rustc_mir::transform::check_consts; use rustc_mir::transform::promote_consts; -use rustc_mir::transform::rustc_peek; use rustc_mir::transform::validate; use rustc_mir::transform::MirPass; +use rustc_mir_dataflow::rustc_peek; pub fn provide(providers: &mut Providers) { check_unsafety::provide(providers); @@ -274,7 +274,7 @@ fn mir_const<'tcx>( let mut body = tcx.mir_built(def).steal(); - util::dump_mir(tcx, None, "mir_map", &0, &body, |_, _| Ok(())); + rustc_middle::mir::dump_mir(tcx, None, "mir_map", &0, &body, |_, _| Ok(())); run_passes( tcx, diff --git a/compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs b/compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs index 52144cbaa87..298bcd9dc24 100644 --- a/compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs +++ b/compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs @@ -1,6 +1,6 @@ -use crate::util::patch::MirPatch; use crate::MirPass; use rustc_index::bit_set::BitSet; +use rustc_middle::mir::patch::MirPatch; use rustc_middle::mir::*; use rustc_middle::ty::TyCtxt; use rustc_target::spec::PanicStrategy; diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index c57c1e12416..4d350fc87cb 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -15,13 +15,13 @@ use rustc_target::spec::abi::Abi; use std::fmt; use std::iter; -use crate::util::elaborate_drops::{self, DropElaborator, DropFlagMode, DropStyle}; use crate::util::expand_aggregate; -use crate::util::patch::MirPatch; use crate::{ abort_unwinding_calls, add_call_guards, add_moves_for_packed_drops, remove_noop_landing_pads, run_passes, simplify, }; +use rustc_middle::mir::patch::MirPatch; +use rustc_mir_dataflow::elaborate_drops::{self, DropElaborator, DropFlagMode, DropStyle}; pub fn provide(providers: &mut Providers) { providers.mir_shims = make_shim; @@ -940,7 +940,7 @@ pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> Body<'_> { span, ); - crate::util::dump_mir(tcx, None, "mir_map", &0, &body, |_, _| Ok(())); + rustc_middle::mir::dump_mir(tcx, None, "mir_map", &0, &body, |_, _| Ok(())); body } diff --git a/src/tools/clippy/clippy_lints/src/lib.rs b/src/tools/clippy/clippy_lints/src/lib.rs index 19719502870..3c6faf117fd 100644 --- a/src/tools/clippy/clippy_lints/src/lib.rs +++ b/src/tools/clippy/clippy_lints/src/lib.rs @@ -31,7 +31,7 @@ extern crate rustc_infer; extern crate rustc_lexer; extern crate rustc_lint; extern crate rustc_middle; -extern crate rustc_mir; +extern crate rustc_mir_dataflow; extern crate rustc_parse; extern crate rustc_parse_format; extern crate rustc_session; diff --git a/src/tools/clippy/clippy_lints/src/redundant_clone.rs b/src/tools/clippy/clippy_lints/src/redundant_clone.rs index f5e43264a5c..7041e4f980e 100644 --- a/src/tools/clippy/clippy_lints/src/redundant_clone.rs +++ b/src/tools/clippy/clippy_lints/src/redundant_clone.rs @@ -15,7 +15,7 @@ use rustc_middle::mir::{ Mutability, }; use rustc_middle::ty::{self, fold::TypeVisitor, Ty, TyCtxt}; -use rustc_mir::dataflow::{Analysis, AnalysisDomain, GenKill, GenKillAnalysis, ResultsCursor}; +use rustc_mir_dataflow::{Analysis, AnalysisDomain, GenKill, GenKillAnalysis, ResultsCursor}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::{BytePos, Span}; use rustc_span::sym; @@ -625,7 +625,10 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> { .flat_map(HybridBitSet::iter) .collect(); - if ContainsRegion(self.cx.tcx).visit_ty(self.body.local_decls[*dest].ty).is_break() { + if ContainsRegion(self.cx.tcx) + .visit_ty(self.body.local_decls[*dest].ty) + .is_break() + { mutable_variables.push(*dest); }