diff --git a/Cargo.lock b/Cargo.lock index 6849c40a54f237b07c9ec9dbaf9b86c8fab535cf..81549bd1d2055c178e30554ad36f5050d98b60f4 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 0000000000000000000000000000000000000000..e919c2cbc4f15523634bb4148005d2b306118216 --- /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 288eda32e414e4a10968ccc6320058e0160bca61..eb4d815bfc3ca3947941f0d3b3d1720f763d78ed 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 56d8045813c425c2d7cb67a8cbdf8eec88d6b549..5702203d7c4ffba938aea53c89e71a1dbf7ba9bf 100644 --- a/compiler/rustc_mir/src/util/borrowck_errors.rs +++ b/compiler/rustc_borrowck/src/borrowck_errors.rs @@ -2,7 +2,7 @@ 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 c84928523d9d6106a997d3a44e23c2d1a23f458e..a40f148cdf88c02a32706c7aeac8080a0f53314b 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::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 9e4cfb2cc00fa0f541e51649c229d0c0f18da8fb..cb9e0234c49ffa5a5a7edc3e653817563f93ee5e 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::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 b944479ca456b387fe7dd23c44e1be17a2840308..98378a98684e2f0ff2589631a42988a14bcc598a 100644 --- a/compiler/rustc_mir/src/borrow_check/constraints/mod.rs +++ b/compiler/rustc_borrowck/src/constraints/mod.rs @@ -5,7 +5,7 @@ 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 c92cff1433f1a50ef520de7fb21089063fea738d..cb440b2cbb9f4ed582fad09018ffa3551ebb0d97 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 ac30093ba826015fba0f9859172857b2f2d3861b..76e779bfec608d25279bd40f4912cedb0e530332 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 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 6561fe37c1c475b00f7520417c9199fedacd221a..8f6181f410df46e2c255ee34f9c5a32628cdbca7 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::{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 @@ pub(in crate::borrow_check) fn report_use_of_moved_or_uninitialized( } } - 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 @@ pub(in crate::borrow_check) fn report_move_out_while_borrowed( 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 @@ pub(in crate::borrow_check) fn report_use_while_mutably_borrowed( 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 @@ fn suggest_split_at_mut_if_applicable( /// 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 @@ pub(in crate::borrow_check) fn describe_place_for_conflicting_borrow( /// 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 @@ fn predecessor_locations( (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 @@ fn explain_deref_coercion(&mut self, loan: &BorrowData<'tcx>, err: &mut Diagnost 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 @@ fn explain_deref_coercion(&mut self, loan: &BorrowData<'tcx>, err: &mut Diagnost /// 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 f40a2db330a97062321e7ab72b26da575ab8a33f..2d12a682e7ae6d9c5c598fa1834b4b4b75f6b2e4 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_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 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 @@ pub(in crate::borrow_check) fn add_explanation_to_diagnostic<'tcx>( _ => {} } } - 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 @@ fn free_region_constraint_info( /// - 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 8d8cdfb52934c3502927d63926a6df09d56fade1..ab4536f00fc4289d702989625a8ff46b44b60b5c 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 55c6410ed320497730f7e1f90ae03f61a682e139..980894d6b4d0f5ee26d79f605107e47324b6abbd 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::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 super::borrow_set::BorrowData; use super::MirBorrowckCtxt; -use crate::dataflow::move_paths::{InitLocation, LookupResult}; mod find_use; mod outlives_suggestion; @@ -899,9 +899,12 @@ pub(super) fn move_spans( 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 66e06325fa982df6d564fa048a2284c2a10343c3..dd4886312da37a85c5b4371d361743b9f02d9016 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_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 4e079ed865ac31d4f29ecaea2285fd8d86407811..b3578afbbb6354dbc9573e471b76039ad8884c3d 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::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 7dc3434bf333867fd21707db468d8d7ed4869b79..9de0c62f186c0f70ebb64880577e7fb55d39091c 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 cbb8f064bb81ae6132770ca6ce15e2225f2d8215..57d2a3c5ce91bba441d81ad723ddcc02f02788fb 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_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 @@ fn is_closure_fn_mut(&self, fr: RegionVid) -> bool { } /// 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 @@ pub(in crate::borrow_check) fn report_region_errors(&mut self, nll_errors: Regio /// ``` /// /// 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 1f168c612f16726f78b3f98ded96658f6be6926e..5edb52b0b650dca370cbced4b8c34a86a2d9def3 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_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 4abc623fc5f371f15a768b3958681a0861d379eb..00f62806753556f477aec00a6280a662d27ba28b 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 215dead5bd15e3ced92ee4d06ce3b6b4522aa12f..ed3f846e4adc9d5024c63435294783b8c5b06c24 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 @@ fn index(self) -> usize { } } -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 b83a427f4757475e80d00ec88afc03d4983b21e0..016fe0bb6dedffbe9ff419991993903f2c5cbde4 100644 --- a/compiler/rustc_mir/src/borrow_check/invalidation.rs +++ b/compiler/rustc_borrowck/src/invalidation.rs @@ -7,12 +7,10 @@ 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 1dcb06765625899768022a79e169f4dfef0a690c..9fe3d79e4ed09582f27a1045e4b050118112cffa 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::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 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 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 @@ pub struct BodyWithBorrowckFacts<'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 @@ fn is_mutable( /// 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 66ca94d3b415d644800462abf385349c43f5982f..d40990d4676bcf4ad9e38ae8d1f0160cae1795a8 100644 --- a/compiler/rustc_mir/src/borrow_check/nll.rs +++ b/compiler/rustc_borrowck/src/nll.rs @@ -20,13 +20,13 @@ 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 @@ /// 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 80de3b4e363bfb369a40b701ff9cf944e43df84a..d5d00b467eeed2bab3184a8724821b470edd9902 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 52fac3e53ee659fc3be18978d66cbd410be9fea1..83ff1595b0be44031dd044b5c2ba6d50dc372a22 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 d21550a8e1af60b5bb0564eae081fedc315ea0b8..773e9e90b0c6be85cfeebb0a2f788c1c17b3c30d 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 213ebff12abc0b65940e94f9845232c3c83cfa95..cfd3acb6bdebdf78a5b875ad7f9443ce6d438a08 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 b944d74e6f23137b3040974955e291d9ce70e26d..95048d50f117f733e4072615efc1ca3e740cd13c 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::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 a96cdbc13f345a2891feb89bb0f55f1f9622de66..48e45a9b1ce72e7f1559df69e847f627d7bb4e0c 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::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 @@ pub fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid { /// 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 @@ fn non_local_universal_upper_bound(&self, r: RegionVid) -> RegionVid { /// 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 @@ pub(in crate::borrow_check) fn universal_upper_bound(&self, r: RegionVid) -> Reg /// 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 12fceeff0884c92a8f4f8ada963004d36b86c8f8..39b83e5043101bbde09f54f02f7f1862dc3c7b43 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 @@ pub(in crate::borrow_check) fn infer_opaque_types( /// 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 5d345a6e63d6b1c8394abd53452dfcfe03676742..056907dcb16563a5daf40ddffa64485e97d96a3d 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 b501716a899752b41db2117da612e6ada703ff34..7a8c0a3da1f1f4854370e6982b9243463fe3a69a 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_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 446a0f8e72fbd9bf1c869589879e099db7c7a94d..b020746848535899733852039c543ac07d71164c 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::{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 6426098d843fe80fd2dd709de1a3dcd3b7fc7fab..e1e8f6a61adb817038607d3c103394d97c29e531 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 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 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 ba9b6926526be010208f568415a9602c2043c62f..9d6f6f60a94f91976edabb4f5c5174614750cb49 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 7e8a33efe114ef6fb6a275c5a1b2a1fb70c170a2..8b74abd94c07711ee3f6a541e8bb546a35ecd274 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_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 a34ae281b70dfdd547ed652226264299e0f37a1f..265c14bb28676c961685e00811f33f0c4e475696 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::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 d285098c52ad2097c9aca8d8296b61533b153a6d..7c087d38eb748d1095ad352383b17065fdc86d5e 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 566c11811e6e1108267411a5d79c688ed0809946..c7d776bfde0d4b552eff940998580f4d76bc4317 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::{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 639bcb8fa94efb7f3768665349a0508e5b703efe..63075d066a6dc8718ef526e0dd8bbb98b152f26d 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::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 @@ 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 971c4daa6b311ae49ce41629b202f1fba271d230..0b9c33ccb775a96ad7fe411259aaa6ba7bbd609e 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::{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 3c9b4272b36497dc3fe826d9986e2c182ba2c5b1..bebd19370299d00cdf360796c578638612f80312 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::{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 e027056842db97d20cf69c0109df7def59377a78..6022a9809502b2fc79b1e98f77f80884f657526c 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 dad5b256e42ab84316fc659ce2d21538602e0ed1..970267d626cd82cca970e9f71be23c0b6ecd8cfc 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 1d542db9b69c3eef068d2f40b1707f3038a0f5d9..df03ff59f461ac2b129f489c5243a70f0c7c5c2c 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -4,6 +4,7 @@ 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 fn prepare_outputs( 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 3049fb3b383b30292f7438823c476758e9998206..43c7b681e05f2209b6d47a951ea9a70f4a77ccee 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 d16366fded900fe343ccc8e0c24419a934a10551..d4f8f994ae90414eecd838c3270574e5b8ecebd0 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 a5badc07d1017518a42456588a323fba799f1793..0bf62db1adac9339af42840e17d841026b438356 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::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 82eb734ed0699a2ae00f18635b59c9414cf552a3..84136c4d78cf1e495bd739b48b181a88936d6882 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 @@ fn reconstruct_terminator_effect( 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 185f0edfeb6bcbeaf6aab1f17c8fb43104510b2d..020a7b188fd1339d64cd33388954ac4dd5ac8a77 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::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 8a426cc1015ccbdd4ae0562156a611fba8400c64..bb38f90a3ba63557266b2e610dc3986fbdb0a18d 100644 --- a/compiler/rustc_mir/src/dataflow/mod.rs +++ b/compiler/rustc_mir/src/dataflow/mod.rs @@ -5,9 +5,9 @@ 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 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 7c630259186032e245999763c8184d41b68214ce..699ec4bbff80fa788ad305ada8cc0c4c4f25c9ca 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 @@ pub struct MovePathIndex { } } +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 @@ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { } 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 @@ pub fn iter_locals_enumerated(&self) -> Enumerated { - 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 e439a247c7f6cbdd036dc0f66be9c4ca94f49b5a..16dddc949df31e971fb456f67fd90a8c6c7278a3 100644 --- a/compiler/rustc_mir/src/lib.rs +++ b/compiler/rustc_mir/src/lib.rs @@ -4,40 +4,35 @@ */ -#![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 @@ 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 1b43670ba3ac103eaa3021f0b2e2a0c7c69545c7..6822ad2d7b5dd0d3e02f0f9a2029b407bd249839 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 ecf3b08a96eedd1573a99d7826975da8bb8416c2..9c56fd722bda619d9da2c54104acf74999b2949b 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::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 3e466b5060febad46d9057bbf047054bad41eb37..8f9db6daba7336e0e161734d384f04e71d8954bc 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 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 92591db668ce9b7a6f0e9b74ec0b8b48133f648c..ec1aa5b476bb7df8c8ca723f3befb991d42b8b0d 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>,