1
Fork 0

Auto merge of #80522 - cjgillot:borrowcrate, r=oli-obk

Split rustc_mir

The `rustc_mir` crate is the second largest in the compiler.
This PR splits it up into 5 crates:
- rustc_borrowck;
- rustc_const_eval;
- rustc_mir_dataflow;
- rustc_mir_transform;
- rustc_monomorphize.
This commit is contained in:
bors 2021-09-08 20:42:42 +00:00
commit 97032a6dfa
200 changed files with 956 additions and 724 deletions

View file

@ -3621,6 +3621,33 @@ dependencies = [
"rustc_span", "rustc_span",
] ]
[[package]]
name = "rustc_borrowck"
version = "0.0.0"
dependencies = [
"either",
"itertools 0.9.0",
"polonius-engine",
"rustc_const_eval",
"rustc_data_structures",
"rustc_errors",
"rustc_graphviz",
"rustc_hir",
"rustc_index",
"rustc_infer",
"rustc_lexer",
"rustc_middle",
"rustc_mir_dataflow",
"rustc_serialize",
"rustc_session",
"rustc_span",
"rustc_target",
"rustc_trait_selection",
"rustc_traits",
"smallvec",
"tracing",
]
[[package]] [[package]]
name = "rustc_builtin_macros" name = "rustc_builtin_macros"
version = "0.0.0" version = "0.0.0"
@ -3704,6 +3731,30 @@ dependencies = [
"tracing", "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]] [[package]]
name = "rustc_data_structures" name = "rustc_data_structures"
version = "0.0.0" version = "0.0.0"
@ -3742,6 +3793,7 @@ dependencies = [
"rustc_ast", "rustc_ast",
"rustc_ast_pretty", "rustc_ast_pretty",
"rustc_codegen_ssa", "rustc_codegen_ssa",
"rustc_const_eval",
"rustc_data_structures", "rustc_data_structures",
"rustc_error_codes", "rustc_error_codes",
"rustc_errors", "rustc_errors",
@ -3752,7 +3804,6 @@ dependencies = [
"rustc_lint", "rustc_lint",
"rustc_metadata", "rustc_metadata",
"rustc_middle", "rustc_middle",
"rustc_mir",
"rustc_parse", "rustc_parse",
"rustc_plugin_impl", "rustc_plugin_impl",
"rustc_save_analysis", "rustc_save_analysis",
@ -3911,9 +3962,11 @@ dependencies = [
"rustc_ast_lowering", "rustc_ast_lowering",
"rustc_ast_passes", "rustc_ast_passes",
"rustc_attr", "rustc_attr",
"rustc_borrowck",
"rustc_builtin_macros", "rustc_builtin_macros",
"rustc_codegen_llvm", "rustc_codegen_llvm",
"rustc_codegen_ssa", "rustc_codegen_ssa",
"rustc_const_eval",
"rustc_data_structures", "rustc_data_structures",
"rustc_errors", "rustc_errors",
"rustc_expand", "rustc_expand",
@ -3922,8 +3975,9 @@ dependencies = [
"rustc_lint", "rustc_lint",
"rustc_metadata", "rustc_metadata",
"rustc_middle", "rustc_middle",
"rustc_mir",
"rustc_mir_build", "rustc_mir_build",
"rustc_mir_transform",
"rustc_monomorphize",
"rustc_parse", "rustc_parse",
"rustc_passes", "rustc_passes",
"rustc_plugin_impl", "rustc_plugin_impl",
@ -4041,6 +4095,8 @@ version = "0.0.0"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"chalk-ir", "chalk-ir",
"either",
"gsgdt",
"polonius-engine", "polonius-engine",
"rustc-rayon-core", "rustc-rayon-core",
"rustc_apfloat", "rustc_apfloat",
@ -4050,6 +4106,7 @@ dependencies = [
"rustc_data_structures", "rustc_data_structures",
"rustc_errors", "rustc_errors",
"rustc_feature", "rustc_feature",
"rustc_graphviz",
"rustc_hir", "rustc_hir",
"rustc_index", "rustc_index",
"rustc_macros", "rustc_macros",
@ -4063,38 +4120,6 @@ dependencies = [
"tracing", "tracing",
] ]
[[package]]
name = "rustc_mir"
version = "0.0.0"
dependencies = [
"coverage_test_macros",
"either",
"gsgdt",
"itertools 0.9.0",
"polonius-engine",
"regex",
"rustc_apfloat",
"rustc_ast",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
"rustc_graphviz",
"rustc_hir",
"rustc_index",
"rustc_infer",
"rustc_lexer",
"rustc_macros",
"rustc_middle",
"rustc_serialize",
"rustc_session",
"rustc_span",
"rustc_target",
"rustc_trait_selection",
"rustc_traits",
"smallvec",
"tracing",
]
[[package]] [[package]]
name = "rustc_mir_build" name = "rustc_mir_build"
version = "0.0.0" version = "0.0.0"
@ -4118,6 +4143,66 @@ dependencies = [
"tracing", "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"
dependencies = [
"coverage_test_macros",
"itertools 0.9.0",
"rustc_ast",
"rustc_attr",
"rustc_const_eval",
"rustc_data_structures",
"rustc_errors",
"rustc_hir",
"rustc_index",
"rustc_middle",
"rustc_mir_dataflow",
"rustc_serialize",
"rustc_session",
"rustc_span",
"rustc_target",
"rustc_trait_selection",
"smallvec",
"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]] [[package]]
name = "rustc_parse" name = "rustc_parse"
version = "0.0.0" version = "0.0.0"

View file

@ -1,5 +1,5 @@
[package] [package]
name = "rustc_mir" name = "rustc_borrowck"
version = "0.0.0" version = "0.0.0"
edition = "2018" edition = "2018"
@ -8,30 +8,23 @@ doctest = false
[dependencies] [dependencies]
either = "1.5.0" either = "1.5.0"
rustc_graphviz = { path = "../rustc_graphviz" }
gsgdt = "0.1.2"
itertools = "0.9" itertools = "0.9"
tracing = "0.1" tracing = "0.1"
polonius-engine = "0.13.0" polonius-engine = "0.13.0"
regex = "1" smallvec = { version = "1.6.1", features = ["union", "may_dangle"] }
rustc_middle = { path = "../rustc_middle" }
rustc_attr = { path = "../rustc_attr" }
rustc_data_structures = { path = "../rustc_data_structures" } rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" } rustc_errors = { path = "../rustc_errors" }
rustc_graphviz = { path = "../rustc_graphviz" }
rustc_hir = { path = "../rustc_hir" } rustc_hir = { path = "../rustc_hir" }
rustc_index = { path = "../rustc_index" } rustc_index = { path = "../rustc_index" }
rustc_infer = { path = "../rustc_infer" } rustc_infer = { path = "../rustc_infer" }
rustc_lexer = { path = "../rustc_lexer" } rustc_lexer = { path = "../rustc_lexer" }
rustc_macros = { path = "../rustc_macros" } rustc_middle = { path = "../rustc_middle" }
rustc_const_eval = { path = "../rustc_const_eval" }
rustc_mir_dataflow = { path = "../rustc_mir_dataflow" }
rustc_serialize = { path = "../rustc_serialize" } rustc_serialize = { path = "../rustc_serialize" }
rustc_session = { path = "../rustc_session" } rustc_session = { path = "../rustc_session" }
rustc_target = { path = "../rustc_target" } rustc_target = { path = "../rustc_target" }
rustc_trait_selection = { path = "../rustc_trait_selection" } rustc_trait_selection = { path = "../rustc_trait_selection" }
rustc_traits = { path = "../rustc_traits" } rustc_traits = { path = "../rustc_traits" }
rustc_ast = { path = "../rustc_ast" }
rustc_span = { path = "../rustc_span" } 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" }

View file

@ -1,14 +1,14 @@
use crate::borrow_check::nll::ToRegionVid; use crate::nll::ToRegionVid;
use crate::borrow_check::path_utils::allow_two_phase_borrow; use crate::path_utils::allow_two_phase_borrow;
use crate::borrow_check::place_ext::PlaceExt; use crate::place_ext::PlaceExt;
use crate::dataflow::indexes::BorrowIndex; use crate::BorrowIndex;
use crate::dataflow::move_paths::MoveData;
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
use rustc_index::bit_set::BitSet; use rustc_index::bit_set::BitSet;
use rustc_middle::mir::traversal; use rustc_middle::mir::traversal;
use rustc_middle::mir::visit::{MutatingUseContext, NonUseContext, PlaceContext, Visitor}; use rustc_middle::mir::visit::{MutatingUseContext, NonUseContext, PlaceContext, Visitor};
use rustc_middle::mir::{self, Body, Local, Location}; use rustc_middle::mir::{self, Body, Local, Location};
use rustc_middle::ty::{RegionVid, TyCtxt}; use rustc_middle::ty::{RegionVid, TyCtxt};
use rustc_mir_dataflow::move_paths::MoveData;
use std::fmt; use std::fmt;
use std::ops::Index; use std::ops::Index;

View file

@ -2,7 +2,7 @@ use rustc_errors::{struct_span_err, DiagnosticBuilder, DiagnosticId};
use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::{MultiSpan, Span}; 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> { 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,) struct_span_err!(self, span, E0505, "cannot move out of {} because it is borrowed", desc,)
} }

View file

@ -9,7 +9,7 @@ use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::{self, RegionVid, Ty}; use rustc_middle::ty::{self, RegionVid, Ty};
use crate::borrow_check::{ use crate::{
borrow_set::BorrowSet, facts::AllFacts, location::LocationTable, nll::ToRegionVid, borrow_set::BorrowSet, facts::AllFacts, location::LocationTable, nll::ToRegionVid,
places_conflict, region_infer::values::LivenessValues, places_conflict, region_infer::values::LivenessValues,
}; };

View file

@ -4,7 +4,7 @@ use rustc_middle::mir::ConstraintCategory;
use rustc_middle::ty::{RegionVid, VarianceDiagInfo}; use rustc_middle::ty::{RegionVid, VarianceDiagInfo};
use rustc_span::DUMMY_SP; use rustc_span::DUMMY_SP;
use crate::borrow_check::{ use crate::{
constraints::OutlivesConstraintIndex, constraints::OutlivesConstraintIndex,
constraints::{OutlivesConstraint, OutlivesConstraintSet}, constraints::{OutlivesConstraint, OutlivesConstraintSet},
type_check::Locations, type_check::Locations,

View file

@ -5,7 +5,7 @@ use rustc_middle::ty::{RegionVid, VarianceDiagInfo};
use std::fmt; use std::fmt;
use std::ops::Index; use std::ops::Index;
use crate::borrow_check::type_check::Locations; use crate::type_check::Locations;
crate mod graph; crate mod graph;

View file

@ -1,18 +1,111 @@
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_data_structures::fx::FxHashMap;
use rustc_index::bit_set::BitSet; use rustc_index::bit_set::BitSet;
use rustc_middle::mir::{self, BasicBlock, Body, Location, Place};
use crate::borrow_check::{ use rustc_middle::ty::RegionVid;
places_conflict, BorrowSet, PlaceConflictBias, PlaceExt, RegionInferenceContext, ToRegionVid, use rustc_middle::ty::TyCtxt;
}; use rustc_mir_dataflow::impls::{EverInitializedPlaces, MaybeUninitializedPlaces};
use crate::dataflow::{self, fmt::DebugWithContext, GenKill}; 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::fmt;
use std::iter; use std::iter;
use crate::{
places_conflict, BorrowSet, PlaceConflictBias, PlaceExt, RegionInferenceContext, ToRegionVid,
};
/// 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<B, U, E> {
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> =
<BorrowckResults<'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! { rustc_index::newtype_index! {
pub struct BorrowIndex { pub struct BorrowIndex {
DEBUG_FORMAT = "bw{}" DEBUG_FORMAT = "bw{}"
@ -230,7 +323,7 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
} }
} }
impl<'tcx> dataflow::AnalysisDomain<'tcx> for Borrows<'_, 'tcx> { impl<'tcx> rustc_mir_dataflow::AnalysisDomain<'tcx> for Borrows<'_, 'tcx> {
type Domain = BitSet<BorrowIndex>; type Domain = BitSet<BorrowIndex>;
const NAME: &'static str = "borrows"; const NAME: &'static str = "borrows";
@ -246,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; type Idx = BorrowIndex;
fn before_statement_effect( fn before_statement_effect(

View file

@ -14,8 +14,8 @@ use rustc_traits::{type_op_ascribe_user_type_with_span, type_op_prove_predicate_
use std::fmt; use std::fmt;
use std::rc::Rc; use std::rc::Rc;
use crate::borrow_check::region_infer::values::RegionElement; use crate::region_infer::values::RegionElement;
use crate::borrow_check::MirBorrowckCtxt; use crate::MirBorrowckCtxt;
#[derive(Clone)] #[derive(Clone)]
crate struct UniverseInfo<'tcx>(UniverseInfoInner<'tcx>); crate struct UniverseInfo<'tcx>(UniverseInfoInner<'tcx>);

View file

@ -10,16 +10,16 @@ use rustc_middle::mir::{
ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, VarBindingForm, ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, VarBindingForm,
}; };
use rustc_middle::ty::{self, suggest_constraining_type_param, Ty}; 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::source_map::DesugaringKind;
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
use rustc_span::{BytePos, MultiSpan, Span, DUMMY_SP}; use rustc_span::{BytePos, MultiSpan, Span, DUMMY_SP};
use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::infer::InferCtxtExt;
use crate::dataflow::drop_flag_effects; use crate::borrowck_errors;
use crate::dataflow::indexes::{MoveOutIndex, MovePathIndex};
use crate::util::borrowck_errors;
use crate::borrow_check::{ use crate::{
borrow_set::BorrowData, diagnostics::Instance, prefixes::IsPrefixOf, borrow_set::BorrowData, diagnostics::Instance, prefixes::IsPrefixOf,
InitializationRequiringAction, MirBorrowckCtxt, PrefixSet, WriteKind, InitializationRequiringAction, MirBorrowckCtxt, PrefixSet, WriteKind,
}; };
@ -49,7 +49,7 @@ enum StorageDeadOrDrop<'tcx> {
} }
impl<'cx, 'tcx> MirBorrowckCtxt<'cx, '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, &mut self,
location: Location, location: Location,
desired_action: InitializationRequiringAction, 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, &mut self,
location: Location, location: Location,
(place, span): (Place<'tcx>, Span), (place, span): (Place<'tcx>, Span),
@ -489,7 +489,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
err.buffer(&mut self.errors_buffer); 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, &mut self,
location: Location, location: Location,
(place, _span): (Place<'tcx>, Span), (place, _span): (Place<'tcx>, Span),
@ -535,7 +535,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
err err
} }
pub(in crate::borrow_check) fn report_conflicting_borrow( pub(crate) fn report_conflicting_borrow(
&mut self, &mut self,
location: Location, location: Location,
(place, span): (Place<'tcx>, Span), (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 /// cannot borrow `a.u` (via `a.u.z.c`) as immutable because it is also borrowed as
/// mutable (via `a.u.s.b`) [E0502] /// 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, &self,
first_borrowed_place: Place<'tcx>, first_borrowed_place: Place<'tcx>,
second_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 /// short a lifetime. (But sometimes it is more useful to report
/// it as a more direct conflict between the execution of a /// it as a more direct conflict between the execution of a
/// `Drop::drop` with an aliasing borrow.) /// `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, &mut self,
location: Location, location: Location,
borrow: &BorrowData<'tcx>, borrow: &BorrowData<'tcx>,
@ -1634,7 +1634,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
(result, reinits_reachable) (result, reinits_reachable)
} }
pub(in crate::borrow_check) fn report_illegal_mutation_of_borrowed( pub(crate) fn report_illegal_mutation_of_borrowed(
&mut self, &mut self,
location: Location, location: Location,
(place, span): (Place<'tcx>, Span), (place, span): (Place<'tcx>, Span),
@ -1695,7 +1695,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
Some((method_did, method_substs)), Some((method_did, method_substs)),
) = ( ) = (
&self.body[loan.reserve_location.block].terminator, &self.body[loan.reserve_location.block].terminator,
crate::util::find_self_call( rustc_const_eval::util::find_self_call(
tcx, tcx,
self.body, self.body,
loan.assigned_place.local, loan.assigned_place.local,
@ -1726,7 +1726,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
/// assigned; `err_place` is a place providing a reason why /// assigned; `err_place` is a place providing a reason why
/// `place` is not mutable (e.g., the non-`mut` local `x` in an /// `place` is not mutable (e.g., the non-`mut` local `x` in an
/// assignment to `x.f`). /// assignment to `x.f`).
pub(in crate::borrow_check) fn report_illegal_reassignment( pub(crate) fn report_illegal_reassignment(
&mut self, &mut self,
_location: Location, _location: Location,
(place, span): (Place<'tcx>, Span), (place, span): (Place<'tcx>, Span),
@ -2226,7 +2226,7 @@ enum AnnotatedBorrowFnSignature<'tcx> {
impl<'tcx> AnnotatedBorrowFnSignature<'tcx> { impl<'tcx> AnnotatedBorrowFnSignature<'tcx> {
/// Annotate the provided diagnostic with information about borrow from the fn signature that /// Annotate the provided diagnostic with information about borrow from the fn signature that
/// helps explain. /// helps explain.
pub(in crate::borrow_check) fn emit( pub(crate) fn emit(
&self, &self,
cx: &mut MirBorrowckCtxt<'_, 'tcx>, cx: &mut MirBorrowckCtxt<'_, 'tcx>,
diag: &mut DiagnosticBuilder<'_>, diag: &mut DiagnosticBuilder<'_>,

View file

@ -15,8 +15,8 @@ use rustc_middle::ty::{self, RegionVid, TyCtxt};
use rustc_span::symbol::Symbol; use rustc_span::symbol::Symbol;
use rustc_span::Span; use rustc_span::Span;
use crate::borrow_check::region_infer::BlameConstraint; use crate::region_infer::BlameConstraint;
use crate::borrow_check::{ use crate::{
borrow_set::BorrowData, nll::ConstraintDescription, region_infer::Cause, MirBorrowckCtxt, borrow_set::BorrowData, nll::ConstraintDescription, region_infer::Cause, MirBorrowckCtxt,
WriteKind, WriteKind,
}; };
@ -24,7 +24,7 @@ use crate::borrow_check::{
use super::{find_use, RegionName, UseSpans}; use super::{find_use, RegionName, UseSpans};
#[derive(Debug)] #[derive(Debug)]
pub(in crate::borrow_check) enum BorrowExplanation { pub(crate) enum BorrowExplanation {
UsedLater(LaterUseKind, Span, Option<Span>), UsedLater(LaterUseKind, Span, Option<Span>),
UsedLaterInLoop(LaterUseKind, Span, Option<Span>), UsedLaterInLoop(LaterUseKind, Span, Option<Span>),
UsedLaterWhenDropped { UsedLaterWhenDropped {
@ -43,7 +43,7 @@ pub(in crate::borrow_check) enum BorrowExplanation {
} }
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub(in crate::borrow_check) enum LaterUseKind { pub(crate) enum LaterUseKind {
TraitCapture, TraitCapture,
ClosureCapture, ClosureCapture,
Call, Call,
@ -52,13 +52,13 @@ pub(in crate::borrow_check) enum LaterUseKind {
} }
impl BorrowExplanation { impl BorrowExplanation {
pub(in crate::borrow_check) fn is_explained(&self) -> bool { pub(crate) fn is_explained(&self) -> bool {
match self { match self {
BorrowExplanation::Unexplained => false, BorrowExplanation::Unexplained => false,
_ => true, _ => true,
} }
} }
pub(in crate::borrow_check) fn add_explanation_to_diagnostic<'tcx>( pub(crate) fn add_explanation_to_diagnostic<'tcx>(
&self, &self,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
body: &Body<'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, &self,
err: &mut DiagnosticBuilder<'_>, err: &mut DiagnosticBuilder<'_>,
category: &ConstraintCategory, category: &ConstraintCategory,
@ -326,7 +326,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
/// - second half is the place being accessed /// - 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 /// [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, &self,
location: Location, location: Location,
borrow: &BorrowData<'tcx>, borrow: &BorrowData<'tcx>,

View file

@ -1,7 +1,7 @@
use std::collections::VecDeque; use std::collections::VecDeque;
use std::rc::Rc; use std::rc::Rc;
use crate::borrow_check::{ use crate::{
def_use::{self, DefUse}, def_use::{self, DefUse},
nll::ToRegionVid, nll::ToRegionVid,
region_infer::{Cause, RegionInferenceContext}, region_infer::{Cause, RegionInferenceContext},

View file

@ -12,6 +12,7 @@ use rustc_middle::mir::{
}; };
use rustc_middle::ty::print::Print; use rustc_middle::ty::print::Print;
use rustc_middle::ty::{self, DefIdTree, Instance, Ty, TyCtxt}; use rustc_middle::ty::{self, DefIdTree, Instance, Ty, TyCtxt};
use rustc_mir_dataflow::move_paths::{InitLocation, LookupResult};
use rustc_span::{ use rustc_span::{
hygiene::{DesugaringKind, ForLoopLoc}, hygiene::{DesugaringKind, ForLoopLoc},
symbol::sym, symbol::sym,
@ -21,7 +22,6 @@ use rustc_target::abi::VariantIdx;
use super::borrow_set::BorrowData; use super::borrow_set::BorrowData;
use super::MirBorrowckCtxt; use super::MirBorrowckCtxt;
use crate::dataflow::move_paths::{InitLocation, LookupResult};
mod find_use; mod find_use;
mod outlives_suggestion; mod outlives_suggestion;
@ -900,8 +900,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
}) = &self.body[location.block].terminator }) = &self.body[location.block].terminator
{ {
let (method_did, method_substs) = if let Some(info) = let (method_did, method_substs) = if let Some(info) =
crate::util::find_self_call(self.infcx.tcx, &self.body, target_temp, location.block) rustc_const_eval::util::find_self_call(
{ self.infcx.tcx,
&self.body,
target_temp,
location.block,
) {
info info
} else { } else {
return normal_ret; return normal_ret;

View file

@ -2,16 +2,16 @@ use rustc_errors::{Applicability, DiagnosticBuilder};
use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::infer::TyCtxtInferExt;
use rustc_middle::mir::*; use rustc_middle::mir::*;
use rustc_middle::ty; use rustc_middle::ty;
use rustc_mir_dataflow::move_paths::{
IllegalMoveOrigin, IllegalMoveOriginKind, LookupResult, MoveError, MovePathIndex,
};
use rustc_span::source_map::DesugaringKind; use rustc_span::source_map::DesugaringKind;
use rustc_span::{sym, Span, DUMMY_SP}; use rustc_span::{sym, Span, DUMMY_SP};
use rustc_trait_selection::traits::type_known_to_meet_bound_modulo_regions; use rustc_trait_selection::traits::type_known_to_meet_bound_modulo_regions;
use crate::borrow_check::diagnostics::UseSpans; use crate::diagnostics::UseSpans;
use crate::borrow_check::prefixes::PrefixSet; use crate::prefixes::PrefixSet;
use crate::borrow_check::MirBorrowckCtxt; use crate::MirBorrowckCtxt;
use crate::dataflow::move_paths::{
IllegalMoveOrigin, IllegalMoveOriginKind, LookupResult, MoveError, MovePathIndex,
};
// Often when desugaring a pattern match we may have many individual moves in // 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 // MIR that are all part of one operation from the user's point-of-view. For

View file

@ -14,9 +14,9 @@ use rustc_span::source_map::DesugaringKind;
use rustc_span::symbol::{kw, Symbol}; use rustc_span::symbol::{kw, Symbol};
use rustc_span::{BytePos, Span}; use rustc_span::{BytePos, Span};
use crate::borrow_check::diagnostics::BorrowedContentSource; use crate::diagnostics::BorrowedContentSource;
use crate::borrow_check::MirBorrowckCtxt; use crate::MirBorrowckCtxt;
use crate::util::collect_writes::FindAssignments; use rustc_const_eval::util::collect_writes::FindAssignments;
use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_errors::{Applicability, DiagnosticBuilder};
#[derive(Copy, Clone, Debug, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Eq, PartialEq)]

View file

@ -1,16 +1,14 @@
//! Contains utilities for generating suggestions for borrowck errors related to unsatisfied //! Contains utilities for generating suggestions for borrowck errors related to unsatisfied
//! outlives constraints. //! outlives constraints.
use std::collections::BTreeMap;
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_errors::DiagnosticBuilder; use rustc_errors::DiagnosticBuilder;
use rustc_middle::ty::RegionVid; use rustc_middle::ty::RegionVid;
use smallvec::SmallVec;
use std::collections::BTreeMap;
use tracing::debug; use tracing::debug;
use smallvec::SmallVec; use crate::MirBorrowckCtxt;
use crate::borrow_check::MirBorrowckCtxt;
use super::{ErrorConstraintInfo, RegionName, RegionNameSource}; use super::{ErrorConstraintInfo, RegionName, RegionNameSource};

View file

@ -11,10 +11,10 @@ use rustc_middle::ty::{self, RegionVid, Ty};
use rustc_span::symbol::{kw, sym}; use rustc_span::symbol::{kw, sym};
use rustc_span::{BytePos, Span}; use rustc_span::{BytePos, Span};
use crate::util::borrowck_errors; use crate::borrowck_errors;
use crate::borrow_check::region_infer::BlameConstraint; use crate::region_infer::BlameConstraint;
use crate::borrow_check::{ use crate::{
nll::ConstraintDescription, nll::ConstraintDescription,
region_infer::{values::RegionElement, TypeTest}, region_infer::{values::RegionElement, TypeTest},
universal_regions::DefiningTy, 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`. /// 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 // Iterate through all the errors, producing a diagnostic for each one. The diagnostics are
// buffered in the `MirBorrowckCtxt`. // 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`. /// 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, &mut self,
fr: RegionVid, fr: RegionVid,
fr_origin: NllRegionVariableOrigin, fr_origin: NllRegionVariableOrigin,

View file

@ -10,7 +10,7 @@ use rustc_middle::ty::{self, RegionVid, Ty};
use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{Span, DUMMY_SP}; 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 /// 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`. /// name like `'1`, a name used by the user like `'a`, or a name like `'static`.

View file

@ -1,5 +1,5 @@
use crate::borrow_check::Upvar; use crate::Upvar;
use crate::borrow_check::{nll::ToRegionVid, region_infer::RegionInferenceContext}; use crate::{nll::ToRegionVid, region_infer::RegionInferenceContext};
use rustc_index::vec::{Idx, IndexVec}; use rustc_index::vec::{Idx, IndexVec};
use rustc_middle::mir::{Body, Local}; use rustc_middle::mir::{Body, Local};
use rustc_middle::ty::{RegionVid, TyCtxt}; use rustc_middle::ty::{RegionVid, TyCtxt};

View file

@ -1,10 +1,11 @@
use crate::borrow_check::location::{LocationIndex, LocationTable}; use crate::location::{LocationIndex, LocationTable};
use crate::dataflow::indexes::{BorrowIndex, MovePathIndex}; use crate::BorrowIndex;
use polonius_engine::AllFacts as PoloniusFacts; use polonius_engine::AllFacts as PoloniusFacts;
use polonius_engine::Atom; use polonius_engine::Atom;
use rustc_index::vec::Idx; use rustc_index::vec::Idx;
use rustc_middle::mir::Local; use rustc_middle::mir::Local;
use rustc_middle::ty::{RegionVid, TyCtxt}; use rustc_middle::ty::{RegionVid, TyCtxt};
use rustc_mir_dataflow::move_paths::MovePathIndex;
use std::error::Error; use std::error::Error;
use std::fmt::Debug; use std::fmt::Debug;
use std::fs::{self, File}; 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> { struct FactWriter<'w> {
location_table: &'w LocationTable, location_table: &'w LocationTable,
dir: &'w Path, dir: &'w Path,

View file

@ -7,12 +7,10 @@ use rustc_middle::mir::{Statement, StatementKind};
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use std::iter; use std::iter;
use crate::dataflow::indexes::BorrowIndex; use crate::{
use crate::borrow_check::{
borrow_set::BorrowSet, facts::AllFacts, location::LocationTable, path_utils::*, AccessDepth, borrow_set::BorrowSet, facts::AllFacts, location::LocationTable, path_utils::*, AccessDepth,
Activation, ArtificialField, Deep, JustWrite, LocalMutationIsAllowed, MutateMode, Read, Activation, ArtificialField, BorrowIndex, Deep, JustWrite, LocalMutationIsAllowed, MutateMode,
ReadKind, ReadOrWrite, Reservation, Shallow, Write, WriteAndRead, WriteKind, Read, ReadKind, ReadOrWrite, Reservation, Shallow, Write, WriteAndRead, WriteKind,
}; };
pub(super) fn generate_invalidates<'tcx>( pub(super) fn generate_invalidates<'tcx>(

View file

@ -1,5 +1,23 @@
//! This query borrow-checks the MIR to (further) ensure it is not broken. //! 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)]
#![recursion_limit = "256"]
#[macro_use]
extern crate rustc_middle;
#[macro_use]
extern crate tracing;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::graph::dominators::Dominators; use rustc_data_structures::graph::dominators::Dominators;
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorReported}; use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorReported};
@ -29,14 +47,13 @@ use std::iter;
use std::mem; use std::mem;
use std::rc::Rc; use std::rc::Rc;
use crate::dataflow; use rustc_mir_dataflow::impls::{
use crate::dataflow::impls::{ EverInitializedPlaces, MaybeInitializedPlaces, MaybeUninitializedPlaces,
Borrows, EverInitializedPlaces, MaybeInitializedPlaces, MaybeUninitializedPlaces,
}; };
use crate::dataflow::indexes::{BorrowIndex, InitIndex, MoveOutIndex, MovePathIndex}; use rustc_mir_dataflow::move_paths::{InitIndex, MoveOutIndex, MovePathIndex};
use crate::dataflow::move_paths::{InitLocation, LookupResult, MoveData, MoveError}; use rustc_mir_dataflow::move_paths::{InitLocation, LookupResult, MoveData, MoveError};
use crate::dataflow::MoveDataParamEnv; use rustc_mir_dataflow::Analysis;
use crate::dataflow::{Analysis, BorrowckFlowState as Flows, BorrowckResults}; use rustc_mir_dataflow::MoveDataParamEnv;
use self::diagnostics::{AccessKind, RegionName}; use self::diagnostics::{AccessKind, RegionName};
use self::location::LocationTable; use self::location::LocationTable;
@ -47,9 +64,10 @@ use facts::AllFacts;
use self::path_utils::*; use self::path_utils::*;
mod borrow_set; mod borrow_set;
mod borrowck_errors;
mod constraint_generation; mod constraint_generation;
mod constraints; mod constraints;
pub mod consumers; mod dataflow;
mod def_use; mod def_use;
mod diagnostics; mod diagnostics;
mod facts; mod facts;
@ -67,15 +85,19 @@ mod type_check;
mod universal_regions; mod universal_regions;
mod used_muts; mod used_muts;
crate use borrow_set::{BorrowData, BorrowSet}; // A public API provided for the Rust compiler consumers.
crate use nll::{PoloniusOutput, ToRegionVid}; pub mod consumers;
crate use place_ext::PlaceExt;
crate use places_conflict::{places_conflict, PlaceConflictBias}; use borrow_set::{BorrowData, BorrowSet};
crate use region_infer::RegionInferenceContext; 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. // FIXME(eddyb) perhaps move this somewhere more centrally.
#[derive(Debug)] #[derive(Debug)]
crate struct Upvar<'tcx> { struct Upvar<'tcx> {
place: CapturedPlace<'tcx>, place: CapturedPlace<'tcx>,
/// If true, the capture is behind a reference. /// If true, the capture is behind a reference.
@ -352,7 +374,7 @@ fn do_mir_borrowck<'a, 'tcx>(
mbcx.report_move_errors(move_errors); mbcx.report_move_errors(move_errors);
dataflow::visit_results( rustc_mir_dataflow::visit_results(
&body, &body,
traversal::reverse_postorder(&body).map(|(bb, _)| bb), traversal::reverse_postorder(&body).map(|(bb, _)| bb),
&results, &results,
@ -495,8 +517,8 @@ pub struct BodyWithBorrowckFacts<'tcx> {
pub location_table: LocationTable, pub location_table: LocationTable,
} }
crate struct MirBorrowckCtxt<'cx, 'tcx> { struct MirBorrowckCtxt<'cx, 'tcx> {
crate infcx: &'cx InferCtxt<'cx, 'tcx>, infcx: &'cx InferCtxt<'cx, 'tcx>,
param_env: ParamEnv<'tcx>, param_env: ParamEnv<'tcx>,
body: &'cx Body<'tcx>, body: &'cx Body<'tcx>,
move_data: &'cx MoveData<'tcx>, move_data: &'cx MoveData<'tcx>,
@ -594,7 +616,7 @@ crate struct MirBorrowckCtxt<'cx, 'tcx> {
// 2. loans made in overlapping scopes do not conflict // 2. loans made in overlapping scopes do not conflict
// 3. assignments do not affect things loaned out as immutable // 3. assignments do not affect things loaned out as immutable
// 4. moves do not affect things loaned out in any way // 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>; type FlowState = Flows<'cx, 'tcx>;
fn visit_statement_before_primary_effect( fn visit_statement_before_primary_effect(
@ -2344,7 +2366,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
/// then returns the index of the field being projected. Note that this closure will always /// 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 /// be `self` in the current MIR, because that is the only time we directly access the fields
/// of a closure type. /// of a closure type.
pub fn is_upvar_field_projection(&self, place_ref: PlaceRef<'tcx>) -> Option<Field> { fn is_upvar_field_projection(&self, place_ref: PlaceRef<'tcx>) -> Option<Field> {
path_utils::is_upvar_field_projection(self.infcx.tcx, &self.upvars, place_ref, self.body()) path_utils::is_upvar_field_projection(self.infcx.tcx, &self.upvars, place_ref, self.body())
} }
} }

View file

@ -4,6 +4,7 @@ use rustc_data_structures::vec_map::VecMap;
use rustc_errors::Diagnostic; use rustc_errors::Diagnostic;
use rustc_index::vec::IndexVec; use rustc_index::vec::IndexVec;
use rustc_infer::infer::InferCtxt; use rustc_infer::infer::InferCtxt;
use rustc_middle::mir::{create_dump_file, dump_enabled, dump_mir, PassWhere};
use rustc_middle::mir::{ use rustc_middle::mir::{
BasicBlock, Body, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, Location, BasicBlock, Body, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, Location,
Promoted, Promoted,
@ -17,16 +18,13 @@ use std::path::PathBuf;
use std::rc::Rc; use std::rc::Rc;
use std::str::FromStr; use std::str::FromStr;
use self::mir_util::PassWhere;
use polonius_engine::{Algorithm, Output}; use polonius_engine::{Algorithm, Output};
use crate::dataflow::impls::MaybeInitializedPlaces; use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
use crate::dataflow::move_paths::{InitKind, InitLocation, MoveData}; use rustc_mir_dataflow::move_paths::{InitKind, InitLocation, MoveData};
use crate::dataflow::ResultsCursor; use rustc_mir_dataflow::ResultsCursor;
use crate::util as mir_util;
use crate::util::pretty;
use crate::borrow_check::{ use crate::{
borrow_set::BorrowSet, borrow_set::BorrowSet,
constraint_generation, constraint_generation,
diagnostics::RegionErrors, diagnostics::RegionErrors,
@ -56,7 +54,7 @@ crate struct NllOutput<'tcx> {
/// Rewrites the regions in the MIR to use NLL variables, also scraping out the set of universal /// 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 /// regions (e.g., region parameters) declared on the function. That set will need to be given to
/// `compute_regions`. /// `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>, infcx: &InferCtxt<'cx, 'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
body: &mut Body<'tcx>, body: &mut Body<'tcx>,
@ -72,7 +70,7 @@ pub(in crate::borrow_check) fn replace_regions_in_mir<'cx, 'tcx>(
// Replace all remaining regions with fresh inference variables. // Replace all remaining regions with fresh inference variables.
renumber::renumber_mir(infcx, body, promoted); 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 universal_regions
} }
@ -155,7 +153,7 @@ fn populate_polonius_move_facts(
/// Computes the (non-lexical) regions from the input MIR. /// Computes the (non-lexical) regions from the input MIR.
/// ///
/// This may result in errors being reported. /// 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>, infcx: &InferCtxt<'cx, 'tcx>,
universal_regions: UniversalRegions<'tcx>, universal_regions: UniversalRegions<'tcx>,
body: &Body<'tcx>, body: &Body<'tcx>,
@ -322,11 +320,11 @@ pub(super) fn dump_mir_results<'a, 'tcx>(
regioncx: &RegionInferenceContext<'tcx>, regioncx: &RegionInferenceContext<'tcx>,
closure_region_requirements: &Option<ClosureRegionRequirements<'_>>, closure_region_requirements: &Option<ClosureRegionRequirements<'_>>,
) { ) {
if !mir_util::dump_enabled(infcx.tcx, "nll", body.source.def_id()) { if !dump_enabled(infcx.tcx, "nll", body.source.def_id()) {
return; 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 { match pass_where {
// Before the CFG, dump out the values for each region variable. // Before the CFG, dump out the values for each region variable.
PassWhere::BeforeCFG => { PassWhere::BeforeCFG => {
@ -354,14 +352,14 @@ pub(super) fn dump_mir_results<'a, 'tcx>(
// Also dump the inference graph constraints as a graphviz file. // Also dump the inference graph constraints as a graphviz file.
let _: io::Result<()> = try { let _: io::Result<()> = try {
let mut file = 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)?; regioncx.dump_graphviz_raw_constraints(&mut file)?;
}; };
// Also dump the inference graph constraints as a graphviz file. // Also dump the inference graph constraints as a graphviz file.
let _: io::Result<()> = try { let _: io::Result<()> = try {
let mut file = 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)?; regioncx.dump_graphviz_scc_constraints(&mut file)?;
}; };
} }

View file

@ -1,8 +1,8 @@
use crate::borrow_check::borrow_set::{BorrowData, BorrowSet, TwoPhaseActivation}; use crate::borrow_set::{BorrowData, BorrowSet, TwoPhaseActivation};
use crate::borrow_check::places_conflict; use crate::places_conflict;
use crate::borrow_check::AccessDepth; use crate::AccessDepth;
use crate::borrow_check::Upvar; use crate::BorrowIndex;
use crate::dataflow::indexes::BorrowIndex; use crate::Upvar;
use rustc_data_structures::graph::dominators::Dominators; use rustc_data_structures::graph::dominators::Dominators;
use rustc_middle::mir::BorrowKind; use rustc_middle::mir::BorrowKind;
use rustc_middle::mir::{BasicBlock, Body, Field, Location, Place, PlaceRef, ProjectionElem}; use rustc_middle::mir::{BasicBlock, Body, Field, Location, Place, PlaceRef, ProjectionElem};

View file

@ -1,4 +1,4 @@
use crate::borrow_check::borrow_set::LocalsStateAtExit; use crate::borrow_set::LocalsStateAtExit;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_middle::mir::ProjectionElem; use rustc_middle::mir::ProjectionElem;
use rustc_middle::mir::{Body, Mutability, Place}; use rustc_middle::mir::{Body, Mutability, Place};

View file

@ -1,6 +1,6 @@
use crate::borrow_check::ArtificialField; use crate::ArtificialField;
use crate::borrow_check::Overlap; use crate::Overlap;
use crate::borrow_check::{AccessDepth, Deep, Shallow}; use crate::{AccessDepth, Deep, Shallow};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_middle::mir::{Body, BorrowKind, Local, Place, PlaceElem, PlaceRef, ProjectionElem}; use rustc_middle::mir::{Body, BorrowKind, Local, Place, PlaceElem, PlaceRef, ProjectionElem};
use rustc_middle::ty::{self, TyCtxt}; use rustc_middle::ty::{self, TyCtxt};

View file

@ -4,7 +4,7 @@
//! context internal state. //! context internal state.
use super::{OutlivesConstraint, RegionInferenceContext}; use super::{OutlivesConstraint, RegionInferenceContext};
use crate::borrow_check::type_check::Locations; use crate::type_check::Locations;
use rustc_infer::infer::NllRegionVariableOrigin; use rustc_infer::infer::NllRegionVariableOrigin;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use std::io::{self, Write}; use std::io::{self, Write};

View file

@ -6,7 +6,7 @@ use std::borrow::Cow;
use std::io::{self, Write}; use std::io::{self, Write};
use super::*; use super::*;
use crate::borrow_check::constraints::OutlivesConstraint; use crate::constraints::OutlivesConstraint;
use rustc_graphviz as dot; use rustc_graphviz as dot;
impl<'tcx> RegionInferenceContext<'tcx> { impl<'tcx> RegionInferenceContext<'tcx> {

View file

@ -17,7 +17,7 @@ use rustc_middle::mir::{
use rustc_middle::ty::{self, subst::SubstsRef, RegionVid, Ty, TyCtxt, TypeFoldable}; use rustc_middle::ty::{self, subst::SubstsRef, RegionVid, Ty, TyCtxt, TypeFoldable};
use rustc_span::Span; use rustc_span::Span;
use crate::borrow_check::{ use crate::{
constraints::{ constraints::{
graph::NormalConstraintGraph, ConstraintSccIndex, OutlivesConstraint, OutlivesConstraintSet, graph::NormalConstraintGraph, ConstraintSccIndex, OutlivesConstraint, OutlivesConstraintSet,
}, },
@ -132,33 +132,33 @@ pub(crate) struct AppliedMemberConstraint {
/// ///
/// The vector if `AppliedMemberConstraint` elements is kept sorted /// The vector if `AppliedMemberConstraint` elements is kept sorted
/// by this field. /// 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 /// The "best option" that `apply_member_constraint` found -- this was
/// added as an "ad-hoc" lower-bound to `member_region_scc`. /// 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 "member constraint index" -- we can find out details about
/// the constraint from /// the constraint from
/// `set.member_constraints[member_constraint_index]`. /// `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> { pub(crate) struct RegionDefinition<'tcx> {
/// What kind of variable is this -- a free region? existential /// What kind of variable is this -- a free region? existential
/// variable? etc. (See the `NllRegionVariableOrigin` for more /// variable? etc. (See the `NllRegionVariableOrigin` for more
/// info.) /// info.)
pub(in crate::borrow_check) origin: NllRegionVariableOrigin, pub(crate) origin: NllRegionVariableOrigin,
/// Which universe is this region variable defined in? This is /// Which universe is this region variable defined in? This is
/// most often `ty::UniverseIndex::ROOT`, but when we encounter /// most often `ty::UniverseIndex::ROOT`, but when we encounter
/// forall-quantifiers like `for<'a> { 'a = 'b }`, we would create /// forall-quantifiers like `for<'a> { 'a = 'b }`, we would create
/// the variable for `'a` in a fresh universe that extends ROOT. /// 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 /// If this is 'static or an early-bound region, then this is
/// `Some(X)` where `X` is the name of the region. /// `Some(X)` where `X` is the name of the region.
pub(in crate::borrow_check) external_name: Option<ty::Region<'tcx>>, pub(crate) external_name: Option<ty::Region<'tcx>>,
} }
/// N.B., the variants in `Cause` are intentionally ordered. Lower /// 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 /// The `outlives_constraints` and `type_tests` are an initial set
/// of constraints produced by the MIR type check. /// of constraints produced by the MIR type check.
pub(in crate::borrow_check) fn new( pub(crate) fn new(
var_infos: VarInfos, var_infos: VarInfos,
universal_regions: Rc<UniversalRegions<'tcx>>, universal_regions: Rc<UniversalRegions<'tcx>>,
placeholder_indices: Rc<PlaceholderIndices>, placeholder_indices: Rc<PlaceholderIndices>,
@ -534,7 +534,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// Once region solving has completed, this function will return /// Once region solving has completed, this function will return
/// the member constraints that were applied to the value of a given /// the member constraints that were applied to the value of a given
/// region `r`. See `AppliedMemberConstraint`. /// region `r`. See `AppliedMemberConstraint`.
pub(in crate::borrow_check) fn applied_member_constraints( pub(crate) fn applied_member_constraints(
&self, &self,
r: impl ToRegionVid, r: impl ToRegionVid,
) -> &[AppliedMemberConstraint] { ) -> &[AppliedMemberConstraint] {
@ -1088,7 +1088,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// include the CFG anyhow. /// include the CFG anyhow.
/// - For each `end('x)` element in `'r`, compute the mutual LUB, yielding /// - For each `end('x)` element in `'r`, compute the mutual LUB, yielding
/// a result `'y`. /// 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)); debug!("universal_upper_bound(r={:?}={})", r, self.region_value_str(r));
// Find the smallest universal region that contains all other // 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, /// Therefore, this method should only be used in diagnostic code,
/// where displaying *some* named universal region is better than /// where displaying *some* named universal region is better than
/// falling back to 'static. /// 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)); debug!("approx_universal_upper_bound(r={:?}={})", r, self.region_value_str(r));
// Find the smallest universal region that contains all other // Find the smallest universal region that contains all other

View file

@ -47,7 +47,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// which has no `external_name` in which case we use `'empty` as the /// which has no `external_name` in which case we use `'empty` as the
/// region to pass to `infer_opaque_definition_from_instantiation`. /// region to pass to `infer_opaque_definition_from_instantiation`.
#[instrument(skip(self, infcx))] #[instrument(skip(self, infcx))]
pub(in crate::borrow_check) fn infer_opaque_types( pub(crate) fn infer_opaque_types(
&self, &self,
infcx: &InferCtxt<'_, 'tcx>, infcx: &InferCtxt<'_, 'tcx>,
opaque_ty_decls: VecMap<OpaqueTypeKey<'tcx>, Ty<'tcx>>, opaque_ty_decls: VecMap<OpaqueTypeKey<'tcx>, Ty<'tcx>>,
@ -105,7 +105,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// that the regions produced are in fact equal to the named region they are /// 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 /// replaced with. This is fine because this function is only to improve the
/// region names in error messages. /// region names in error messages.
pub(in crate::borrow_check) fn name_regions<T>(&self, tcx: TyCtxt<'tcx>, ty: T) -> T pub(crate) fn name_regions<T>(&self, tcx: TyCtxt<'tcx>, ty: T) -> T
where where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
{ {

View file

@ -1,5 +1,5 @@
use crate::borrow_check::constraints::ConstraintSccIndex; use crate::constraints::ConstraintSccIndex;
use crate::borrow_check::RegionInferenceContext; use crate::RegionInferenceContext;
use itertools::Itertools; use itertools::Itertools;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::graph::vec_graph::VecGraph; use rustc_data_structures::graph::vec_graph::VecGraph;

View file

@ -8,7 +8,7 @@ use rustc_span::Span;
use rustc_trait_selection::traits::query::type_op::{self, TypeOpOutput}; use rustc_trait_selection::traits::query::type_op::{self, TypeOpOutput};
use rustc_trait_selection::traits::query::Fallible; use rustc_trait_selection::traits::query::Fallible;
use crate::borrow_check::diagnostics::{ToUniverseInfo, UniverseInfo}; use crate::diagnostics::{ToUniverseInfo, UniverseInfo};
use super::{Locations, NormalizeLocation, TypeChecker}; use super::{Locations, NormalizeLocation, TypeChecker};

View file

@ -9,7 +9,7 @@ use rustc_middle::ty::subst::GenericArgKind;
use rustc_middle::ty::{self, TyCtxt}; use rustc_middle::ty::{self, TyCtxt};
use rustc_span::DUMMY_SP; use rustc_span::DUMMY_SP;
use crate::borrow_check::{ use crate::{
constraints::OutlivesConstraint, constraints::OutlivesConstraint,
nll::ToRegionVid, nll::ToRegionVid,
region_infer::TypeTest, region_infer::TypeTest,

View file

@ -13,7 +13,7 @@ use rustc_trait_selection::traits::query::type_op::{self, TypeOp};
use std::rc::Rc; use std::rc::Rc;
use type_op::TypeOpOutput; use type_op::TypeOpOutput;
use crate::borrow_check::{ use crate::{
nll::ToRegionVid, nll::ToRegionVid,
type_check::constraint_conversion, type_check::constraint_conversion,
type_check::{Locations, MirTypeckRegionConstraints}, type_check::{Locations, MirTypeckRegionConstraints},
@ -55,7 +55,7 @@ type RegionBoundPairs<'tcx> = Vec<(ty::Region<'tcx>, GenericKind<'tcx>)>;
type NormalizedInputsAndOutput<'tcx> = Vec<Ty<'tcx>>; type NormalizedInputsAndOutput<'tcx> = Vec<Ty<'tcx>>;
crate struct CreateResult<'tcx> { crate struct CreateResult<'tcx> {
pub(in crate::borrow_check) universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>, crate universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
crate region_bound_pairs: RegionBoundPairs<'tcx>, crate region_bound_pairs: RegionBoundPairs<'tcx>,
crate normalized_inputs_and_output: NormalizedInputsAndOutput<'tcx>, crate normalized_inputs_and_output: NormalizedInputsAndOutput<'tcx>,
} }

View file

@ -7,16 +7,15 @@
//! `RETURN_PLACE` the MIR arguments) are always fully normalized (and //! `RETURN_PLACE` the MIR arguments) are always fully normalized (and
//! contain revealed `impl Trait` values). //! contain revealed `impl Trait` values).
use rustc_index::vec::Idx;
use rustc_infer::infer::LateBoundRegionConversionTime; use rustc_infer::infer::LateBoundRegionConversionTime;
use rustc_middle::mir::*; use rustc_middle::mir::*;
use rustc_middle::traits::ObligationCause; use rustc_middle::traits::ObligationCause;
use rustc_middle::ty::{self, Ty}; use rustc_middle::ty::{self, Ty};
use rustc_span::Span;
use rustc_trait_selection::traits::query::normalize::AtExt; use rustc_trait_selection::traits::query::normalize::AtExt;
use rustc_index::vec::Idx; use crate::universal_regions::UniversalRegions;
use rustc_span::Span;
use crate::borrow_check::universal_regions::UniversalRegions;
use super::{Locations, TypeChecker}; use super::{Locations, TypeChecker};

View file

@ -3,8 +3,8 @@ use rustc_index::vec::IndexVec;
use rustc_middle::mir::visit::{PlaceContext, Visitor}; use rustc_middle::mir::visit::{PlaceContext, Visitor};
use rustc_middle::mir::{Body, Local, Location}; use rustc_middle::mir::{Body, Local, Location};
use crate::borrow_check::def_use::{self, DefUse}; use crate::def_use::{self, DefUse};
use crate::borrow_check::region_infer::values::{PointIndex, RegionValueElements}; use crate::region_infer::values::{PointIndex, RegionValueElements};
/// A map that cross references each local with the locations where it /// A map that cross references each local with the locations where it
/// is defined (assigned), used, or dropped. Used during liveness /// is defined (assigned), used, or dropped. Used during liveness

View file

@ -3,11 +3,11 @@ use rustc_middle::mir::{Body, Local};
use rustc_middle::ty::{RegionVid, TyCtxt}; use rustc_middle::ty::{RegionVid, TyCtxt};
use std::rc::Rc; use std::rc::Rc;
use crate::dataflow::impls::MaybeInitializedPlaces; use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
use crate::dataflow::move_paths::MoveData; use rustc_mir_dataflow::move_paths::MoveData;
use crate::dataflow::ResultsCursor; use rustc_mir_dataflow::ResultsCursor;
use crate::borrow_check::{ use crate::{
constraints::OutlivesConstraintSet, constraints::OutlivesConstraintSet,
facts::{AllFacts, AllFactsExt}, facts::{AllFacts, AllFactsExt},
location::LocationTable, location::LocationTable,

View file

@ -1,10 +1,9 @@
use crate::borrow_check::def_use::{self, DefUse}; use crate::def_use::{self, DefUse};
use crate::borrow_check::location::{LocationIndex, LocationTable}; use crate::location::{LocationIndex, LocationTable};
use crate::dataflow::indexes::MovePathIndex;
use crate::dataflow::move_paths::{LookupResult, MoveData};
use rustc_middle::mir::visit::{MutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::visit::{MutatingUseContext, PlaceContext, Visitor};
use rustc_middle::mir::{Body, Local, Location, Place}; use rustc_middle::mir::{Body, Local, Location, Place};
use rustc_middle::ty::subst::GenericArg; use rustc_middle::ty::subst::GenericArg;
use rustc_mir_dataflow::move_paths::{LookupResult, MoveData, MovePathIndex};
use super::TypeChecker; use super::TypeChecker;

View file

@ -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 rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput};
use std::rc::Rc; use std::rc::Rc;
use crate::dataflow::impls::MaybeInitializedPlaces; use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
use crate::dataflow::indexes::MovePathIndex; use rustc_mir_dataflow::move_paths::{HasMoveData, MoveData, MovePathIndex};
use crate::dataflow::move_paths::{HasMoveData, MoveData}; use rustc_mir_dataflow::ResultsCursor;
use crate::dataflow::ResultsCursor;
use crate::borrow_check::{ use crate::{
region_infer::values::{self, PointIndex, RegionValueElements}, region_infer::values::{self, PointIndex, RegionValueElements},
type_check::liveness::local_use_map::LocalUseMap, type_check::liveness::local_use_map::LocalUseMap,
type_check::liveness::polonius, type_check::liveness::polonius,

View file

@ -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::query::Fallible;
use rustc_trait_selection::traits::{self, ObligationCause, PredicateObligations}; use rustc_trait_selection::traits::{self, ObligationCause, PredicateObligations};
use crate::dataflow::impls::MaybeInitializedPlaces; use rustc_const_eval::transform::{
use crate::dataflow::move_paths::MoveData;
use crate::dataflow::ResultsCursor;
use crate::transform::{
check_consts::ConstCx, promote_consts::is_const_fn_in_array_repeat_expression, 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_check::{ use crate::{
borrow_set::BorrowSet, borrow_set::BorrowSet,
constraints::{OutlivesConstraint, OutlivesConstraintSet}, constraints::{OutlivesConstraint, OutlivesConstraintSet},
diagnostics::UniverseInfo, diagnostics::UniverseInfo,
@ -68,7 +68,7 @@ use crate::borrow_check::{
macro_rules! span_mirbug { macro_rules! span_mirbug {
($context:expr, $elem:expr, $($message:tt)*) => ({ ($context:expr, $elem:expr, $($message:tt)*) => ({
$crate::borrow_check::type_check::mirbug( $crate::type_check::mirbug(
$context.tcx(), $context.tcx(),
$context.last_span, $context.last_span,
&format!( &format!(
@ -887,7 +887,7 @@ struct BorrowCheckContext<'a, 'tcx> {
crate struct MirTypeckResults<'tcx> { crate struct MirTypeckResults<'tcx> {
crate constraints: MirTypeckRegionConstraints<'tcx>, crate constraints: MirTypeckRegionConstraints<'tcx>,
pub(in crate::borrow_check) universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>, crate universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
crate opaque_type_values: VecMap<OpaqueTypeKey<'tcx>, Ty<'tcx>>, crate opaque_type_values: VecMap<OpaqueTypeKey<'tcx>, Ty<'tcx>>,
} }

View file

@ -5,9 +5,9 @@ use rustc_middle::ty::relate::TypeRelation;
use rustc_middle::ty::{self, Const, Ty}; use rustc_middle::ty::{self, Const, Ty};
use rustc_trait_selection::traits::query::Fallible; use rustc_trait_selection::traits::query::Fallible;
use crate::borrow_check::constraints::OutlivesConstraint; use crate::constraints::OutlivesConstraint;
use crate::borrow_check::diagnostics::UniverseInfo; use crate::diagnostics::UniverseInfo;
use crate::borrow_check::type_check::{BorrowCheckContext, Locations}; use crate::type_check::{BorrowCheckContext, Locations};
/// Adds sufficient constraints to ensure that `a R b` where `R` depends on `v`: /// Adds sufficient constraints to ensure that `a R b` where `R` depends on `v`:
/// ///

View file

@ -26,7 +26,7 @@ use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef};
use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt}; use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt};
use std::iter; use std::iter;
use crate::borrow_check::nll::ToRegionVid; use crate::nll::ToRegionVid;
#[derive(Debug)] #[derive(Debug)]
pub struct UniversalRegions<'tcx> { pub struct UniversalRegions<'tcx> {

View file

@ -1,11 +1,10 @@
use rustc_data_structures::fx::FxHashSet;
use rustc_middle::mir::visit::{PlaceContext, Visitor}; use rustc_middle::mir::visit::{PlaceContext, Visitor};
use rustc_middle::mir::{ use rustc_middle::mir::{
Local, Location, Place, Statement, StatementKind, Terminator, TerminatorKind, Local, Location, Place, Statement, StatementKind, Terminator, TerminatorKind,
}; };
use rustc_data_structures::fx::FxHashSet; use crate::MirBorrowckCtxt;
use crate::borrow_check::MirBorrowckCtxt;
impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
/// Walks the MIR adding to the set of `used_mut` locals that will be ignored for the purposes /// Walks the MIR adding to the set of `used_mut` locals that will be ignored for the purposes

View file

@ -42,7 +42,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
continue; 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_incremental::assert_dep_graph::assert_dep_graph")
|| stack.contains("rustc_symbol_mangling::test::report_symbol_names") || stack.contains("rustc_symbol_mangling::test::report_symbol_names")
{ {
@ -81,7 +81,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
} }
const COLLECT_AND_PARTITION_MONO_ITEMS: &str = 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) { if let Some(index) = stack.find(COLLECT_AND_PARTITION_MONO_ITEMS) {
stack = &stack[..index + COLLECT_AND_PARTITION_MONO_ITEMS.len()]; stack = &stack[..index + COLLECT_AND_PARTITION_MONO_ITEMS.len()];
} }

View file

@ -23,7 +23,7 @@ pub(crate) fn codegen_fn<'tcx>(
let mir = tcx.instance_mir(instance.def); let mir = tcx.instance_mir(instance.def);
let _mir_guard = crate::PrintOnPanic(|| { let _mir_guard = crate::PrintOnPanic(|| {
let mut buf = Vec::new(); 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() String::from_utf8_lossy(&buf).into_owned()
}); });

View file

@ -16,7 +16,6 @@ extern crate rustc_incremental;
extern crate rustc_index; extern crate rustc_index;
extern crate rustc_interface; extern crate rustc_interface;
extern crate rustc_metadata; extern crate rustc_metadata;
extern crate rustc_mir;
extern crate rustc_session; extern crate rustc_session;
extern crate rustc_span; extern crate rustc_span;
extern crate rustc_target; extern crate rustc_target;

View file

@ -0,0 +1,27 @@
[package]
name = "rustc_const_eval"
version = "0.0.0"
edition = "2018"
[lib]
doctest = false
[dependencies]
either = "1.5.0"
gsgdt = "0.1.2"
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_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_mir_dataflow = { path = "../rustc_mir_dataflow" }
rustc_session = { path = "../rustc_session" }
rustc_target = { path = "../rustc_target" }
rustc_trait_selection = { path = "../rustc_trait_selection" }
rustc_span = { path = "../rustc_span" }

View file

@ -5,12 +5,12 @@ use crate::interpret::{
Immediate, InternKind, InterpCx, InterpResult, MPlaceTy, MemoryKind, OpTy, RefTracking, Scalar, Immediate, InternKind, InterpCx, InterpResult, MPlaceTy, MemoryKind, OpTy, RefTracking, Scalar,
ScalarMaybeUninit, StackPopCleanup, ScalarMaybeUninit, StackPopCleanup,
}; };
use crate::util::pretty::display_allocation;
use rustc_errors::ErrorReported; use rustc_errors::ErrorReported;
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
use rustc_middle::mir; use rustc_middle::mir;
use rustc_middle::mir::interpret::ErrorHandled; use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::mir::pretty::display_allocation;
use rustc_middle::traits::Reveal; use rustc_middle::traits::Reveal;
use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::print::with_no_trimmed_paths;

View file

@ -12,6 +12,7 @@ use rustc_middle::ty::layout::{self, LayoutError, LayoutOf, LayoutOfHelpers, TyA
use rustc_middle::ty::{ use rustc_middle::ty::{
self, query::TyCtxtAt, subst::SubstsRef, ParamEnv, Ty, TyCtxt, TypeFoldable, self, query::TyCtxtAt, subst::SubstsRef, ParamEnv, Ty, TyCtxt, TypeFoldable,
}; };
use rustc_mir_dataflow::storage::AlwaysLiveLocals;
use rustc_session::Limit; use rustc_session::Limit;
use rustc_span::{Pos, Span}; use rustc_span::{Pos, Span};
use rustc_target::abi::{Align, HasDataLayout, Size, TargetDataLayout}; use rustc_target::abi::{Align, HasDataLayout, Size, TargetDataLayout};
@ -22,7 +23,6 @@ use super::{
ScalarMaybeUninit, StackPopJump, ScalarMaybeUninit, StackPopJump,
}; };
use crate::transform::validate::equal_up_to_regions; use crate::transform::validate::equal_up_to_regions;
use crate::util::storage::AlwaysLiveLocals;
pub struct InterpCx<'mir, 'tcx, M: Machine<'mir, 'tcx>> { pub struct InterpCx<'mir, 'tcx, M: Machine<'mir, 'tcx>> {
/// Stores the `Machine` instance. /// Stores the `Machine` instance.

View file

@ -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 /// 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 /// it. Once your own mutation code is done, the backing `Allocation` is removed from the
/// current `Memory` and returned. /// current `Memory` and returned.
pub(crate) fn intern_with_temp_alloc( pub fn intern_with_temp_alloc(
&mut self, &mut self,
layout: TyAndLayout<'tcx>, layout: TyAndLayout<'tcx>,
f: impl FnOnce( f: impl FnOnce(

View file

@ -15,6 +15,7 @@ use std::ptr;
use rustc_ast::Mutability; use rustc_ast::Mutability;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_middle::mir::display_allocation;
use rustc_middle::ty::{Instance, ParamEnv, TyCtxt}; use rustc_middle::ty::{Instance, ParamEnv, TyCtxt};
use rustc_target::abi::{Align, HasDataLayout, Size, TargetDataLayout}; use rustc_target::abi::{Align, HasDataLayout, Size, TargetDataLayout};
@ -23,7 +24,6 @@ use super::{
InterpResult, Machine, MayLeak, Pointer, PointerArithmetic, Provenance, Scalar, InterpResult, Machine, MayLeak, Pointer, PointerArithmetic, Provenance, Scalar,
ScalarMaybeUninit, ScalarMaybeUninit,
}; };
use crate::util::pretty;
#[derive(Debug, PartialEq, Copy, Clone)] #[derive(Debug, PartialEq, Copy, Clone)]
pub enum MemoryKind<T> { pub enum MemoryKind<T> {
@ -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()) { for alloc_id in alloc.relocations().values().map(|tag| tag.get_alloc_id()) {
allocs_to_print.push_back(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(); let mut allocs_to_print: VecDeque<_> = self.allocs.iter().copied().collect();

View file

@ -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 /// 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 /// succeed! Whether it succeeds depends on whether the layout can be represented
/// in an `Immediate`, not on which data is stored there currently. /// in an `Immediate`, not on which data is stored there currently.
pub(crate) fn try_read_immediate( pub fn try_read_immediate(
&self, &self,
src: &OpTy<'tcx, M::PointerTag>, src: &OpTy<'tcx, M::PointerTag>,
) -> InterpResult<'tcx, Result<ImmTy<'tcx, M::PointerTag>, MPlaceTy<'tcx, M::PointerTag>>> { ) -> InterpResult<'tcx, Result<ImmTy<'tcx, M::PointerTag>, 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 // in patterns via the `const_eval` module
/// The `val` and `layout` are assumed to already be in our interpreter /// The `val` and `layout` are assumed to already be in our interpreter
/// "universe" (param_env). /// "universe" (param_env).
crate fn const_to_op( pub fn const_to_op(
&self, &self,
val: &ty::Const<'tcx>, val: &ty::Const<'tcx>,
layout: Option<TyAndLayout<'tcx>>, layout: Option<TyAndLayout<'tcx>>,
@ -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, &self,
val: &mir::ConstantKind<'tcx>, val: &mir::ConstantKind<'tcx>,
layout: Option<TyAndLayout<'tcx>>, layout: Option<TyAndLayout<'tcx>>,

View file

@ -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 /// Runs the interpretation logic for the given `mir::Statement` at the current frame and
/// statement counter. This also moves the statement counter forward. /// 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); info!("{:?}", stmt);
use rustc_middle::mir::StatementKind::*; use rustc_middle::mir::StatementKind::*;

View file

@ -4,32 +4,25 @@ Rust MIR: a lowered representation of Rust.
*/ */
#![feature(nll)]
#![feature(in_band_lifetimes)]
#![feature(array_windows)]
#![feature(assert_matches)] #![feature(assert_matches)]
#![cfg_attr(bootstrap, feature(bindings_after_at))] #![cfg_attr(bootstrap, feature(bindings_after_at))]
#![feature(bool_to_option)] #![feature(bool_to_option)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(control_flow_enum)]
#![feature(crate_visibility_modifier)] #![feature(crate_visibility_modifier)]
#![feature(decl_macro)] #![feature(decl_macro)]
#![feature(exact_size_is_empty)] #![feature(exact_size_is_empty)]
#![feature(format_args_capture)] #![feature(in_band_lifetimes)]
#![feature(iter_zip)] #![feature(iter_zip)]
#![feature(never_type)]
#![feature(map_try_insert)] #![feature(map_try_insert)]
#![feature(min_specialization)] #![feature(min_specialization)]
#![feature(slice_ptr_get)] #![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(option_get_or_insert_default)]
#![feature(once_cell)] #![feature(never_type)]
#![feature(control_flow_enum)] #![feature(trait_alias)]
#![feature(try_reserve)] #![feature(trusted_len)]
#![feature(try_reserve_kind)] #![feature(trusted_step)]
#![feature(try_blocks)]
#![recursion_limit = "256"] #![recursion_limit = "256"]
#[macro_use] #[macro_use]
@ -37,32 +30,18 @@ extern crate tracing;
#[macro_use] #[macro_use]
extern crate rustc_middle; extern crate rustc_middle;
mod borrow_check;
pub mod const_eval; pub mod const_eval;
pub mod dataflow;
pub mod interpret; pub mod interpret;
pub mod monomorphize;
mod shim;
pub mod transform; pub mod transform;
pub mod util; pub mod util;
// A public API provided for the Rust compiler consumers.
pub use self::borrow_check::consumers;
use rustc_middle::ty::query::Providers; use rustc_middle::ty::query::Providers;
pub fn provide(providers: &mut Providers) { pub fn provide(providers: &mut Providers) {
borrow_check::provide(providers);
const_eval::provide(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_const_value_raw = const_eval::eval_to_const_value_raw_provider;
providers.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider; providers.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider;
providers.const_caller_location = const_eval::const_caller_location; 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| { providers.destructure_const = |tcx, param_env_and_value| {
let (param_env, value) = param_env_and_value.into_parts(); let (param_env, value) = param_env_and_value.into_parts();
const_eval::destructure_const(tcx, param_env, value) const_eval::destructure_const(tcx, param_env, value)

View file

@ -12,6 +12,8 @@ use rustc_middle::ty::cast::CastTy;
use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts}; use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts};
use rustc_middle::ty::{self, adjustment::PointerCast, Instance, InstanceDef, Ty, TyCtxt}; use rustc_middle::ty::{self, adjustment::PointerCast, Instance, InstanceDef, Ty, TyCtxt};
use rustc_middle::ty::{Binder, TraitPredicate, TraitRef}; 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_span::{sym, Span, Symbol};
use rustc_trait_selection::traits::error_reporting::InferCtxtExt; use rustc_trait_selection::traits::error_reporting::InferCtxtExt;
use rustc_trait_selection::traits::{self, SelectionContext, TraitEngine}; 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::resolver::FlowSensitiveAnalysis;
use super::{is_lang_panic_fn, ConstCx, Qualif}; use super::{is_lang_panic_fn, ConstCx, Qualif};
use crate::const_eval::is_unstable_const_fn; 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 // 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` // 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`. // kills locals upon `StorageDead` because a local will never be used after a `StorageDead`.
type IndirectlyMutableResults<'mir, 'tcx> = 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> = 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)] #[derive(Default)]
pub struct Qualifs<'mir, 'tcx> { pub struct Qualifs<'mir, 'tcx> {

View file

@ -9,7 +9,6 @@ use rustc_middle::mir::{self, BasicBlock, Local, Location};
use std::marker::PhantomData; use std::marker::PhantomData;
use super::{qualifs, ConstCx, Qualif}; use super::{qualifs, ConstCx, Qualif};
use crate::dataflow;
/// A `Visitor` that propagates qualifs between locals. This defines the transfer function of /// A `Visitor` that propagates qualifs between locals. This defines the transfer function of
/// `FlowSensitiveAnalysis`. /// `FlowSensitiveAnalysis`.
@ -165,7 +164,7 @@ where
} }
} }
impl<Q> dataflow::AnalysisDomain<'tcx> for FlowSensitiveAnalysis<'_, '_, 'tcx, Q> impl<Q> rustc_mir_dataflow::AnalysisDomain<'tcx> for FlowSensitiveAnalysis<'_, '_, 'tcx, Q>
where where
Q: Qualif, Q: Qualif,
{ {
@ -182,7 +181,7 @@ where
} }
} }
impl<Q> dataflow::Analysis<'tcx> for FlowSensitiveAnalysis<'_, '_, 'tcx, Q> impl<Q> rustc_mir_dataflow::Analysis<'tcx> for FlowSensitiveAnalysis<'_, '_, 'tcx, Q>
where where
Q: Qualif, Q: Qualif,
{ {

View file

@ -0,0 +1,5 @@
pub mod check_consts;
pub mod promote_consts;
pub mod validate;
pub use rustc_middle::mir::MirPass;

View file

@ -1058,7 +1058,7 @@ pub fn promote_candidates<'tcx>(
/// This function returns `true` if the function being called in the array /// This function returns `true` if the function being called in the array
/// repeat expression is a `const` function. /// 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>, ccx: &ConstCx<'_, 'tcx>,
place: &Place<'tcx>, place: &Place<'tcx>,
body: &Body<'tcx>, body: &Body<'tcx>,

View file

@ -1,9 +1,5 @@
//! Validates the MIR to ensure that invariants are upheld. //! 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 super::MirPass;
use rustc_index::bit_set::BitSet; use rustc_index::bit_set::BitSet;
use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::infer::TyCtxtInferExt;
@ -17,6 +13,9 @@ use rustc_middle::mir::{
}; };
use rustc_middle::ty::fold::BottomUpFolder; use rustc_middle::ty::fold::BottomUpFolder;
use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt, TypeFoldable}; 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; use rustc_target::abi::Size;
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]

View file

@ -2,7 +2,7 @@ use rustc_middle::mir::visit::PlaceContext;
use rustc_middle::mir::visit::Visitor; use rustc_middle::mir::visit::Visitor;
use rustc_middle::mir::{Body, Local, Location}; use rustc_middle::mir::{Body, Local, Location};
crate trait FindAssignments { pub trait FindAssignments {
// Finds all statements that assign directly to local (i.e., X = ...) // Finds all statements that assign directly to local (i.e., X = ...)
// and returns their locations. // and returns their locations.
fn find_assignments(&self, local: Local) -> Vec<Location>; fn find_assignments(&self, local: Local) -> Vec<Location>;

View file

@ -0,0 +1,8 @@
pub mod aggregate;
mod alignment;
pub mod collect_writes;
mod find_self_call;
pub use self::aggregate::expand_aggregate;
pub use self::alignment::is_disaligned;
pub use self::find_self_call::find_self_call;

View file

@ -22,7 +22,7 @@ rustc_feature = { path = "../rustc_feature" }
rustc_hir = { path = "../rustc_hir" } rustc_hir = { path = "../rustc_hir" }
rustc_hir_pretty = { path = "../rustc_hir_pretty" } rustc_hir_pretty = { path = "../rustc_hir_pretty" }
rustc_metadata = { path = "../rustc_metadata" } rustc_metadata = { path = "../rustc_metadata" }
rustc_mir = { path = "../rustc_mir" } rustc_const_eval = { path = "../rustc_const_eval" }
rustc_parse = { path = "../rustc_parse" } rustc_parse = { path = "../rustc_parse" }
rustc_plugin_impl = { path = "../rustc_plugin_impl" } rustc_plugin_impl = { path = "../rustc_plugin_impl" }
rustc_save_analysis = { path = "../rustc_save_analysis" } rustc_save_analysis = { path = "../rustc_save_analysis" }

View file

@ -6,8 +6,8 @@ use rustc_errors::ErrorReported;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir_pretty as pprust_hir; use rustc_hir_pretty as pprust_hir;
use rustc_middle::hir::map as hir_map; 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_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::config::{Input, PpAstTreeMode, PpHirMode, PpMode, PpSourceMode};
use rustc_session::Session; use rustc_session::Session;
use rustc_span::symbol::Ident; use rustc_span::symbol::Ident;

View file

@ -14,6 +14,7 @@ rayon = { version = "0.3.1", package = "rustc-rayon" }
smallvec = { version = "1.6.1", features = ["union", "may_dangle"] } smallvec = { version = "1.6.1", features = ["union", "may_dangle"] }
rustc_ast = { path = "../rustc_ast" } rustc_ast = { path = "../rustc_ast" }
rustc_attr = { path = "../rustc_attr" } rustc_attr = { path = "../rustc_attr" }
rustc_borrowck = { path = "../rustc_borrowck" }
rustc_builtin_macros = { path = "../rustc_builtin_macros" } rustc_builtin_macros = { path = "../rustc_builtin_macros" }
rustc_expand = { path = "../rustc_expand" } rustc_expand = { path = "../rustc_expand" }
rustc_parse = { path = "../rustc_parse" } rustc_parse = { path = "../rustc_parse" }
@ -31,8 +32,10 @@ rustc_symbol_mangling = { path = "../rustc_symbol_mangling" }
rustc_codegen_llvm = { path = "../rustc_codegen_llvm", optional = true } rustc_codegen_llvm = { path = "../rustc_codegen_llvm", optional = true }
rustc_hir = { path = "../rustc_hir" } rustc_hir = { path = "../rustc_hir" }
rustc_metadata = { path = "../rustc_metadata" } 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_build = { path = "../rustc_mir_build" }
rustc_mir_transform = { path = "../rustc_mir_transform" }
rustc_monomorphize = { path = "../rustc_monomorphize" }
rustc_passes = { path = "../rustc_passes" } rustc_passes = { path = "../rustc_passes" }
rustc_typeck = { path = "../rustc_typeck" } rustc_typeck = { path = "../rustc_typeck" }
rustc_lint = { path = "../rustc_lint" } rustc_lint = { path = "../rustc_lint" }

View file

@ -4,6 +4,7 @@ use crate::util;
use rustc_ast::mut_visit::MutVisitor; use rustc_ast::mut_visit::MutVisitor;
use rustc_ast::{self as ast, visit}; 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::back::link::emit_metadata;
use rustc_codegen_ssa::traits::CodegenBackend; use rustc_codegen_ssa::traits::CodegenBackend;
use rustc_data_structures::parallel; use rustc_data_structures::parallel;
@ -21,7 +22,6 @@ use rustc_middle::middle;
use rustc_middle::middle::cstore::{MetadataLoader, MetadataLoaderDyn}; use rustc_middle::middle::cstore::{MetadataLoader, MetadataLoaderDyn};
use rustc_middle::ty::query::Providers; use rustc_middle::ty::query::Providers;
use rustc_middle::ty::{self, GlobalCtxt, ResolverOutputs, TyCtxt}; use rustc_middle::ty::{self, GlobalCtxt, ResolverOutputs, TyCtxt};
use rustc_mir as mir;
use rustc_mir_build as mir_build; use rustc_mir_build as mir_build;
use rustc_parse::{parse_crate_from_file, parse_crate_from_source_str}; use rustc_parse::{parse_crate_from_file, parse_crate_from_source_str};
use rustc_passes::{self, hir_stats, layout_test}; use rustc_passes::{self, hir_stats, layout_test};
@ -737,9 +737,12 @@ pub static DEFAULT_QUERY_PROVIDERS: SyncLazy<Providers> = SyncLazy::new(|| {
let providers = &mut Providers::default(); let providers = &mut Providers::default();
providers.analysis = analysis; providers.analysis = analysis;
proc_macro_decls::provide(providers); proc_macro_decls::provide(providers);
rustc_const_eval::provide(providers);
rustc_middle::hir::provide(providers); rustc_middle::hir::provide(providers);
mir::provide(providers); mir_borrowck::provide(providers);
mir_build::provide(providers); mir_build::provide(providers);
rustc_mir_transform::provide(providers);
rustc_monomorphize::provide(providers);
rustc_privacy::provide(providers); rustc_privacy::provide(providers);
typeck::provide(providers); typeck::provide(providers);
ty::provide(providers); ty::provide(providers);
@ -911,7 +914,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
for def_id in tcx.body_owners() { for def_id in tcx.body_owners() {
tcx.ensure().thir_check_unsafety(def_id); tcx.ensure().thir_check_unsafety(def_id);
if !tcx.sess.opts.debugging_opts.thir_unsafeck { 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() { if tcx.hir().body_const_context(def_id).is_some() {
@ -1059,7 +1062,7 @@ pub fn start_codegen<'tcx>(
info!("Post-codegen\n{:?}", tcx.debug_stats()); info!("Post-codegen\n{:?}", tcx.debug_stats());
if tcx.sess.opts.output_types.contains_key(&OutputType::Mir) { 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.err(&format!("could not emit MIR: {}", e));
tcx.sess.abort_if_errors(); tcx.sess.abort_if_errors();
} }

View file

@ -9,6 +9,8 @@ doctest = false
[dependencies] [dependencies]
rustc_arena = { path = "../rustc_arena" } rustc_arena = { path = "../rustc_arena" }
bitflags = "1.2.1" bitflags = "1.2.1"
either = "1.5.0"
gsgdt = "0.1.2"
tracing = "0.1" tracing = "0.1"
rustc-rayon-core = "0.3.1" rustc-rayon-core = "0.3.1"
polonius-engine = "0.13.0" polonius-engine = "0.13.0"
@ -21,6 +23,7 @@ rustc_macros = { path = "../rustc_macros" }
rustc_data_structures = { path = "../rustc_data_structures" } rustc_data_structures = { path = "../rustc_data_structures" }
rustc_query_system = { path = "../rustc_query_system" } rustc_query_system = { path = "../rustc_query_system" }
rustc_errors = { path = "../rustc_errors" } rustc_errors = { path = "../rustc_errors" }
rustc_graphviz = { path = "../rustc_graphviz" }
rustc_index = { path = "../rustc_index" } rustc_index = { path = "../rustc_index" }
rustc_serialize = { path = "../rustc_serialize" } rustc_serialize = { path = "../rustc_serialize" }
rustc_ast = { path = "../rustc_ast" } rustc_ast = { path = "../rustc_ast" }

View file

@ -8,7 +8,7 @@
//! - **MIR.** The "mid-level (M) intermediate representation (IR)" is //! - **MIR.** The "mid-level (M) intermediate representation (IR)" is
//! defined in the `mir` module. This module contains only the //! defined in the `mir` module. This module contains only the
//! *definition* of the MIR; the passes that transform and operate //! *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 //! - **Types.** The internal representation of types used in rustc is
//! defined in the `ty` module. This includes the **type context** //! defined in the `ty` module. This includes the **type context**
//! (or `tcx`), which is the central context during most of //! (or `tcx`), which is the central context during most of
@ -51,6 +51,8 @@
#![feature(associated_type_defaults)] #![feature(associated_type_defaults)]
#![feature(iter_zip)] #![feature(iter_zip)]
#![feature(thread_local_const_init)] #![feature(thread_local_const_init)]
#![feature(trusted_step)]
#![feature(try_blocks)]
#![feature(try_reserve)] #![feature(try_reserve)]
#![feature(try_reserve_kind)] #![feature(try_reserve_kind)]
#![feature(nonzero_ops)] #![feature(nonzero_ops)]

Some files were not shown because too many files have changed in this diff Show more