Skip to content

Commit 31a61cc

Browse files
committed
Move rustc_mir::borrow_check to new crate rustc_borrowck.
1 parent 8ceea01 commit 31a61cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+372
-315
lines changed

Cargo.lock

+27-2
Original file line numberDiff line numberDiff line change
@@ -3598,6 +3598,32 @@ dependencies = [
35983598
"rustc_span",
35993599
]
36003600

3601+
[[package]]
3602+
name = "rustc_borrowck"
3603+
version = "0.0.0"
3604+
dependencies = [
3605+
"either",
3606+
"itertools 0.9.0",
3607+
"polonius-engine",
3608+
"rustc_data_structures",
3609+
"rustc_errors",
3610+
"rustc_graphviz",
3611+
"rustc_hir",
3612+
"rustc_index",
3613+
"rustc_infer",
3614+
"rustc_lexer",
3615+
"rustc_middle",
3616+
"rustc_mir",
3617+
"rustc_serialize",
3618+
"rustc_session",
3619+
"rustc_span",
3620+
"rustc_target",
3621+
"rustc_trait_selection",
3622+
"rustc_traits",
3623+
"smallvec",
3624+
"tracing",
3625+
]
3626+
36013627
[[package]]
36023628
name = "rustc_builtin_macros"
36033629
version = "0.0.0"
@@ -3888,6 +3914,7 @@ dependencies = [
38883914
"rustc_ast_lowering",
38893915
"rustc_ast_passes",
38903916
"rustc_attr",
3917+
"rustc_borrowck",
38913918
"rustc_builtin_macros",
38923919
"rustc_codegen_llvm",
38933920
"rustc_codegen_ssa",
@@ -4059,15 +4086,13 @@ dependencies = [
40594086
"rustc_hir",
40604087
"rustc_index",
40614088
"rustc_infer",
4062-
"rustc_lexer",
40634089
"rustc_macros",
40644090
"rustc_middle",
40654091
"rustc_serialize",
40664092
"rustc_session",
40674093
"rustc_span",
40684094
"rustc_target",
40694095
"rustc_trait_selection",
4070-
"rustc_traits",
40714096
"smallvec",
40724097
"tracing",
40734098
]

compiler/rustc_borrowck/Cargo.toml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[package]
2+
authors = ["The Rust Project Developers"]
3+
name = "rustc_borrowck"
4+
version = "0.0.0"
5+
edition = "2018"
6+
7+
[lib]
8+
doctest = false
9+
10+
[dependencies]
11+
either = "1.5.0"
12+
itertools = "0.9"
13+
tracing = "0.1"
14+
polonius-engine = "0.13.0"
15+
smallvec = { version = "1.6.1", features = ["union", "may_dangle"] }
16+
rustc_data_structures = { path = "../rustc_data_structures" }
17+
rustc_errors = { path = "../rustc_errors" }
18+
rustc_graphviz = { path = "../rustc_graphviz" }
19+
rustc_hir = { path = "../rustc_hir" }
20+
rustc_index = { path = "../rustc_index" }
21+
rustc_infer = { path = "../rustc_infer" }
22+
rustc_lexer = { path = "../rustc_lexer" }
23+
rustc_middle = { path = "../rustc_middle" }
24+
rustc_mir = { path = "../rustc_mir" }
25+
rustc_serialize = { path = "../rustc_serialize" }
26+
rustc_session = { path = "../rustc_session" }
27+
rustc_target = { path = "../rustc_target" }
28+
rustc_trait_selection = { path = "../rustc_trait_selection" }
29+
rustc_traits = { path = "../rustc_traits" }
30+
rustc_span = { path = "../rustc_span" }

compiler/rustc_mir/src/borrow_check/borrow_set.rs renamed to compiler/rustc_borrowck/src/borrow_set.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
use crate::borrow_check::nll::ToRegionVid;
2-
use crate::borrow_check::path_utils::allow_two_phase_borrow;
3-
use crate::borrow_check::place_ext::PlaceExt;
4-
use crate::dataflow::indexes::BorrowIndex;
5-
use crate::dataflow::move_paths::MoveData;
1+
use crate::nll::ToRegionVid;
2+
use crate::path_utils::allow_two_phase_borrow;
3+
use crate::place_ext::PlaceExt;
4+
use crate::BorrowIndex;
65
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
76
use rustc_index::bit_set::BitSet;
87
use rustc_middle::mir::traversal;
98
use rustc_middle::mir::visit::{MutatingUseContext, NonUseContext, PlaceContext, Visitor};
109
use rustc_middle::mir::{self, Body, Local, Location};
1110
use rustc_middle::ty::{RegionVid, TyCtxt};
11+
use rustc_mir::dataflow::move_paths::MoveData;
1212
use std::fmt;
1313
use std::ops::Index;
1414

compiler/rustc_mir/src/util/borrowck_errors.rs renamed to compiler/rustc_borrowck/src/borrowck_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_errors::{struct_span_err, DiagnosticBuilder, DiagnosticId};
22
use rustc_middle::ty::{self, Ty, TyCtxt};
33
use rustc_span::{MultiSpan, Span};
44

5-
impl<'cx, 'tcx> crate::borrow_check::MirBorrowckCtxt<'cx, 'tcx> {
5+
impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
66
crate fn cannot_move_when_borrowed(&self, span: Span, desc: &str) -> DiagnosticBuilder<'cx> {
77
struct_span_err!(self, span, E0505, "cannot move out of {} because it is borrowed", desc,)
88
}

compiler/rustc_mir/src/borrow_check/constraint_generation.rs renamed to compiler/rustc_borrowck/src/constraint_generation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_middle::ty::fold::TypeFoldable;
99
use rustc_middle::ty::subst::SubstsRef;
1010
use rustc_middle::ty::{self, RegionVid, Ty};
1111

12-
use crate::borrow_check::{
12+
use crate::{
1313
borrow_set::BorrowSet, facts::AllFacts, location::LocationTable, nll::ToRegionVid,
1414
places_conflict, region_infer::values::LivenessValues,
1515
};

compiler/rustc_mir/src/borrow_check/constraints/graph.rs renamed to compiler/rustc_borrowck/src/constraints/graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_middle::mir::ConstraintCategory;
44
use rustc_middle::ty::{RegionVid, VarianceDiagInfo};
55
use rustc_span::DUMMY_SP;
66

7-
use crate::borrow_check::{
7+
use crate::{
88
constraints::OutlivesConstraintIndex,
99
constraints::{OutlivesConstraint, OutlivesConstraintSet},
1010
type_check::Locations,

compiler/rustc_mir/src/borrow_check/constraints/mod.rs renamed to compiler/rustc_borrowck/src/constraints/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_middle::ty::{RegionVid, VarianceDiagInfo};
55
use std::fmt;
66
use std::ops::Index;
77

8-
use crate::borrow_check::type_check::Locations;
8+
use crate::type_check::Locations;
99

1010
crate mod graph;
1111

compiler/rustc_mir/src/dataflow/impls/borrows.rs renamed to compiler/rustc_borrowck/src/dataflow.rs

+101-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,110 @@
1-
use rustc_middle::mir::{self, Body, Location, Place};
2-
use rustc_middle::ty::RegionVid;
3-
use rustc_middle::ty::TyCtxt;
4-
51
use rustc_data_structures::fx::FxHashMap;
62
use rustc_index::bit_set::BitSet;
3+
use rustc_middle::mir::{self, BasicBlock, Body, Location, Place};
4+
use rustc_middle::ty::RegionVid;
5+
use rustc_middle::ty::TyCtxt;
6+
use rustc_mir::dataflow::impls::{EverInitializedPlaces, MaybeUninitializedPlaces};
7+
use rustc_mir::dataflow::ResultsVisitable;
8+
use rustc_mir::dataflow::{self, fmt::DebugWithContext, GenKill};
9+
use rustc_mir::dataflow::{Analysis, Direction, Results};
10+
use std::fmt;
11+
use std::iter;
712

8-
use crate::borrow_check::{
13+
use crate::{
914
places_conflict, BorrowSet, PlaceConflictBias, PlaceExt, RegionInferenceContext, ToRegionVid,
1015
};
11-
use crate::dataflow::{self, fmt::DebugWithContext, GenKill};
1216

13-
use std::fmt;
14-
use std::iter;
17+
/// A tuple with named fields that can hold either the results or the transient state of the
18+
/// dataflow analyses used by the borrow checker.
19+
#[derive(Debug)]
20+
pub struct BorrowckAnalyses<B, U, E> {
21+
pub borrows: B,
22+
pub uninits: U,
23+
pub ever_inits: E,
24+
}
25+
26+
/// The results of the dataflow analyses used by the borrow checker.
27+
pub type BorrowckResults<'mir, 'tcx> = BorrowckAnalyses<
28+
Results<'tcx, Borrows<'mir, 'tcx>>,
29+
Results<'tcx, MaybeUninitializedPlaces<'mir, 'tcx>>,
30+
Results<'tcx, EverInitializedPlaces<'mir, 'tcx>>,
31+
>;
32+
33+
/// The transient state of the dataflow analyses used by the borrow checker.
34+
pub type BorrowckFlowState<'mir, 'tcx> =
35+
<BorrowckResults<'mir, 'tcx> as ResultsVisitable<'tcx>>::FlowState;
36+
37+
macro_rules! impl_visitable {
38+
( $(
39+
$T:ident { $( $field:ident : $A:ident ),* $(,)? }
40+
)* ) => { $(
41+
impl<'tcx, $($A),*, D: Direction> ResultsVisitable<'tcx> for $T<$( Results<'tcx, $A> ),*>
42+
where
43+
$( $A: Analysis<'tcx, Direction = D>, )*
44+
{
45+
type Direction = D;
46+
type FlowState = $T<$( $A::Domain ),*>;
47+
48+
fn new_flow_state(&self, body: &mir::Body<'tcx>) -> Self::FlowState {
49+
$T {
50+
$( $field: self.$field.analysis.bottom_value(body) ),*
51+
}
52+
}
53+
54+
fn reset_to_block_entry(
55+
&self,
56+
state: &mut Self::FlowState,
57+
block: BasicBlock,
58+
) {
59+
$( state.$field.clone_from(&self.$field.entry_set_for_block(block)); )*
60+
}
61+
62+
fn reconstruct_before_statement_effect(
63+
&self,
64+
state: &mut Self::FlowState,
65+
stmt: &mir::Statement<'tcx>,
66+
loc: Location,
67+
) {
68+
$( self.$field.analysis
69+
.apply_before_statement_effect(&mut state.$field, stmt, loc); )*
70+
}
71+
72+
fn reconstruct_statement_effect(
73+
&self,
74+
state: &mut Self::FlowState,
75+
stmt: &mir::Statement<'tcx>,
76+
loc: Location,
77+
) {
78+
$( self.$field.analysis
79+
.apply_statement_effect(&mut state.$field, stmt, loc); )*
80+
}
81+
82+
fn reconstruct_before_terminator_effect(
83+
&self,
84+
state: &mut Self::FlowState,
85+
term: &mir::Terminator<'tcx>,
86+
loc: Location,
87+
) {
88+
$( self.$field.analysis
89+
.apply_before_terminator_effect(&mut state.$field, term, loc); )*
90+
}
91+
92+
fn reconstruct_terminator_effect(
93+
&self,
94+
state: &mut Self::FlowState,
95+
term: &mir::Terminator<'tcx>,
96+
loc: Location,
97+
) {
98+
$( self.$field.analysis
99+
.apply_terminator_effect(&mut state.$field, term, loc); )*
100+
}
101+
}
102+
)* }
103+
}
104+
105+
impl_visitable! {
106+
BorrowckAnalyses { borrows: B, uninits: U, ever_inits: E }
107+
}
15108

16109
rustc_index::newtype_index! {
17110
pub struct BorrowIndex {

compiler/rustc_mir/src/borrow_check/diagnostics/bound_region_errors.rs renamed to compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use rustc_traits::{type_op_ascribe_user_type_with_span, type_op_prove_predicate_
1414
use std::fmt;
1515
use std::rc::Rc;
1616

17-
use crate::borrow_check::region_infer::values::RegionElement;
18-
use crate::borrow_check::MirBorrowckCtxt;
17+
use crate::region_infer::values::RegionElement;
18+
use crate::MirBorrowckCtxt;
1919

2020
#[derive(Clone)]
2121
crate struct UniverseInfo<'tcx>(UniverseInfoInner<'tcx>);

compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs renamed to compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ use rustc_span::symbol::sym;
1515
use rustc_span::{BytePos, MultiSpan, Span, DUMMY_SP};
1616
use rustc_trait_selection::infer::InferCtxtExt;
1717

18-
use crate::dataflow::drop_flag_effects;
19-
use crate::dataflow::indexes::{MoveOutIndex, MovePathIndex};
20-
use crate::util::borrowck_errors;
18+
use crate::borrowck_errors;
19+
use rustc_mir::dataflow::drop_flag_effects;
20+
use rustc_mir::dataflow::move_paths::{MoveOutIndex, MovePathIndex};
2121

22-
use crate::borrow_check::{
22+
use crate::{
2323
borrow_set::BorrowData, diagnostics::Instance, prefixes::IsPrefixOf,
2424
InitializationRequiringAction, MirBorrowckCtxt, PrefixSet, WriteKind,
2525
};
@@ -49,7 +49,7 @@ enum StorageDeadOrDrop<'tcx> {
4949
}
5050

5151
impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
52-
pub(in crate::borrow_check) fn report_use_of_moved_or_uninitialized(
52+
pub(crate) fn report_use_of_moved_or_uninitialized(
5353
&mut self,
5454
location: Location,
5555
desired_action: InitializationRequiringAction,
@@ -441,7 +441,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
441441
}
442442
}
443443

444-
pub(in crate::borrow_check) fn report_move_out_while_borrowed(
444+
pub(crate) fn report_move_out_while_borrowed(
445445
&mut self,
446446
location: Location,
447447
(place, span): (Place<'tcx>, Span),
@@ -489,7 +489,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
489489
err.buffer(&mut self.errors_buffer);
490490
}
491491

492-
pub(in crate::borrow_check) fn report_use_while_mutably_borrowed(
492+
pub(crate) fn report_use_while_mutably_borrowed(
493493
&mut self,
494494
location: Location,
495495
(place, _span): (Place<'tcx>, Span),
@@ -535,7 +535,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
535535
err
536536
}
537537

538-
pub(in crate::borrow_check) fn report_conflicting_borrow(
538+
pub(crate) fn report_conflicting_borrow(
539539
&mut self,
540540
location: Location,
541541
(place, span): (Place<'tcx>, Span),
@@ -798,7 +798,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
798798
/// cannot borrow `a.u` (via `a.u.z.c`) as immutable because it is also borrowed as
799799
/// mutable (via `a.u.s.b`) [E0502]
800800
/// ```
801-
pub(in crate::borrow_check) fn describe_place_for_conflicting_borrow(
801+
pub(crate) fn describe_place_for_conflicting_borrow(
802802
&self,
803803
first_borrowed_place: Place<'tcx>,
804804
second_borrowed_place: Place<'tcx>,
@@ -875,7 +875,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
875875
/// short a lifetime. (But sometimes it is more useful to report
876876
/// it as a more direct conflict between the execution of a
877877
/// `Drop::drop` with an aliasing borrow.)
878-
pub(in crate::borrow_check) fn report_borrowed_value_does_not_live_long_enough(
878+
pub(crate) fn report_borrowed_value_does_not_live_long_enough(
879879
&mut self,
880880
location: Location,
881881
borrow: &BorrowData<'tcx>,
@@ -1634,7 +1634,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16341634
(result, reinits_reachable)
16351635
}
16361636

1637-
pub(in crate::borrow_check) fn report_illegal_mutation_of_borrowed(
1637+
pub(crate) fn report_illegal_mutation_of_borrowed(
16381638
&mut self,
16391639
location: Location,
16401640
(place, span): (Place<'tcx>, Span),
@@ -1695,7 +1695,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16951695
Some((method_did, method_substs)),
16961696
) = (
16971697
&self.body[loan.reserve_location.block].terminator,
1698-
crate::util::find_self_call(
1698+
rustc_mir::util::find_self_call(
16991699
tcx,
17001700
self.body,
17011701
loan.assigned_place.local,
@@ -1726,7 +1726,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
17261726
/// assigned; `err_place` is a place providing a reason why
17271727
/// `place` is not mutable (e.g., the non-`mut` local `x` in an
17281728
/// assignment to `x.f`).
1729-
pub(in crate::borrow_check) fn report_illegal_reassignment(
1729+
pub(crate) fn report_illegal_reassignment(
17301730
&mut self,
17311731
_location: Location,
17321732
(place, span): (Place<'tcx>, Span),
@@ -2226,7 +2226,7 @@ enum AnnotatedBorrowFnSignature<'tcx> {
22262226
impl<'tcx> AnnotatedBorrowFnSignature<'tcx> {
22272227
/// Annotate the provided diagnostic with information about borrow from the fn signature that
22282228
/// helps explain.
2229-
pub(in crate::borrow_check) fn emit(
2229+
pub(crate) fn emit(
22302230
&self,
22312231
cx: &mut MirBorrowckCtxt<'_, 'tcx>,
22322232
diag: &mut DiagnosticBuilder<'_>,

0 commit comments

Comments
 (0)