From 31a61ccc38201a13c2549b20772daf15ce0e0309 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 30 Dec 2020 18:48:40 +0100 Subject: [PATCH 1/7] Move rustc_mir::borrow_check to new crate rustc_borrowck. --- Cargo.lock | 29 ++++- compiler/rustc_borrowck/Cargo.toml | 30 +++++ .../src}/borrow_set.rs | 10 +- .../src}/borrowck_errors.rs | 2 +- .../src}/constraint_generation.rs | 2 +- .../src}/constraints/graph.rs | 2 +- .../src}/constraints/mod.rs | 2 +- .../src}/consumers.rs | 0 .../src/dataflow.rs} | 109 ++++++++++++++++-- .../src}/def_use.rs | 0 .../src}/diagnostics/bound_region_errors.rs | 4 +- .../src}/diagnostics/conflict_errors.rs | 28 ++--- .../src}/diagnostics/explain_borrow.rs | 16 +-- .../src}/diagnostics/find_use.rs | 2 +- .../src}/diagnostics/mod.rs | 11 +- .../src}/diagnostics/move_errors.rs | 12 +- .../src}/diagnostics/mutability_errors.rs | 6 +- .../src}/diagnostics/outlives_suggestion.rs | 8 +- .../src}/diagnostics/region_errors.rs | 10 +- .../src}/diagnostics/region_name.rs | 2 +- .../src}/diagnostics/var_name.rs | 4 +- .../src}/facts.rs | 11 +- .../src}/invalidation.rs | 8 +- .../mod.rs => rustc_borrowck/src/lib.rs} | 59 +++++++--- .../src}/location.rs | 0 .../src}/member_constraints.rs | 0 .../src}/nll.rs | 16 +-- .../src}/path_utils.rs | 10 +- .../src}/place_ext.rs | 2 +- .../src}/places_conflict.rs | 6 +- .../src}/prefixes.rs | 0 .../src}/region_infer/dump_mir.rs | 2 +- .../src}/region_infer/graphviz.rs | 2 +- .../src}/region_infer/mod.rs | 22 ++-- .../src}/region_infer/opaque_types.rs | 4 +- .../src}/region_infer/reverse_sccs.rs | 4 +- .../src}/region_infer/values.rs | 0 .../src}/renumber.rs | 0 .../src}/type_check/canonical.rs | 2 +- .../src}/type_check/constraint_conversion.rs | 2 +- .../src}/type_check/free_region_relations.rs | 4 +- .../src}/type_check/input_output.rs | 7 +- .../src}/type_check/liveness/local_use_map.rs | 4 +- .../src}/type_check/liveness/mod.rs | 8 +- .../src}/type_check/liveness/polonius.rs | 7 +- .../src}/type_check/liveness/trace.rs | 9 +- .../src}/type_check/mod.rs | 14 +-- .../src}/type_check/relate_tys.rs | 6 +- .../src}/universal_regions.rs | 2 +- .../src}/used_muts.rs | 5 +- compiler/rustc_interface/Cargo.toml | 1 + compiler/rustc_interface/src/passes.rs | 2 + compiler/rustc_mir/Cargo.toml | 14 +-- .../src/dataflow/drop_flag_effects.rs | 2 +- .../rustc_mir/src/dataflow/framework/mod.rs | 3 +- .../src/dataflow/framework/visitor.rs | 93 --------------- compiler/rustc_mir/src/dataflow/impls/mod.rs | 2 - compiler/rustc_mir/src/dataflow/mod.rs | 15 +-- .../rustc_mir/src/dataflow/move_paths/mod.rs | 14 ++- compiler/rustc_mir/src/lib.rs | 27 ++--- .../rustc_mir/src/transform/promote_consts.rs | 2 +- compiler/rustc_mir/src/util/collect_writes.rs | 2 +- compiler/rustc_mir/src/util/mod.rs | 3 +- compiler/rustc_mir/src/util/pretty.rs | 2 +- 64 files changed, 372 insertions(+), 315 deletions(-) create mode 100644 compiler/rustc_borrowck/Cargo.toml rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/borrow_set.rs (98%) rename compiler/{rustc_mir/src/util => rustc_borrowck/src}/borrowck_errors.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/constraint_generation.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/constraints/graph.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/constraints/mod.rs (98%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/consumers.rs (100%) rename compiler/{rustc_mir/src/dataflow/impls/borrows.rs => rustc_borrowck/src/dataflow.rs} (79%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/def_use.rs (100%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/diagnostics/bound_region_errors.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/diagnostics/conflict_errors.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/diagnostics/explain_borrow.rs (98%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/diagnostics/find_use.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/diagnostics/mod.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/diagnostics/move_errors.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/diagnostics/mutability_errors.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/diagnostics/outlives_suggestion.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/diagnostics/region_errors.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/diagnostics/region_name.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/diagnostics/var_name.rs (97%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/facts.rs (95%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/invalidation.rs (98%) rename compiler/{rustc_mir/src/borrow_check/mod.rs => rustc_borrowck/src/lib.rs} (98%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/location.rs (100%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/member_constraints.rs (100%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/nll.rs (97%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/path_utils.rs (96%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/place_ext.rs (98%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/places_conflict.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/prefixes.rs (100%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/region_infer/dump_mir.rs (98%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/region_infer/graphviz.rs (98%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/region_infer/mod.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/region_infer/opaque_types.rs (97%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/region_infer/reverse_sccs.rs (95%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/region_infer/values.rs (100%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/renumber.rs (100%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/type_check/canonical.rs (98%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/type_check/constraint_conversion.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/type_check/free_region_relations.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/type_check/input_output.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/type_check/liveness/local_use_map.rs (97%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/type_check/liveness/mod.rs (96%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/type_check/liveness/polonius.rs (96%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/type_check/liveness/trace.rs (98%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/type_check/mod.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/type_check/relate_tys.rs (96%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/universal_regions.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/used_muts.rs (99%) diff --git a/Cargo.lock b/Cargo.lock index 6849c40a54f23..81549bd1d2055 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3598,6 +3598,32 @@ dependencies = [ "rustc_span", ] +[[package]] +name = "rustc_borrowck" +version = "0.0.0" +dependencies = [ + "either", + "itertools 0.9.0", + "polonius-engine", + "rustc_data_structures", + "rustc_errors", + "rustc_graphviz", + "rustc_hir", + "rustc_index", + "rustc_infer", + "rustc_lexer", + "rustc_middle", + "rustc_mir", + "rustc_serialize", + "rustc_session", + "rustc_span", + "rustc_target", + "rustc_trait_selection", + "rustc_traits", + "smallvec", + "tracing", +] + [[package]] name = "rustc_builtin_macros" version = "0.0.0" @@ -3888,6 +3914,7 @@ dependencies = [ "rustc_ast_lowering", "rustc_ast_passes", "rustc_attr", + "rustc_borrowck", "rustc_builtin_macros", "rustc_codegen_llvm", "rustc_codegen_ssa", @@ -4059,7 +4086,6 @@ dependencies = [ "rustc_hir", "rustc_index", "rustc_infer", - "rustc_lexer", "rustc_macros", "rustc_middle", "rustc_serialize", @@ -4067,7 +4093,6 @@ dependencies = [ "rustc_span", "rustc_target", "rustc_trait_selection", - "rustc_traits", "smallvec", "tracing", ] diff --git a/compiler/rustc_borrowck/Cargo.toml b/compiler/rustc_borrowck/Cargo.toml new file mode 100644 index 0000000000000..e919c2cbc4f15 --- /dev/null +++ b/compiler/rustc_borrowck/Cargo.toml @@ -0,0 +1,30 @@ +[package] +authors = ["The Rust Project Developers"] +name = "rustc_borrowck" +version = "0.0.0" +edition = "2018" + +[lib] +doctest = false + +[dependencies] +either = "1.5.0" +itertools = "0.9" +tracing = "0.1" +polonius-engine = "0.13.0" +smallvec = { version = "1.6.1", features = ["union", "may_dangle"] } +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_lexer = { path = "../rustc_lexer" } +rustc_middle = { path = "../rustc_middle" } +rustc_mir = { path = "../rustc_mir" } +rustc_serialize = { path = "../rustc_serialize" } +rustc_session = { path = "../rustc_session" } +rustc_target = { path = "../rustc_target" } +rustc_trait_selection = { path = "../rustc_trait_selection" } +rustc_traits = { path = "../rustc_traits" } +rustc_span = { path = "../rustc_span" } diff --git a/compiler/rustc_mir/src/borrow_check/borrow_set.rs b/compiler/rustc_borrowck/src/borrow_set.rs similarity index 98% rename from compiler/rustc_mir/src/borrow_check/borrow_set.rs rename to compiler/rustc_borrowck/src/borrow_set.rs index 288eda32e414e..eb4d815bfc3ca 100644 --- a/compiler/rustc_mir/src/borrow_check/borrow_set.rs +++ b/compiler/rustc_borrowck/src/borrow_set.rs @@ -1,14 +1,14 @@ -use crate::borrow_check::nll::ToRegionVid; -use crate::borrow_check::path_utils::allow_two_phase_borrow; -use crate::borrow_check::place_ext::PlaceExt; -use crate::dataflow::indexes::BorrowIndex; -use crate::dataflow::move_paths::MoveData; +use crate::nll::ToRegionVid; +use crate::path_utils::allow_two_phase_borrow; +use crate::place_ext::PlaceExt; +use crate::BorrowIndex; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; use rustc_index::bit_set::BitSet; 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 std::fmt; use std::ops::Index; diff --git a/compiler/rustc_mir/src/util/borrowck_errors.rs b/compiler/rustc_borrowck/src/borrowck_errors.rs similarity index 99% rename from compiler/rustc_mir/src/util/borrowck_errors.rs rename to compiler/rustc_borrowck/src/borrowck_errors.rs index 56d8045813c42..5702203d7c4ff 100644 --- a/compiler/rustc_mir/src/util/borrowck_errors.rs +++ b/compiler/rustc_borrowck/src/borrowck_errors.rs @@ -2,7 +2,7 @@ use rustc_errors::{struct_span_err, DiagnosticBuilder, DiagnosticId}; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_span::{MultiSpan, Span}; -impl<'cx, 'tcx> crate::borrow_check::MirBorrowckCtxt<'cx, 'tcx> { +impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { crate fn cannot_move_when_borrowed(&self, span: Span, desc: &str) -> DiagnosticBuilder<'cx> { struct_span_err!(self, span, E0505, "cannot move out of {} because it is borrowed", desc,) } diff --git a/compiler/rustc_mir/src/borrow_check/constraint_generation.rs b/compiler/rustc_borrowck/src/constraint_generation.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/constraint_generation.rs rename to compiler/rustc_borrowck/src/constraint_generation.rs index c84928523d9d6..a40f148cdf88c 100644 --- a/compiler/rustc_mir/src/borrow_check/constraint_generation.rs +++ b/compiler/rustc_borrowck/src/constraint_generation.rs @@ -9,7 +9,7 @@ use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::{self, RegionVid, Ty}; -use crate::borrow_check::{ +use crate::{ borrow_set::BorrowSet, facts::AllFacts, location::LocationTable, nll::ToRegionVid, places_conflict, region_infer::values::LivenessValues, }; diff --git a/compiler/rustc_mir/src/borrow_check/constraints/graph.rs b/compiler/rustc_borrowck/src/constraints/graph.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/constraints/graph.rs rename to compiler/rustc_borrowck/src/constraints/graph.rs index 9e4cfb2cc00fa..cb9e0234c49ff 100644 --- a/compiler/rustc_mir/src/borrow_check/constraints/graph.rs +++ b/compiler/rustc_borrowck/src/constraints/graph.rs @@ -4,7 +4,7 @@ use rustc_middle::mir::ConstraintCategory; use rustc_middle::ty::{RegionVid, VarianceDiagInfo}; use rustc_span::DUMMY_SP; -use crate::borrow_check::{ +use crate::{ constraints::OutlivesConstraintIndex, constraints::{OutlivesConstraint, OutlivesConstraintSet}, type_check::Locations, diff --git a/compiler/rustc_mir/src/borrow_check/constraints/mod.rs b/compiler/rustc_borrowck/src/constraints/mod.rs similarity index 98% rename from compiler/rustc_mir/src/borrow_check/constraints/mod.rs rename to compiler/rustc_borrowck/src/constraints/mod.rs index b944479ca456b..98378a98684e2 100644 --- a/compiler/rustc_mir/src/borrow_check/constraints/mod.rs +++ b/compiler/rustc_borrowck/src/constraints/mod.rs @@ -5,7 +5,7 @@ use rustc_middle::ty::{RegionVid, VarianceDiagInfo}; use std::fmt; use std::ops::Index; -use crate::borrow_check::type_check::Locations; +use crate::type_check::Locations; crate mod graph; diff --git a/compiler/rustc_mir/src/borrow_check/consumers.rs b/compiler/rustc_borrowck/src/consumers.rs similarity index 100% rename from compiler/rustc_mir/src/borrow_check/consumers.rs rename to compiler/rustc_borrowck/src/consumers.rs diff --git a/compiler/rustc_mir/src/dataflow/impls/borrows.rs b/compiler/rustc_borrowck/src/dataflow.rs similarity index 79% rename from compiler/rustc_mir/src/dataflow/impls/borrows.rs rename to compiler/rustc_borrowck/src/dataflow.rs index c92cff1433f1a..cb440b2cbb9f4 100644 --- a/compiler/rustc_mir/src/dataflow/impls/borrows.rs +++ b/compiler/rustc_borrowck/src/dataflow.rs @@ -1,17 +1,110 @@ -use rustc_middle::mir::{self, Body, Location, Place}; -use rustc_middle::ty::RegionVid; -use rustc_middle::ty::TyCtxt; - use rustc_data_structures::fx::FxHashMap; 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 std::fmt; +use std::iter; -use crate::borrow_check::{ +use crate::{ places_conflict, BorrowSet, PlaceConflictBias, PlaceExt, RegionInferenceContext, ToRegionVid, }; -use crate::dataflow::{self, fmt::DebugWithContext, GenKill}; -use std::fmt; -use std::iter; +/// A tuple with named fields that can hold either the results or the transient state of the +/// dataflow analyses used by the borrow checker. +#[derive(Debug)] +pub struct BorrowckAnalyses { + pub borrows: B, + pub uninits: U, + pub ever_inits: E, +} + +/// The results of the dataflow analyses used by the borrow checker. +pub type BorrowckResults<'mir, 'tcx> = BorrowckAnalyses< + Results<'tcx, Borrows<'mir, 'tcx>>, + Results<'tcx, MaybeUninitializedPlaces<'mir, 'tcx>>, + Results<'tcx, EverInitializedPlaces<'mir, 'tcx>>, +>; + +/// The transient state of the dataflow analyses used by the borrow checker. +pub type BorrowckFlowState<'mir, 'tcx> = + as ResultsVisitable<'tcx>>::FlowState; + +macro_rules! impl_visitable { + ( $( + $T:ident { $( $field:ident : $A:ident ),* $(,)? } + )* ) => { $( + impl<'tcx, $($A),*, D: Direction> ResultsVisitable<'tcx> for $T<$( Results<'tcx, $A> ),*> + where + $( $A: Analysis<'tcx, Direction = D>, )* + { + type Direction = D; + type FlowState = $T<$( $A::Domain ),*>; + + fn new_flow_state(&self, body: &mir::Body<'tcx>) -> Self::FlowState { + $T { + $( $field: self.$field.analysis.bottom_value(body) ),* + } + } + + fn reset_to_block_entry( + &self, + state: &mut Self::FlowState, + block: BasicBlock, + ) { + $( state.$field.clone_from(&self.$field.entry_set_for_block(block)); )* + } + + fn reconstruct_before_statement_effect( + &self, + state: &mut Self::FlowState, + stmt: &mir::Statement<'tcx>, + loc: Location, + ) { + $( self.$field.analysis + .apply_before_statement_effect(&mut state.$field, stmt, loc); )* + } + + fn reconstruct_statement_effect( + &self, + state: &mut Self::FlowState, + stmt: &mir::Statement<'tcx>, + loc: Location, + ) { + $( self.$field.analysis + .apply_statement_effect(&mut state.$field, stmt, loc); )* + } + + fn reconstruct_before_terminator_effect( + &self, + state: &mut Self::FlowState, + term: &mir::Terminator<'tcx>, + loc: Location, + ) { + $( self.$field.analysis + .apply_before_terminator_effect(&mut state.$field, term, loc); )* + } + + fn reconstruct_terminator_effect( + &self, + state: &mut Self::FlowState, + term: &mir::Terminator<'tcx>, + loc: Location, + ) { + $( self.$field.analysis + .apply_terminator_effect(&mut state.$field, term, loc); )* + } + } + )* } +} + +impl_visitable! { + BorrowckAnalyses { borrows: B, uninits: U, ever_inits: E } +} rustc_index::newtype_index! { pub struct BorrowIndex { diff --git a/compiler/rustc_mir/src/borrow_check/def_use.rs b/compiler/rustc_borrowck/src/def_use.rs similarity index 100% rename from compiler/rustc_mir/src/borrow_check/def_use.rs rename to compiler/rustc_borrowck/src/def_use.rs diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/bound_region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/diagnostics/bound_region_errors.rs rename to compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs index ac30093ba8260..76e779bfec608 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/bound_region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs @@ -14,8 +14,8 @@ use rustc_traits::{type_op_ascribe_user_type_with_span, type_op_prove_predicate_ use std::fmt; use std::rc::Rc; -use crate::borrow_check::region_infer::values::RegionElement; -use crate::borrow_check::MirBorrowckCtxt; +use crate::region_infer::values::RegionElement; +use crate::MirBorrowckCtxt; #[derive(Clone)] crate struct UniverseInfo<'tcx>(UniverseInfoInner<'tcx>); diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs rename to compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 6561fe37c1c47..8f6181f410df4 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -15,11 +15,11 @@ use rustc_span::symbol::sym; use rustc_span::{BytePos, MultiSpan, Span, DUMMY_SP}; use rustc_trait_selection::infer::InferCtxtExt; -use crate::dataflow::drop_flag_effects; -use crate::dataflow::indexes::{MoveOutIndex, MovePathIndex}; -use crate::util::borrowck_errors; +use crate::borrowck_errors; +use rustc_mir::dataflow::drop_flag_effects; +use rustc_mir::dataflow::move_paths::{MoveOutIndex, MovePathIndex}; -use crate::borrow_check::{ +use crate::{ borrow_set::BorrowData, diagnostics::Instance, prefixes::IsPrefixOf, InitializationRequiringAction, MirBorrowckCtxt, PrefixSet, WriteKind, }; @@ -49,7 +49,7 @@ enum StorageDeadOrDrop<'tcx> { } impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { - pub(in crate::borrow_check) fn report_use_of_moved_or_uninitialized( + pub(crate) fn report_use_of_moved_or_uninitialized( &mut self, location: Location, desired_action: InitializationRequiringAction, @@ -441,7 +441,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { } } - pub(in crate::borrow_check) fn report_move_out_while_borrowed( + pub(crate) fn report_move_out_while_borrowed( &mut self, location: Location, (place, span): (Place<'tcx>, Span), @@ -489,7 +489,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { err.buffer(&mut self.errors_buffer); } - pub(in crate::borrow_check) fn report_use_while_mutably_borrowed( + pub(crate) fn report_use_while_mutably_borrowed( &mut self, location: Location, (place, _span): (Place<'tcx>, Span), @@ -535,7 +535,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { err } - pub(in crate::borrow_check) fn report_conflicting_borrow( + pub(crate) fn report_conflicting_borrow( &mut self, location: Location, (place, span): (Place<'tcx>, Span), @@ -798,7 +798,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { /// cannot borrow `a.u` (via `a.u.z.c`) as immutable because it is also borrowed as /// mutable (via `a.u.s.b`) [E0502] /// ``` - pub(in crate::borrow_check) fn describe_place_for_conflicting_borrow( + pub(crate) fn describe_place_for_conflicting_borrow( &self, first_borrowed_place: Place<'tcx>, second_borrowed_place: Place<'tcx>, @@ -875,7 +875,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { /// short a lifetime. (But sometimes it is more useful to report /// it as a more direct conflict between the execution of a /// `Drop::drop` with an aliasing borrow.) - pub(in crate::borrow_check) fn report_borrowed_value_does_not_live_long_enough( + pub(crate) fn report_borrowed_value_does_not_live_long_enough( &mut self, location: Location, borrow: &BorrowData<'tcx>, @@ -1634,7 +1634,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { (result, reinits_reachable) } - pub(in crate::borrow_check) fn report_illegal_mutation_of_borrowed( + pub(crate) fn report_illegal_mutation_of_borrowed( &mut self, location: Location, (place, span): (Place<'tcx>, Span), @@ -1695,7 +1695,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { Some((method_did, method_substs)), ) = ( &self.body[loan.reserve_location.block].terminator, - crate::util::find_self_call( + rustc_mir::util::find_self_call( tcx, self.body, loan.assigned_place.local, @@ -1726,7 +1726,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { /// assigned; `err_place` is a place providing a reason why /// `place` is not mutable (e.g., the non-`mut` local `x` in an /// assignment to `x.f`). - pub(in crate::borrow_check) fn report_illegal_reassignment( + pub(crate) fn report_illegal_reassignment( &mut self, _location: Location, (place, span): (Place<'tcx>, Span), @@ -2226,7 +2226,7 @@ enum AnnotatedBorrowFnSignature<'tcx> { impl<'tcx> AnnotatedBorrowFnSignature<'tcx> { /// Annotate the provided diagnostic with information about borrow from the fn signature that /// helps explain. - pub(in crate::borrow_check) fn emit( + pub(crate) fn emit( &self, cx: &mut MirBorrowckCtxt<'_, 'tcx>, diag: &mut DiagnosticBuilder<'_>, diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/explain_borrow.rs b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs similarity index 98% rename from compiler/rustc_mir/src/borrow_check/diagnostics/explain_borrow.rs rename to compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs index f40a2db330a97..2d12a682e7ae6 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/explain_borrow.rs +++ b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs @@ -15,8 +15,8 @@ use rustc_middle::ty::{self, RegionVid, TyCtxt}; use rustc_span::symbol::Symbol; use rustc_span::Span; -use crate::borrow_check::region_infer::BlameConstraint; -use crate::borrow_check::{ +use crate::region_infer::BlameConstraint; +use crate::{ borrow_set::BorrowData, nll::ConstraintDescription, region_infer::Cause, MirBorrowckCtxt, WriteKind, }; @@ -24,7 +24,7 @@ use crate::borrow_check::{ use super::{find_use, RegionName, UseSpans}; #[derive(Debug)] -pub(in crate::borrow_check) enum BorrowExplanation { +pub(crate) enum BorrowExplanation { UsedLater(LaterUseKind, Span, Option), UsedLaterInLoop(LaterUseKind, Span, Option), UsedLaterWhenDropped { @@ -43,7 +43,7 @@ pub(in crate::borrow_check) enum BorrowExplanation { } #[derive(Clone, Copy, Debug)] -pub(in crate::borrow_check) enum LaterUseKind { +pub(crate) enum LaterUseKind { TraitCapture, ClosureCapture, Call, @@ -52,13 +52,13 @@ pub(in crate::borrow_check) enum LaterUseKind { } impl BorrowExplanation { - pub(in crate::borrow_check) fn is_explained(&self) -> bool { + pub(crate) fn is_explained(&self) -> bool { match self { BorrowExplanation::Unexplained => false, _ => true, } } - pub(in crate::borrow_check) fn add_explanation_to_diagnostic<'tcx>( + pub(crate) fn add_explanation_to_diagnostic<'tcx>( &self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>, @@ -267,7 +267,7 @@ impl BorrowExplanation { _ => {} } } - pub(in crate::borrow_check) fn add_lifetime_bound_suggestion_to_diagnostic( + pub(crate) fn add_lifetime_bound_suggestion_to_diagnostic( &self, err: &mut DiagnosticBuilder<'_>, category: &ConstraintCategory, @@ -326,7 +326,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { /// - second half is the place being accessed /// /// [d]: https://rust-lang.github.io/rfcs/2094-nll.html#leveraging-intuition-framing-errors-in-terms-of-points - pub(in crate::borrow_check) fn explain_why_borrow_contains_point( + pub(crate) fn explain_why_borrow_contains_point( &self, location: Location, borrow: &BorrowData<'tcx>, diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/find_use.rs b/compiler/rustc_borrowck/src/diagnostics/find_use.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/diagnostics/find_use.rs rename to compiler/rustc_borrowck/src/diagnostics/find_use.rs index 8d8cdfb52934c..ab4536f00fc42 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/find_use.rs +++ b/compiler/rustc_borrowck/src/diagnostics/find_use.rs @@ -1,7 +1,7 @@ use std::collections::VecDeque; use std::rc::Rc; -use crate::borrow_check::{ +use crate::{ def_use::{self, DefUse}, nll::ToRegionVid, region_infer::{Cause, RegionInferenceContext}, diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/diagnostics/mod.rs rename to compiler/rustc_borrowck/src/diagnostics/mod.rs index 55c6410ed3204..980894d6b4d0f 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -12,6 +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_span::{ hygiene::{DesugaringKind, ForLoopLoc}, symbol::sym, @@ -21,7 +22,6 @@ use rustc_target::abi::VariantIdx; use super::borrow_set::BorrowData; use super::MirBorrowckCtxt; -use crate::dataflow::move_paths::{InitLocation, LookupResult}; mod find_use; mod outlives_suggestion; @@ -899,9 +899,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { kind: TerminatorKind::Call { fn_span, from_hir_call, .. }, .. }) = &self.body[location.block].terminator { - let (method_did, method_substs) = if let Some(info) = - crate::util::find_self_call(self.infcx.tcx, &self.body, target_temp, location.block) - { + let (method_did, method_substs) = if let Some(info) = rustc_mir::util::find_self_call( + self.infcx.tcx, + &self.body, + target_temp, + location.block, + ) { info } else { return normal_ret; diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/move_errors.rs b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/diagnostics/move_errors.rs rename to compiler/rustc_borrowck/src/diagnostics/move_errors.rs index 66e06325fa982..dd4886312da37 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/move_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs @@ -2,16 +2,16 @@ use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_infer::infer::TyCtxtInferExt; use rustc_middle::mir::*; use rustc_middle::ty; +use rustc_mir::dataflow::move_paths::{ + IllegalMoveOrigin, IllegalMoveOriginKind, LookupResult, MoveError, MovePathIndex, +}; use rustc_span::source_map::DesugaringKind; use rustc_span::{sym, Span, DUMMY_SP}; use rustc_trait_selection::traits::type_known_to_meet_bound_modulo_regions; -use crate::borrow_check::diagnostics::UseSpans; -use crate::borrow_check::prefixes::PrefixSet; -use crate::borrow_check::MirBorrowckCtxt; -use crate::dataflow::move_paths::{ - IllegalMoveOrigin, IllegalMoveOriginKind, LookupResult, MoveError, MovePathIndex, -}; +use crate::diagnostics::UseSpans; +use crate::prefixes::PrefixSet; +use crate::MirBorrowckCtxt; // Often when desugaring a pattern match we may have many individual moves in // MIR that are all part of one operation from the user's point-of-view. For diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs rename to compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index 4e079ed865ac3..b3578afbbb635 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -14,10 +14,10 @@ use rustc_span::source_map::DesugaringKind; use rustc_span::symbol::{kw, Symbol}; use rustc_span::{BytePos, Span}; -use crate::borrow_check::diagnostics::BorrowedContentSource; -use crate::borrow_check::MirBorrowckCtxt; -use crate::util::collect_writes::FindAssignments; +use crate::diagnostics::BorrowedContentSource; +use crate::MirBorrowckCtxt; use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_mir::util::collect_writes::FindAssignments; #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub(crate) enum AccessKind { diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/outlives_suggestion.rs b/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/diagnostics/outlives_suggestion.rs rename to compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs index 7dc3434bf3338..9de0c62f186c0 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/outlives_suggestion.rs +++ b/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs @@ -1,16 +1,14 @@ //! Contains utilities for generating suggestions for borrowck errors related to unsatisfied //! outlives constraints. -use std::collections::BTreeMap; - use rustc_data_structures::fx::FxHashSet; use rustc_errors::DiagnosticBuilder; use rustc_middle::ty::RegionVid; -use tracing::debug; - use smallvec::SmallVec; +use std::collections::BTreeMap; +use tracing::debug; -use crate::borrow_check::MirBorrowckCtxt; +use crate::MirBorrowckCtxt; use super::{ErrorConstraintInfo, RegionName, RegionNameSource}; diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/diagnostics/region_errors.rs rename to compiler/rustc_borrowck/src/diagnostics/region_errors.rs index cbb8f064bb81a..57d2a3c5ce91b 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -11,10 +11,10 @@ use rustc_middle::ty::{self, RegionVid, Ty}; use rustc_span::symbol::{kw, sym}; use rustc_span::{BytePos, Span}; -use crate::util::borrowck_errors; +use crate::borrowck_errors; -use crate::borrow_check::region_infer::BlameConstraint; -use crate::borrow_check::{ +use crate::region_infer::BlameConstraint; +use crate::{ nll::ConstraintDescription, region_infer::{values::RegionElement, TypeTest}, universal_regions::DefiningTy, @@ -152,7 +152,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { } /// Produces nice borrowck error diagnostics for all the errors collected in `nll_errors`. - pub(in crate::borrow_check) fn report_region_errors(&mut self, nll_errors: RegionErrors<'tcx>) { + pub(crate) fn report_region_errors(&mut self, nll_errors: RegionErrors<'tcx>) { // Iterate through all the errors, producing a diagnostic for each one. The diagnostics are // buffered in the `MirBorrowckCtxt`. @@ -265,7 +265,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { /// ``` /// /// Here we would be invoked with `fr = 'a` and `outlived_fr = `'b`. - pub(in crate::borrow_check) fn report_region_error( + pub(crate) fn report_region_error( &mut self, fr: RegionVid, fr_origin: NllRegionVariableOrigin, diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/diagnostics/region_name.rs rename to compiler/rustc_borrowck/src/diagnostics/region_name.rs index 1f168c612f167..5edb52b0b650d 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/region_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs @@ -10,7 +10,7 @@ use rustc_middle::ty::{self, RegionVid, Ty}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{Span, DUMMY_SP}; -use crate::borrow_check::{nll::ToRegionVid, universal_regions::DefiningTy, MirBorrowckCtxt}; +use crate::{nll::ToRegionVid, universal_regions::DefiningTy, MirBorrowckCtxt}; /// A name for a particular region used in emitting diagnostics. This name could be a generated /// name like `'1`, a name used by the user like `'a`, or a name like `'static`. diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/var_name.rs b/compiler/rustc_borrowck/src/diagnostics/var_name.rs similarity index 97% rename from compiler/rustc_mir/src/borrow_check/diagnostics/var_name.rs rename to compiler/rustc_borrowck/src/diagnostics/var_name.rs index 4abc623fc5f37..00f6280675355 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/var_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/var_name.rs @@ -1,5 +1,5 @@ -use crate::borrow_check::Upvar; -use crate::borrow_check::{nll::ToRegionVid, region_infer::RegionInferenceContext}; +use crate::Upvar; +use crate::{nll::ToRegionVid, region_infer::RegionInferenceContext}; use rustc_index::vec::{Idx, IndexVec}; use rustc_middle::mir::{Body, Local}; use rustc_middle::ty::{RegionVid, TyCtxt}; diff --git a/compiler/rustc_mir/src/borrow_check/facts.rs b/compiler/rustc_borrowck/src/facts.rs similarity index 95% rename from compiler/rustc_mir/src/borrow_check/facts.rs rename to compiler/rustc_borrowck/src/facts.rs index 215dead5bd15e..ed3f846e4adc9 100644 --- a/compiler/rustc_mir/src/borrow_check/facts.rs +++ b/compiler/rustc_borrowck/src/facts.rs @@ -1,10 +1,11 @@ -use crate::borrow_check::location::{LocationIndex, LocationTable}; -use crate::dataflow::indexes::{BorrowIndex, MovePathIndex}; +use crate::location::{LocationIndex, LocationTable}; +use crate::BorrowIndex; use polonius_engine::AllFacts as PoloniusFacts; 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 std::error::Error; use std::fmt::Debug; use std::fs::{self, File}; @@ -100,12 +101,6 @@ impl Atom for LocationIndex { } } -impl Atom for MovePathIndex { - fn index(self) -> usize { - Idx::index(self) - } -} - struct FactWriter<'w> { location_table: &'w LocationTable, dir: &'w Path, diff --git a/compiler/rustc_mir/src/borrow_check/invalidation.rs b/compiler/rustc_borrowck/src/invalidation.rs similarity index 98% rename from compiler/rustc_mir/src/borrow_check/invalidation.rs rename to compiler/rustc_borrowck/src/invalidation.rs index b83a427f47574..016fe0bb6dedf 100644 --- a/compiler/rustc_mir/src/borrow_check/invalidation.rs +++ b/compiler/rustc_borrowck/src/invalidation.rs @@ -7,12 +7,10 @@ use rustc_middle::mir::{Statement, StatementKind}; use rustc_middle::ty::TyCtxt; use std::iter; -use crate::dataflow::indexes::BorrowIndex; - -use crate::borrow_check::{ +use crate::{ borrow_set::BorrowSet, facts::AllFacts, location::LocationTable, path_utils::*, AccessDepth, - Activation, ArtificialField, Deep, JustWrite, LocalMutationIsAllowed, MutateMode, Read, - ReadKind, ReadOrWrite, Reservation, Shallow, Write, WriteAndRead, WriteKind, + Activation, ArtificialField, BorrowIndex, Deep, JustWrite, LocalMutationIsAllowed, MutateMode, + Read, ReadKind, ReadOrWrite, Reservation, Shallow, Write, WriteAndRead, WriteKind, }; pub(super) fn generate_invalidates<'tcx>( diff --git a/compiler/rustc_mir/src/borrow_check/mod.rs b/compiler/rustc_borrowck/src/lib.rs similarity index 98% rename from compiler/rustc_mir/src/borrow_check/mod.rs rename to compiler/rustc_borrowck/src/lib.rs index 1dcb067656258..9fe3d79e4ed09 100644 --- a/compiler/rustc_mir/src/borrow_check/mod.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -1,5 +1,22 @@ //! This query borrow-checks the MIR to (further) ensure it is not broken. +#![feature(bool_to_option)] +#![feature(box_patterns)] +#![feature(const_panic)] +#![feature(crate_visibility_modifier)] +#![feature(format_args_capture)] +#![feature(in_band_lifetimes)] +#![feature(iter_zip)] +#![feature(min_specialization)] +#![feature(stmt_expr_attributes)] +#![feature(trusted_step)] +#![feature(try_blocks)] + +#[macro_use] +extern crate rustc_middle; +#[macro_use] +extern crate tracing; + use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::graph::dominators::Dominators; use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorReported}; @@ -29,14 +46,13 @@ use std::iter; use std::mem; use std::rc::Rc; -use crate::dataflow; -use crate::dataflow::impls::{ - Borrows, EverInitializedPlaces, MaybeInitializedPlaces, MaybeUninitializedPlaces, +use rustc_mir::dataflow::impls::{ + EverInitializedPlaces, MaybeInitializedPlaces, MaybeUninitializedPlaces, }; -use crate::dataflow::indexes::{BorrowIndex, InitIndex, MoveOutIndex, MovePathIndex}; -use crate::dataflow::move_paths::{InitLocation, LookupResult, MoveData, MoveError}; -use crate::dataflow::MoveDataParamEnv; -use crate::dataflow::{Analysis, BorrowckFlowState as Flows, BorrowckResults}; +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; @@ -47,9 +63,10 @@ use facts::AllFacts; use self::path_utils::*; mod borrow_set; +mod borrowck_errors; mod constraint_generation; mod constraints; -pub mod consumers; +mod dataflow; mod def_use; mod diagnostics; mod facts; @@ -67,15 +84,19 @@ mod type_check; mod universal_regions; mod used_muts; -crate use borrow_set::{BorrowData, BorrowSet}; -crate use nll::{PoloniusOutput, ToRegionVid}; -crate use place_ext::PlaceExt; -crate use places_conflict::{places_conflict, PlaceConflictBias}; -crate use region_infer::RegionInferenceContext; +// A public API provided for the Rust compiler consumers. +pub mod consumers; + +use borrow_set::{BorrowData, BorrowSet}; +use dataflow::{BorrowIndex, BorrowckFlowState as Flows, BorrowckResults, Borrows}; +use nll::{PoloniusOutput, ToRegionVid}; +use place_ext::PlaceExt; +use places_conflict::{places_conflict, PlaceConflictBias}; +use region_infer::RegionInferenceContext; // FIXME(eddyb) perhaps move this somewhere more centrally. #[derive(Debug)] -crate struct Upvar<'tcx> { +struct Upvar<'tcx> { place: CapturedPlace<'tcx>, /// If true, the capture is behind a reference. @@ -352,7 +373,7 @@ fn do_mir_borrowck<'a, 'tcx>( mbcx.report_move_errors(move_errors); - dataflow::visit_results( + rustc_mir::dataflow::visit_results( &body, traversal::reverse_postorder(&body).map(|(bb, _)| bb), &results, @@ -495,8 +516,8 @@ pub struct BodyWithBorrowckFacts<'tcx> { pub location_table: LocationTable, } -crate struct MirBorrowckCtxt<'cx, 'tcx> { - crate infcx: &'cx InferCtxt<'cx, 'tcx>, +struct MirBorrowckCtxt<'cx, 'tcx> { + infcx: &'cx InferCtxt<'cx, 'tcx>, param_env: ParamEnv<'tcx>, body: &'cx Body<'tcx>, move_data: &'cx MoveData<'tcx>, @@ -594,7 +615,7 @@ crate 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> 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( @@ -2344,7 +2365,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { /// then returns the index of the field being projected. Note that this closure will always /// be `self` in the current MIR, because that is the only time we directly access the fields /// of a closure type. - pub fn is_upvar_field_projection(&self, place_ref: PlaceRef<'tcx>) -> Option { + fn is_upvar_field_projection(&self, place_ref: PlaceRef<'tcx>) -> Option { path_utils::is_upvar_field_projection(self.infcx.tcx, &self.upvars, place_ref, self.body()) } } diff --git a/compiler/rustc_mir/src/borrow_check/location.rs b/compiler/rustc_borrowck/src/location.rs similarity index 100% rename from compiler/rustc_mir/src/borrow_check/location.rs rename to compiler/rustc_borrowck/src/location.rs diff --git a/compiler/rustc_mir/src/borrow_check/member_constraints.rs b/compiler/rustc_borrowck/src/member_constraints.rs similarity index 100% rename from compiler/rustc_mir/src/borrow_check/member_constraints.rs rename to compiler/rustc_borrowck/src/member_constraints.rs diff --git a/compiler/rustc_mir/src/borrow_check/nll.rs b/compiler/rustc_borrowck/src/nll.rs similarity index 97% rename from compiler/rustc_mir/src/borrow_check/nll.rs rename to compiler/rustc_borrowck/src/nll.rs index 66ca94d3b415d..d40990d4676bc 100644 --- a/compiler/rustc_mir/src/borrow_check/nll.rs +++ b/compiler/rustc_borrowck/src/nll.rs @@ -20,13 +20,13 @@ use std::str::FromStr; use self::mir_util::PassWhere; use polonius_engine::{Algorithm, Output}; -use crate::dataflow::impls::MaybeInitializedPlaces; -use crate::dataflow::move_paths::{InitKind, InitLocation, MoveData}; -use crate::dataflow::ResultsCursor; -use crate::util as mir_util; -use crate::util::pretty; +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 crate::borrow_check::{ +use crate::{ borrow_set::BorrowSet, constraint_generation, diagnostics::RegionErrors, @@ -56,7 +56,7 @@ crate struct NllOutput<'tcx> { /// Rewrites the regions in the MIR to use NLL variables, also scraping out the set of universal /// regions (e.g., region parameters) declared on the function. That set will need to be given to /// `compute_regions`. -pub(in crate::borrow_check) fn replace_regions_in_mir<'cx, 'tcx>( +pub(crate) fn replace_regions_in_mir<'cx, 'tcx>( infcx: &InferCtxt<'cx, 'tcx>, param_env: ty::ParamEnv<'tcx>, body: &mut Body<'tcx>, @@ -155,7 +155,7 @@ fn populate_polonius_move_facts( /// Computes the (non-lexical) regions from the input MIR. /// /// This may result in errors being reported. -pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>( +pub(crate) fn compute_regions<'cx, 'tcx>( infcx: &InferCtxt<'cx, 'tcx>, universal_regions: UniversalRegions<'tcx>, body: &Body<'tcx>, diff --git a/compiler/rustc_mir/src/borrow_check/path_utils.rs b/compiler/rustc_borrowck/src/path_utils.rs similarity index 96% rename from compiler/rustc_mir/src/borrow_check/path_utils.rs rename to compiler/rustc_borrowck/src/path_utils.rs index 80de3b4e363bf..d5d00b467eeed 100644 --- a/compiler/rustc_mir/src/borrow_check/path_utils.rs +++ b/compiler/rustc_borrowck/src/path_utils.rs @@ -1,8 +1,8 @@ -use crate::borrow_check::borrow_set::{BorrowData, BorrowSet, TwoPhaseActivation}; -use crate::borrow_check::places_conflict; -use crate::borrow_check::AccessDepth; -use crate::borrow_check::Upvar; -use crate::dataflow::indexes::BorrowIndex; +use crate::borrow_set::{BorrowData, BorrowSet, TwoPhaseActivation}; +use crate::places_conflict; +use crate::AccessDepth; +use crate::BorrowIndex; +use crate::Upvar; use rustc_data_structures::graph::dominators::Dominators; use rustc_middle::mir::BorrowKind; use rustc_middle::mir::{BasicBlock, Body, Field, Location, Place, PlaceRef, ProjectionElem}; diff --git a/compiler/rustc_mir/src/borrow_check/place_ext.rs b/compiler/rustc_borrowck/src/place_ext.rs similarity index 98% rename from compiler/rustc_mir/src/borrow_check/place_ext.rs rename to compiler/rustc_borrowck/src/place_ext.rs index 52fac3e53ee65..83ff1595b0be4 100644 --- a/compiler/rustc_mir/src/borrow_check/place_ext.rs +++ b/compiler/rustc_borrowck/src/place_ext.rs @@ -1,4 +1,4 @@ -use crate::borrow_check::borrow_set::LocalsStateAtExit; +use crate::borrow_set::LocalsStateAtExit; use rustc_hir as hir; use rustc_middle::mir::ProjectionElem; use rustc_middle::mir::{Body, Mutability, Place}; diff --git a/compiler/rustc_mir/src/borrow_check/places_conflict.rs b/compiler/rustc_borrowck/src/places_conflict.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/places_conflict.rs rename to compiler/rustc_borrowck/src/places_conflict.rs index d21550a8e1af6..773e9e90b0c6b 100644 --- a/compiler/rustc_mir/src/borrow_check/places_conflict.rs +++ b/compiler/rustc_borrowck/src/places_conflict.rs @@ -1,6 +1,6 @@ -use crate::borrow_check::ArtificialField; -use crate::borrow_check::Overlap; -use crate::borrow_check::{AccessDepth, Deep, Shallow}; +use crate::ArtificialField; +use crate::Overlap; +use crate::{AccessDepth, Deep, Shallow}; use rustc_hir as hir; use rustc_middle::mir::{Body, BorrowKind, Local, Place, PlaceElem, PlaceRef, ProjectionElem}; use rustc_middle::ty::{self, TyCtxt}; diff --git a/compiler/rustc_mir/src/borrow_check/prefixes.rs b/compiler/rustc_borrowck/src/prefixes.rs similarity index 100% rename from compiler/rustc_mir/src/borrow_check/prefixes.rs rename to compiler/rustc_borrowck/src/prefixes.rs diff --git a/compiler/rustc_mir/src/borrow_check/region_infer/dump_mir.rs b/compiler/rustc_borrowck/src/region_infer/dump_mir.rs similarity index 98% rename from compiler/rustc_mir/src/borrow_check/region_infer/dump_mir.rs rename to compiler/rustc_borrowck/src/region_infer/dump_mir.rs index 213ebff12abc0..cfd3acb6bdebd 100644 --- a/compiler/rustc_mir/src/borrow_check/region_infer/dump_mir.rs +++ b/compiler/rustc_borrowck/src/region_infer/dump_mir.rs @@ -4,7 +4,7 @@ //! context internal state. use super::{OutlivesConstraint, RegionInferenceContext}; -use crate::borrow_check::type_check::Locations; +use crate::type_check::Locations; use rustc_infer::infer::NllRegionVariableOrigin; use rustc_middle::ty::TyCtxt; use std::io::{self, Write}; diff --git a/compiler/rustc_mir/src/borrow_check/region_infer/graphviz.rs b/compiler/rustc_borrowck/src/region_infer/graphviz.rs similarity index 98% rename from compiler/rustc_mir/src/borrow_check/region_infer/graphviz.rs rename to compiler/rustc_borrowck/src/region_infer/graphviz.rs index b944d74e6f231..95048d50f117f 100644 --- a/compiler/rustc_mir/src/borrow_check/region_infer/graphviz.rs +++ b/compiler/rustc_borrowck/src/region_infer/graphviz.rs @@ -6,7 +6,7 @@ use std::borrow::Cow; use std::io::{self, Write}; use super::*; -use crate::borrow_check::constraints::OutlivesConstraint; +use crate::constraints::OutlivesConstraint; use rustc_graphviz as dot; impl<'tcx> RegionInferenceContext<'tcx> { diff --git a/compiler/rustc_mir/src/borrow_check/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/region_infer/mod.rs rename to compiler/rustc_borrowck/src/region_infer/mod.rs index a96cdbc13f345..48e45a9b1ce72 100644 --- a/compiler/rustc_mir/src/borrow_check/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -17,7 +17,7 @@ use rustc_middle::mir::{ use rustc_middle::ty::{self, subst::SubstsRef, RegionVid, Ty, TyCtxt, TypeFoldable}; use rustc_span::Span; -use crate::borrow_check::{ +use crate::{ constraints::{ graph::NormalConstraintGraph, ConstraintSccIndex, OutlivesConstraint, OutlivesConstraintSet, }, @@ -132,33 +132,33 @@ pub(crate) struct AppliedMemberConstraint { /// /// The vector if `AppliedMemberConstraint` elements is kept sorted /// by this field. - pub(in crate::borrow_check) member_region_scc: ConstraintSccIndex, + pub(crate) member_region_scc: ConstraintSccIndex, /// The "best option" that `apply_member_constraint` found -- this was /// added as an "ad-hoc" lower-bound to `member_region_scc`. - pub(in crate::borrow_check) min_choice: ty::RegionVid, + pub(crate) min_choice: ty::RegionVid, /// The "member constraint index" -- we can find out details about /// the constraint from /// `set.member_constraints[member_constraint_index]`. - pub(in crate::borrow_check) member_constraint_index: NllMemberConstraintIndex, + pub(crate) member_constraint_index: NllMemberConstraintIndex, } pub(crate) struct RegionDefinition<'tcx> { /// What kind of variable is this -- a free region? existential /// variable? etc. (See the `NllRegionVariableOrigin` for more /// info.) - pub(in crate::borrow_check) origin: NllRegionVariableOrigin, + pub(crate) origin: NllRegionVariableOrigin, /// Which universe is this region variable defined in? This is /// most often `ty::UniverseIndex::ROOT`, but when we encounter /// forall-quantifiers like `for<'a> { 'a = 'b }`, we would create /// the variable for `'a` in a fresh universe that extends ROOT. - pub(in crate::borrow_check) universe: ty::UniverseIndex, + pub(crate) universe: ty::UniverseIndex, /// If this is 'static or an early-bound region, then this is /// `Some(X)` where `X` is the name of the region. - pub(in crate::borrow_check) external_name: Option>, + pub(crate) external_name: Option>, } /// N.B., the variants in `Cause` are intentionally ordered. Lower @@ -245,7 +245,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// /// The `outlives_constraints` and `type_tests` are an initial set /// of constraints produced by the MIR type check. - pub(in crate::borrow_check) fn new( + pub(crate) fn new( var_infos: VarInfos, universal_regions: Rc>, placeholder_indices: Rc, @@ -534,7 +534,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// Once region solving has completed, this function will return /// the member constraints that were applied to the value of a given /// region `r`. See `AppliedMemberConstraint`. - pub(in crate::borrow_check) fn applied_member_constraints( + pub(crate) fn applied_member_constraints( &self, r: impl ToRegionVid, ) -> &[AppliedMemberConstraint] { @@ -1088,7 +1088,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// include the CFG anyhow. /// - For each `end('x)` element in `'r`, compute the mutual LUB, yielding /// a result `'y`. - pub(in crate::borrow_check) fn universal_upper_bound(&self, r: RegionVid) -> RegionVid { + pub(crate) fn universal_upper_bound(&self, r: RegionVid) -> RegionVid { debug!("universal_upper_bound(r={:?}={})", r, self.region_value_str(r)); // Find the smallest universal region that contains all other @@ -1115,7 +1115,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// Therefore, this method should only be used in diagnostic code, /// where displaying *some* named universal region is better than /// falling back to 'static. - pub(in crate::borrow_check) fn approx_universal_upper_bound(&self, r: RegionVid) -> RegionVid { + pub(crate) fn approx_universal_upper_bound(&self, r: RegionVid) -> RegionVid { debug!("approx_universal_upper_bound(r={:?}={})", r, self.region_value_str(r)); // Find the smallest universal region that contains all other diff --git a/compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs similarity index 97% rename from compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs rename to compiler/rustc_borrowck/src/region_infer/opaque_types.rs index 12fceeff0884c..39b83e5043101 100644 --- a/compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs +++ b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs @@ -47,7 +47,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// which has no `external_name` in which case we use `'empty` as the /// region to pass to `infer_opaque_definition_from_instantiation`. #[instrument(skip(self, infcx))] - pub(in crate::borrow_check) fn infer_opaque_types( + pub(crate) fn infer_opaque_types( &self, infcx: &InferCtxt<'_, 'tcx>, opaque_ty_decls: VecMap, Ty<'tcx>>, @@ -105,7 +105,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// that the regions produced are in fact equal to the named region they are /// replaced with. This is fine because this function is only to improve the /// region names in error messages. - pub(in crate::borrow_check) fn name_regions(&self, tcx: TyCtxt<'tcx>, ty: T) -> T + pub(crate) fn name_regions(&self, tcx: TyCtxt<'tcx>, ty: T) -> T where T: TypeFoldable<'tcx>, { diff --git a/compiler/rustc_mir/src/borrow_check/region_infer/reverse_sccs.rs b/compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs similarity index 95% rename from compiler/rustc_mir/src/borrow_check/region_infer/reverse_sccs.rs rename to compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs index 5d345a6e63d6b..056907dcb1656 100644 --- a/compiler/rustc_mir/src/borrow_check/region_infer/reverse_sccs.rs +++ b/compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs @@ -1,5 +1,5 @@ -use crate::borrow_check::constraints::ConstraintSccIndex; -use crate::borrow_check::RegionInferenceContext; +use crate::constraints::ConstraintSccIndex; +use crate::RegionInferenceContext; use itertools::Itertools; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::graph::vec_graph::VecGraph; diff --git a/compiler/rustc_mir/src/borrow_check/region_infer/values.rs b/compiler/rustc_borrowck/src/region_infer/values.rs similarity index 100% rename from compiler/rustc_mir/src/borrow_check/region_infer/values.rs rename to compiler/rustc_borrowck/src/region_infer/values.rs diff --git a/compiler/rustc_mir/src/borrow_check/renumber.rs b/compiler/rustc_borrowck/src/renumber.rs similarity index 100% rename from compiler/rustc_mir/src/borrow_check/renumber.rs rename to compiler/rustc_borrowck/src/renumber.rs diff --git a/compiler/rustc_mir/src/borrow_check/type_check/canonical.rs b/compiler/rustc_borrowck/src/type_check/canonical.rs similarity index 98% rename from compiler/rustc_mir/src/borrow_check/type_check/canonical.rs rename to compiler/rustc_borrowck/src/type_check/canonical.rs index b501716a89975..7a8c0a3da1f1f 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/canonical.rs +++ b/compiler/rustc_borrowck/src/type_check/canonical.rs @@ -8,7 +8,7 @@ use rustc_span::Span; use rustc_trait_selection::traits::query::type_op::{self, TypeOpOutput}; use rustc_trait_selection::traits::query::Fallible; -use crate::borrow_check::diagnostics::{ToUniverseInfo, UniverseInfo}; +use crate::diagnostics::{ToUniverseInfo, UniverseInfo}; use super::{Locations, NormalizeLocation, TypeChecker}; diff --git a/compiler/rustc_mir/src/borrow_check/type_check/constraint_conversion.rs b/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/type_check/constraint_conversion.rs rename to compiler/rustc_borrowck/src/type_check/constraint_conversion.rs index 446a0f8e72fbd..b020746848535 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/constraint_conversion.rs +++ b/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs @@ -9,7 +9,7 @@ use rustc_middle::ty::subst::GenericArgKind; use rustc_middle::ty::{self, TyCtxt}; use rustc_span::DUMMY_SP; -use crate::borrow_check::{ +use crate::{ constraints::OutlivesConstraint, nll::ToRegionVid, region_infer::TypeTest, diff --git a/compiler/rustc_mir/src/borrow_check/type_check/free_region_relations.rs b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/type_check/free_region_relations.rs rename to compiler/rustc_borrowck/src/type_check/free_region_relations.rs index 6426098d843fe..e1e8f6a61adb8 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/free_region_relations.rs +++ b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs @@ -13,7 +13,7 @@ use rustc_trait_selection::traits::query::type_op::{self, TypeOp}; use std::rc::Rc; use type_op::TypeOpOutput; -use crate::borrow_check::{ +use crate::{ nll::ToRegionVid, type_check::constraint_conversion, type_check::{Locations, MirTypeckRegionConstraints}, @@ -55,7 +55,7 @@ type RegionBoundPairs<'tcx> = Vec<(ty::Region<'tcx>, GenericKind<'tcx>)>; type NormalizedInputsAndOutput<'tcx> = Vec>; crate struct CreateResult<'tcx> { - pub(in crate::borrow_check) universal_region_relations: Frozen>, + crate universal_region_relations: Frozen>, crate region_bound_pairs: RegionBoundPairs<'tcx>, crate normalized_inputs_and_output: NormalizedInputsAndOutput<'tcx>, } diff --git a/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs b/compiler/rustc_borrowck/src/type_check/input_output.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/type_check/input_output.rs rename to compiler/rustc_borrowck/src/type_check/input_output.rs index ba9b6926526be..9d6f6f60a94f9 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs +++ b/compiler/rustc_borrowck/src/type_check/input_output.rs @@ -7,16 +7,15 @@ //! `RETURN_PLACE` the MIR arguments) are always fully normalized (and //! contain revealed `impl Trait` values). +use rustc_index::vec::Idx; use rustc_infer::infer::LateBoundRegionConversionTime; use rustc_middle::mir::*; use rustc_middle::traits::ObligationCause; use rustc_middle::ty::{self, Ty}; -use rustc_trait_selection::traits::query::normalize::AtExt; - -use rustc_index::vec::Idx; use rustc_span::Span; +use rustc_trait_selection::traits::query::normalize::AtExt; -use crate::borrow_check::universal_regions::UniversalRegions; +use crate::universal_regions::UniversalRegions; use super::{Locations, TypeChecker}; diff --git a/compiler/rustc_mir/src/borrow_check/type_check/liveness/local_use_map.rs b/compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs similarity index 97% rename from compiler/rustc_mir/src/borrow_check/type_check/liveness/local_use_map.rs rename to compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs index 7e8a33efe114e..8b74abd94c077 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/liveness/local_use_map.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs @@ -3,8 +3,8 @@ use rustc_index::vec::IndexVec; use rustc_middle::mir::visit::{PlaceContext, Visitor}; use rustc_middle::mir::{Body, Local, Location}; -use crate::borrow_check::def_use::{self, DefUse}; -use crate::borrow_check::region_infer::values::{PointIndex, RegionValueElements}; +use crate::def_use::{self, DefUse}; +use crate::region_infer::values::{PointIndex, RegionValueElements}; /// A map that cross references each local with the locations where it /// is defined (assigned), used, or dropped. Used during liveness diff --git a/compiler/rustc_mir/src/borrow_check/type_check/liveness/mod.rs b/compiler/rustc_borrowck/src/type_check/liveness/mod.rs similarity index 96% rename from compiler/rustc_mir/src/borrow_check/type_check/liveness/mod.rs rename to compiler/rustc_borrowck/src/type_check/liveness/mod.rs index a34ae281b70df..265c14bb28676 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/liveness/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/mod.rs @@ -3,11 +3,11 @@ use rustc_middle::mir::{Body, Local}; use rustc_middle::ty::{RegionVid, TyCtxt}; use std::rc::Rc; -use crate::dataflow::impls::MaybeInitializedPlaces; -use crate::dataflow::move_paths::MoveData; -use crate::dataflow::ResultsCursor; +use rustc_mir::dataflow::impls::MaybeInitializedPlaces; +use rustc_mir::dataflow::move_paths::MoveData; +use rustc_mir::dataflow::ResultsCursor; -use crate::borrow_check::{ +use crate::{ constraints::OutlivesConstraintSet, facts::{AllFacts, AllFactsExt}, location::LocationTable, diff --git a/compiler/rustc_mir/src/borrow_check/type_check/liveness/polonius.rs b/compiler/rustc_borrowck/src/type_check/liveness/polonius.rs similarity index 96% rename from compiler/rustc_mir/src/borrow_check/type_check/liveness/polonius.rs rename to compiler/rustc_borrowck/src/type_check/liveness/polonius.rs index d285098c52ad2..7c087d38eb748 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/liveness/polonius.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/polonius.rs @@ -1,10 +1,9 @@ -use crate::borrow_check::def_use::{self, DefUse}; -use crate::borrow_check::location::{LocationIndex, LocationTable}; -use crate::dataflow::indexes::MovePathIndex; -use crate::dataflow::move_paths::{LookupResult, MoveData}; +use crate::def_use::{self, DefUse}; +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 super::TypeChecker; diff --git a/compiler/rustc_mir/src/borrow_check/type_check/liveness/trace.rs b/compiler/rustc_borrowck/src/type_check/liveness/trace.rs similarity index 98% rename from compiler/rustc_mir/src/borrow_check/type_check/liveness/trace.rs rename to compiler/rustc_borrowck/src/type_check/liveness/trace.rs index 566c11811e6e1..c7d776bfde0d4 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/liveness/trace.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/trace.rs @@ -8,12 +8,11 @@ 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 crate::dataflow::impls::MaybeInitializedPlaces; -use crate::dataflow::indexes::MovePathIndex; -use crate::dataflow::move_paths::{HasMoveData, MoveData}; -use crate::dataflow::ResultsCursor; +use rustc_mir::dataflow::impls::MaybeInitializedPlaces; +use rustc_mir::dataflow::move_paths::{HasMoveData, MoveData, MovePathIndex}; +use rustc_mir::dataflow::ResultsCursor; -use crate::borrow_check::{ +use crate::{ region_infer::values::{self, PointIndex, RegionValueElements}, type_check::liveness::local_use_map::LocalUseMap, type_check::liveness::polonius, diff --git a/compiler/rustc_mir/src/borrow_check/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/type_check/mod.rs rename to compiler/rustc_borrowck/src/type_check/mod.rs index 639bcb8fa94ef..63075d066a6dc 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -41,14 +41,14 @@ 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 crate::dataflow::impls::MaybeInitializedPlaces; -use crate::dataflow::move_paths::MoveData; -use crate::dataflow::ResultsCursor; -use crate::transform::{ +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 crate::borrow_check::{ +use crate::{ borrow_set::BorrowSet, constraints::{OutlivesConstraint, OutlivesConstraintSet}, diagnostics::UniverseInfo, @@ -68,7 +68,7 @@ use crate::borrow_check::{ macro_rules! span_mirbug { ($context:expr, $elem:expr, $($message:tt)*) => ({ - $crate::borrow_check::type_check::mirbug( + $crate::type_check::mirbug( $context.tcx(), $context.last_span, &format!( @@ -887,7 +887,7 @@ struct BorrowCheckContext<'a, 'tcx> { crate struct MirTypeckResults<'tcx> { crate constraints: MirTypeckRegionConstraints<'tcx>, - pub(in crate::borrow_check) universal_region_relations: Frozen>, + crate universal_region_relations: Frozen>, crate opaque_type_values: VecMap, Ty<'tcx>>, } diff --git a/compiler/rustc_mir/src/borrow_check/type_check/relate_tys.rs b/compiler/rustc_borrowck/src/type_check/relate_tys.rs similarity index 96% rename from compiler/rustc_mir/src/borrow_check/type_check/relate_tys.rs rename to compiler/rustc_borrowck/src/type_check/relate_tys.rs index 971c4daa6b311..0b9c33ccb775a 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/relate_tys.rs +++ b/compiler/rustc_borrowck/src/type_check/relate_tys.rs @@ -5,9 +5,9 @@ use rustc_middle::ty::relate::TypeRelation; use rustc_middle::ty::{self, Const, Ty}; use rustc_trait_selection::traits::query::Fallible; -use crate::borrow_check::constraints::OutlivesConstraint; -use crate::borrow_check::diagnostics::UniverseInfo; -use crate::borrow_check::type_check::{BorrowCheckContext, Locations}; +use crate::constraints::OutlivesConstraint; +use crate::diagnostics::UniverseInfo; +use crate::type_check::{BorrowCheckContext, Locations}; /// Adds sufficient constraints to ensure that `a R b` where `R` depends on `v`: /// diff --git a/compiler/rustc_mir/src/borrow_check/universal_regions.rs b/compiler/rustc_borrowck/src/universal_regions.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/universal_regions.rs rename to compiler/rustc_borrowck/src/universal_regions.rs index 3c9b4272b3649..bebd19370299d 100644 --- a/compiler/rustc_mir/src/borrow_check/universal_regions.rs +++ b/compiler/rustc_borrowck/src/universal_regions.rs @@ -26,7 +26,7 @@ use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef}; use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt}; use std::iter; -use crate::borrow_check::nll::ToRegionVid; +use crate::nll::ToRegionVid; #[derive(Debug)] pub struct UniversalRegions<'tcx> { diff --git a/compiler/rustc_mir/src/borrow_check/used_muts.rs b/compiler/rustc_borrowck/src/used_muts.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/used_muts.rs rename to compiler/rustc_borrowck/src/used_muts.rs index e027056842db9..6022a9809502b 100644 --- a/compiler/rustc_mir/src/borrow_check/used_muts.rs +++ b/compiler/rustc_borrowck/src/used_muts.rs @@ -1,11 +1,10 @@ +use rustc_data_structures::fx::FxHashSet; use rustc_middle::mir::visit::{PlaceContext, Visitor}; use rustc_middle::mir::{ Local, Location, Place, Statement, StatementKind, Terminator, TerminatorKind, }; -use rustc_data_structures::fx::FxHashSet; - -use crate::borrow_check::MirBorrowckCtxt; +use crate::MirBorrowckCtxt; impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { /// Walks the MIR adding to the set of `used_mut` locals that will be ignored for the purposes diff --git a/compiler/rustc_interface/Cargo.toml b/compiler/rustc_interface/Cargo.toml index dad5b256e42ab..970267d626cd8 100644 --- a/compiler/rustc_interface/Cargo.toml +++ b/compiler/rustc_interface/Cargo.toml @@ -14,6 +14,7 @@ rayon = { version = "0.3.1", package = "rustc-rayon" } smallvec = { version = "1.6.1", features = ["union", "may_dangle"] } rustc_ast = { path = "../rustc_ast" } rustc_attr = { path = "../rustc_attr" } +rustc_borrowck = { path = "../rustc_borrowck" } rustc_builtin_macros = { path = "../rustc_builtin_macros" } rustc_expand = { path = "../rustc_expand" } rustc_parse = { path = "../rustc_parse" } diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 1d542db9b69c3..df03ff59f461a 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -4,6 +4,7 @@ use crate::util; use rustc_ast::mut_visit::MutVisitor; use rustc_ast::{self as ast, visit}; +use rustc_borrowck as mir_borrowck; use rustc_codegen_ssa::back::link::emit_metadata; use rustc_codegen_ssa::traits::CodegenBackend; use rustc_data_structures::parallel; @@ -739,6 +740,7 @@ pub static DEFAULT_QUERY_PROVIDERS: SyncLazy = SyncLazy::new(|| { proc_macro_decls::provide(providers); rustc_middle::hir::provide(providers); mir::provide(providers); + mir_borrowck::provide(providers); mir_build::provide(providers); rustc_privacy::provide(providers); typeck::provide(providers); diff --git a/compiler/rustc_mir/Cargo.toml b/compiler/rustc_mir/Cargo.toml index 3049fb3b383b3..43c7b681e05f2 100644 --- a/compiler/rustc_mir/Cargo.toml +++ b/compiler/rustc_mir/Cargo.toml @@ -8,30 +8,28 @@ doctest = false [dependencies] either = "1.5.0" -rustc_graphviz = { path = "../rustc_graphviz" } gsgdt = "0.1.2" itertools = "0.9" -tracing = "0.1" polonius-engine = "0.13.0" regex = "1" -rustc_middle = { path = "../rustc_middle" } +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_lexer = { path = "../rustc_lexer" } rustc_macros = { path = "../rustc_macros" } +rustc_middle = { path = "../rustc_middle" } rustc_serialize = { path = "../rustc_serialize" } rustc_session = { path = "../rustc_session" } rustc_target = { path = "../rustc_target" } rustc_trait_selection = { path = "../rustc_trait_selection" } -rustc_traits = { path = "../rustc_traits" } -rustc_ast = { path = "../rustc_ast" } rustc_span = { path = "../rustc_span" } -rustc_apfloat = { path = "../rustc_apfloat" } -smallvec = { version = "1.6.1", features = ["union", "may_dangle"] } [dev-dependencies] coverage_test_macros = { path = "src/transform/coverage/test_macros" } diff --git a/compiler/rustc_mir/src/dataflow/drop_flag_effects.rs b/compiler/rustc_mir/src/dataflow/drop_flag_effects.rs index d16366fded900..d4f8f994ae904 100644 --- a/compiler/rustc_mir/src/dataflow/drop_flag_effects.rs +++ b/compiler/rustc_mir/src/dataflow/drop_flag_effects.rs @@ -204,7 +204,7 @@ pub(crate) fn drop_flag_effects_for_location<'tcx, F>( for_location_inits(tcx, body, move_data, loc, |mpi| callback(mpi, DropFlagState::Present)); } -pub(crate) fn for_location_inits<'tcx, F>( +pub fn for_location_inits<'tcx, F>( tcx: TyCtxt<'tcx>, body: &Body<'tcx>, move_data: &MoveData<'tcx>, diff --git a/compiler/rustc_mir/src/dataflow/framework/mod.rs b/compiler/rustc_mir/src/dataflow/framework/mod.rs index a5badc07d1017..0bf62db1adac9 100644 --- a/compiler/rustc_mir/src/dataflow/framework/mod.rs +++ b/compiler/rustc_mir/src/dataflow/framework/mod.rs @@ -50,8 +50,7 @@ pub use self::cursor::{ResultsCursor, ResultsRefCursor}; pub use self::direction::{Backward, Direction, Forward}; pub use self::engine::{Engine, Results}; pub use self::lattice::{JoinSemiLattice, MeetSemiLattice}; -pub use self::visitor::{visit_results, ResultsVisitor}; -pub use self::visitor::{BorrowckFlowState, BorrowckResults}; +pub use self::visitor::{visit_results, ResultsVisitable, ResultsVisitor}; /// Define the domain of a dataflow problem. /// diff --git a/compiler/rustc_mir/src/dataflow/framework/visitor.rs b/compiler/rustc_mir/src/dataflow/framework/visitor.rs index 82eb734ed0699..84136c4d78cf1 100644 --- a/compiler/rustc_mir/src/dataflow/framework/visitor.rs +++ b/compiler/rustc_mir/src/dataflow/framework/visitor.rs @@ -1,7 +1,6 @@ use rustc_middle::mir::{self, BasicBlock, Location}; use super::{Analysis, Direction, Results}; -use crate::dataflow::impls::{borrows::Borrows, EverInitializedPlaces, MaybeUninitializedPlaces}; /// Calls the corresponding method in `ResultsVisitor` for every location in a `mir::Body` with the /// dataflow state at that location. @@ -186,95 +185,3 @@ where self.analysis.apply_terminator_effect(state, term, loc); } } - -/// A tuple with named fields that can hold either the results or the transient state of the -/// dataflow analyses used by the borrow checker. -#[derive(Debug)] -pub struct BorrowckAnalyses { - pub borrows: B, - pub uninits: U, - pub ever_inits: E, -} - -/// The results of the dataflow analyses used by the borrow checker. -pub type BorrowckResults<'mir, 'tcx> = BorrowckAnalyses< - Results<'tcx, Borrows<'mir, 'tcx>>, - Results<'tcx, MaybeUninitializedPlaces<'mir, 'tcx>>, - Results<'tcx, EverInitializedPlaces<'mir, 'tcx>>, ->; - -/// The transient state of the dataflow analyses used by the borrow checker. -pub type BorrowckFlowState<'mir, 'tcx> = - as ResultsVisitable<'tcx>>::FlowState; - -macro_rules! impl_visitable { - ( $( - $T:ident { $( $field:ident : $A:ident ),* $(,)? } - )* ) => { $( - impl<'tcx, $($A),*, D: Direction> ResultsVisitable<'tcx> for $T<$( Results<'tcx, $A> ),*> - where - $( $A: Analysis<'tcx, Direction = D>, )* - { - type Direction = D; - type FlowState = $T<$( $A::Domain ),*>; - - fn new_flow_state(&self, body: &mir::Body<'tcx>) -> Self::FlowState { - $T { - $( $field: self.$field.analysis.bottom_value(body) ),* - } - } - - fn reset_to_block_entry( - &self, - state: &mut Self::FlowState, - block: BasicBlock, - ) { - $( state.$field.clone_from(&self.$field.entry_set_for_block(block)); )* - } - - fn reconstruct_before_statement_effect( - &self, - state: &mut Self::FlowState, - stmt: &mir::Statement<'tcx>, - loc: Location, - ) { - $( self.$field.analysis - .apply_before_statement_effect(&mut state.$field, stmt, loc); )* - } - - fn reconstruct_statement_effect( - &self, - state: &mut Self::FlowState, - stmt: &mir::Statement<'tcx>, - loc: Location, - ) { - $( self.$field.analysis - .apply_statement_effect(&mut state.$field, stmt, loc); )* - } - - fn reconstruct_before_terminator_effect( - &self, - state: &mut Self::FlowState, - term: &mir::Terminator<'tcx>, - loc: Location, - ) { - $( self.$field.analysis - .apply_before_terminator_effect(&mut state.$field, term, loc); )* - } - - fn reconstruct_terminator_effect( - &self, - state: &mut Self::FlowState, - term: &mir::Terminator<'tcx>, - loc: Location, - ) { - $( self.$field.analysis - .apply_terminator_effect(&mut state.$field, term, loc); )* - } - } - )* } -} - -impl_visitable! { - BorrowckAnalyses { borrows: B, uninits: U, ever_inits: E } -} diff --git a/compiler/rustc_mir/src/dataflow/impls/mod.rs b/compiler/rustc_mir/src/dataflow/impls/mod.rs index 185f0edfeb6bc..020a7b188fd13 100644 --- a/compiler/rustc_mir/src/dataflow/impls/mod.rs +++ b/compiler/rustc_mir/src/dataflow/impls/mod.rs @@ -21,13 +21,11 @@ use crate::dataflow::drop_flag_effects; use crate::dataflow::framework::SwitchIntEdgeEffects; mod borrowed_locals; -pub(super) mod borrows; mod init_locals; mod liveness; mod storage_liveness; pub use self::borrowed_locals::{MaybeBorrowedLocals, MaybeMutBorrowedLocals}; -pub use self::borrows::Borrows; pub use self::init_locals::MaybeInitializedLocals; pub use self::liveness::MaybeLiveLocals; pub use self::storage_liveness::{MaybeRequiresStorage, MaybeStorageLive}; diff --git a/compiler/rustc_mir/src/dataflow/mod.rs b/compiler/rustc_mir/src/dataflow/mod.rs index 8a426cc1015cc..bb38f90a3ba63 100644 --- a/compiler/rustc_mir/src/dataflow/mod.rs +++ b/compiler/rustc_mir/src/dataflow/mod.rs @@ -5,9 +5,9 @@ use rustc_span::symbol::{sym, Symbol}; pub(crate) use self::drop_flag_effects::*; pub use self::framework::{ - fmt, graphviz, lattice, visit_results, Analysis, AnalysisDomain, Backward, BorrowckFlowState, - BorrowckResults, Engine, Forward, GenKill, GenKillAnalysis, JoinSemiLattice, Results, - ResultsCursor, ResultsRefCursor, ResultsVisitor, SwitchIntEdgeEffects, + fmt, lattice, visit_results, Analysis, AnalysisDomain, Backward, Direction, Engine, Forward, + GenKill, GenKillAnalysis, JoinSemiLattice, Results, ResultsCursor, ResultsRefCursor, + ResultsVisitable, ResultsVisitor, }; use self::move_paths::MoveData; @@ -18,15 +18,12 @@ pub mod impls; pub mod move_paths; pub(crate) mod indexes { - pub(crate) use super::{ - impls::borrows::BorrowIndex, - move_paths::{InitIndex, MoveOutIndex, MovePathIndex}, - }; + pub(crate) use super::move_paths::MovePathIndex; } pub struct MoveDataParamEnv<'tcx> { - pub(crate) move_data: MoveData<'tcx>, - pub(crate) param_env: ty::ParamEnv<'tcx>, + pub move_data: MoveData<'tcx>, + pub param_env: ty::ParamEnv<'tcx>, } pub(crate) fn has_rustc_mir_with( diff --git a/compiler/rustc_mir/src/dataflow/move_paths/mod.rs b/compiler/rustc_mir/src/dataflow/move_paths/mod.rs index 7c63025918603..699ec4bbff80f 100644 --- a/compiler/rustc_mir/src/dataflow/move_paths/mod.rs +++ b/compiler/rustc_mir/src/dataflow/move_paths/mod.rs @@ -19,6 +19,12 @@ rustc_index::newtype_index! { } } +impl polonius_engine::Atom for MovePathIndex { + fn index(self) -> usize { + rustc_index::vec::Idx::index(self) + } +} + rustc_index::newtype_index! { pub struct MoveOutIndex { DEBUG_FORMAT = "mo{}" @@ -276,7 +282,7 @@ impl fmt::Debug for Init { } impl Init { - crate fn span<'tcx>(&self, body: &Body<'tcx>) -> Span { + pub fn span<'tcx>(&self, body: &Body<'tcx>) -> Span { match self.location { InitLocation::Argument(local) => body.local_decls[local].source_info.span, InitLocation::Statement(location) => body.source_info(location).span, @@ -338,12 +344,12 @@ impl MovePathLookup { #[derive(Debug)] pub struct IllegalMoveOrigin<'tcx> { - pub(crate) location: Location, - pub(crate) kind: IllegalMoveOriginKind<'tcx>, + pub location: Location, + pub kind: IllegalMoveOriginKind<'tcx>, } #[derive(Debug)] -pub(crate) enum IllegalMoveOriginKind<'tcx> { +pub enum IllegalMoveOriginKind<'tcx> { /// Illegal move due to attempt to move from behind a reference. BorrowedContent { /// The place the reference refers to: if erroneous code was trying to diff --git a/compiler/rustc_mir/src/lib.rs b/compiler/rustc_mir/src/lib.rs index e439a247c7f6c..16dddc949df31 100644 --- a/compiler/rustc_mir/src/lib.rs +++ b/compiler/rustc_mir/src/lib.rs @@ -4,40 +4,35 @@ Rust MIR: a lowered representation of Rust. */ -#![feature(nll)] -#![feature(in_band_lifetimes)] #![feature(array_windows)] #![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)] #![feature(crate_visibility_modifier)] #![feature(decl_macro)] #![feature(exact_size_is_empty)] -#![feature(format_args_capture)] +#![feature(in_band_lifetimes)] #![feature(iter_zip)] -#![feature(never_type)] #![feature(map_try_insert)] #![feature(min_specialization)] #![feature(slice_ptr_get)] -#![feature(trusted_len)] -#![feature(try_blocks)] -#![feature(associated_type_defaults)] -#![feature(stmt_expr_attributes)] -#![feature(trait_alias)] #![feature(option_get_or_insert_default)] #![feature(once_cell)] -#![feature(control_flow_enum)] -#![feature(try_reserve)] -#![feature(try_reserve_kind)] -#![recursion_limit = "256"] +#![feature(never_type)] +#![feature(stmt_expr_attributes)] +#![feature(trait_alias)] +#![feature(trusted_len)] +#![feature(trusted_step)] +#![feature(try_blocks)] #[macro_use] extern crate tracing; #[macro_use] extern crate rustc_middle; -mod borrow_check; pub mod const_eval; pub mod dataflow; pub mod interpret; @@ -46,13 +41,9 @@ mod shim; pub mod transform; pub mod util; -// A public API provided for the Rust compiler consumers. -pub use self::borrow_check::consumers; - use rustc_middle::ty::query::Providers; pub fn provide(providers: &mut Providers) { - borrow_check::provide(providers); const_eval::provide(providers); shim::provide(providers); transform::provide(providers); diff --git a/compiler/rustc_mir/src/transform/promote_consts.rs b/compiler/rustc_mir/src/transform/promote_consts.rs index 1b43670ba3ac1..6822ad2d7b5dd 100644 --- a/compiler/rustc_mir/src/transform/promote_consts.rs +++ b/compiler/rustc_mir/src/transform/promote_consts.rs @@ -1058,7 +1058,7 @@ pub fn promote_candidates<'tcx>( /// This function returns `true` if the function being called in the array /// repeat expression is a `const` function. -crate fn is_const_fn_in_array_repeat_expression<'tcx>( +pub fn is_const_fn_in_array_repeat_expression<'tcx>( ccx: &ConstCx<'_, 'tcx>, place: &Place<'tcx>, body: &Body<'tcx>, diff --git a/compiler/rustc_mir/src/util/collect_writes.rs b/compiler/rustc_mir/src/util/collect_writes.rs index ecf3b08a96eed..9c56fd722bda6 100644 --- a/compiler/rustc_mir/src/util/collect_writes.rs +++ b/compiler/rustc_mir/src/util/collect_writes.rs @@ -2,7 +2,7 @@ use rustc_middle::mir::visit::PlaceContext; use rustc_middle::mir::visit::Visitor; use rustc_middle::mir::{Body, Local, Location}; -crate trait FindAssignments { +pub trait FindAssignments { // Finds all statements that assign directly to local (i.e., X = ...) // and returns their locations. fn find_assignments(&self, local: Local) -> Vec; diff --git a/compiler/rustc_mir/src/util/mod.rs b/compiler/rustc_mir/src/util/mod.rs index 3e466b5060feb..8f9db6daba733 100644 --- a/compiler/rustc_mir/src/util/mod.rs +++ b/compiler/rustc_mir/src/util/mod.rs @@ -1,5 +1,4 @@ pub mod aggregate; -pub mod borrowck_errors; pub mod elaborate_drops; pub mod patch; pub mod storage; @@ -10,7 +9,7 @@ mod find_self_call; mod generic_graph; pub(crate) mod generic_graphviz; mod graphviz; -pub(crate) mod pretty; +pub mod pretty; pub(crate) mod spanview; pub use self::aggregate::expand_aggregate; diff --git a/compiler/rustc_mir/src/util/pretty.rs b/compiler/rustc_mir/src/util/pretty.rs index 92591db668ce9..ec1aa5b476bb7 100644 --- a/compiler/rustc_mir/src/util/pretty.rs +++ b/compiler/rustc_mir/src/util/pretty.rs @@ -250,7 +250,7 @@ fn create_dump_file_with_basename( /// bit of MIR-related data. Used by `mir-dump`, but also by other /// bits of code (e.g., NLL inference) that dump graphviz data or /// other things, and hence takes the extension as an argument. -pub(crate) fn create_dump_file( +pub fn create_dump_file( tcx: TyCtxt<'_>, extension: &str, pass_num: Option<&dyn Display>, From bba4be681d664a50ab307ec732f957c02255e067 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 1 Jan 2021 01:53:25 +0100 Subject: [PATCH 2/7] Move rustc_mir::transform to rustc_mir_transform. --- Cargo.lock | 26 +- compiler/rustc_interface/Cargo.toml | 1 + compiler/rustc_interface/src/passes.rs | 5 +- compiler/rustc_mir/Cargo.toml | 4 - .../src/dataflow/drop_flag_effects.rs | 10 +- compiler/rustc_mir/src/dataflow/mod.rs | 8 +- compiler/rustc_mir/src/interpret/intern.rs | 2 +- compiler/rustc_mir/src/interpret/operand.rs | 6 +- compiler/rustc_mir/src/interpret/step.rs | 2 +- compiler/rustc_mir/src/lib.rs | 5 - compiler/rustc_mir/src/transform/mod.rs | 605 +---------------- compiler/rustc_mir/src/util/mod.rs | 4 +- compiler/rustc_mir/src/util/pretty.rs | 2 +- compiler/rustc_mir_transform/Cargo.toml | 29 + .../src}/abort_unwinding_calls.rs | 2 +- .../src}/add_call_guards.rs | 2 +- .../src}/add_moves_for_packed_drops.rs | 2 +- .../src}/add_retag.rs | 2 +- .../src}/check_const_item_mutation.rs | 2 +- .../src}/check_packed_ref.rs | 2 +- .../src}/check_unsafety.rs | 0 .../src}/cleanup_post_borrowck.rs | 2 +- .../src}/const_debuginfo.rs | 2 +- .../src}/const_goto.rs | 2 +- .../src}/const_prop.rs | 6 +- .../src}/coverage/counters.rs | 0 .../src}/coverage/debug.rs | 16 +- .../src}/coverage/graph.rs | 0 .../src}/coverage/mod.rs | 2 +- .../src}/coverage/query.rs | 0 .../src}/coverage/spans.rs | 0 .../src}/coverage/test_macros/Cargo.toml | 0 .../src}/coverage/test_macros/src/lib.rs | 0 .../src}/coverage/tests.rs | 0 .../src}/deaggregator.rs | 2 +- .../src}/deduplicate_blocks.rs | 2 +- .../src}/dest_prop.rs | 6 +- .../src}/dump_mir.rs | 2 +- .../src}/early_otherwise_branch.rs | 2 +- .../src}/elaborate_drops.rs | 16 +- .../src}/function_item_references.rs | 2 +- .../src}/generator.rs | 12 +- .../src}/inline.rs | 2 +- .../src}/inline/cycle.rs | 0 .../src}/instcombine.rs | 2 +- compiler/rustc_mir_transform/src/lib.rs | 632 ++++++++++++++++++ .../src}/lower_intrinsics.rs | 2 +- .../src}/lower_slice_len.rs | 2 +- .../src}/match_branches.rs | 4 +- .../src}/multiple_return_terminators.rs | 2 +- .../src}/nrvo.rs | 2 +- .../src}/remove_noop_landing_pads.rs | 2 +- .../src}/remove_storage_markers.rs | 2 +- .../src}/remove_unneeded_drops.rs | 2 +- .../src}/remove_zsts.rs | 2 +- .../src}/required_consts.rs | 0 .../src}/separate_const_switch.rs | 2 +- .../src/shim.rs | 8 +- .../src}/simplify.rs | 2 +- .../src}/simplify_branches.rs | 2 +- .../src}/simplify_comparison_integral.rs | 0 .../src}/simplify_try.rs | 2 +- .../src}/uninhabited_enum_branching.rs | 2 +- .../src}/unreachable_prop.rs | 4 +- 64 files changed, 775 insertions(+), 698 deletions(-) create mode 100644 compiler/rustc_mir_transform/Cargo.toml rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/abort_unwinding_calls.rs (99%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/add_call_guards.rs (98%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/add_moves_for_packed_drops.rs (99%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/add_retag.rs (99%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/check_const_item_mutation.rs (99%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/check_packed_ref.rs (99%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/check_unsafety.rs (100%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/cleanup_post_borrowck.rs (98%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/const_debuginfo.rs (99%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/const_goto.rs (99%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/const_prop.rs (99%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/coverage/counters.rs (100%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/coverage/debug.rs (98%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/coverage/graph.rs (100%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/coverage/mod.rs (99%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/coverage/query.rs (100%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/coverage/spans.rs (100%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/coverage/test_macros/Cargo.toml (100%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/coverage/test_macros/src/lib.rs (100%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/coverage/tests.rs (100%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/deaggregator.rs (98%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/deduplicate_blocks.rs (99%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/dest_prop.rs (99%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/dump_mir.rs (97%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/early_otherwise_branch.rs (99%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/elaborate_drops.rs (98%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/function_item_references.rs (99%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/generator.rs (99%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/inline.rs (99%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/inline/cycle.rs (100%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/instcombine.rs (99%) create mode 100644 compiler/rustc_mir_transform/src/lib.rs rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/lower_intrinsics.rs (99%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/lower_slice_len.rs (98%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/match_branches.rs (98%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/multiple_return_terminators.rs (96%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/nrvo.rs (99%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/remove_noop_landing_pads.rs (99%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/remove_storage_markers.rs (96%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/remove_unneeded_drops.rs (97%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/remove_zsts.rs (98%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/required_consts.rs (100%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/separate_const_switch.rs (99%) rename compiler/{rustc_mir => rustc_mir_transform}/src/shim.rs (99%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/simplify.rs (99%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/simplify_branches.rs (98%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/simplify_comparison_integral.rs (100%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/simplify_try.rs (99%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/uninhabited_enum_branching.rs (99%) rename compiler/{rustc_mir/src/transform => rustc_mir_transform/src}/unreachable_prop.rs (98%) diff --git a/Cargo.lock b/Cargo.lock index 81549bd1d2055..3ec143d2492f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3928,6 +3928,7 @@ dependencies = [ "rustc_middle", "rustc_mir", "rustc_mir_build", + "rustc_mir_transform", "rustc_parse", "rustc_passes", "rustc_plugin_impl", @@ -4071,10 +4072,8 @@ dependencies = [ name = "rustc_mir" version = "0.0.0" dependencies = [ - "coverage_test_macros", "either", "gsgdt", - "itertools 0.9.0", "polonius-engine", "regex", "rustc_apfloat", @@ -4120,6 +4119,29 @@ dependencies = [ "tracing", ] +[[package]] +name = "rustc_mir_transform" +version = "0.0.0" +dependencies = [ + "coverage_test_macros", + "itertools 0.9.0", + "rustc_ast", + "rustc_attr", + "rustc_data_structures", + "rustc_errors", + "rustc_hir", + "rustc_index", + "rustc_middle", + "rustc_mir", + "rustc_serialize", + "rustc_session", + "rustc_span", + "rustc_target", + "rustc_trait_selection", + "smallvec", + "tracing", +] + [[package]] name = "rustc_parse" version = "0.0.0" diff --git a/compiler/rustc_interface/Cargo.toml b/compiler/rustc_interface/Cargo.toml index 970267d626cd8..8b27726925835 100644 --- a/compiler/rustc_interface/Cargo.toml +++ b/compiler/rustc_interface/Cargo.toml @@ -34,6 +34,7 @@ rustc_hir = { path = "../rustc_hir" } rustc_metadata = { path = "../rustc_metadata" } rustc_mir = { path = "../rustc_mir" } rustc_mir_build = { path = "../rustc_mir_build" } +rustc_mir_transform = { path = "../rustc_mir_transform" } rustc_passes = { path = "../rustc_passes" } rustc_typeck = { path = "../rustc_typeck" } rustc_lint = { path = "../rustc_lint" } diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index df03ff59f461a..7d41db0d4aeee 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -742,6 +742,7 @@ pub static DEFAULT_QUERY_PROVIDERS: SyncLazy = SyncLazy::new(|| { mir::provide(providers); mir_borrowck::provide(providers); mir_build::provide(providers); + rustc_mir_transform::provide(providers); rustc_privacy::provide(providers); typeck::provide(providers); ty::provide(providers); @@ -913,7 +914,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> { for def_id in tcx.body_owners() { tcx.ensure().thir_check_unsafety(def_id); if !tcx.sess.opts.debugging_opts.thir_unsafeck { - mir::transform::check_unsafety::check_unsafety(tcx, def_id); + rustc_mir_transform::check_unsafety::check_unsafety(tcx, def_id); } if tcx.hir().body_const_context(def_id).is_some() { @@ -1061,7 +1062,7 @@ pub fn start_codegen<'tcx>( info!("Post-codegen\n{:?}", tcx.debug_stats()); if tcx.sess.opts.output_types.contains_key(&OutputType::Mir) { - if let Err(e) = mir::transform::dump_mir::emit_mir(tcx, outputs) { + if let Err(e) = rustc_mir_transform::dump_mir::emit_mir(tcx, outputs) { tcx.sess.err(&format!("could not emit MIR: {}", e)); tcx.sess.abort_if_errors(); } diff --git a/compiler/rustc_mir/Cargo.toml b/compiler/rustc_mir/Cargo.toml index 43c7b681e05f2..0207d9c012ed0 100644 --- a/compiler/rustc_mir/Cargo.toml +++ b/compiler/rustc_mir/Cargo.toml @@ -9,7 +9,6 @@ doctest = false [dependencies] either = "1.5.0" gsgdt = "0.1.2" -itertools = "0.9" polonius-engine = "0.13.0" regex = "1" smallvec = { version = "1.0", features = ["union", "may_dangle"] } @@ -30,6 +29,3 @@ rustc_session = { path = "../rustc_session" } rustc_target = { path = "../rustc_target" } rustc_trait_selection = { path = "../rustc_trait_selection" } rustc_span = { path = "../rustc_span" } - -[dev-dependencies] -coverage_test_macros = { path = "src/transform/coverage/test_macros" } diff --git a/compiler/rustc_mir/src/dataflow/drop_flag_effects.rs b/compiler/rustc_mir/src/dataflow/drop_flag_effects.rs index d4f8f994ae904..fa449a2368861 100644 --- a/compiler/rustc_mir/src/dataflow/drop_flag_effects.rs +++ b/compiler/rustc_mir/src/dataflow/drop_flag_effects.rs @@ -79,7 +79,7 @@ fn place_contents_drop_state_cannot_differ<'tcx>( } } -pub(crate) fn on_lookup_result_bits<'tcx, F>( +pub fn on_lookup_result_bits<'tcx, F>( tcx: TyCtxt<'tcx>, body: &Body<'tcx>, move_data: &MoveData<'tcx>, @@ -96,7 +96,7 @@ pub(crate) fn on_lookup_result_bits<'tcx, F>( } } -pub(crate) fn on_all_children_bits<'tcx, F>( +pub fn on_all_children_bits<'tcx, F>( tcx: TyCtxt<'tcx>, body: &Body<'tcx>, move_data: &MoveData<'tcx>, @@ -138,7 +138,7 @@ pub(crate) fn on_all_children_bits<'tcx, F>( on_all_children_bits(tcx, body, move_data, move_path_index, &mut each_child); } -pub(crate) fn on_all_drop_children_bits<'tcx, F>( +pub fn on_all_drop_children_bits<'tcx, F>( tcx: TyCtxt<'tcx>, body: &Body<'tcx>, ctxt: &MoveDataParamEnv<'tcx>, @@ -161,7 +161,7 @@ pub(crate) fn on_all_drop_children_bits<'tcx, F>( }) } -pub(crate) fn drop_flag_effects_for_function_entry<'tcx, F>( +pub fn drop_flag_effects_for_function_entry<'tcx, F>( tcx: TyCtxt<'tcx>, body: &Body<'tcx>, ctxt: &MoveDataParamEnv<'tcx>, @@ -179,7 +179,7 @@ pub(crate) fn drop_flag_effects_for_function_entry<'tcx, F>( } } -pub(crate) fn drop_flag_effects_for_location<'tcx, F>( +pub fn drop_flag_effects_for_location<'tcx, F>( tcx: TyCtxt<'tcx>, body: &Body<'tcx>, ctxt: &MoveDataParamEnv<'tcx>, diff --git a/compiler/rustc_mir/src/dataflow/mod.rs b/compiler/rustc_mir/src/dataflow/mod.rs index bb38f90a3ba63..f388d41d31771 100644 --- a/compiler/rustc_mir/src/dataflow/mod.rs +++ b/compiler/rustc_mir/src/dataflow/mod.rs @@ -3,7 +3,11 @@ use rustc_middle::ty; use rustc_session::Session; use rustc_span::symbol::{sym, Symbol}; -pub(crate) use self::drop_flag_effects::*; +pub use self::drop_flag_effects::{ + drop_flag_effects_for_function_entry, drop_flag_effects_for_location, + move_path_children_matching, on_all_children_bits, on_all_drop_children_bits, + on_lookup_result_bits, +}; pub use self::framework::{ fmt, lattice, visit_results, Analysis, AnalysisDomain, Backward, Direction, Engine, Forward, GenKill, GenKillAnalysis, JoinSemiLattice, Results, ResultsCursor, ResultsRefCursor, @@ -26,7 +30,7 @@ pub struct MoveDataParamEnv<'tcx> { pub param_env: ty::ParamEnv<'tcx>, } -pub(crate) fn has_rustc_mir_with( +pub fn has_rustc_mir_with( _sess: &Session, attrs: &[ast::Attribute], name: Symbol, diff --git a/compiler/rustc_mir/src/interpret/intern.rs b/compiler/rustc_mir/src/interpret/intern.rs index f2457d11d9ee3..84e79408397e5 100644 --- a/compiler/rustc_mir/src/interpret/intern.rs +++ b/compiler/rustc_mir/src/interpret/intern.rs @@ -420,7 +420,7 @@ impl<'mir, 'tcx: 'mir, M: super::intern::CompileTimeMachine<'mir, 'tcx, !>> /// A helper function that allocates memory for the layout given and gives you access to mutate /// it. Once your own mutation code is done, the backing `Allocation` is removed from the /// current `Memory` and returned. - pub(crate) fn intern_with_temp_alloc( + pub fn intern_with_temp_alloc( &mut self, layout: TyAndLayout<'tcx>, f: impl FnOnce( diff --git a/compiler/rustc_mir/src/interpret/operand.rs b/compiler/rustc_mir/src/interpret/operand.rs index e67a6690836ad..63aca67c9443c 100644 --- a/compiler/rustc_mir/src/interpret/operand.rs +++ b/compiler/rustc_mir/src/interpret/operand.rs @@ -296,7 +296,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { /// Note that for a given layout, this operation will either always fail or always /// succeed! Whether it succeeds depends on whether the layout can be represented /// in an `Immediate`, not on which data is stored there currently. - pub(crate) fn try_read_immediate( + pub fn try_read_immediate( &self, src: &OpTy<'tcx, M::PointerTag>, ) -> InterpResult<'tcx, Result, MPlaceTy<'tcx, M::PointerTag>>> { @@ -547,7 +547,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // in patterns via the `const_eval` module /// The `val` and `layout` are assumed to already be in our interpreter /// "universe" (param_env). - crate fn const_to_op( + pub fn const_to_op( &self, val: &ty::Const<'tcx>, layout: Option>, @@ -566,7 +566,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } } - crate fn mir_const_to_op( + pub fn mir_const_to_op( &self, val: &mir::ConstantKind<'tcx>, layout: Option>, diff --git a/compiler/rustc_mir/src/interpret/step.rs b/compiler/rustc_mir/src/interpret/step.rs index 1e96581c392d2..09bd07660a33e 100644 --- a/compiler/rustc_mir/src/interpret/step.rs +++ b/compiler/rustc_mir/src/interpret/step.rs @@ -76,7 +76,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { /// Runs the interpretation logic for the given `mir::Statement` at the current frame and /// statement counter. This also moves the statement counter forward. - crate fn statement(&mut self, stmt: &mir::Statement<'tcx>) -> InterpResult<'tcx> { + pub fn statement(&mut self, stmt: &mir::Statement<'tcx>) -> InterpResult<'tcx> { info!("{:?}", stmt); use rustc_middle::mir::StatementKind::*; diff --git a/compiler/rustc_mir/src/lib.rs b/compiler/rustc_mir/src/lib.rs index 16dddc949df31..4c79c7da15c52 100644 --- a/compiler/rustc_mir/src/lib.rs +++ b/compiler/rustc_mir/src/lib.rs @@ -37,7 +37,6 @@ pub mod const_eval; pub mod dataflow; pub mod interpret; pub mod monomorphize; -mod shim; pub mod transform; pub mod util; @@ -45,15 +44,11 @@ use rustc_middle::ty::query::Providers; pub fn provide(providers: &mut Providers) { const_eval::provide(providers); - shim::provide(providers); - transform::provide(providers); monomorphize::partitioning::provide(providers); monomorphize::polymorphize::provide(providers); providers.eval_to_const_value_raw = const_eval::eval_to_const_value_raw_provider; providers.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider; providers.const_caller_location = const_eval::const_caller_location; - providers.mir_callgraph_reachable = transform::inline::cycle::mir_callgraph_reachable; - providers.mir_inliner_callees = transform::inline::cycle::mir_inliner_callees; providers.destructure_const = |tcx, param_env_and_value| { let (param_env, value) = param_env_and_value.into_parts(); const_eval::destructure_const(tcx, param_env, value) diff --git a/compiler/rustc_mir/src/transform/mod.rs b/compiler/rustc_mir/src/transform/mod.rs index d4c2456e9a436..abf43dd1d23bb 100644 --- a/compiler/rustc_mir/src/transform/mod.rs +++ b/compiler/rustc_mir/src/transform/mod.rs @@ -1,149 +1,12 @@ -use crate::{shim, util}; -use required_consts::RequiredConstsVisitor; -use rustc_data_structures::fx::FxHashSet; -use rustc_data_structures::steal::Steal; -use rustc_hir as hir; -use rustc_hir::def_id::{DefId, LocalDefId}; -use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; -use rustc_index::vec::IndexVec; -use rustc_middle::mir::visit::Visitor as _; -use rustc_middle::mir::{traversal, Body, ConstQualifs, MirPhase, Promoted}; -use rustc_middle::ty::query::Providers; -use rustc_middle::ty::{self, TyCtxt, TypeFoldable}; -use rustc_span::{Span, Symbol}; +use rustc_middle::mir::Body; +use rustc_middle::ty::TyCtxt; use std::borrow::Cow; -pub mod abort_unwinding_calls; -pub mod add_call_guards; -pub mod add_moves_for_packed_drops; -pub mod add_retag; -pub mod check_const_item_mutation; pub mod check_consts; -pub mod check_packed_ref; -pub mod check_unsafety; -pub mod cleanup_post_borrowck; -pub mod const_debuginfo; -pub mod const_goto; -pub mod const_prop; -pub mod coverage; -pub mod deaggregator; -pub mod deduplicate_blocks; -pub mod dest_prop; -pub mod dump_mir; -pub mod early_otherwise_branch; -pub mod elaborate_drops; -pub mod function_item_references; -pub mod generator; -pub mod inline; -pub mod instcombine; -pub mod lower_intrinsics; -pub mod lower_slice_len; -pub mod match_branches; -pub mod multiple_return_terminators; -pub mod nrvo; pub mod promote_consts; -pub mod remove_noop_landing_pads; -pub mod remove_storage_markers; -pub mod remove_unneeded_drops; -pub mod remove_zsts; -pub mod required_consts; pub mod rustc_peek; -pub mod separate_const_switch; -pub mod simplify; -pub mod simplify_branches; -pub mod simplify_comparison_integral; -pub mod simplify_try; -pub mod uninhabited_enum_branching; -pub mod unreachable_prop; pub mod validate; -pub use rustc_middle::mir::MirSource; - -pub(crate) fn provide(providers: &mut Providers) { - self::check_unsafety::provide(providers); - self::check_packed_ref::provide(providers); - *providers = Providers { - mir_keys, - mir_const, - mir_const_qualif: |tcx, def_id| { - let def_id = def_id.expect_local(); - if let Some(def) = ty::WithOptConstParam::try_lookup(def_id, tcx) { - tcx.mir_const_qualif_const_arg(def) - } else { - mir_const_qualif(tcx, ty::WithOptConstParam::unknown(def_id)) - } - }, - mir_const_qualif_const_arg: |tcx, (did, param_did)| { - mir_const_qualif(tcx, ty::WithOptConstParam { did, const_param_did: Some(param_did) }) - }, - mir_promoted, - mir_drops_elaborated_and_const_checked, - mir_for_ctfe, - mir_for_ctfe_of_const_arg, - optimized_mir, - is_mir_available, - is_ctfe_mir_available: |tcx, did| is_mir_available(tcx, did), - promoted_mir: |tcx, def_id| { - let def_id = def_id.expect_local(); - if let Some(def) = ty::WithOptConstParam::try_lookup(def_id, tcx) { - tcx.promoted_mir_of_const_arg(def) - } else { - promoted_mir(tcx, ty::WithOptConstParam::unknown(def_id)) - } - }, - promoted_mir_of_const_arg: |tcx, (did, param_did)| { - promoted_mir(tcx, ty::WithOptConstParam { did, const_param_did: Some(param_did) }) - }, - ..*providers - }; - coverage::query::provide(providers); -} - -fn is_mir_available(tcx: TyCtxt<'_>, def_id: DefId) -> bool { - let def_id = def_id.expect_local(); - tcx.mir_keys(()).contains(&def_id) -} - -/// Finds the full set of `DefId`s within the current crate that have -/// MIR associated with them. -fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxHashSet { - let mut set = FxHashSet::default(); - - // All body-owners have MIR associated with them. - set.extend(tcx.body_owners()); - - // Additionally, tuple struct/variant constructors have MIR, but - // they don't have a BodyId, so we need to build them separately. - struct GatherCtors<'a, 'tcx> { - tcx: TyCtxt<'tcx>, - set: &'a mut FxHashSet, - } - impl<'a, 'tcx> Visitor<'tcx> for GatherCtors<'a, 'tcx> { - fn visit_variant_data( - &mut self, - v: &'tcx hir::VariantData<'tcx>, - _: Symbol, - _: &'tcx hir::Generics<'tcx>, - _: hir::HirId, - _: Span, - ) { - if let hir::VariantData::Tuple(_, hir_id) = *v { - self.set.insert(self.tcx.hir().local_def_id(hir_id)); - } - intravisit::walk_struct_def(self, v) - } - type Map = intravisit::ErasedMap<'tcx>; - fn nested_visit_map(&mut self) -> NestedVisitorMap { - NestedVisitorMap::None - } - } - tcx.hir() - .krate() - .visit_all_item_likes(&mut GatherCtors { tcx, set: &mut set }.as_deep_visitor()); - - set -} - /// Generates a default name for the pass based on the name of the /// type `T`. pub fn default_name() -> Cow<'static, str> { @@ -161,467 +24,3 @@ pub trait MirPass<'tcx> { fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>); } - -pub fn run_passes( - tcx: TyCtxt<'tcx>, - body: &mut Body<'tcx>, - mir_phase: MirPhase, - passes: &[&[&dyn MirPass<'tcx>]], -) { - let phase_index = mir_phase.phase_index(); - let validate = tcx.sess.opts.debugging_opts.validate_mir; - - if body.phase >= mir_phase { - return; - } - - if validate { - validate::Validator { when: format!("input to phase {:?}", mir_phase), mir_phase } - .run_pass(tcx, body); - } - - let mut index = 0; - let mut run_pass = |pass: &dyn MirPass<'tcx>| { - let run_hooks = |body: &_, index, is_after| { - dump_mir::on_mir_pass( - tcx, - &format_args!("{:03}-{:03}", phase_index, index), - &pass.name(), - body, - is_after, - ); - }; - run_hooks(body, index, false); - pass.run_pass(tcx, body); - run_hooks(body, index, true); - - if validate { - validate::Validator { - when: format!("after {} in phase {:?}", pass.name(), mir_phase), - mir_phase, - } - .run_pass(tcx, body); - } - - index += 1; - }; - - for pass_group in passes { - for pass in *pass_group { - run_pass(*pass); - } - } - - body.phase = mir_phase; - - if mir_phase == MirPhase::Optimization { - validate::Validator { when: format!("end of phase {:?}", mir_phase), mir_phase } - .run_pass(tcx, body); - } -} - -fn mir_const_qualif(tcx: TyCtxt<'_>, def: ty::WithOptConstParam) -> ConstQualifs { - let const_kind = tcx.hir().body_const_context(def.did); - - // No need to const-check a non-const `fn`. - if const_kind.is_none() { - return Default::default(); - } - - // N.B., this `borrow()` is guaranteed to be valid (i.e., the value - // cannot yet be stolen), because `mir_promoted()`, which steals - // from `mir_const(), forces this query to execute before - // performing the steal. - let body = &tcx.mir_const(def).borrow(); - - if body.return_ty().references_error() { - tcx.sess.delay_span_bug(body.span, "mir_const_qualif: MIR had errors"); - return Default::default(); - } - - let ccx = check_consts::ConstCx { body, tcx, const_kind, param_env: tcx.param_env(def.did) }; - - let mut validator = check_consts::check::Checker::new(&ccx); - validator.check_body(); - - // We return the qualifs in the return place for every MIR body, even though it is only used - // when deciding to promote a reference to a `const` for now. - validator.qualifs_in_return_place() -} - -/// Make MIR ready for const evaluation. This is run on all MIR, not just on consts! -fn mir_const<'tcx>( - tcx: TyCtxt<'tcx>, - def: ty::WithOptConstParam, -) -> &'tcx Steal> { - if let Some(def) = def.try_upgrade(tcx) { - return tcx.mir_const(def); - } - - // Unsafety check uses the raw mir, so make sure it is run. - if !tcx.sess.opts.debugging_opts.thir_unsafeck { - if let Some(param_did) = def.const_param_did { - tcx.ensure().unsafety_check_result_for_const_arg((def.did, param_did)); - } else { - tcx.ensure().unsafety_check_result(def.did); - } - } - - let mut body = tcx.mir_built(def).steal(); - - util::dump_mir(tcx, None, "mir_map", &0, &body, |_, _| Ok(())); - - run_passes( - tcx, - &mut body, - MirPhase::Const, - &[&[ - // MIR-level lints. - &check_packed_ref::CheckPackedRef, - &check_const_item_mutation::CheckConstItemMutation, - &function_item_references::FunctionItemReferences, - // What we need to do constant evaluation. - &simplify::SimplifyCfg::new("initial"), - &rustc_peek::SanityCheck, - ]], - ); - tcx.alloc_steal_mir(body) -} - -/// Compute the main MIR body and the list of MIR bodies of the promoteds. -fn mir_promoted( - tcx: TyCtxt<'tcx>, - def: ty::WithOptConstParam, -) -> (&'tcx Steal>, &'tcx Steal>>) { - if let Some(def) = def.try_upgrade(tcx) { - return tcx.mir_promoted(def); - } - - // Ensure that we compute the `mir_const_qualif` for constants at - // this point, before we steal the mir-const result. - // Also this means promotion can rely on all const checks having been done. - let _ = tcx.mir_const_qualif_opt_const_arg(def); - let _ = tcx.mir_abstract_const_opt_const_arg(def.to_global()); - let mut body = tcx.mir_const(def).steal(); - - let mut required_consts = Vec::new(); - let mut required_consts_visitor = RequiredConstsVisitor::new(&mut required_consts); - for (bb, bb_data) in traversal::reverse_postorder(&body) { - required_consts_visitor.visit_basic_block_data(bb, bb_data); - } - body.required_consts = required_consts; - - let promote_pass = promote_consts::PromoteTemps::default(); - let promote: &[&dyn MirPass<'tcx>] = &[ - // What we need to run borrowck etc. - &promote_pass, - &simplify::SimplifyCfg::new("promote-consts"), - ]; - - let opt_coverage: &[&dyn MirPass<'tcx>] = - if tcx.sess.instrument_coverage() { &[&coverage::InstrumentCoverage] } else { &[] }; - - run_passes(tcx, &mut body, MirPhase::ConstPromotion, &[promote, opt_coverage]); - - let promoted = promote_pass.promoted_fragments.into_inner(); - (tcx.alloc_steal_mir(body), tcx.alloc_steal_promoted(promoted)) -} - -/// Compute the MIR that is used during CTFE (and thus has no optimizations run on it) -fn mir_for_ctfe<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx Body<'tcx> { - let did = def_id.expect_local(); - if let Some(def) = ty::WithOptConstParam::try_lookup(did, tcx) { - tcx.mir_for_ctfe_of_const_arg(def) - } else { - tcx.arena.alloc(inner_mir_for_ctfe(tcx, ty::WithOptConstParam::unknown(did))) - } -} - -/// Same as `mir_for_ctfe`, but used to get the MIR of a const generic parameter. -/// The docs on `WithOptConstParam` explain this a bit more, but the TLDR is that -/// we'd get cycle errors with `mir_for_ctfe`, because typeck would need to typeck -/// the const parameter while type checking the main body, which in turn would try -/// to type check the main body again. -fn mir_for_ctfe_of_const_arg<'tcx>( - tcx: TyCtxt<'tcx>, - (did, param_did): (LocalDefId, DefId), -) -> &'tcx Body<'tcx> { - tcx.arena.alloc(inner_mir_for_ctfe( - tcx, - ty::WithOptConstParam { did, const_param_did: Some(param_did) }, - )) -} - -fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: ty::WithOptConstParam) -> Body<'_> { - // FIXME: don't duplicate this between the optimized_mir/mir_for_ctfe queries - if tcx.is_constructor(def.did.to_def_id()) { - // There's no reason to run all of the MIR passes on constructors when - // we can just output the MIR we want directly. This also saves const - // qualification and borrow checking the trouble of special casing - // constructors. - return shim::build_adt_ctor(tcx, def.did.to_def_id()); - } - - let context = tcx - .hir() - .body_const_context(def.did) - .expect("mir_for_ctfe should not be used for runtime functions"); - - let mut body = tcx.mir_drops_elaborated_and_const_checked(def).borrow().clone(); - - match context { - // Do not const prop functions, either they get executed at runtime or exported to metadata, - // so we run const prop on them, or they don't, in which case we const evaluate some control - // flow paths of the function and any errors in those paths will get emitted as const eval - // errors. - hir::ConstContext::ConstFn => {} - // Static items always get evaluated, so we can just let const eval see if any erroneous - // control flow paths get executed. - hir::ConstContext::Static(_) => {} - // Associated constants get const prop run so we detect common failure situations in the - // crate that defined the constant. - // Technically we want to not run on regular const items, but oli-obk doesn't know how to - // conveniently detect that at this point without looking at the HIR. - hir::ConstContext::Const => { - #[rustfmt::skip] - let optimizations: &[&dyn MirPass<'_>] = &[ - &const_prop::ConstProp, - ]; - - #[rustfmt::skip] - run_passes( - tcx, - &mut body, - MirPhase::Optimization, - &[ - optimizations, - ], - ); - } - } - - debug_assert!(!body.has_free_regions(tcx), "Free regions in MIR for CTFE"); - - body -} - -/// Obtain just the main MIR (no promoteds) and run some cleanups on it. This also runs -/// mir borrowck *before* doing so in order to ensure that borrowck can be run and doesn't -/// end up missing the source MIR due to stealing happening. -fn mir_drops_elaborated_and_const_checked<'tcx>( - tcx: TyCtxt<'tcx>, - def: ty::WithOptConstParam, -) -> &'tcx Steal> { - if let Some(def) = def.try_upgrade(tcx) { - return tcx.mir_drops_elaborated_and_const_checked(def); - } - - // (Mir-)Borrowck uses `mir_promoted`, so we have to force it to - // execute before we can steal. - if let Some(param_did) = def.const_param_did { - tcx.ensure().mir_borrowck_const_arg((def.did, param_did)); - } else { - tcx.ensure().mir_borrowck(def.did); - } - - let hir_id = tcx.hir().local_def_id_to_hir_id(def.did); - use rustc_middle::hir::map::blocks::FnLikeNode; - let is_fn_like = FnLikeNode::from_node(tcx.hir().get(hir_id)).is_some(); - if is_fn_like { - let did = def.did.to_def_id(); - let def = ty::WithOptConstParam::unknown(did); - - // Do not compute the mir call graph without said call graph actually being used. - if inline::is_enabled(tcx) { - let _ = tcx.mir_inliner_callees(ty::InstanceDef::Item(def)); - } - } - - let (body, _) = tcx.mir_promoted(def); - let mut body = body.steal(); - - run_post_borrowck_cleanup_passes(tcx, &mut body); - check_consts::post_drop_elaboration::check_live_drops(tcx, &body); - tcx.alloc_steal_mir(body) -} - -/// After this series of passes, no lifetime analysis based on borrowing can be done. -fn run_post_borrowck_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { - debug!("post_borrowck_cleanup({:?})", body.source.def_id()); - - let post_borrowck_cleanup: &[&dyn MirPass<'tcx>] = &[ - // Remove all things only needed by analysis - &simplify_branches::SimplifyBranches::new("initial"), - &remove_noop_landing_pads::RemoveNoopLandingPads, - &cleanup_post_borrowck::CleanupNonCodegenStatements, - &simplify::SimplifyCfg::new("early-opt"), - // These next passes must be executed together - &add_call_guards::CriticalCallEdges, - &elaborate_drops::ElaborateDrops, - // This will remove extraneous landing pads which are no longer - // necessary as well as well as forcing any call in a non-unwinding - // function calling a possibly-unwinding function to abort the process. - &abort_unwinding_calls::AbortUnwindingCalls, - // AddMovesForPackedDrops needs to run after drop - // elaboration. - &add_moves_for_packed_drops::AddMovesForPackedDrops, - // `AddRetag` needs to run after `ElaborateDrops`. Otherwise it should run fairly late, - // but before optimizations begin. - &add_retag::AddRetag, - &lower_intrinsics::LowerIntrinsics, - &simplify::SimplifyCfg::new("elaborate-drops"), - // `Deaggregator` is conceptually part of MIR building, some backends rely on it happening - // and it can help optimizations. - &deaggregator::Deaggregator, - ]; - - run_passes(tcx, body, MirPhase::DropLowering, &[post_borrowck_cleanup]); -} - -fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { - let mir_opt_level = tcx.sess.mir_opt_level(); - - // Lowering generator control-flow and variables has to happen before we do anything else - // to them. We run some optimizations before that, because they may be harder to do on the state - // machine than on MIR with async primitives. - let optimizations_with_generators: &[&dyn MirPass<'tcx>] = &[ - &lower_slice_len::LowerSliceLenCalls, // has to be done before inlining, otherwise actual call will be almost always inlined. Also simple, so can just do first - &unreachable_prop::UnreachablePropagation, - &uninhabited_enum_branching::UninhabitedEnumBranching, - &simplify::SimplifyCfg::new("after-uninhabited-enum-branching"), - &inline::Inline, - &generator::StateTransform, - ]; - - // Even if we don't do optimizations, we still have to lower generators for codegen. - let no_optimizations_with_generators: &[&dyn MirPass<'tcx>] = &[&generator::StateTransform]; - - // The main optimizations that we do on MIR. - let optimizations: &[&dyn MirPass<'tcx>] = &[ - &remove_storage_markers::RemoveStorageMarkers, - &remove_zsts::RemoveZsts, - &const_goto::ConstGoto, - &remove_unneeded_drops::RemoveUnneededDrops, - &match_branches::MatchBranchSimplification, - // inst combine is after MatchBranchSimplification to clean up Ne(_1, false) - &multiple_return_terminators::MultipleReturnTerminators, - &instcombine::InstCombine, - &separate_const_switch::SeparateConstSwitch, - &const_prop::ConstProp, - &simplify_branches::SimplifyBranches::new("after-const-prop"), - &early_otherwise_branch::EarlyOtherwiseBranch, - &simplify_comparison_integral::SimplifyComparisonIntegral, - &simplify_try::SimplifyArmIdentity, - &simplify_try::SimplifyBranchSame, - &dest_prop::DestinationPropagation, - &simplify_branches::SimplifyBranches::new("final"), - &remove_noop_landing_pads::RemoveNoopLandingPads, - &simplify::SimplifyCfg::new("final"), - &nrvo::RenameReturnPlace, - &const_debuginfo::ConstDebugInfo, - &simplify::SimplifyLocals, - &multiple_return_terminators::MultipleReturnTerminators, - &deduplicate_blocks::DeduplicateBlocks, - ]; - - // Optimizations to run even if mir optimizations have been disabled. - let no_optimizations: &[&dyn MirPass<'tcx>] = &[ - // FIXME(#70073): This pass is responsible for both optimization as well as some lints. - &const_prop::ConstProp, - ]; - - // Some cleanup necessary at least for LLVM and potentially other codegen backends. - let pre_codegen_cleanup: &[&dyn MirPass<'tcx>] = &[ - &add_call_guards::CriticalCallEdges, - // Dump the end result for testing and debugging purposes. - &dump_mir::Marker("PreCodegen"), - ]; - - // End of pass declarations, now actually run the passes. - // Generator Lowering - #[rustfmt::skip] - run_passes( - tcx, - body, - MirPhase::GeneratorLowering, - &[ - if mir_opt_level > 0 { - optimizations_with_generators - } else { - no_optimizations_with_generators - } - ], - ); - - // Main optimization passes - #[rustfmt::skip] - run_passes( - tcx, - body, - MirPhase::Optimization, - &[ - if mir_opt_level > 0 { optimizations } else { no_optimizations }, - pre_codegen_cleanup, - ], - ); -} - -/// Optimize the MIR and prepare it for codegen. -fn optimized_mir<'tcx>(tcx: TyCtxt<'tcx>, did: DefId) -> &'tcx Body<'tcx> { - let did = did.expect_local(); - assert_eq!(ty::WithOptConstParam::try_lookup(did, tcx), None); - tcx.arena.alloc(inner_optimized_mir(tcx, did)) -} - -fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> { - if tcx.is_constructor(did.to_def_id()) { - // There's no reason to run all of the MIR passes on constructors when - // we can just output the MIR we want directly. This also saves const - // qualification and borrow checking the trouble of special casing - // constructors. - return shim::build_adt_ctor(tcx, did.to_def_id()); - } - - match tcx.hir().body_const_context(did) { - // Run the `mir_for_ctfe` query, which depends on `mir_drops_elaborated_and_const_checked` - // which we are going to steal below. Thus we need to run `mir_for_ctfe` first, so it - // computes and caches its result. - Some(hir::ConstContext::ConstFn) => tcx.ensure().mir_for_ctfe(did), - None => {} - Some(other) => panic!("do not use `optimized_mir` for constants: {:?}", other), - } - let mut body = - tcx.mir_drops_elaborated_and_const_checked(ty::WithOptConstParam::unknown(did)).steal(); - run_optimization_passes(tcx, &mut body); - - debug_assert!(!body.has_free_regions(tcx), "Free regions in optimized MIR"); - - body -} - -/// Fetch all the promoteds of an item and prepare their MIR bodies to be ready for -/// constant evaluation once all substitutions become known. -fn promoted_mir<'tcx>( - tcx: TyCtxt<'tcx>, - def: ty::WithOptConstParam, -) -> &'tcx IndexVec> { - if tcx.is_constructor(def.did.to_def_id()) { - return tcx.arena.alloc(IndexVec::new()); - } - - if let Some(param_did) = def.const_param_did { - tcx.ensure().mir_borrowck_const_arg((def.did, param_did)); - } else { - tcx.ensure().mir_borrowck(def.did); - } - let (_, promoted) = tcx.mir_promoted(def); - let mut promoted = promoted.steal(); - - for body in &mut promoted { - run_post_borrowck_cleanup_passes(tcx, body); - } - - debug_assert!(!promoted.has_free_regions(tcx), "Free regions in promoted MIR"); - - tcx.arena.alloc(promoted) -} diff --git a/compiler/rustc_mir/src/util/mod.rs b/compiler/rustc_mir/src/util/mod.rs index 8f9db6daba733..741c1e6b2c60f 100644 --- a/compiler/rustc_mir/src/util/mod.rs +++ b/compiler/rustc_mir/src/util/mod.rs @@ -7,10 +7,10 @@ mod alignment; pub mod collect_writes; mod find_self_call; mod generic_graph; -pub(crate) mod generic_graphviz; +pub mod generic_graphviz; mod graphviz; pub mod pretty; -pub(crate) mod spanview; +pub mod spanview; pub use self::aggregate::expand_aggregate; pub use self::alignment::is_disaligned; diff --git a/compiler/rustc_mir/src/util/pretty.rs b/compiler/rustc_mir/src/util/pretty.rs index ec1aa5b476bb7..db98cb763430f 100644 --- a/compiler/rustc_mir/src/util/pretty.rs +++ b/compiler/rustc_mir/src/util/pretty.rs @@ -7,7 +7,6 @@ use std::path::{Path, PathBuf}; use super::graphviz::write_mir_fn_graphviz; use super::spanview::write_mir_fn_spanview; -use crate::transform::MirSource; use either::Either; use rustc_data_structures::fx::FxHashMap; use rustc_hir::def_id::DefId; @@ -16,6 +15,7 @@ use rustc_middle::mir::interpret::{ read_target_uint, AllocId, Allocation, ConstValue, GlobalAlloc, Pointer, Provenance, }; use rustc_middle::mir::visit::Visitor; +use rustc_middle::mir::MirSource; use rustc_middle::mir::*; use rustc_middle::ty::{self, TyCtxt, TyS, TypeFoldable, TypeVisitor}; use rustc_target::abi::Size; diff --git a/compiler/rustc_mir_transform/Cargo.toml b/compiler/rustc_mir_transform/Cargo.toml new file mode 100644 index 0000000000000..cba3ab5176eb3 --- /dev/null +++ b/compiler/rustc_mir_transform/Cargo.toml @@ -0,0 +1,29 @@ +[package] +authors = ["The Rust Project Developers"] +name = "rustc_mir_transform" +version = "0.0.0" +edition = "2018" + +[lib] +doctest = false + +[dependencies] +itertools = "0.9" +smallvec = { version = "1.6.1", features = ["union", "may_dangle"] } +tracing = "0.1" +rustc_ast = { path = "../rustc_ast" } +rustc_attr = { path = "../rustc_attr" } +rustc_data_structures = { path = "../rustc_data_structures" } +rustc_errors = { path = "../rustc_errors" } +rustc_hir = { path = "../rustc_hir" } +rustc_index = { path = "../rustc_index" } +rustc_middle = { path = "../rustc_middle" } +rustc_mir = { path = "../rustc_mir" } +rustc_serialize = { path = "../rustc_serialize" } +rustc_session = { path = "../rustc_session" } +rustc_target = { path = "../rustc_target" } +rustc_trait_selection = { path = "../rustc_trait_selection" } +rustc_span = { path = "../rustc_span" } + +[dev-dependencies] +coverage_test_macros = { path = "src/coverage/test_macros" } diff --git a/compiler/rustc_mir/src/transform/abort_unwinding_calls.rs b/compiler/rustc_mir_transform/src/abort_unwinding_calls.rs similarity index 99% rename from compiler/rustc_mir/src/transform/abort_unwinding_calls.rs rename to compiler/rustc_mir_transform/src/abort_unwinding_calls.rs index aecb2373eaf36..855dcbc431b1e 100644 --- a/compiler/rustc_mir/src/transform/abort_unwinding_calls.rs +++ b/compiler/rustc_mir_transform/src/abort_unwinding_calls.rs @@ -1,4 +1,4 @@ -use crate::transform::MirPass; +use crate::MirPass; use rustc_hir::def::DefKind; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::mir::*; diff --git a/compiler/rustc_mir/src/transform/add_call_guards.rs b/compiler/rustc_mir_transform/src/add_call_guards.rs similarity index 98% rename from compiler/rustc_mir/src/transform/add_call_guards.rs rename to compiler/rustc_mir_transform/src/add_call_guards.rs index 12ee6bb4c67fa..cd6b671a0dbfd 100644 --- a/compiler/rustc_mir/src/transform/add_call_guards.rs +++ b/compiler/rustc_mir_transform/src/add_call_guards.rs @@ -1,4 +1,4 @@ -use crate::transform::MirPass; +use crate::MirPass; use rustc_index::vec::{Idx, IndexVec}; use rustc_middle::mir::*; use rustc_middle::ty::TyCtxt; diff --git a/compiler/rustc_mir/src/transform/add_moves_for_packed_drops.rs b/compiler/rustc_mir_transform/src/add_moves_for_packed_drops.rs similarity index 99% rename from compiler/rustc_mir/src/transform/add_moves_for_packed_drops.rs rename to compiler/rustc_mir_transform/src/add_moves_for_packed_drops.rs index 417e0a51aecf0..c48d0c8b8f2cf 100644 --- a/compiler/rustc_mir/src/transform/add_moves_for_packed_drops.rs +++ b/compiler/rustc_mir_transform/src/add_moves_for_packed_drops.rs @@ -1,9 +1,9 @@ use rustc_middle::mir::*; use rustc_middle::ty::TyCtxt; -use crate::transform::MirPass; use crate::util; use crate::util::patch::MirPatch; +use crate::MirPass; // 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/src/transform/add_retag.rs b/compiler/rustc_mir_transform/src/add_retag.rs similarity index 99% rename from compiler/rustc_mir/src/transform/add_retag.rs rename to compiler/rustc_mir_transform/src/add_retag.rs index cb608819ea8ac..7a8dee09c29f0 100644 --- a/compiler/rustc_mir/src/transform/add_retag.rs +++ b/compiler/rustc_mir_transform/src/add_retag.rs @@ -4,7 +4,7 @@ //! of MIR building, and only after this pass we think of the program has having the //! normal MIR semantics. -use crate::transform::MirPass; +use crate::MirPass; use rustc_middle::mir::*; use rustc_middle::ty::{self, Ty, TyCtxt}; diff --git a/compiler/rustc_mir/src/transform/check_const_item_mutation.rs b/compiler/rustc_mir_transform/src/check_const_item_mutation.rs similarity index 99% rename from compiler/rustc_mir/src/transform/check_const_item_mutation.rs rename to compiler/rustc_mir_transform/src/check_const_item_mutation.rs index e2d50ba034ad3..27fe80a456f7d 100644 --- a/compiler/rustc_mir/src/transform/check_const_item_mutation.rs +++ b/compiler/rustc_mir_transform/src/check_const_item_mutation.rs @@ -6,7 +6,7 @@ use rustc_middle::ty::TyCtxt; use rustc_session::lint::builtin::CONST_ITEM_MUTATION; use rustc_span::def_id::DefId; -use crate::transform::MirPass; +use crate::MirPass; pub struct CheckConstItemMutation; diff --git a/compiler/rustc_mir/src/transform/check_packed_ref.rs b/compiler/rustc_mir_transform/src/check_packed_ref.rs similarity index 99% rename from compiler/rustc_mir/src/transform/check_packed_ref.rs rename to compiler/rustc_mir_transform/src/check_packed_ref.rs index 13b7221046bda..49be34c7a2845 100644 --- a/compiler/rustc_mir/src/transform/check_packed_ref.rs +++ b/compiler/rustc_mir_transform/src/check_packed_ref.rs @@ -6,8 +6,8 @@ use rustc_middle::ty::{self, TyCtxt}; use rustc_session::lint::builtin::UNALIGNED_REFERENCES; use rustc_span::symbol::sym; -use crate::transform::MirPass; use crate::util; +use crate::MirPass; pub(crate) fn provide(providers: &mut Providers) { *providers = Providers { unsafe_derive_on_repr_packed, ..*providers }; diff --git a/compiler/rustc_mir/src/transform/check_unsafety.rs b/compiler/rustc_mir_transform/src/check_unsafety.rs similarity index 100% rename from compiler/rustc_mir/src/transform/check_unsafety.rs rename to compiler/rustc_mir_transform/src/check_unsafety.rs diff --git a/compiler/rustc_mir/src/transform/cleanup_post_borrowck.rs b/compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs similarity index 98% rename from compiler/rustc_mir/src/transform/cleanup_post_borrowck.rs rename to compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs index 8ff0fae768618..611d29a4ee29a 100644 --- a/compiler/rustc_mir/src/transform/cleanup_post_borrowck.rs +++ b/compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs @@ -18,7 +18,7 @@ //! [`ForMatchGuard`]: rustc_middle::mir::FakeReadCause::ForMatchGuard //! [`Nop`]: rustc_middle::mir::StatementKind::Nop -use crate::transform::MirPass; +use crate::MirPass; use rustc_middle::mir::visit::MutVisitor; use rustc_middle::mir::{Body, BorrowKind, Location, Rvalue}; use rustc_middle::mir::{Statement, StatementKind}; diff --git a/compiler/rustc_mir/src/transform/const_debuginfo.rs b/compiler/rustc_mir_transform/src/const_debuginfo.rs similarity index 99% rename from compiler/rustc_mir/src/transform/const_debuginfo.rs rename to compiler/rustc_mir_transform/src/const_debuginfo.rs index 3cdaf4c7dcd47..b613634560fbd 100644 --- a/compiler/rustc_mir/src/transform/const_debuginfo.rs +++ b/compiler/rustc_mir_transform/src/const_debuginfo.rs @@ -9,7 +9,7 @@ use rustc_middle::{ ty::TyCtxt, }; -use crate::transform::MirPass; +use crate::MirPass; use rustc_index::{bit_set::BitSet, vec::IndexVec}; pub struct ConstDebugInfo; diff --git a/compiler/rustc_mir/src/transform/const_goto.rs b/compiler/rustc_mir_transform/src/const_goto.rs similarity index 99% rename from compiler/rustc_mir/src/transform/const_goto.rs rename to compiler/rustc_mir_transform/src/const_goto.rs index ba10b54c5ae2e..d319fdcaa6b7e 100644 --- a/compiler/rustc_mir/src/transform/const_goto.rs +++ b/compiler/rustc_mir_transform/src/const_goto.rs @@ -17,7 +17,7 @@ //! } //! ``` -use crate::transform::MirPass; +use crate::MirPass; use rustc_middle::mir::*; use rustc_middle::ty::TyCtxt; use rustc_middle::{mir::visit::Visitor, ty::ParamEnv}; diff --git a/compiler/rustc_mir/src/transform/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs similarity index 99% rename from compiler/rustc_mir/src/transform/const_prop.rs rename to compiler/rustc_mir_transform/src/const_prop.rs index 71c07be4c6d8d..51240ee067711 100644 --- a/compiler/rustc_mir/src/transform/const_prop.rs +++ b/compiler/rustc_mir_transform/src/const_prop.rs @@ -28,13 +28,13 @@ use rustc_target::abi::{HasDataLayout, Size, TargetDataLayout}; use rustc_target::spec::abi::Abi; use rustc_trait_selection::traits; -use crate::const_eval::ConstEvalErr; -use crate::interpret::{ +use crate::MirPass; +use rustc_mir::const_eval::ConstEvalErr; +use rustc_mir::interpret::{ self, compile_time_machine, AllocId, Allocation, ConstValue, CtfeValidationMode, Frame, ImmTy, Immediate, InterpCx, InterpResult, LocalState, LocalValue, MemPlace, MemoryKind, OpTy, Operand as InterpOperand, PlaceTy, Scalar, ScalarMaybeUninit, StackPopCleanup, StackPopUnwind, }; -use crate::transform::MirPass; /// The maximum number of bytes that we'll allocate space for a local or the return value. /// Needed for #66397, because otherwise we eval into large places and that can cause OOM or just diff --git a/compiler/rustc_mir/src/transform/coverage/counters.rs b/compiler/rustc_mir_transform/src/coverage/counters.rs similarity index 100% rename from compiler/rustc_mir/src/transform/coverage/counters.rs rename to compiler/rustc_mir_transform/src/coverage/counters.rs diff --git a/compiler/rustc_mir/src/transform/coverage/debug.rs b/compiler/rustc_mir_transform/src/coverage/debug.rs similarity index 98% rename from compiler/rustc_mir/src/transform/coverage/debug.rs rename to compiler/rustc_mir_transform/src/coverage/debug.rs index 464079656f9fb..9de2f4a5f847b 100644 --- a/compiler/rustc_mir/src/transform/coverage/debug.rs +++ b/compiler/rustc_mir_transform/src/coverage/debug.rs @@ -44,7 +44,7 @@ //! points, which can be enabled via environment variable: //! //! ```shell -//! RUSTC_LOG=rustc_mir::transform::coverage=debug +//! RUSTC_LOG=rustc_mir_transform::transform::coverage=debug //! ``` //! //! Other module paths with coverage-related debug logs may also be of interest, particularly for @@ -52,7 +52,7 @@ //! code generation pass). For example: //! //! ```shell -//! RUSTC_LOG=rustc_mir::transform::coverage,rustc_codegen_ssa::coverageinfo,rustc_codegen_llvm::coverageinfo=debug +//! RUSTC_LOG=rustc_mir_transform::transform::coverage,rustc_codegen_ssa::coverageinfo,rustc_codegen_llvm::coverageinfo=debug //! ``` //! //! Coverage Debug Options @@ -181,13 +181,11 @@ impl DebugOptions { } }; } - _ => { - bug!( - "Unsupported setting `{}` in environment variable {}", - option, - RUSTC_COVERAGE_DEBUG_OPTIONS - ) - } + _ => bug!( + "Unsupported setting `{}` in environment variable {}", + option, + RUSTC_COVERAGE_DEBUG_OPTIONS + ), }; } } diff --git a/compiler/rustc_mir/src/transform/coverage/graph.rs b/compiler/rustc_mir_transform/src/coverage/graph.rs similarity index 100% rename from compiler/rustc_mir/src/transform/coverage/graph.rs rename to compiler/rustc_mir_transform/src/coverage/graph.rs diff --git a/compiler/rustc_mir/src/transform/coverage/mod.rs b/compiler/rustc_mir_transform/src/coverage/mod.rs similarity index 99% rename from compiler/rustc_mir/src/transform/coverage/mod.rs rename to compiler/rustc_mir_transform/src/coverage/mod.rs index f7fbea6ad5371..f7f0191502198 100644 --- a/compiler/rustc_mir/src/transform/coverage/mod.rs +++ b/compiler/rustc_mir_transform/src/coverage/mod.rs @@ -12,8 +12,8 @@ use counters::CoverageCounters; use graph::{BasicCoverageBlock, BasicCoverageBlockData, CoverageGraph}; use spans::{CoverageSpan, CoverageSpans}; -use crate::transform::MirPass; use crate::util::pretty; +use crate::MirPass; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::graph::WithNumNodes; diff --git a/compiler/rustc_mir/src/transform/coverage/query.rs b/compiler/rustc_mir_transform/src/coverage/query.rs similarity index 100% rename from compiler/rustc_mir/src/transform/coverage/query.rs rename to compiler/rustc_mir_transform/src/coverage/query.rs diff --git a/compiler/rustc_mir/src/transform/coverage/spans.rs b/compiler/rustc_mir_transform/src/coverage/spans.rs similarity index 100% rename from compiler/rustc_mir/src/transform/coverage/spans.rs rename to compiler/rustc_mir_transform/src/coverage/spans.rs diff --git a/compiler/rustc_mir/src/transform/coverage/test_macros/Cargo.toml b/compiler/rustc_mir_transform/src/coverage/test_macros/Cargo.toml similarity index 100% rename from compiler/rustc_mir/src/transform/coverage/test_macros/Cargo.toml rename to compiler/rustc_mir_transform/src/coverage/test_macros/Cargo.toml diff --git a/compiler/rustc_mir/src/transform/coverage/test_macros/src/lib.rs b/compiler/rustc_mir_transform/src/coverage/test_macros/src/lib.rs similarity index 100% rename from compiler/rustc_mir/src/transform/coverage/test_macros/src/lib.rs rename to compiler/rustc_mir_transform/src/coverage/test_macros/src/lib.rs diff --git a/compiler/rustc_mir/src/transform/coverage/tests.rs b/compiler/rustc_mir_transform/src/coverage/tests.rs similarity index 100% rename from compiler/rustc_mir/src/transform/coverage/tests.rs rename to compiler/rustc_mir_transform/src/coverage/tests.rs diff --git a/compiler/rustc_mir/src/transform/deaggregator.rs b/compiler/rustc_mir_transform/src/deaggregator.rs similarity index 98% rename from compiler/rustc_mir/src/transform/deaggregator.rs rename to compiler/rustc_mir_transform/src/deaggregator.rs index 5bd7256c666c6..a5491f0ef4e2d 100644 --- a/compiler/rustc_mir/src/transform/deaggregator.rs +++ b/compiler/rustc_mir_transform/src/deaggregator.rs @@ -1,5 +1,5 @@ -use crate::transform::MirPass; use crate::util::expand_aggregate; +use crate::MirPass; use rustc_middle::mir::*; use rustc_middle::ty::TyCtxt; diff --git a/compiler/rustc_mir/src/transform/deduplicate_blocks.rs b/compiler/rustc_mir_transform/src/deduplicate_blocks.rs similarity index 99% rename from compiler/rustc_mir/src/transform/deduplicate_blocks.rs rename to compiler/rustc_mir_transform/src/deduplicate_blocks.rs index 912505c65983e..8d2413433a92b 100644 --- a/compiler/rustc_mir/src/transform/deduplicate_blocks.rs +++ b/compiler/rustc_mir_transform/src/deduplicate_blocks.rs @@ -3,7 +3,7 @@ use std::{collections::hash_map::Entry, hash::Hash, hash::Hasher, iter}; -use crate::transform::MirPass; +use crate::MirPass; use rustc_data_structures::fx::FxHashMap; use rustc_middle::mir::visit::MutVisitor; diff --git a/compiler/rustc_mir/src/transform/dest_prop.rs b/compiler/rustc_mir_transform/src/dest_prop.rs similarity index 99% rename from compiler/rustc_mir/src/transform/dest_prop.rs rename to compiler/rustc_mir_transform/src/dest_prop.rs index 4f5a467a6ee62..ec9279ff00ccd 100644 --- a/compiler/rustc_mir/src/transform/dest_prop.rs +++ b/compiler/rustc_mir_transform/src/dest_prop.rs @@ -96,11 +96,9 @@ //! [previous attempt]: https://github.com/rust-lang/rust/pull/47954 //! [subsequent approach]: https://github.com/rust-lang/rust/pull/71003 -use crate::dataflow::impls::{MaybeInitializedLocals, MaybeLiveLocals}; -use crate::dataflow::Analysis; use crate::{ - transform::MirPass, util::{dump_mir, PassWhere}, + MirPass, }; use itertools::Itertools; use rustc_data_structures::unify::{InPlaceUnificationTable, UnifyKey}; @@ -115,6 +113,8 @@ use rustc_middle::mir::{ Rvalue, Statement, StatementKind, Terminator, TerminatorKind, }; use rustc_middle::ty::TyCtxt; +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/src/transform/dump_mir.rs b/compiler/rustc_mir_transform/src/dump_mir.rs similarity index 97% rename from compiler/rustc_mir/src/transform/dump_mir.rs rename to compiler/rustc_mir_transform/src/dump_mir.rs index 5b6edf17d06ab..753948dacb370 100644 --- a/compiler/rustc_mir/src/transform/dump_mir.rs +++ b/compiler/rustc_mir_transform/src/dump_mir.rs @@ -5,8 +5,8 @@ use std::fmt; use std::fs::File; use std::io; -use crate::transform::MirPass; use crate::util as mir_util; +use crate::MirPass; use rustc_middle::mir::Body; use rustc_middle::ty::TyCtxt; use rustc_session::config::{OutputFilenames, OutputType}; diff --git a/compiler/rustc_mir/src/transform/early_otherwise_branch.rs b/compiler/rustc_mir_transform/src/early_otherwise_branch.rs similarity index 99% rename from compiler/rustc_mir/src/transform/early_otherwise_branch.rs rename to compiler/rustc_mir_transform/src/early_otherwise_branch.rs index e507bcb0f812c..01d0c10eddcd3 100644 --- a/compiler/rustc_mir/src/transform/early_otherwise_branch.rs +++ b/compiler/rustc_mir_transform/src/early_otherwise_branch.rs @@ -1,4 +1,4 @@ -use crate::{transform::MirPass, util::patch::MirPatch}; +use crate::{util::patch::MirPatch, MirPass}; use rustc_middle::mir::*; use rustc_middle::ty::{Ty, TyCtxt}; use std::fmt::Debug; diff --git a/compiler/rustc_mir/src/transform/elaborate_drops.rs b/compiler/rustc_mir_transform/src/elaborate_drops.rs similarity index 98% rename from compiler/rustc_mir/src/transform/elaborate_drops.rs rename to compiler/rustc_mir_transform/src/elaborate_drops.rs index 9b44af06b7dee..5ed13a0268d83 100644 --- a/compiler/rustc_mir/src/transform/elaborate_drops.rs +++ b/compiler/rustc_mir_transform/src/elaborate_drops.rs @@ -1,18 +1,18 @@ -use crate::dataflow; -use crate::dataflow::impls::{MaybeInitializedPlaces, MaybeUninitializedPlaces}; -use crate::dataflow::move_paths::{LookupResult, MoveData, MovePathIndex}; -use crate::dataflow::on_lookup_result_bits; -use crate::dataflow::MoveDataParamEnv; -use crate::dataflow::{on_all_children_bits, on_all_drop_children_bits}; -use crate::dataflow::{Analysis, ResultsCursor}; -use crate::transform::MirPass; 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::*; 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_span::Span; use rustc_target::abi::VariantIdx; use std::fmt; diff --git a/compiler/rustc_mir/src/transform/function_item_references.rs b/compiler/rustc_mir_transform/src/function_item_references.rs similarity index 99% rename from compiler/rustc_mir/src/transform/function_item_references.rs rename to compiler/rustc_mir_transform/src/function_item_references.rs index ba2c91a9347ec..d96a067fdda79 100644 --- a/compiler/rustc_mir/src/transform/function_item_references.rs +++ b/compiler/rustc_mir_transform/src/function_item_references.rs @@ -11,7 +11,7 @@ use rustc_session::lint::builtin::FUNCTION_ITEM_REFERENCES; use rustc_span::{symbol::sym, Span}; use rustc_target::spec::abi::Abi; -use crate::transform::MirPass; +use crate::MirPass; pub struct FunctionItemReferences; diff --git a/compiler/rustc_mir/src/transform/generator.rs b/compiler/rustc_mir_transform/src/generator.rs similarity index 99% rename from compiler/rustc_mir/src/transform/generator.rs rename to compiler/rustc_mir_transform/src/generator.rs index acdaa5b456857..f2486b58aac48 100644 --- a/compiler/rustc_mir/src/transform/generator.rs +++ b/compiler/rustc_mir_transform/src/generator.rs @@ -49,15 +49,11 @@ //! For generators with state 1 (returned) and state 2 (poisoned) it does nothing. //! Otherwise it drops all the values in scope at the last suspension point. -use crate::dataflow::impls::{ - MaybeBorrowedLocals, MaybeLiveLocals, MaybeRequiresStorage, MaybeStorageLive, -}; -use crate::dataflow::{self, Analysis}; -use crate::transform::simplify; -use crate::transform::MirPass; +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; @@ -68,6 +64,10 @@ 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::{ + MaybeBorrowedLocals, MaybeLiveLocals, MaybeRequiresStorage, MaybeStorageLive, +}; +use rustc_mir::dataflow::{self, Analysis}; use rustc_target::abi::VariantIdx; use rustc_target::spec::PanicStrategy; use std::{iter, ops}; diff --git a/compiler/rustc_mir/src/transform/inline.rs b/compiler/rustc_mir_transform/src/inline.rs similarity index 99% rename from compiler/rustc_mir/src/transform/inline.rs rename to compiler/rustc_mir_transform/src/inline.rs index 8e9da31eba11f..d43528a1cf098 100644 --- a/compiler/rustc_mir/src/transform/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -13,7 +13,7 @@ use rustc_span::{hygiene::ExpnKind, ExpnData, Span}; use rustc_target::spec::abi::Abi; use super::simplify::{remove_dead_blocks, CfgSimplifier}; -use crate::transform::MirPass; +use crate::MirPass; use std::iter; use std::ops::{Range, RangeFrom}; diff --git a/compiler/rustc_mir/src/transform/inline/cycle.rs b/compiler/rustc_mir_transform/src/inline/cycle.rs similarity index 100% rename from compiler/rustc_mir/src/transform/inline/cycle.rs rename to compiler/rustc_mir_transform/src/inline/cycle.rs diff --git a/compiler/rustc_mir/src/transform/instcombine.rs b/compiler/rustc_mir_transform/src/instcombine.rs similarity index 99% rename from compiler/rustc_mir/src/transform/instcombine.rs rename to compiler/rustc_mir_transform/src/instcombine.rs index 805f546104cae..e15a69c95ae9c 100644 --- a/compiler/rustc_mir/src/transform/instcombine.rs +++ b/compiler/rustc_mir_transform/src/instcombine.rs @@ -1,6 +1,6 @@ //! Performs various peephole optimizations. -use crate::transform::MirPass; +use crate::MirPass; use rustc_hir::Mutability; use rustc_middle::mir::{ BinOp, Body, Constant, LocalDecls, Operand, Place, ProjectionElem, Rvalue, SourceInfo, diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs new file mode 100644 index 0000000000000..93f0a7f3d04ad --- /dev/null +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -0,0 +1,632 @@ +#![feature(bindings_after_at)] +#![feature(box_patterns)] +#![feature(box_syntax)] +#![feature(crate_visibility_modifier)] +#![feature(const_panic)] +#![feature(in_band_lifetimes)] +#![feature(iter_zip)] +#![feature(map_try_insert)] +#![feature(min_specialization)] +#![feature(option_get_or_insert_default)] +#![feature(once_cell)] +#![feature(never_type)] +#![feature(trusted_step)] +#![feature(try_blocks)] + +#[macro_use] +extern crate tracing; +#[macro_use] +extern crate rustc_middle; + +use required_consts::RequiredConstsVisitor; +use rustc_data_structures::fx::FxHashSet; +use rustc_data_structures::steal::Steal; +use rustc_hir as hir; +use rustc_hir::def_id::{DefId, LocalDefId}; +use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; +use rustc_index::vec::IndexVec; +use rustc_middle::mir::visit::Visitor as _; +use rustc_middle::mir::{traversal, Body, ConstQualifs, MirPhase, Promoted}; +use rustc_middle::ty::query::Providers; +use rustc_middle::ty::{self, TyCtxt, TypeFoldable}; +use rustc_mir::util; +use rustc_span::{Span, Symbol}; + +mod abort_unwinding_calls; +mod add_call_guards; +mod add_moves_for_packed_drops; +mod add_retag; +mod check_const_item_mutation; +mod check_packed_ref; +pub mod check_unsafety; +mod cleanup_post_borrowck; +mod const_debuginfo; +mod const_goto; +mod const_prop; +mod coverage; +mod deaggregator; +mod deduplicate_blocks; +mod dest_prop; +pub mod dump_mir; +mod early_otherwise_branch; +mod elaborate_drops; +mod function_item_references; +mod generator; +mod inline; +mod instcombine; +mod lower_intrinsics; +mod lower_slice_len; +mod match_branches; +mod multiple_return_terminators; +mod nrvo; +mod remove_noop_landing_pads; +mod remove_storage_markers; +mod remove_unneeded_drops; +mod remove_zsts; +mod required_consts; +mod separate_const_switch; +mod shim; +mod simplify; +mod simplify_branches; +mod simplify_comparison_integral; +mod simplify_try; +mod uninhabited_enum_branching; +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; + +pub fn provide(providers: &mut Providers) { + check_unsafety::provide(providers); + check_packed_ref::provide(providers); + coverage::query::provide(providers); + shim::provide(providers); + *providers = Providers { + mir_keys, + mir_const, + mir_const_qualif: |tcx, def_id| { + let def_id = def_id.expect_local(); + if let Some(def) = ty::WithOptConstParam::try_lookup(def_id, tcx) { + tcx.mir_const_qualif_const_arg(def) + } else { + mir_const_qualif(tcx, ty::WithOptConstParam::unknown(def_id)) + } + }, + mir_const_qualif_const_arg: |tcx, (did, param_did)| { + mir_const_qualif(tcx, ty::WithOptConstParam { did, const_param_did: Some(param_did) }) + }, + mir_promoted, + mir_drops_elaborated_and_const_checked, + mir_for_ctfe, + mir_for_ctfe_of_const_arg, + optimized_mir, + is_mir_available, + is_ctfe_mir_available: |tcx, did| is_mir_available(tcx, did), + mir_callgraph_reachable: inline::cycle::mir_callgraph_reachable, + mir_inliner_callees: inline::cycle::mir_inliner_callees, + promoted_mir: |tcx, def_id| { + let def_id = def_id.expect_local(); + if let Some(def) = ty::WithOptConstParam::try_lookup(def_id, tcx) { + tcx.promoted_mir_of_const_arg(def) + } else { + promoted_mir(tcx, ty::WithOptConstParam::unknown(def_id)) + } + }, + promoted_mir_of_const_arg: |tcx, (did, param_did)| { + promoted_mir(tcx, ty::WithOptConstParam { did, const_param_did: Some(param_did) }) + }, + ..*providers + }; +} + +fn is_mir_available(tcx: TyCtxt<'_>, def_id: DefId) -> bool { + let def_id = def_id.expect_local(); + tcx.mir_keys(()).contains(&def_id) +} + +/// Finds the full set of `DefId`s within the current crate that have +/// MIR associated with them. +fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxHashSet { + let mut set = FxHashSet::default(); + + // All body-owners have MIR associated with them. + set.extend(tcx.body_owners()); + + // Additionally, tuple struct/variant constructors have MIR, but + // they don't have a BodyId, so we need to build them separately. + struct GatherCtors<'a, 'tcx> { + tcx: TyCtxt<'tcx>, + set: &'a mut FxHashSet, + } + impl<'a, 'tcx> Visitor<'tcx> for GatherCtors<'a, 'tcx> { + fn visit_variant_data( + &mut self, + v: &'tcx hir::VariantData<'tcx>, + _: Symbol, + _: &'tcx hir::Generics<'tcx>, + _: hir::HirId, + _: Span, + ) { + if let hir::VariantData::Tuple(_, hir_id) = *v { + self.set.insert(self.tcx.hir().local_def_id(hir_id)); + } + intravisit::walk_struct_def(self, v) + } + type Map = intravisit::ErasedMap<'tcx>; + fn nested_visit_map(&mut self) -> NestedVisitorMap { + NestedVisitorMap::None + } + } + tcx.hir() + .krate() + .visit_all_item_likes(&mut GatherCtors { tcx, set: &mut set }.as_deep_visitor()); + + set +} + +fn run_passes( + tcx: TyCtxt<'tcx>, + body: &mut Body<'tcx>, + mir_phase: MirPhase, + passes: &[&[&dyn MirPass<'tcx>]], +) { + let phase_index = mir_phase.phase_index(); + let validate = tcx.sess.opts.debugging_opts.validate_mir; + + if body.phase >= mir_phase { + return; + } + + if validate { + validate::Validator { when: format!("input to phase {:?}", mir_phase), mir_phase } + .run_pass(tcx, body); + } + + let mut index = 0; + let mut run_pass = |pass: &dyn MirPass<'tcx>| { + let run_hooks = |body: &_, index, is_after| { + dump_mir::on_mir_pass( + tcx, + &format_args!("{:03}-{:03}", phase_index, index), + &pass.name(), + body, + is_after, + ); + }; + run_hooks(body, index, false); + pass.run_pass(tcx, body); + run_hooks(body, index, true); + + if validate { + validate::Validator { + when: format!("after {} in phase {:?}", pass.name(), mir_phase), + mir_phase, + } + .run_pass(tcx, body); + } + + index += 1; + }; + + for pass_group in passes { + for pass in *pass_group { + run_pass(*pass); + } + } + + body.phase = mir_phase; + + if mir_phase == MirPhase::Optimization { + validate::Validator { when: format!("end of phase {:?}", mir_phase), mir_phase } + .run_pass(tcx, body); + } +} + +fn mir_const_qualif(tcx: TyCtxt<'_>, def: ty::WithOptConstParam) -> ConstQualifs { + let const_kind = tcx.hir().body_const_context(def.did); + + // No need to const-check a non-const `fn`. + if const_kind.is_none() { + return Default::default(); + } + + // N.B., this `borrow()` is guaranteed to be valid (i.e., the value + // cannot yet be stolen), because `mir_promoted()`, which steals + // from `mir_const(), forces this query to execute before + // performing the steal. + let body = &tcx.mir_const(def).borrow(); + + if body.return_ty().references_error() { + tcx.sess.delay_span_bug(body.span, "mir_const_qualif: MIR had errors"); + return Default::default(); + } + + let ccx = check_consts::ConstCx { body, tcx, const_kind, param_env: tcx.param_env(def.did) }; + + let mut validator = check_consts::check::Checker::new(&ccx); + validator.check_body(); + + // We return the qualifs in the return place for every MIR body, even though it is only used + // when deciding to promote a reference to a `const` for now. + validator.qualifs_in_return_place() +} + +/// Make MIR ready for const evaluation. This is run on all MIR, not just on consts! +fn mir_const<'tcx>( + tcx: TyCtxt<'tcx>, + def: ty::WithOptConstParam, +) -> &'tcx Steal> { + if let Some(def) = def.try_upgrade(tcx) { + return tcx.mir_const(def); + } + + // Unsafety check uses the raw mir, so make sure it is run. + if !tcx.sess.opts.debugging_opts.thir_unsafeck { + if let Some(param_did) = def.const_param_did { + tcx.ensure().unsafety_check_result_for_const_arg((def.did, param_did)); + } else { + tcx.ensure().unsafety_check_result(def.did); + } + } + + let mut body = tcx.mir_built(def).steal(); + + util::dump_mir(tcx, None, "mir_map", &0, &body, |_, _| Ok(())); + + run_passes( + tcx, + &mut body, + MirPhase::Const, + &[&[ + // MIR-level lints. + &check_packed_ref::CheckPackedRef, + &check_const_item_mutation::CheckConstItemMutation, + &function_item_references::FunctionItemReferences, + // What we need to do constant evaluation. + &simplify::SimplifyCfg::new("initial"), + &rustc_peek::SanityCheck, + ]], + ); + tcx.alloc_steal_mir(body) +} + +/// Compute the main MIR body and the list of MIR bodies of the promoteds. +fn mir_promoted( + tcx: TyCtxt<'tcx>, + def: ty::WithOptConstParam, +) -> (&'tcx Steal>, &'tcx Steal>>) { + if let Some(def) = def.try_upgrade(tcx) { + return tcx.mir_promoted(def); + } + + // Ensure that we compute the `mir_const_qualif` for constants at + // this point, before we steal the mir-const result. + // Also this means promotion can rely on all const checks having been done. + let _ = tcx.mir_const_qualif_opt_const_arg(def); + let _ = tcx.mir_abstract_const_opt_const_arg(def.to_global()); + let mut body = tcx.mir_const(def).steal(); + + let mut required_consts = Vec::new(); + let mut required_consts_visitor = RequiredConstsVisitor::new(&mut required_consts); + for (bb, bb_data) in traversal::reverse_postorder(&body) { + required_consts_visitor.visit_basic_block_data(bb, bb_data); + } + body.required_consts = required_consts; + + let promote_pass = promote_consts::PromoteTemps::default(); + let promote: &[&dyn MirPass<'tcx>] = &[ + // What we need to run borrowck etc. + &promote_pass, + &simplify::SimplifyCfg::new("promote-consts"), + ]; + + let opt_coverage: &[&dyn MirPass<'tcx>] = + if tcx.sess.instrument_coverage() { &[&coverage::InstrumentCoverage] } else { &[] }; + + run_passes(tcx, &mut body, MirPhase::ConstPromotion, &[promote, opt_coverage]); + + let promoted = promote_pass.promoted_fragments.into_inner(); + (tcx.alloc_steal_mir(body), tcx.alloc_steal_promoted(promoted)) +} + +/// Compute the MIR that is used during CTFE (and thus has no optimizations run on it) +fn mir_for_ctfe<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx Body<'tcx> { + let did = def_id.expect_local(); + if let Some(def) = ty::WithOptConstParam::try_lookup(did, tcx) { + tcx.mir_for_ctfe_of_const_arg(def) + } else { + tcx.arena.alloc(inner_mir_for_ctfe(tcx, ty::WithOptConstParam::unknown(did))) + } +} + +/// Same as `mir_for_ctfe`, but used to get the MIR of a const generic parameter. +/// The docs on `WithOptConstParam` explain this a bit more, but the TLDR is that +/// we'd get cycle errors with `mir_for_ctfe`, because typeck would need to typeck +/// the const parameter while type checking the main body, which in turn would try +/// to type check the main body again. +fn mir_for_ctfe_of_const_arg<'tcx>( + tcx: TyCtxt<'tcx>, + (did, param_did): (LocalDefId, DefId), +) -> &'tcx Body<'tcx> { + tcx.arena.alloc(inner_mir_for_ctfe( + tcx, + ty::WithOptConstParam { did, const_param_did: Some(param_did) }, + )) +} + +fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: ty::WithOptConstParam) -> Body<'_> { + // FIXME: don't duplicate this between the optimized_mir/mir_for_ctfe queries + if tcx.is_constructor(def.did.to_def_id()) { + // There's no reason to run all of the MIR passes on constructors when + // we can just output the MIR we want directly. This also saves const + // qualification and borrow checking the trouble of special casing + // constructors. + return shim::build_adt_ctor(tcx, def.did.to_def_id()); + } + + let context = tcx + .hir() + .body_const_context(def.did) + .expect("mir_for_ctfe should not be used for runtime functions"); + + let mut body = tcx.mir_drops_elaborated_and_const_checked(def).borrow().clone(); + + match context { + // Do not const prop functions, either they get executed at runtime or exported to metadata, + // so we run const prop on them, or they don't, in which case we const evaluate some control + // flow paths of the function and any errors in those paths will get emitted as const eval + // errors. + hir::ConstContext::ConstFn => {} + // Static items always get evaluated, so we can just let const eval see if any erroneous + // control flow paths get executed. + hir::ConstContext::Static(_) => {} + // Associated constants get const prop run so we detect common failure situations in the + // crate that defined the constant. + // Technically we want to not run on regular const items, but oli-obk doesn't know how to + // conveniently detect that at this point without looking at the HIR. + hir::ConstContext::Const => { + #[rustfmt::skip] + let optimizations: &[&dyn MirPass<'_>] = &[ + &const_prop::ConstProp, + ]; + + #[rustfmt::skip] + run_passes( + tcx, + &mut body, + MirPhase::Optimization, + &[ + optimizations, + ], + ); + } + } + + debug_assert!(!body.has_free_regions(tcx), "Free regions in MIR for CTFE"); + + body +} + +/// Obtain just the main MIR (no promoteds) and run some cleanups on it. This also runs +/// mir borrowck *before* doing so in order to ensure that borrowck can be run and doesn't +/// end up missing the source MIR due to stealing happening. +fn mir_drops_elaborated_and_const_checked<'tcx>( + tcx: TyCtxt<'tcx>, + def: ty::WithOptConstParam, +) -> &'tcx Steal> { + if let Some(def) = def.try_upgrade(tcx) { + return tcx.mir_drops_elaborated_and_const_checked(def); + } + + // (Mir-)Borrowck uses `mir_promoted`, so we have to force it to + // execute before we can steal. + if let Some(param_did) = def.const_param_did { + tcx.ensure().mir_borrowck_const_arg((def.did, param_did)); + } else { + tcx.ensure().mir_borrowck(def.did); + } + + let hir_id = tcx.hir().local_def_id_to_hir_id(def.did); + use rustc_middle::hir::map::blocks::FnLikeNode; + let is_fn_like = FnLikeNode::from_node(tcx.hir().get(hir_id)).is_some(); + if is_fn_like { + let did = def.did.to_def_id(); + let def = ty::WithOptConstParam::unknown(did); + + // Do not compute the mir call graph without said call graph actually being used. + if inline::is_enabled(tcx) { + let _ = tcx.mir_inliner_callees(ty::InstanceDef::Item(def)); + } + } + + let (body, _) = tcx.mir_promoted(def); + let mut body = body.steal(); + + run_post_borrowck_cleanup_passes(tcx, &mut body); + check_consts::post_drop_elaboration::check_live_drops(tcx, &body); + tcx.alloc_steal_mir(body) +} + +/// After this series of passes, no lifetime analysis based on borrowing can be done. +fn run_post_borrowck_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + debug!("post_borrowck_cleanup({:?})", body.source.def_id()); + + let post_borrowck_cleanup: &[&dyn MirPass<'tcx>] = &[ + // Remove all things only needed by analysis + &simplify_branches::SimplifyBranches::new("initial"), + &remove_noop_landing_pads::RemoveNoopLandingPads, + &cleanup_post_borrowck::CleanupNonCodegenStatements, + &simplify::SimplifyCfg::new("early-opt"), + // These next passes must be executed together + &add_call_guards::CriticalCallEdges, + &elaborate_drops::ElaborateDrops, + // This will remove extraneous landing pads which are no longer + // necessary as well as well as forcing any call in a non-unwinding + // function calling a possibly-unwinding function to abort the process. + &abort_unwinding_calls::AbortUnwindingCalls, + // AddMovesForPackedDrops needs to run after drop + // elaboration. + &add_moves_for_packed_drops::AddMovesForPackedDrops, + // `AddRetag` needs to run after `ElaborateDrops`. Otherwise it should run fairly late, + // but before optimizations begin. + &add_retag::AddRetag, + &lower_intrinsics::LowerIntrinsics, + &simplify::SimplifyCfg::new("elaborate-drops"), + // `Deaggregator` is conceptually part of MIR building, some backends rely on it happening + // and it can help optimizations. + &deaggregator::Deaggregator, + ]; + + run_passes(tcx, body, MirPhase::DropLowering, &[post_borrowck_cleanup]); +} + +fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + let mir_opt_level = tcx.sess.mir_opt_level(); + + // Lowering generator control-flow and variables has to happen before we do anything else + // to them. We run some optimizations before that, because they may be harder to do on the state + // machine than on MIR with async primitives. + let optimizations_with_generators: &[&dyn MirPass<'tcx>] = &[ + &lower_slice_len::LowerSliceLenCalls, // has to be done before inlining, otherwise actual call will be almost always inlined. Also simple, so can just do first + &unreachable_prop::UnreachablePropagation, + &uninhabited_enum_branching::UninhabitedEnumBranching, + &simplify::SimplifyCfg::new("after-uninhabited-enum-branching"), + &inline::Inline, + &generator::StateTransform, + ]; + + // Even if we don't do optimizations, we still have to lower generators for codegen. + let no_optimizations_with_generators: &[&dyn MirPass<'tcx>] = &[&generator::StateTransform]; + + // The main optimizations that we do on MIR. + let optimizations: &[&dyn MirPass<'tcx>] = &[ + &remove_storage_markers::RemoveStorageMarkers, + &remove_zsts::RemoveZsts, + &const_goto::ConstGoto, + &remove_unneeded_drops::RemoveUnneededDrops, + &match_branches::MatchBranchSimplification, + // inst combine is after MatchBranchSimplification to clean up Ne(_1, false) + &multiple_return_terminators::MultipleReturnTerminators, + &instcombine::InstCombine, + &separate_const_switch::SeparateConstSwitch, + &const_prop::ConstProp, + &simplify_branches::SimplifyBranches::new("after-const-prop"), + &early_otherwise_branch::EarlyOtherwiseBranch, + &simplify_comparison_integral::SimplifyComparisonIntegral, + &simplify_try::SimplifyArmIdentity, + &simplify_try::SimplifyBranchSame, + &dest_prop::DestinationPropagation, + &simplify_branches::SimplifyBranches::new("final"), + &remove_noop_landing_pads::RemoveNoopLandingPads, + &simplify::SimplifyCfg::new("final"), + &nrvo::RenameReturnPlace, + &const_debuginfo::ConstDebugInfo, + &simplify::SimplifyLocals, + &multiple_return_terminators::MultipleReturnTerminators, + &deduplicate_blocks::DeduplicateBlocks, + ]; + + // Optimizations to run even if mir optimizations have been disabled. + let no_optimizations: &[&dyn MirPass<'tcx>] = &[ + // FIXME(#70073): This pass is responsible for both optimization as well as some lints. + &const_prop::ConstProp, + ]; + + // Some cleanup necessary at least for LLVM and potentially other codegen backends. + let pre_codegen_cleanup: &[&dyn MirPass<'tcx>] = &[ + &add_call_guards::CriticalCallEdges, + // Dump the end result for testing and debugging purposes. + &dump_mir::Marker("PreCodegen"), + ]; + + // End of pass declarations, now actually run the passes. + // Generator Lowering + #[rustfmt::skip] + run_passes( + tcx, + body, + MirPhase::GeneratorLowering, + &[ + if mir_opt_level > 0 { + optimizations_with_generators + } else { + no_optimizations_with_generators + } + ], + ); + + // Main optimization passes + #[rustfmt::skip] + run_passes( + tcx, + body, + MirPhase::Optimization, + &[ + if mir_opt_level > 0 { optimizations } else { no_optimizations }, + pre_codegen_cleanup, + ], + ); +} + +/// Optimize the MIR and prepare it for codegen. +fn optimized_mir<'tcx>(tcx: TyCtxt<'tcx>, did: DefId) -> &'tcx Body<'tcx> { + let did = did.expect_local(); + assert_eq!(ty::WithOptConstParam::try_lookup(did, tcx), None); + tcx.arena.alloc(inner_optimized_mir(tcx, did)) +} + +fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> { + if tcx.is_constructor(did.to_def_id()) { + // There's no reason to run all of the MIR passes on constructors when + // we can just output the MIR we want directly. This also saves const + // qualification and borrow checking the trouble of special casing + // constructors. + return shim::build_adt_ctor(tcx, did.to_def_id()); + } + + match tcx.hir().body_const_context(did) { + // Run the `mir_for_ctfe` query, which depends on `mir_drops_elaborated_and_const_checked` + // which we are going to steal below. Thus we need to run `mir_for_ctfe` first, so it + // computes and caches its result. + Some(hir::ConstContext::ConstFn) => tcx.ensure().mir_for_ctfe(did), + None => {} + Some(other) => panic!("do not use `optimized_mir` for constants: {:?}", other), + } + let mut body = + tcx.mir_drops_elaborated_and_const_checked(ty::WithOptConstParam::unknown(did)).steal(); + run_optimization_passes(tcx, &mut body); + + debug_assert!(!body.has_free_regions(tcx), "Free regions in optimized MIR"); + + body +} + +/// Fetch all the promoteds of an item and prepare their MIR bodies to be ready for +/// constant evaluation once all substitutions become known. +fn promoted_mir<'tcx>( + tcx: TyCtxt<'tcx>, + def: ty::WithOptConstParam, +) -> &'tcx IndexVec> { + if tcx.is_constructor(def.did.to_def_id()) { + return tcx.arena.alloc(IndexVec::new()); + } + + if let Some(param_did) = def.const_param_did { + tcx.ensure().mir_borrowck_const_arg((def.did, param_did)); + } else { + tcx.ensure().mir_borrowck(def.did); + } + let (_, promoted) = tcx.mir_promoted(def); + let mut promoted = promoted.steal(); + + for body in &mut promoted { + run_post_borrowck_cleanup_passes(tcx, body); + } + + debug_assert!(!promoted.has_free_regions(tcx), "Free regions in promoted MIR"); + + tcx.arena.alloc(promoted) +} diff --git a/compiler/rustc_mir/src/transform/lower_intrinsics.rs b/compiler/rustc_mir_transform/src/lower_intrinsics.rs similarity index 99% rename from compiler/rustc_mir/src/transform/lower_intrinsics.rs rename to compiler/rustc_mir_transform/src/lower_intrinsics.rs index e9f1d4f2ce827..2f89b041c27b1 100644 --- a/compiler/rustc_mir/src/transform/lower_intrinsics.rs +++ b/compiler/rustc_mir_transform/src/lower_intrinsics.rs @@ -1,6 +1,6 @@ //! Lowers intrinsic calls -use crate::transform::MirPass; +use crate::MirPass; use rustc_middle::mir::*; use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::{self, Ty, TyCtxt}; diff --git a/compiler/rustc_mir/src/transform/lower_slice_len.rs b/compiler/rustc_mir_transform/src/lower_slice_len.rs similarity index 98% rename from compiler/rustc_mir/src/transform/lower_slice_len.rs rename to compiler/rustc_mir_transform/src/lower_slice_len.rs index c3eb2d9f921b3..eac2b97a14cf1 100644 --- a/compiler/rustc_mir/src/transform/lower_slice_len.rs +++ b/compiler/rustc_mir_transform/src/lower_slice_len.rs @@ -1,11 +1,11 @@ //! This pass lowers calls to core::slice::len to just Len op. //! It should run before inlining! -use crate::transform::MirPass; use rustc_hir::def_id::DefId; use rustc_index::vec::IndexVec; use rustc_middle::mir::*; use rustc_middle::ty::{self, TyCtxt}; +use rustc_mir::transform::MirPass; pub struct LowerSliceLenCalls; diff --git a/compiler/rustc_mir/src/transform/match_branches.rs b/compiler/rustc_mir_transform/src/match_branches.rs similarity index 98% rename from compiler/rustc_mir/src/transform/match_branches.rs rename to compiler/rustc_mir_transform/src/match_branches.rs index 37a3fa50a52dd..24eaf27897715 100644 --- a/compiler/rustc_mir/src/transform/match_branches.rs +++ b/compiler/rustc_mir_transform/src/match_branches.rs @@ -1,4 +1,4 @@ -use crate::transform::MirPass; +use crate::MirPass; use rustc_middle::mir::*; use rustc_middle::ty::TyCtxt; use std::iter; @@ -134,7 +134,7 @@ impl<'tcx> MirPass<'tcx> for MatchBranchSimplification { let const_cmp = Operand::const_from_scalar( tcx, switch_ty, - crate::interpret::Scalar::from_uint(val, size), + rustc_mir::interpret::Scalar::from_uint(val, size), rustc_span::DUMMY_SP, ); let op = if f_b { BinOp::Eq } else { BinOp::Ne }; diff --git a/compiler/rustc_mir/src/transform/multiple_return_terminators.rs b/compiler/rustc_mir_transform/src/multiple_return_terminators.rs similarity index 96% rename from compiler/rustc_mir/src/transform/multiple_return_terminators.rs rename to compiler/rustc_mir_transform/src/multiple_return_terminators.rs index cd2db18055286..b614917a88369 100644 --- a/compiler/rustc_mir/src/transform/multiple_return_terminators.rs +++ b/compiler/rustc_mir_transform/src/multiple_return_terminators.rs @@ -1,7 +1,7 @@ //! This pass removes jumps to basic blocks containing only a return, and replaces them with a //! return instead. -use crate::transform::{simplify, MirPass}; +use crate::{simplify, MirPass}; use rustc_index::bit_set::BitSet; use rustc_middle::mir::*; use rustc_middle::ty::TyCtxt; diff --git a/compiler/rustc_mir/src/transform/nrvo.rs b/compiler/rustc_mir_transform/src/nrvo.rs similarity index 99% rename from compiler/rustc_mir/src/transform/nrvo.rs rename to compiler/rustc_mir_transform/src/nrvo.rs index 445dc12909c14..3ac4e77cf9a75 100644 --- a/compiler/rustc_mir/src/transform/nrvo.rs +++ b/compiler/rustc_mir_transform/src/nrvo.rs @@ -6,7 +6,7 @@ use rustc_middle::mir::visit::{MutVisitor, NonUseContext, PlaceContext, Visitor} use rustc_middle::mir::{self, BasicBlock, Local, Location}; use rustc_middle::ty::TyCtxt; -use crate::transform::MirPass; +use crate::MirPass; /// This pass looks for MIR that always copies the same local into the return place and eliminates /// the copy by renaming all uses of that local to `_0`. diff --git a/compiler/rustc_mir/src/transform/remove_noop_landing_pads.rs b/compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs similarity index 99% rename from compiler/rustc_mir/src/transform/remove_noop_landing_pads.rs rename to compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs index 5347846a4b334..52144cbaa876b 100644 --- a/compiler/rustc_mir/src/transform/remove_noop_landing_pads.rs +++ b/compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs @@ -1,5 +1,5 @@ -use crate::transform::MirPass; use crate::util::patch::MirPatch; +use crate::MirPass; use rustc_index::bit_set::BitSet; use rustc_middle::mir::*; use rustc_middle::ty::TyCtxt; diff --git a/compiler/rustc_mir/src/transform/remove_storage_markers.rs b/compiler/rustc_mir_transform/src/remove_storage_markers.rs similarity index 96% rename from compiler/rustc_mir/src/transform/remove_storage_markers.rs rename to compiler/rustc_mir_transform/src/remove_storage_markers.rs index 2d529feb072f9..0c7323cbac5b1 100644 --- a/compiler/rustc_mir/src/transform/remove_storage_markers.rs +++ b/compiler/rustc_mir_transform/src/remove_storage_markers.rs @@ -1,6 +1,6 @@ //! This pass removes storage markers if they won't be emitted during codegen. -use crate::transform::MirPass; +use crate::MirPass; use rustc_middle::mir::*; use rustc_middle::ty::TyCtxt; diff --git a/compiler/rustc_mir/src/transform/remove_unneeded_drops.rs b/compiler/rustc_mir_transform/src/remove_unneeded_drops.rs similarity index 97% rename from compiler/rustc_mir/src/transform/remove_unneeded_drops.rs rename to compiler/rustc_mir_transform/src/remove_unneeded_drops.rs index 02e45021a0aaf..5c9d04a08bfec 100644 --- a/compiler/rustc_mir/src/transform/remove_unneeded_drops.rs +++ b/compiler/rustc_mir_transform/src/remove_unneeded_drops.rs @@ -1,6 +1,6 @@ //! This pass replaces a drop of a type that does not need dropping, with a goto -use crate::transform::MirPass; +use crate::MirPass; use rustc_middle::mir::*; use rustc_middle::ty::TyCtxt; diff --git a/compiler/rustc_mir/src/transform/remove_zsts.rs b/compiler/rustc_mir_transform/src/remove_zsts.rs similarity index 98% rename from compiler/rustc_mir/src/transform/remove_zsts.rs rename to compiler/rustc_mir_transform/src/remove_zsts.rs index 03277b1b2e0be..25e3c52132cca 100644 --- a/compiler/rustc_mir/src/transform/remove_zsts.rs +++ b/compiler/rustc_mir_transform/src/remove_zsts.rs @@ -1,6 +1,6 @@ //! Removes assignments to ZST places. -use crate::transform::MirPass; +use crate::MirPass; use rustc_middle::mir::tcx::PlaceTy; use rustc_middle::mir::{Body, LocalDecls, Place, StatementKind}; use rustc_middle::ty::{self, Ty, TyCtxt}; diff --git a/compiler/rustc_mir/src/transform/required_consts.rs b/compiler/rustc_mir_transform/src/required_consts.rs similarity index 100% rename from compiler/rustc_mir/src/transform/required_consts.rs rename to compiler/rustc_mir_transform/src/required_consts.rs diff --git a/compiler/rustc_mir/src/transform/separate_const_switch.rs b/compiler/rustc_mir_transform/src/separate_const_switch.rs similarity index 99% rename from compiler/rustc_mir/src/transform/separate_const_switch.rs rename to compiler/rustc_mir_transform/src/separate_const_switch.rs index 87cd27984a073..1945e551485d8 100644 --- a/compiler/rustc_mir/src/transform/separate_const_switch.rs +++ b/compiler/rustc_mir_transform/src/separate_const_switch.rs @@ -37,7 +37,7 @@ //! simplicity rather than completeness (it notably //! sometimes duplicates abusively). -use crate::transform::MirPass; +use crate::MirPass; use rustc_middle::mir::*; use rustc_middle::ty::TyCtxt; use smallvec::SmallVec; diff --git a/compiler/rustc_mir/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs similarity index 99% rename from compiler/rustc_mir/src/shim.rs rename to compiler/rustc_mir_transform/src/shim.rs index 8083ec954478a..c57c1e1241691 100644 --- a/compiler/rustc_mir/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::transform::{ - abort_unwinding_calls, add_call_guards, add_moves_for_packed_drops, remove_noop_landing_pads, - run_passes, simplify, -}; 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, +}; pub fn provide(providers: &mut Providers) { providers.mir_shims = make_shim; diff --git a/compiler/rustc_mir/src/transform/simplify.rs b/compiler/rustc_mir_transform/src/simplify.rs similarity index 99% rename from compiler/rustc_mir/src/transform/simplify.rs rename to compiler/rustc_mir_transform/src/simplify.rs index 3ecb5133e3b48..e3cfd1d0afcd7 100644 --- a/compiler/rustc_mir/src/transform/simplify.rs +++ b/compiler/rustc_mir_transform/src/simplify.rs @@ -27,7 +27,7 @@ //! naively generate still contains the `_a = ()` write in the unreachable block "after" the //! return. -use crate::transform::MirPass; +use crate::MirPass; use rustc_index::vec::{Idx, IndexVec}; use rustc_middle::mir::coverage::*; use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Visitor}; diff --git a/compiler/rustc_mir/src/transform/simplify_branches.rs b/compiler/rustc_mir_transform/src/simplify_branches.rs similarity index 98% rename from compiler/rustc_mir/src/transform/simplify_branches.rs rename to compiler/rustc_mir_transform/src/simplify_branches.rs index a9a45e61a38cb..df90cfa318df0 100644 --- a/compiler/rustc_mir/src/transform/simplify_branches.rs +++ b/compiler/rustc_mir_transform/src/simplify_branches.rs @@ -1,6 +1,6 @@ //! A pass that simplifies branches when their condition is known. -use crate::transform::MirPass; +use crate::MirPass; use rustc_middle::mir::*; use rustc_middle::ty::TyCtxt; diff --git a/compiler/rustc_mir/src/transform/simplify_comparison_integral.rs b/compiler/rustc_mir_transform/src/simplify_comparison_integral.rs similarity index 100% rename from compiler/rustc_mir/src/transform/simplify_comparison_integral.rs rename to compiler/rustc_mir_transform/src/simplify_comparison_integral.rs diff --git a/compiler/rustc_mir/src/transform/simplify_try.rs b/compiler/rustc_mir_transform/src/simplify_try.rs similarity index 99% rename from compiler/rustc_mir/src/transform/simplify_try.rs rename to compiler/rustc_mir_transform/src/simplify_try.rs index 7c35dab694f3c..fd36671b36f54 100644 --- a/compiler/rustc_mir/src/transform/simplify_try.rs +++ b/compiler/rustc_mir_transform/src/simplify_try.rs @@ -9,7 +9,7 @@ //! //! into just `x`. -use crate::transform::{simplify, MirPass}; +use crate::{simplify, MirPass}; use itertools::Itertools as _; use rustc_index::{bit_set::BitSet, vec::IndexVec}; use rustc_middle::mir::visit::{NonUseContext, PlaceContext, Visitor}; diff --git a/compiler/rustc_mir/src/transform/uninhabited_enum_branching.rs b/compiler/rustc_mir_transform/src/uninhabited_enum_branching.rs similarity index 99% rename from compiler/rustc_mir/src/transform/uninhabited_enum_branching.rs rename to compiler/rustc_mir_transform/src/uninhabited_enum_branching.rs index 5c6c158d46e3a..5cef64d7786b3 100644 --- a/compiler/rustc_mir/src/transform/uninhabited_enum_branching.rs +++ b/compiler/rustc_mir_transform/src/uninhabited_enum_branching.rs @@ -1,6 +1,6 @@ //! A pass that eliminates branches on uninhabited enum variants. -use crate::transform::MirPass; +use crate::MirPass; use rustc_data_structures::stable_set::FxHashSet; use rustc_middle::mir::{ BasicBlock, BasicBlockData, Body, Local, Operand, Rvalue, StatementKind, SwitchTargets, diff --git a/compiler/rustc_mir/src/transform/unreachable_prop.rs b/compiler/rustc_mir_transform/src/unreachable_prop.rs similarity index 98% rename from compiler/rustc_mir/src/transform/unreachable_prop.rs rename to compiler/rustc_mir_transform/src/unreachable_prop.rs index e7fb6b4f6b4ad..baf381081ddab 100644 --- a/compiler/rustc_mir/src/transform/unreachable_prop.rs +++ b/compiler/rustc_mir_transform/src/unreachable_prop.rs @@ -2,8 +2,8 @@ //! when all of their successors are unreachable. This is achieved through a //! post-order traversal of the blocks. -use crate::transform::simplify; -use crate::transform::MirPass; +use crate::simplify; +use crate::MirPass; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_middle::mir::*; use rustc_middle::ty::TyCtxt; From 81a600b6b7db07ebac28c8ddedd357e3c5b9951d Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 2 Jan 2021 14:42:15 +0100 Subject: [PATCH 3/7] Move monomorphize code to its own crate. --- Cargo.lock | 17 +++++++++++ .../scripts/filter_profile.rs | 4 +-- compiler/rustc_interface/Cargo.toml | 1 + compiler/rustc_interface/src/passes.rs | 1 + compiler/rustc_mir/src/lib.rs | 4 --- compiler/rustc_monomorphize/Cargo.toml | 20 +++++++++++++ .../src}/collector.rs | 6 ++-- .../mod.rs => rustc_monomorphize/src/lib.rs} | 28 +++++++++++++++---- .../src}/partitioning/default.rs | 6 ++-- .../src}/partitioning/merging.rs | 2 +- .../src}/partitioning/mod.rs | 4 +-- .../src}/polymorphize.rs | 0 .../src}/util.rs | 0 13 files changed, 71 insertions(+), 22 deletions(-) create mode 100644 compiler/rustc_monomorphize/Cargo.toml rename compiler/{rustc_mir/src/monomorphize => rustc_monomorphize/src}/collector.rs (99%) rename compiler/{rustc_mir/src/monomorphize/mod.rs => rustc_monomorphize/src/lib.rs} (66%) rename compiler/{rustc_mir/src/monomorphize => rustc_monomorphize/src}/partitioning/default.rs (99%) rename compiler/{rustc_mir/src/monomorphize => rustc_monomorphize/src}/partitioning/merging.rs (98%) rename compiler/{rustc_mir/src/monomorphize => rustc_monomorphize/src}/partitioning/mod.rs (99%) rename compiler/{rustc_mir/src/monomorphize => rustc_monomorphize/src}/polymorphize.rs (100%) rename compiler/{rustc_mir/src/monomorphize => rustc_monomorphize/src}/util.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 3ec143d2492f9..841fc608476d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3929,6 +3929,7 @@ dependencies = [ "rustc_mir", "rustc_mir_build", "rustc_mir_transform", + "rustc_monomorphize", "rustc_parse", "rustc_passes", "rustc_plugin_impl", @@ -4142,6 +4143,22 @@ dependencies = [ "tracing", ] +[[package]] +name = "rustc_monomorphize" +version = "0.0.0" +dependencies = [ + "rustc_data_structures", + "rustc_errors", + "rustc_hir", + "rustc_index", + "rustc_middle", + "rustc_session", + "rustc_span", + "rustc_target", + "smallvec", + "tracing", +] + [[package]] name = "rustc_parse" version = "0.0.0" diff --git a/compiler/rustc_codegen_cranelift/scripts/filter_profile.rs b/compiler/rustc_codegen_cranelift/scripts/filter_profile.rs index c4801a0a87b88..7a51293f5cda5 100755 --- a/compiler/rustc_codegen_cranelift/scripts/filter_profile.rs +++ b/compiler/rustc_codegen_cranelift/scripts/filter_profile.rs @@ -42,7 +42,7 @@ fn main() -> Result<(), Box> { continue; } - if stack.contains("rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items") + if stack.contains("rustc_monomorphize::partitioning::collect_and_partition_mono_items") || stack.contains("rustc_incremental::assert_dep_graph::assert_dep_graph") || stack.contains("rustc_symbol_mangling::test::report_symbol_names") { @@ -81,7 +81,7 @@ fn main() -> Result<(), Box> { } const COLLECT_AND_PARTITION_MONO_ITEMS: &str = - "rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items"; + "rustc_monomorphize::partitioning::collect_and_partition_mono_items"; if let Some(index) = stack.find(COLLECT_AND_PARTITION_MONO_ITEMS) { stack = &stack[..index + COLLECT_AND_PARTITION_MONO_ITEMS.len()]; } diff --git a/compiler/rustc_interface/Cargo.toml b/compiler/rustc_interface/Cargo.toml index 8b27726925835..306728dbeac59 100644 --- a/compiler/rustc_interface/Cargo.toml +++ b/compiler/rustc_interface/Cargo.toml @@ -35,6 +35,7 @@ rustc_metadata = { path = "../rustc_metadata" } rustc_mir = { path = "../rustc_mir" } rustc_mir_build = { path = "../rustc_mir_build" } rustc_mir_transform = { path = "../rustc_mir_transform" } +rustc_monomorphize = { path = "../rustc_monomorphize" } rustc_passes = { path = "../rustc_passes" } rustc_typeck = { path = "../rustc_typeck" } rustc_lint = { path = "../rustc_lint" } diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 7d41db0d4aeee..547823a067cf5 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -743,6 +743,7 @@ pub static DEFAULT_QUERY_PROVIDERS: SyncLazy = SyncLazy::new(|| { mir_borrowck::provide(providers); mir_build::provide(providers); rustc_mir_transform::provide(providers); + rustc_monomorphize::provide(providers); rustc_privacy::provide(providers); typeck::provide(providers); ty::provide(providers); diff --git a/compiler/rustc_mir/src/lib.rs b/compiler/rustc_mir/src/lib.rs index 4c79c7da15c52..fa1f27daa804f 100644 --- a/compiler/rustc_mir/src/lib.rs +++ b/compiler/rustc_mir/src/lib.rs @@ -4,7 +4,6 @@ Rust MIR: a lowered representation of Rust. */ -#![feature(array_windows)] #![feature(assert_matches)] #![cfg_attr(bootstrap, feature(bindings_after_at))] #![feature(associated_type_defaults)] @@ -36,7 +35,6 @@ extern crate rustc_middle; pub mod const_eval; pub mod dataflow; pub mod interpret; -pub mod monomorphize; pub mod transform; pub mod util; @@ -44,8 +42,6 @@ use rustc_middle::ty::query::Providers; pub fn provide(providers: &mut Providers) { const_eval::provide(providers); - monomorphize::partitioning::provide(providers); - monomorphize::polymorphize::provide(providers); providers.eval_to_const_value_raw = const_eval::eval_to_const_value_raw_provider; providers.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider; providers.const_caller_location = const_eval::const_caller_location; diff --git a/compiler/rustc_monomorphize/Cargo.toml b/compiler/rustc_monomorphize/Cargo.toml new file mode 100644 index 0000000000000..93a964bf3cc0e --- /dev/null +++ b/compiler/rustc_monomorphize/Cargo.toml @@ -0,0 +1,20 @@ +[package] +authors = ["The Rust Project Developers"] +name = "rustc_monomorphize" +version = "0.0.0" +edition = "2018" + +[lib] +doctest = false + +[dependencies] +smallvec = { version = "1.6.1", features = ["union", "may_dangle"] } +tracing = "0.1" +rustc_data_structures = { path = "../rustc_data_structures" } +rustc_errors = { path = "../rustc_errors" } +rustc_hir = { path = "../rustc_hir" } +rustc_index = { path = "../rustc_index" } +rustc_middle = { path = "../rustc_middle" } +rustc_session = { path = "../rustc_session" } +rustc_span = { path = "../rustc_span" } +rustc_target = { path = "../rustc_target" } diff --git a/compiler/rustc_mir/src/monomorphize/collector.rs b/compiler/rustc_monomorphize/src/collector.rs similarity index 99% rename from compiler/rustc_mir/src/monomorphize/collector.rs rename to compiler/rustc_monomorphize/src/collector.rs index 4cb362238c1c5..1e39b1bd5e80e 100644 --- a/compiler/rustc_mir/src/monomorphize/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -178,8 +178,6 @@ //! this is not implemented however: a mono item will be produced //! regardless of whether it is actually needed or not. -use crate::monomorphize; - use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync::{par_iter, MTLock, MTRef, ParallelIterator}; use rustc_errors::{ErrorReported, FatalError}; @@ -1052,7 +1050,7 @@ fn find_vtable_types_for_unsizing<'tcx>( assert_eq!(source_adt_def, target_adt_def); let CustomCoerceUnsized::Struct(coerce_index) = - monomorphize::custom_coerce_unsize_info(tcx, source_ty, target_ty); + crate::custom_coerce_unsize_info(tcx, source_ty, target_ty); let source_fields = &source_adt_def.non_enum_variant().fields; let target_fields = &target_adt_def.non_enum_variant().fields; @@ -1085,7 +1083,7 @@ fn create_fn_mono_item<'tcx>( let def_id = instance.def_id(); if tcx.sess.opts.debugging_opts.profile_closures && def_id.is_local() && tcx.is_closure(def_id) { - monomorphize::util::dump_closure_profile(tcx, instance); + crate::util::dump_closure_profile(tcx, instance); } respan(source, MonoItem::Fn(instance.polymorphize(tcx))) diff --git a/compiler/rustc_mir/src/monomorphize/mod.rs b/compiler/rustc_monomorphize/src/lib.rs similarity index 66% rename from compiler/rustc_mir/src/monomorphize/mod.rs rename to compiler/rustc_monomorphize/src/lib.rs index 57d2723cf9cfd..2a40eeac5bdcb 100644 --- a/compiler/rustc_mir/src/monomorphize/mod.rs +++ b/compiler/rustc_monomorphize/src/lib.rs @@ -1,13 +1,24 @@ +#![feature(array_windows)] +#![feature(bool_to_option)] +#![feature(crate_visibility_modifier)] +#![feature(control_flow_enum)] +#![feature(in_band_lifetimes)] + +#[macro_use] +extern crate tracing; +#[macro_use] +extern crate rustc_middle; + +use rustc_hir::lang_items::LangItem; use rustc_middle::traits; use rustc_middle::ty::adjustment::CustomCoerceUnsized; +use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, Ty, TyCtxt}; -use rustc_hir::lang_items::LangItem; - -pub mod collector; -pub mod partitioning; -pub mod polymorphize; -pub mod util; +mod collector; +mod partitioning; +mod polymorphize; +mod util; fn custom_coerce_unsize_info<'tcx>( tcx: TyCtxt<'tcx>, @@ -31,3 +42,8 @@ fn custom_coerce_unsize_info<'tcx>( } } } + +pub fn provide(providers: &mut Providers) { + partitioning::provide(providers); + polymorphize::provide(providers); +} diff --git a/compiler/rustc_mir/src/monomorphize/partitioning/default.rs b/compiler/rustc_monomorphize/src/partitioning/default.rs similarity index 99% rename from compiler/rustc_mir/src/monomorphize/partitioning/default.rs rename to compiler/rustc_monomorphize/src/partitioning/default.rs index a559a6ce415a3..429ed53d37977 100644 --- a/compiler/rustc_mir/src/monomorphize/partitioning/default.rs +++ b/compiler/rustc_monomorphize/src/partitioning/default.rs @@ -13,9 +13,9 @@ use rustc_middle::ty::{self, DefIdTree, InstanceDef, TyCtxt}; use rustc_span::symbol::Symbol; use super::PartitioningCx; -use crate::monomorphize::collector::InliningMap; -use crate::monomorphize::partitioning::merging; -use crate::monomorphize::partitioning::{ +use crate::collector::InliningMap; +use crate::partitioning::merging; +use crate::partitioning::{ MonoItemPlacement, Partitioner, PostInliningPartitioning, PreInliningPartitioning, }; diff --git a/compiler/rustc_mir/src/monomorphize/partitioning/merging.rs b/compiler/rustc_monomorphize/src/partitioning/merging.rs similarity index 98% rename from compiler/rustc_mir/src/monomorphize/partitioning/merging.rs rename to compiler/rustc_monomorphize/src/partitioning/merging.rs index cbe366657905a..229468b47ff62 100644 --- a/compiler/rustc_mir/src/monomorphize/partitioning/merging.rs +++ b/compiler/rustc_monomorphize/src/partitioning/merging.rs @@ -6,7 +6,7 @@ use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder}; use rustc_span::symbol::{Symbol, SymbolStr}; use super::PartitioningCx; -use crate::monomorphize::partitioning::PreInliningPartitioning; +use crate::partitioning::PreInliningPartitioning; pub fn merge_codegen_units<'tcx>( cx: &PartitioningCx<'_, 'tcx>, diff --git a/compiler/rustc_mir/src/monomorphize/partitioning/mod.rs b/compiler/rustc_monomorphize/src/partitioning/mod.rs similarity index 99% rename from compiler/rustc_mir/src/monomorphize/partitioning/mod.rs rename to compiler/rustc_monomorphize/src/partitioning/mod.rs index 6ed0ab8be41ee..7a7a56a034ed2 100644 --- a/compiler/rustc_mir/src/monomorphize/partitioning/mod.rs +++ b/compiler/rustc_monomorphize/src/partitioning/mod.rs @@ -105,8 +105,8 @@ use rustc_middle::ty::query::Providers; use rustc_middle::ty::TyCtxt; use rustc_span::symbol::Symbol; -use crate::monomorphize::collector::InliningMap; -use crate::monomorphize::collector::{self, MonoItemCollectionMode}; +use crate::collector::InliningMap; +use crate::collector::{self, MonoItemCollectionMode}; pub struct PartitioningCx<'a, 'tcx> { tcx: TyCtxt<'tcx>, diff --git a/compiler/rustc_mir/src/monomorphize/polymorphize.rs b/compiler/rustc_monomorphize/src/polymorphize.rs similarity index 100% rename from compiler/rustc_mir/src/monomorphize/polymorphize.rs rename to compiler/rustc_monomorphize/src/polymorphize.rs diff --git a/compiler/rustc_mir/src/monomorphize/util.rs b/compiler/rustc_monomorphize/src/util.rs similarity index 100% rename from compiler/rustc_mir/src/monomorphize/util.rs rename to compiler/rustc_monomorphize/src/util.rs From fd9c04fe32d3b7700d600ae1be72d5758ffd66ff Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 5 Jan 2021 19:53:07 +0100 Subject: [PATCH 4/7] 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 841fc608476d1..ab9126fb5f9a5 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 e919c2cbc4f15..11b3ec28d45ff 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 eb4d815bfc3ca..ee2ce1d3f74c3 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 cb440b2cbb9f4..1e660ece90868 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 8f6181f410df4..758a660525d7a 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 980894d6b4d0f..cc09db0e3dc20 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 dd4886312da37..3c11408458629 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 ed3f846e4adc9..86b719bdfa0c7 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 9fe3d79e4ed09..c1aa4df992455 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 d40990d4676bc..8b2c0362261ca 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 265c14bb28676..1e712354d6a83 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 7c087d38eb748..79ab8b713f95d 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 c7d776bfde0d4..1671c7c627e19 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 63075d066a6dc..19224ca43dd91 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 e99a227a3a6ea..46a7485e4ef9c 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 2e5e8f683cdaa..87193e3ef5341 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 579ba43b6d8e7..a25cc000443c7 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 2403ce2d24f55..68b83fccc85fd 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 6868be50f1d06..c7c26cf599094 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 83f6e79d5fcf6..ef2154b31f4b3 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 0207d9c012ed0..b187b716199c8 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 3e8a93e08c29d..171fc45ea4696 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 05502d8b21f1c..0521443533b78 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 4d13274a1200d..b8b6ff93753f0 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 fa1f27daa804f..c24c9a9b5ee2b 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 0c38127682359..d02b4286c175a 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 a00301952b328..8e1b69a1d7413 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 abf43dd1d23bb..38c28f34934a4 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 835789069bb2e..40a32a76c9446 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 741c1e6b2c60f..4a406f8bfd088 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 0000000000000..adc3882f84325 --- /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 fa449a2368861..e2269562b3d9b 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 50756fc15fb85..7607ccc3aba83 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 7ff7c860591fb..804abc3b42b53 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 35115ca9db756..1d1553bbbd984 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 4e54257a1cb2d..a370f8e40f9ae 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 65e04ed6831cc..81d84f80ad4c1 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 bb7292cd0337a..07570e764f5e0 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 2d20f0d9547c1..0039d3188d57a 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 020a7b188fd13..771ad90af28d6 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 792664597fd9a..b468e50b391ca 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 f388d41d31771..282ea8db1bbdc 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 f4a1b0ddba53f..29ffed9934421 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 cba3ab5176eb3..bc0f69d190cd2 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 c48d0c8b8f2cf..9eaf2b6a21113 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 9de2f4a5f847b..513a85b591306 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 f7f0191502198..6043606c37957 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 08cc87ccc349d..2ea2e06029d67 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 ec9279ff00ccd..dd95f00142309 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 753948dacb370..2a24e1ea8d7ed 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 01d0c10eddcd3..d7f1ad7f69643 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 5ed13a0268d83..b9a48197a351a 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 f2486b58aac48..06366b6fc31d5 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 93f0a7f3d04ad..2c8bdf4a20750 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 52144cbaa876b..298bcd9dc24f9 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 c57c1e1241691..4d350fc87cb3a 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 19719502870bd..3c6faf117fde5 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 f5e43264a5c69..7041e4f980ef4 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); } From c5fc2609f0f81698616734e22adee9b9ed67f729 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 5 Jan 2021 20:08:11 +0100 Subject: [PATCH 5/7] Rename rustc_mir to rustc_const_eval. --- Cargo.lock | 56 +++++++++---------- compiler/rustc_borrowck/Cargo.toml | 2 +- .../src/diagnostics/conflict_errors.rs | 2 +- .../rustc_borrowck/src/diagnostics/mod.rs | 13 +++-- .../src/diagnostics/mutability_errors.rs | 2 +- compiler/rustc_borrowck/src/type_check/mod.rs | 2 +- .../Cargo.toml | 2 +- .../src/const_eval/error.rs | 0 .../src/const_eval/eval_queries.rs | 0 .../src/const_eval/fn_queries.rs | 0 .../src/const_eval/machine.rs | 0 .../src/const_eval/mod.rs | 0 .../src/interpret/cast.rs | 0 .../src/interpret/eval_context.rs | 0 .../src/interpret/intern.rs | 0 .../src/interpret/intrinsics.rs | 0 .../interpret/intrinsics/caller_location.rs | 0 .../src/interpret/intrinsics/type_name.rs | 0 .../src/interpret/machine.rs | 0 .../src/interpret/memory.rs | 0 .../src/interpret/mod.rs | 0 .../src/interpret/operand.rs | 0 .../src/interpret/operator.rs | 0 .../src/interpret/place.rs | 0 .../src/interpret/step.rs | 0 .../src/interpret/terminator.rs | 0 .../src/interpret/traits.rs | 0 .../src/interpret/util.rs | 0 .../src/interpret/validity.rs | 0 .../src/interpret/visitor.rs | 0 .../src/lib.rs | 0 .../src/transform/check_consts/check.rs | 0 .../src/transform/check_consts/mod.rs | 0 .../src/transform/check_consts/ops.rs | 0 .../check_consts/post_drop_elaboration.rs | 0 .../src/transform/check_consts/qualifs.rs | 0 .../src/transform/check_consts/resolver.rs | 0 .../src/transform/mod.rs | 0 .../src/transform/promote_consts.rs | 0 .../src/transform/validate.rs | 0 .../src/util/aggregate.rs | 0 .../src/util/alignment.rs | 0 .../src/util/collect_writes.rs | 0 .../src/util/find_self_call.rs | 0 .../src/util/mod.rs | 0 compiler/rustc_driver/Cargo.toml | 2 +- compiler/rustc_interface/Cargo.toml | 2 +- compiler/rustc_interface/src/passes.rs | 3 +- compiler/rustc_middle/src/lib.rs | 2 +- compiler/rustc_middle/src/mir/mod.rs | 2 +- compiler/rustc_middle/src/mir/query.rs | 4 +- compiler/rustc_middle/src/ty/sty.rs | 4 +- .../rustc_mir_dataflow/src/framework/mod.rs | 2 +- compiler/rustc_mir_transform/Cargo.toml | 2 +- .../rustc_mir_transform/src/const_prop.rs | 4 +- compiler/rustc_mir_transform/src/lib.rs | 10 ++-- .../src/lower_slice_len.rs | 2 +- .../rustc_mir_transform/src/match_branches.rs | 2 +- .../src/check/generator_interior.rs | 2 +- src/librustdoc/clean/mod.rs | 2 +- src/librustdoc/lib.rs | 2 +- .../sepcomp-cci-copies/Makefile | 2 +- src/tools/clippy/clippy_utils/src/lib.rs | 2 +- .../clippy_utils/src/qualify_min_const_fn.rs | 2 +- 64 files changed, 66 insertions(+), 66 deletions(-) rename compiler/{rustc_mir => rustc_const_eval}/Cargo.toml (96%) rename compiler/{rustc_mir => rustc_const_eval}/src/const_eval/error.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/const_eval/eval_queries.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/const_eval/fn_queries.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/const_eval/machine.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/const_eval/mod.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/interpret/cast.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/interpret/eval_context.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/interpret/intern.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/interpret/intrinsics.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/interpret/intrinsics/caller_location.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/interpret/intrinsics/type_name.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/interpret/machine.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/interpret/memory.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/interpret/mod.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/interpret/operand.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/interpret/operator.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/interpret/place.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/interpret/step.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/interpret/terminator.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/interpret/traits.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/interpret/util.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/interpret/validity.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/interpret/visitor.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/lib.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/transform/check_consts/check.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/transform/check_consts/mod.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/transform/check_consts/ops.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/transform/check_consts/post_drop_elaboration.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/transform/check_consts/qualifs.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/transform/check_consts/resolver.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/transform/mod.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/transform/promote_consts.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/transform/validate.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/util/aggregate.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/util/alignment.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/util/collect_writes.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/util/find_self_call.rs (100%) rename compiler/{rustc_mir => rustc_const_eval}/src/util/mod.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index ab9126fb5f9a5..3875ea9921642 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3605,6 +3605,7 @@ dependencies = [ "either", "itertools 0.9.0", "polonius-engine", + "rustc_const_eval", "rustc_data_structures", "rustc_errors", "rustc_graphviz", @@ -3613,7 +3614,6 @@ dependencies = [ "rustc_infer", "rustc_lexer", "rustc_middle", - "rustc_mir", "rustc_mir_dataflow", "rustc_serialize", "rustc_session", @@ -3708,6 +3708,30 @@ dependencies = [ "tracing", ] +[[package]] +name = "rustc_const_eval" +version = "0.0.0" +dependencies = [ + "either", + "gsgdt", + "rustc_apfloat", + "rustc_ast", + "rustc_attr", + "rustc_data_structures", + "rustc_errors", + "rustc_hir", + "rustc_index", + "rustc_infer", + "rustc_macros", + "rustc_middle", + "rustc_mir_dataflow", + "rustc_session", + "rustc_span", + "rustc_target", + "rustc_trait_selection", + "tracing", +] + [[package]] name = "rustc_data_structures" version = "0.0.0" @@ -3746,6 +3770,7 @@ dependencies = [ "rustc_ast", "rustc_ast_pretty", "rustc_codegen_ssa", + "rustc_const_eval", "rustc_data_structures", "rustc_error_codes", "rustc_errors", @@ -3756,7 +3781,6 @@ dependencies = [ "rustc_lint", "rustc_metadata", "rustc_middle", - "rustc_mir", "rustc_parse", "rustc_plugin_impl", "rustc_save_analysis", @@ -3919,6 +3943,7 @@ dependencies = [ "rustc_builtin_macros", "rustc_codegen_llvm", "rustc_codegen_ssa", + "rustc_const_eval", "rustc_data_structures", "rustc_errors", "rustc_expand", @@ -3927,7 +3952,6 @@ dependencies = [ "rustc_lint", "rustc_metadata", "rustc_middle", - "rustc_mir", "rustc_mir_build", "rustc_mir_transform", "rustc_monomorphize", @@ -4073,30 +4097,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "rustc_mir" -version = "0.0.0" -dependencies = [ - "either", - "gsgdt", - "rustc_apfloat", - "rustc_ast", - "rustc_attr", - "rustc_data_structures", - "rustc_errors", - "rustc_hir", - "rustc_index", - "rustc_infer", - "rustc_macros", - "rustc_middle", - "rustc_mir_dataflow", - "rustc_session", - "rustc_span", - "rustc_target", - "rustc_trait_selection", - "tracing", -] - [[package]] name = "rustc_mir_build" version = "0.0.0" @@ -4148,12 +4148,12 @@ dependencies = [ "itertools 0.9.0", "rustc_ast", "rustc_attr", + "rustc_const_eval", "rustc_data_structures", "rustc_errors", "rustc_hir", "rustc_index", "rustc_middle", - "rustc_mir", "rustc_mir_dataflow", "rustc_serialize", "rustc_session", diff --git a/compiler/rustc_borrowck/Cargo.toml b/compiler/rustc_borrowck/Cargo.toml index 11b3ec28d45ff..543631de2dced 100644 --- a/compiler/rustc_borrowck/Cargo.toml +++ b/compiler/rustc_borrowck/Cargo.toml @@ -21,7 +21,7 @@ rustc_index = { path = "../rustc_index" } rustc_infer = { path = "../rustc_infer" } rustc_lexer = { path = "../rustc_lexer" } rustc_middle = { path = "../rustc_middle" } -rustc_mir = { path = "../rustc_mir" } +rustc_const_eval = { path = "../rustc_const_eval" } rustc_mir_dataflow = { path = "../rustc_mir_dataflow" } rustc_serialize = { path = "../rustc_serialize" } rustc_session = { path = "../rustc_session" } diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 758a660525d7a..ce1e7c14b1ff6 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -1695,7 +1695,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { Some((method_did, method_substs)), ) = ( &self.body[loan.reserve_location.block].terminator, - rustc_mir::util::find_self_call( + rustc_const_eval::util::find_self_call( tcx, self.body, loan.assigned_place.local, diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs index cc09db0e3dc20..50130dc2a27ed 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -899,12 +899,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { kind: TerminatorKind::Call { fn_span, from_hir_call, .. }, .. }) = &self.body[location.block].terminator { - let (method_did, method_substs) = if let Some(info) = rustc_mir::util::find_self_call( - self.infcx.tcx, - &self.body, - target_temp, - location.block, - ) { + let (method_did, method_substs) = if let Some(info) = + rustc_const_eval::util::find_self_call( + self.infcx.tcx, + &self.body, + target_temp, + location.block, + ) { info } else { return normal_ret; diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index b3578afbbb635..7ca72cbed8de8 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -16,8 +16,8 @@ use rustc_span::{BytePos, Span}; use crate::diagnostics::BorrowedContentSource; use crate::MirBorrowckCtxt; +use rustc_const_eval::util::collect_writes::FindAssignments; use rustc_errors::{Applicability, DiagnosticBuilder}; -use rustc_mir::util::collect_writes::FindAssignments; #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub(crate) enum AccessKind { diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 19224ca43dd91..2c8ff45b00da4 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -41,7 +41,7 @@ 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::transform::{ +use rustc_const_eval::transform::{ check_consts::ConstCx, promote_consts::is_const_fn_in_array_repeat_expression, }; use rustc_mir_dataflow::impls::MaybeInitializedPlaces; diff --git a/compiler/rustc_mir/Cargo.toml b/compiler/rustc_const_eval/Cargo.toml similarity index 96% rename from compiler/rustc_mir/Cargo.toml rename to compiler/rustc_const_eval/Cargo.toml index b187b716199c8..1653d5cf6c560 100644 --- a/compiler/rustc_mir/Cargo.toml +++ b/compiler/rustc_const_eval/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "rustc_mir" +name = "rustc_const_eval" version = "0.0.0" edition = "2018" diff --git a/compiler/rustc_mir/src/const_eval/error.rs b/compiler/rustc_const_eval/src/const_eval/error.rs similarity index 100% rename from compiler/rustc_mir/src/const_eval/error.rs rename to compiler/rustc_const_eval/src/const_eval/error.rs diff --git a/compiler/rustc_mir/src/const_eval/eval_queries.rs b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs similarity index 100% rename from compiler/rustc_mir/src/const_eval/eval_queries.rs rename to compiler/rustc_const_eval/src/const_eval/eval_queries.rs diff --git a/compiler/rustc_mir/src/const_eval/fn_queries.rs b/compiler/rustc_const_eval/src/const_eval/fn_queries.rs similarity index 100% rename from compiler/rustc_mir/src/const_eval/fn_queries.rs rename to compiler/rustc_const_eval/src/const_eval/fn_queries.rs diff --git a/compiler/rustc_mir/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs similarity index 100% rename from compiler/rustc_mir/src/const_eval/machine.rs rename to compiler/rustc_const_eval/src/const_eval/machine.rs diff --git a/compiler/rustc_mir/src/const_eval/mod.rs b/compiler/rustc_const_eval/src/const_eval/mod.rs similarity index 100% rename from compiler/rustc_mir/src/const_eval/mod.rs rename to compiler/rustc_const_eval/src/const_eval/mod.rs diff --git a/compiler/rustc_mir/src/interpret/cast.rs b/compiler/rustc_const_eval/src/interpret/cast.rs similarity index 100% rename from compiler/rustc_mir/src/interpret/cast.rs rename to compiler/rustc_const_eval/src/interpret/cast.rs diff --git a/compiler/rustc_mir/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs similarity index 100% rename from compiler/rustc_mir/src/interpret/eval_context.rs rename to compiler/rustc_const_eval/src/interpret/eval_context.rs diff --git a/compiler/rustc_mir/src/interpret/intern.rs b/compiler/rustc_const_eval/src/interpret/intern.rs similarity index 100% rename from compiler/rustc_mir/src/interpret/intern.rs rename to compiler/rustc_const_eval/src/interpret/intern.rs diff --git a/compiler/rustc_mir/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs similarity index 100% rename from compiler/rustc_mir/src/interpret/intrinsics.rs rename to compiler/rustc_const_eval/src/interpret/intrinsics.rs diff --git a/compiler/rustc_mir/src/interpret/intrinsics/caller_location.rs b/compiler/rustc_const_eval/src/interpret/intrinsics/caller_location.rs similarity index 100% rename from compiler/rustc_mir/src/interpret/intrinsics/caller_location.rs rename to compiler/rustc_const_eval/src/interpret/intrinsics/caller_location.rs diff --git a/compiler/rustc_mir/src/interpret/intrinsics/type_name.rs b/compiler/rustc_const_eval/src/interpret/intrinsics/type_name.rs similarity index 100% rename from compiler/rustc_mir/src/interpret/intrinsics/type_name.rs rename to compiler/rustc_const_eval/src/interpret/intrinsics/type_name.rs diff --git a/compiler/rustc_mir/src/interpret/machine.rs b/compiler/rustc_const_eval/src/interpret/machine.rs similarity index 100% rename from compiler/rustc_mir/src/interpret/machine.rs rename to compiler/rustc_const_eval/src/interpret/machine.rs diff --git a/compiler/rustc_mir/src/interpret/memory.rs b/compiler/rustc_const_eval/src/interpret/memory.rs similarity index 100% rename from compiler/rustc_mir/src/interpret/memory.rs rename to compiler/rustc_const_eval/src/interpret/memory.rs diff --git a/compiler/rustc_mir/src/interpret/mod.rs b/compiler/rustc_const_eval/src/interpret/mod.rs similarity index 100% rename from compiler/rustc_mir/src/interpret/mod.rs rename to compiler/rustc_const_eval/src/interpret/mod.rs diff --git a/compiler/rustc_mir/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs similarity index 100% rename from compiler/rustc_mir/src/interpret/operand.rs rename to compiler/rustc_const_eval/src/interpret/operand.rs diff --git a/compiler/rustc_mir/src/interpret/operator.rs b/compiler/rustc_const_eval/src/interpret/operator.rs similarity index 100% rename from compiler/rustc_mir/src/interpret/operator.rs rename to compiler/rustc_const_eval/src/interpret/operator.rs diff --git a/compiler/rustc_mir/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs similarity index 100% rename from compiler/rustc_mir/src/interpret/place.rs rename to compiler/rustc_const_eval/src/interpret/place.rs diff --git a/compiler/rustc_mir/src/interpret/step.rs b/compiler/rustc_const_eval/src/interpret/step.rs similarity index 100% rename from compiler/rustc_mir/src/interpret/step.rs rename to compiler/rustc_const_eval/src/interpret/step.rs diff --git a/compiler/rustc_mir/src/interpret/terminator.rs b/compiler/rustc_const_eval/src/interpret/terminator.rs similarity index 100% rename from compiler/rustc_mir/src/interpret/terminator.rs rename to compiler/rustc_const_eval/src/interpret/terminator.rs diff --git a/compiler/rustc_mir/src/interpret/traits.rs b/compiler/rustc_const_eval/src/interpret/traits.rs similarity index 100% rename from compiler/rustc_mir/src/interpret/traits.rs rename to compiler/rustc_const_eval/src/interpret/traits.rs diff --git a/compiler/rustc_mir/src/interpret/util.rs b/compiler/rustc_const_eval/src/interpret/util.rs similarity index 100% rename from compiler/rustc_mir/src/interpret/util.rs rename to compiler/rustc_const_eval/src/interpret/util.rs diff --git a/compiler/rustc_mir/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs similarity index 100% rename from compiler/rustc_mir/src/interpret/validity.rs rename to compiler/rustc_const_eval/src/interpret/validity.rs diff --git a/compiler/rustc_mir/src/interpret/visitor.rs b/compiler/rustc_const_eval/src/interpret/visitor.rs similarity index 100% rename from compiler/rustc_mir/src/interpret/visitor.rs rename to compiler/rustc_const_eval/src/interpret/visitor.rs diff --git a/compiler/rustc_mir/src/lib.rs b/compiler/rustc_const_eval/src/lib.rs similarity index 100% rename from compiler/rustc_mir/src/lib.rs rename to compiler/rustc_const_eval/src/lib.rs diff --git a/compiler/rustc_mir/src/transform/check_consts/check.rs b/compiler/rustc_const_eval/src/transform/check_consts/check.rs similarity index 100% rename from compiler/rustc_mir/src/transform/check_consts/check.rs rename to compiler/rustc_const_eval/src/transform/check_consts/check.rs diff --git a/compiler/rustc_mir/src/transform/check_consts/mod.rs b/compiler/rustc_const_eval/src/transform/check_consts/mod.rs similarity index 100% rename from compiler/rustc_mir/src/transform/check_consts/mod.rs rename to compiler/rustc_const_eval/src/transform/check_consts/mod.rs diff --git a/compiler/rustc_mir/src/transform/check_consts/ops.rs b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs similarity index 100% rename from compiler/rustc_mir/src/transform/check_consts/ops.rs rename to compiler/rustc_const_eval/src/transform/check_consts/ops.rs diff --git a/compiler/rustc_mir/src/transform/check_consts/post_drop_elaboration.rs b/compiler/rustc_const_eval/src/transform/check_consts/post_drop_elaboration.rs similarity index 100% rename from compiler/rustc_mir/src/transform/check_consts/post_drop_elaboration.rs rename to compiler/rustc_const_eval/src/transform/check_consts/post_drop_elaboration.rs diff --git a/compiler/rustc_mir/src/transform/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs similarity index 100% rename from compiler/rustc_mir/src/transform/check_consts/qualifs.rs rename to compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs diff --git a/compiler/rustc_mir/src/transform/check_consts/resolver.rs b/compiler/rustc_const_eval/src/transform/check_consts/resolver.rs similarity index 100% rename from compiler/rustc_mir/src/transform/check_consts/resolver.rs rename to compiler/rustc_const_eval/src/transform/check_consts/resolver.rs diff --git a/compiler/rustc_mir/src/transform/mod.rs b/compiler/rustc_const_eval/src/transform/mod.rs similarity index 100% rename from compiler/rustc_mir/src/transform/mod.rs rename to compiler/rustc_const_eval/src/transform/mod.rs diff --git a/compiler/rustc_mir/src/transform/promote_consts.rs b/compiler/rustc_const_eval/src/transform/promote_consts.rs similarity index 100% rename from compiler/rustc_mir/src/transform/promote_consts.rs rename to compiler/rustc_const_eval/src/transform/promote_consts.rs diff --git a/compiler/rustc_mir/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs similarity index 100% rename from compiler/rustc_mir/src/transform/validate.rs rename to compiler/rustc_const_eval/src/transform/validate.rs diff --git a/compiler/rustc_mir/src/util/aggregate.rs b/compiler/rustc_const_eval/src/util/aggregate.rs similarity index 100% rename from compiler/rustc_mir/src/util/aggregate.rs rename to compiler/rustc_const_eval/src/util/aggregate.rs diff --git a/compiler/rustc_mir/src/util/alignment.rs b/compiler/rustc_const_eval/src/util/alignment.rs similarity index 100% rename from compiler/rustc_mir/src/util/alignment.rs rename to compiler/rustc_const_eval/src/util/alignment.rs diff --git a/compiler/rustc_mir/src/util/collect_writes.rs b/compiler/rustc_const_eval/src/util/collect_writes.rs similarity index 100% rename from compiler/rustc_mir/src/util/collect_writes.rs rename to compiler/rustc_const_eval/src/util/collect_writes.rs diff --git a/compiler/rustc_mir/src/util/find_self_call.rs b/compiler/rustc_const_eval/src/util/find_self_call.rs similarity index 100% rename from compiler/rustc_mir/src/util/find_self_call.rs rename to compiler/rustc_const_eval/src/util/find_self_call.rs diff --git a/compiler/rustc_mir/src/util/mod.rs b/compiler/rustc_const_eval/src/util/mod.rs similarity index 100% rename from compiler/rustc_mir/src/util/mod.rs rename to compiler/rustc_const_eval/src/util/mod.rs diff --git a/compiler/rustc_driver/Cargo.toml b/compiler/rustc_driver/Cargo.toml index 57159962a9e68..ba8616cc6ef73 100644 --- a/compiler/rustc_driver/Cargo.toml +++ b/compiler/rustc_driver/Cargo.toml @@ -22,7 +22,7 @@ rustc_feature = { path = "../rustc_feature" } rustc_hir = { path = "../rustc_hir" } rustc_hir_pretty = { path = "../rustc_hir_pretty" } rustc_metadata = { path = "../rustc_metadata" } -rustc_mir = { path = "../rustc_mir" } +rustc_const_eval = { path = "../rustc_const_eval" } rustc_parse = { path = "../rustc_parse" } rustc_plugin_impl = { path = "../rustc_plugin_impl" } rustc_save_analysis = { path = "../rustc_save_analysis" } diff --git a/compiler/rustc_interface/Cargo.toml b/compiler/rustc_interface/Cargo.toml index 306728dbeac59..e76fa6d8a1bc6 100644 --- a/compiler/rustc_interface/Cargo.toml +++ b/compiler/rustc_interface/Cargo.toml @@ -32,7 +32,7 @@ rustc_symbol_mangling = { path = "../rustc_symbol_mangling" } rustc_codegen_llvm = { path = "../rustc_codegen_llvm", optional = true } rustc_hir = { path = "../rustc_hir" } rustc_metadata = { path = "../rustc_metadata" } -rustc_mir = { path = "../rustc_mir" } +rustc_const_eval = { path = "../rustc_const_eval" } rustc_mir_build = { path = "../rustc_mir_build" } rustc_mir_transform = { path = "../rustc_mir_transform" } rustc_monomorphize = { path = "../rustc_monomorphize" } diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 547823a067cf5..1f3d6f70ff837 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -22,7 +22,6 @@ use rustc_middle::middle; use rustc_middle::middle::cstore::{MetadataLoader, MetadataLoaderDyn}; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, GlobalCtxt, ResolverOutputs, TyCtxt}; -use rustc_mir as mir; use rustc_mir_build as mir_build; use rustc_parse::{parse_crate_from_file, parse_crate_from_source_str}; use rustc_passes::{self, hir_stats, layout_test}; @@ -738,8 +737,8 @@ pub static DEFAULT_QUERY_PROVIDERS: SyncLazy = SyncLazy::new(|| { let providers = &mut Providers::default(); providers.analysis = analysis; proc_macro_decls::provide(providers); + rustc_const_eval::provide(providers); rustc_middle::hir::provide(providers); - mir::provide(providers); mir_borrowck::provide(providers); mir_build::provide(providers); rustc_mir_transform::provide(providers); diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index c7c26cf599094..a366232c349d7 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -8,7 +8,7 @@ //! - **MIR.** The "mid-level (M) intermediate representation (IR)" is //! defined in the `mir` module. This module contains only the //! *definition* of the MIR; the passes that transform and operate -//! on MIR are found in `rustc_mir` crate. +//! on MIR are found in `rustc_const_eval` crate. //! - **Types.** The internal representation of types used in rustc is //! defined in the `ty` module. This includes the **type context** //! (or `tcx`), which is the central context during most of diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index ef2154b31f4b3..38d4c5b4bd10e 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1170,7 +1170,7 @@ rustc_index::newtype_index! { /// [CFG]: https://rustc-dev-guide.rust-lang.org/appendix/background.html#cfg /// [data-flow analyses]: /// https://rustc-dev-guide.rust-lang.org/appendix/background.html#what-is-a-dataflow-analysis - /// [`CriticalCallEdges`]: ../../rustc_mir/transform/add_call_guards/enum.AddCallGuards.html#variant.CriticalCallEdges + /// [`CriticalCallEdges`]: ../../rustc_const_eval/transform/add_call_guards/enum.AddCallGuards.html#variant.CriticalCallEdges /// [guide-mir]: https://rustc-dev-guide.rust-lang.org/mir/ pub struct BasicBlock { derive [HashStable] diff --git a/compiler/rustc_middle/src/mir/query.rs b/compiler/rustc_middle/src/mir/query.rs index 4fb737f463a86..1bdb6ca012b4a 100644 --- a/compiler/rustc_middle/src/mir/query.rs +++ b/compiler/rustc_middle/src/mir/query.rs @@ -219,7 +219,7 @@ pub struct BorrowCheckResult<'tcx> { /// The result of the `mir_const_qualif` query. /// /// Each field (except `error_occured`) corresponds to an implementer of the `Qualif` trait in -/// `rustc_mir/src/transform/check_consts/qualifs.rs`. See that file for more information on each +/// `rustc_const_eval/src/transform/check_consts/qualifs.rs`. See that file for more information on each /// `Qualif`. #[derive(Clone, Copy, Debug, Default, TyEncodable, TyDecodable, HashStable)] pub struct ConstQualifs { @@ -313,7 +313,7 @@ pub struct ClosureOutlivesRequirement<'tcx> { /// are interesting (for error reporting). Order of variants indicates sort /// order of the category, thereby influencing diagnostic output. /// -/// See also `rustc_mir::borrow_check::constraints`. +/// See also `rustc_const_eval::borrow_check::constraints`. #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)] #[derive(TyEncodable, TyDecodable, HashStable)] pub enum ConstraintCategory { diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 65dd61b63295c..0fbaf81c21e40 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -643,7 +643,7 @@ impl<'tcx> GeneratorSubsts<'tcx> { } /// This returns the types of the MIR locals which had to be stored across suspension points. - /// It is calculated in rustc_mir::transform::generator::StateTransform. + /// It is calculated in rustc_const_eval::transform::generator::StateTransform. /// All the types here must be in the tuple in GeneratorInterior. /// /// The locals are grouped by their variant number. Note that some locals may @@ -1268,7 +1268,7 @@ pub type Region<'tcx> = &'tcx RegionKind; /// Representation of regions. Note that the NLL checker uses a distinct /// representation of regions. For this reason, it internally replaces all the /// regions with inference variables -- the index of the variable is then used -/// to index into internal NLL data structures. See `rustc_mir::borrow_check` +/// to index into internal NLL data structures. See `rustc_const_eval::borrow_check` /// module for more information. /// /// ## The Region lattice within a given function diff --git a/compiler/rustc_mir_dataflow/src/framework/mod.rs b/compiler/rustc_mir_dataflow/src/framework/mod.rs index 0bf62db1adac9..f0c9ac4c504a3 100644 --- a/compiler/rustc_mir_dataflow/src/framework/mod.rs +++ b/compiler/rustc_mir_dataflow/src/framework/mod.rs @@ -11,7 +11,7 @@ //! `visit_results`. The following example uses the `ResultsCursor` approach. //! //! ```ignore (cross-crate-imports) -//! use rustc_mir::dataflow::Analysis; // Makes `into_engine` available. +//! use rustc_const_eval::dataflow::Analysis; // Makes `into_engine` available. //! //! fn do_my_analysis(tcx: TyCtxt<'tcx>, body: &mir::Body<'tcx>) { //! let analysis = MyAnalysis::new() diff --git a/compiler/rustc_mir_transform/Cargo.toml b/compiler/rustc_mir_transform/Cargo.toml index bc0f69d190cd2..7956bf8ffcf11 100644 --- a/compiler/rustc_mir_transform/Cargo.toml +++ b/compiler/rustc_mir_transform/Cargo.toml @@ -18,7 +18,7 @@ rustc_errors = { path = "../rustc_errors" } rustc_hir = { path = "../rustc_hir" } rustc_index = { path = "../rustc_index" } rustc_middle = { path = "../rustc_middle" } -rustc_mir = { path = "../rustc_mir" } +rustc_const_eval = { path = "../rustc_const_eval" } rustc_mir_dataflow = { path = "../rustc_mir_dataflow" } rustc_serialize = { path = "../rustc_serialize" } rustc_session = { path = "../rustc_session" } diff --git a/compiler/rustc_mir_transform/src/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs index 51240ee067711..71b3a555587f7 100644 --- a/compiler/rustc_mir_transform/src/const_prop.rs +++ b/compiler/rustc_mir_transform/src/const_prop.rs @@ -29,8 +29,8 @@ use rustc_target::spec::abi::Abi; use rustc_trait_selection::traits; use crate::MirPass; -use rustc_mir::const_eval::ConstEvalErr; -use rustc_mir::interpret::{ +use rustc_const_eval::const_eval::ConstEvalErr; +use rustc_const_eval::interpret::{ self, compile_time_machine, AllocId, Allocation, ConstValue, CtfeValidationMode, Frame, ImmTy, Immediate, InterpCx, InterpResult, LocalState, LocalValue, MemPlace, MemoryKind, OpTy, Operand as InterpOperand, PlaceTy, Scalar, ScalarMaybeUninit, StackPopCleanup, StackPopUnwind, diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index 2c8bdf4a20750..771c3ed72db31 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -19,6 +19,7 @@ extern crate tracing; extern crate rustc_middle; use required_consts::RequiredConstsVisitor; +use rustc_const_eval::util; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::steal::Steal; use rustc_hir as hir; @@ -29,7 +30,6 @@ use rustc_middle::mir::visit::Visitor as _; use rustc_middle::mir::{traversal, Body, ConstQualifs, MirPhase, Promoted}; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, TyCtxt, TypeFoldable}; -use rustc_mir::util; use rustc_span::{Span, Symbol}; mod abort_unwinding_calls; @@ -73,10 +73,10 @@ mod simplify_try; mod uninhabited_enum_branching; mod unreachable_prop; -use rustc_mir::transform::check_consts; -use rustc_mir::transform::promote_consts; -use rustc_mir::transform::validate; -use rustc_mir::transform::MirPass; +use rustc_const_eval::transform::check_consts; +use rustc_const_eval::transform::promote_consts; +use rustc_const_eval::transform::validate; +use rustc_const_eval::transform::MirPass; use rustc_mir_dataflow::rustc_peek; pub fn provide(providers: &mut Providers) { diff --git a/compiler/rustc_mir_transform/src/lower_slice_len.rs b/compiler/rustc_mir_transform/src/lower_slice_len.rs index eac2b97a14cf1..30de374a2d822 100644 --- a/compiler/rustc_mir_transform/src/lower_slice_len.rs +++ b/compiler/rustc_mir_transform/src/lower_slice_len.rs @@ -1,11 +1,11 @@ //! This pass lowers calls to core::slice::len to just Len op. //! It should run before inlining! +use crate::MirPass; use rustc_hir::def_id::DefId; use rustc_index::vec::IndexVec; use rustc_middle::mir::*; use rustc_middle::ty::{self, TyCtxt}; -use rustc_mir::transform::MirPass; pub struct LowerSliceLenCalls; diff --git a/compiler/rustc_mir_transform/src/match_branches.rs b/compiler/rustc_mir_transform/src/match_branches.rs index 24eaf27897715..c618abe9d0599 100644 --- a/compiler/rustc_mir_transform/src/match_branches.rs +++ b/compiler/rustc_mir_transform/src/match_branches.rs @@ -134,7 +134,7 @@ impl<'tcx> MirPass<'tcx> for MatchBranchSimplification { let const_cmp = Operand::const_from_scalar( tcx, switch_ty, - rustc_mir::interpret::Scalar::from_uint(val, size), + rustc_const_eval::interpret::Scalar::from_uint(val, size), rustc_span::DUMMY_SP, ); let op = if f_b { BinOp::Eq } else { BinOp::Ne }; diff --git a/compiler/rustc_typeck/src/check/generator_interior.rs b/compiler/rustc_typeck/src/check/generator_interior.rs index 5f26e701c0ab7..3da9fd159a728 100644 --- a/compiler/rustc_typeck/src/check/generator_interior.rs +++ b/compiler/rustc_typeck/src/check/generator_interior.rs @@ -1,6 +1,6 @@ //! This calculates the types which has storage which lives across a suspension point in a //! generator from the perspective of typeck. The actual types used at runtime -//! is calculated in `rustc_mir::transform::generator` and may be a subset of the +//! is calculated in `rustc_const_eval::transform::generator` and may be a subset of the //! types computed here. use super::FnCtxt; diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 71348b3eb65ff..f2941e67ac30a 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -11,6 +11,7 @@ crate mod utils; use rustc_ast as ast; use rustc_attr as attr; +use rustc_const_eval::const_eval::{is_const_fn, is_unstable_const_fn}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; use rustc_hir::def::{CtorKind, DefKind, Res}; @@ -22,7 +23,6 @@ use rustc_middle::ty::fold::TypeFolder; use rustc_middle::ty::subst::{InternalSubsts, Subst}; use rustc_middle::ty::{self, AdtKind, DefIdTree, Lift, Ty, TyCtxt}; use rustc_middle::{bug, span_bug}; -use rustc_mir::const_eval::{is_const_fn, is_unstable_const_fn}; use rustc_span::hygiene::{AstPass, MacroKind}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{self, ExpnKind}; diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 2dbe4c42b888e..8246834a74688 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -34,6 +34,7 @@ extern crate rustc_ast; extern crate rustc_ast_lowering; extern crate rustc_ast_pretty; extern crate rustc_attr; +extern crate rustc_const_eval; extern crate rustc_data_structures; extern crate rustc_driver; extern crate rustc_errors; @@ -49,7 +50,6 @@ extern crate rustc_lint; extern crate rustc_lint_defs; extern crate rustc_metadata; extern crate rustc_middle; -extern crate rustc_mir; extern crate rustc_parse; extern crate rustc_passes; extern crate rustc_resolve; diff --git a/src/test/run-make-fulldeps/sepcomp-cci-copies/Makefile b/src/test/run-make-fulldeps/sepcomp-cci-copies/Makefile index 36f913ff3faac..77d1d71e9b269 100644 --- a/src/test/run-make-fulldeps/sepcomp-cci-copies/Makefile +++ b/src/test/run-make-fulldeps/sepcomp-cci-copies/Makefile @@ -3,7 +3,7 @@ # Check that cross-crate inlined items are inlined in all compilation units # that refer to them, and not in any other compilation units. # Note that we have to pass `-C codegen-units=6` because up to two CGUs may be -# created for each source module (see `rustc_mir::monomorphize::partitioning`). +# created for each source module (see `rustc_const_eval::monomorphize::partitioning`). all: $(RUSTC) cci_lib.rs diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index ddff1686ba2ce..0906f958cfb1f 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -17,6 +17,7 @@ extern crate rustc_ast; extern crate rustc_ast_pretty; extern crate rustc_attr; +extern crate rustc_const_eval; extern crate rustc_data_structures; extern crate rustc_errors; extern crate rustc_hir; @@ -24,7 +25,6 @@ extern crate rustc_infer; extern crate rustc_lexer; extern crate rustc_lint; extern crate rustc_middle; -extern crate rustc_mir; extern crate rustc_session; extern crate rustc_span; extern crate rustc_target; diff --git a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs index e5bbf75c3b0a1..4fb9e6b07e71a 100644 --- a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs +++ b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs @@ -366,7 +366,7 @@ fn check_terminator( } fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: Option<&RustcVersion>) -> bool { - rustc_mir::const_eval::is_const_fn(tcx, def_id) + rustc_const_eval::const_eval::is_const_fn(tcx, def_id) && tcx.lookup_const_stability(def_id).map_or(true, |const_stab| { if let rustc_attr::StabilityLevel::Stable { since } = const_stab.level { // Checking MSRV is manually necessary because `rustc` has no such concept. This entire From 058fddcb77c1bbfe76f0bce9c35b78a800d08584 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 2 Sep 2021 19:02:55 +0200 Subject: [PATCH 6/7] Update run-make-fulldeps. --- src/test/run-make-fulldeps/obtain-borrowck/driver.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/run-make-fulldeps/obtain-borrowck/driver.rs b/src/test/run-make-fulldeps/obtain-borrowck/driver.rs index 308df0b030c27..961ea518c13ab 100644 --- a/src/test/run-make-fulldeps/obtain-borrowck/driver.rs +++ b/src/test/run-make-fulldeps/obtain-borrowck/driver.rs @@ -11,13 +11,14 @@ //! `optimized_mir` and pulls out the MIR bodies with the borrowck information //! from the thread local storage. +extern crate rustc_borrowck; extern crate rustc_driver; extern crate rustc_hir; extern crate rustc_interface; extern crate rustc_middle; -extern crate rustc_mir; extern crate rustc_session; +use rustc_borrowck::consumers::BodyWithBorrowckFacts; use rustc_driver::Compilation; use rustc_hir::def_id::LocalDefId; use rustc_hir::itemlikevisit::ItemLikeVisitor; @@ -26,7 +27,6 @@ use rustc_interface::{Config, Queries}; use rustc_middle::ty::query::query_values::mir_borrowck; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, TyCtxt}; -use rustc_mir::consumers::BodyWithBorrowckFacts; use rustc_session::Session; use std::cell::RefCell; use std::collections::HashMap; @@ -108,7 +108,7 @@ thread_local! { } fn mir_borrowck<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> mir_borrowck<'tcx> { - let body_with_facts = rustc_mir::consumers::get_body_with_borrowck_facts( + let body_with_facts = rustc_borrowck::consumers::get_body_with_borrowck_facts( tcx, ty::WithOptConstParam::unknown(def_id), ); @@ -120,7 +120,7 @@ fn mir_borrowck<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> mir_borrowck<'tc assert!(map.insert(def_id, body_with_facts).is_none()); }); let mut providers = Providers::default(); - rustc_mir::provide(&mut providers); + rustc_borrowck::provide(&mut providers); let original_mir_borrowck = providers.mir_borrowck; original_mir_borrowck(tcx, def_id) } From 924dbc36c9888eebacdcd06ec444418683b0d5fd Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 1 Sep 2021 21:05:35 +0200 Subject: [PATCH 7/7] Rebase fallout. --- compiler/rustc_borrowck/Cargo.toml | 1 - compiler/rustc_borrowck/src/lib.rs | 1 + compiler/rustc_const_eval/src/lib.rs | 1 + compiler/rustc_mir_dataflow/Cargo.toml | 1 - compiler/rustc_mir_dataflow/src/lib.rs | 1 + compiler/rustc_mir_transform/Cargo.toml | 1 - compiler/rustc_mir_transform/src/lib.rs | 3 ++- compiler/rustc_monomorphize/Cargo.toml | 1 - compiler/rustc_monomorphize/src/lib.rs | 1 + 9 files changed, 6 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_borrowck/Cargo.toml b/compiler/rustc_borrowck/Cargo.toml index 543631de2dced..c683c388ba9ea 100644 --- a/compiler/rustc_borrowck/Cargo.toml +++ b/compiler/rustc_borrowck/Cargo.toml @@ -1,5 +1,4 @@ [package] -authors = ["The Rust Project Developers"] name = "rustc_borrowck" version = "0.0.0" edition = "2018" diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index c1aa4df992455..4e4b8a953cd12 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -11,6 +11,7 @@ #![feature(stmt_expr_attributes)] #![feature(trusted_step)] #![feature(try_blocks)] +#![recursion_limit = "256"] #[macro_use] extern crate rustc_middle; diff --git a/compiler/rustc_const_eval/src/lib.rs b/compiler/rustc_const_eval/src/lib.rs index c24c9a9b5ee2b..0aa2dfb010f54 100644 --- a/compiler/rustc_const_eval/src/lib.rs +++ b/compiler/rustc_const_eval/src/lib.rs @@ -23,6 +23,7 @@ Rust MIR: a lowered representation of Rust. #![feature(trusted_len)] #![feature(trusted_step)] #![feature(try_blocks)] +#![recursion_limit = "256"] #[macro_use] extern crate tracing; diff --git a/compiler/rustc_mir_dataflow/Cargo.toml b/compiler/rustc_mir_dataflow/Cargo.toml index adc3882f84325..3cd4892402e4c 100644 --- a/compiler/rustc_mir_dataflow/Cargo.toml +++ b/compiler/rustc_mir_dataflow/Cargo.toml @@ -1,5 +1,4 @@ [package] -authors = ["The Rust Project Developers"] name = "rustc_mir_dataflow" version = "0.0.0" edition = "2018" diff --git a/compiler/rustc_mir_dataflow/src/lib.rs b/compiler/rustc_mir_dataflow/src/lib.rs index 282ea8db1bbdc..bfae09b7760a0 100644 --- a/compiler/rustc_mir_dataflow/src/lib.rs +++ b/compiler/rustc_mir_dataflow/src/lib.rs @@ -10,6 +10,7 @@ #![feature(once_cell)] #![feature(stmt_expr_attributes)] #![feature(trusted_step)] +#![recursion_limit = "256"] #[macro_use] extern crate tracing; diff --git a/compiler/rustc_mir_transform/Cargo.toml b/compiler/rustc_mir_transform/Cargo.toml index 7956bf8ffcf11..5e1a587b0ecea 100644 --- a/compiler/rustc_mir_transform/Cargo.toml +++ b/compiler/rustc_mir_transform/Cargo.toml @@ -1,5 +1,4 @@ [package] -authors = ["The Rust Project Developers"] name = "rustc_mir_transform" version = "0.0.0" edition = "2018" diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index 771c3ed72db31..22abce65a4b7d 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -1,4 +1,4 @@ -#![feature(bindings_after_at)] +#![cfg_attr(bootstrap, feature(bindings_after_at))] #![feature(box_patterns)] #![feature(box_syntax)] #![feature(crate_visibility_modifier)] @@ -12,6 +12,7 @@ #![feature(never_type)] #![feature(trusted_step)] #![feature(try_blocks)] +#![recursion_limit = "256"] #[macro_use] extern crate tracing; diff --git a/compiler/rustc_monomorphize/Cargo.toml b/compiler/rustc_monomorphize/Cargo.toml index 93a964bf3cc0e..350ae08877718 100644 --- a/compiler/rustc_monomorphize/Cargo.toml +++ b/compiler/rustc_monomorphize/Cargo.toml @@ -1,5 +1,4 @@ [package] -authors = ["The Rust Project Developers"] name = "rustc_monomorphize" version = "0.0.0" edition = "2018" diff --git a/compiler/rustc_monomorphize/src/lib.rs b/compiler/rustc_monomorphize/src/lib.rs index 2a40eeac5bdcb..08b1d7b7fabd7 100644 --- a/compiler/rustc_monomorphize/src/lib.rs +++ b/compiler/rustc_monomorphize/src/lib.rs @@ -3,6 +3,7 @@ #![feature(crate_visibility_modifier)] #![feature(control_flow_enum)] #![feature(in_band_lifetimes)] +#![recursion_limit = "256"] #[macro_use] extern crate tracing;