Skip to content

Commit 81695a1

Browse files
committed
Split lifetimes on mir borrowck dataflow
1 parent 4bdf8d2 commit 81695a1

File tree

8 files changed

+94
-86
lines changed

8 files changed

+94
-86
lines changed

compiler/rustc_borrowck/src/dataflow.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,24 @@ use std::fmt;
1515
use crate::{places_conflict, BorrowSet, PlaceConflictBias, PlaceExt, RegionInferenceContext};
1616

1717
/// The results of the dataflow analyses used by the borrow checker.
18-
pub struct BorrowckResults<'mir, 'tcx> {
19-
pub(crate) borrows: Results<'tcx, Borrows<'mir, 'tcx>>,
20-
pub(crate) uninits: Results<'tcx, MaybeUninitializedPlaces<'mir, 'tcx>>,
21-
pub(crate) ever_inits: Results<'tcx, EverInitializedPlaces<'mir, 'tcx>>,
18+
pub struct BorrowckResults<'a, 'mir, 'tcx> {
19+
pub(crate) borrows: Results<'tcx, Borrows<'a, 'mir, 'tcx>>,
20+
pub(crate) uninits: Results<'tcx, MaybeUninitializedPlaces<'a, 'mir, 'tcx>>,
21+
pub(crate) ever_inits: Results<'tcx, EverInitializedPlaces<'a, 'mir, 'tcx>>,
2222
}
2323

2424
/// The transient state of the dataflow analyses used by the borrow checker.
2525
#[derive(Debug)]
26-
pub struct BorrowckFlowState<'mir, 'tcx> {
27-
pub(crate) borrows: <Borrows<'mir, 'tcx> as AnalysisDomain<'tcx>>::Domain,
28-
pub(crate) uninits: <MaybeUninitializedPlaces<'mir, 'tcx> as AnalysisDomain<'tcx>>::Domain,
29-
pub(crate) ever_inits: <EverInitializedPlaces<'mir, 'tcx> as AnalysisDomain<'tcx>>::Domain,
26+
pub struct BorrowckFlowState<'a, 'mir, 'tcx> {
27+
pub(crate) borrows: <Borrows<'a, 'mir, 'tcx> as AnalysisDomain<'tcx>>::Domain,
28+
pub(crate) uninits: <MaybeUninitializedPlaces<'a, 'mir, 'tcx> as AnalysisDomain<'tcx>>::Domain,
29+
pub(crate) ever_inits: <EverInitializedPlaces<'a, 'mir, 'tcx> as AnalysisDomain<'tcx>>::Domain,
3030
}
3131

32-
impl<'mir, 'tcx> ResultsVisitable<'tcx> for BorrowckResults<'mir, 'tcx> {
32+
impl<'a, 'mir, 'tcx> ResultsVisitable<'tcx> for BorrowckResults<'a, 'mir, 'tcx> {
3333
// All three analyses are forward, but we have to use just one here.
34-
type Direction = <Borrows<'mir, 'tcx> as AnalysisDomain<'tcx>>::Direction;
35-
type FlowState = BorrowckFlowState<'mir, 'tcx>;
34+
type Direction = <Borrows<'a, 'mir, 'tcx> as AnalysisDomain<'tcx>>::Direction;
35+
type FlowState = BorrowckFlowState<'a, 'mir, 'tcx>;
3636

3737
fn new_flow_state(&self, body: &mir::Body<'tcx>) -> Self::FlowState {
3838
BorrowckFlowState {
@@ -106,11 +106,11 @@ rustc_index::newtype_index! {
106106
/// `BorrowIndex`, and maps each such index to a `BorrowData`
107107
/// describing the borrow. These indexes are used for representing the
108108
/// borrows in compact bitvectors.
109-
pub struct Borrows<'mir, 'tcx> {
109+
pub struct Borrows<'a, 'mir, 'tcx> {
110110
tcx: TyCtxt<'tcx>,
111111
body: &'mir Body<'tcx>,
112112

113-
borrow_set: &'mir BorrowSet<'tcx>,
113+
borrow_set: &'a BorrowSet<'tcx>,
114114
borrows_out_of_scope_at_location: FxIndexMap<Location, Vec<BorrowIndex>>,
115115
}
116116

@@ -389,12 +389,12 @@ impl<'tcx> PoloniusOutOfScopePrecomputer<'_, 'tcx> {
389389
}
390390
}
391391

392-
impl<'mir, 'tcx> Borrows<'mir, 'tcx> {
392+
impl<'a, 'mir, 'tcx> Borrows<'a, 'mir, 'tcx> {
393393
pub fn new(
394394
tcx: TyCtxt<'tcx>,
395395
body: &'mir Body<'tcx>,
396-
regioncx: &'mir RegionInferenceContext<'tcx>,
397-
borrow_set: &'mir BorrowSet<'tcx>,
396+
regioncx: &RegionInferenceContext<'tcx>,
397+
borrow_set: &'a BorrowSet<'tcx>,
398398
) -> Self {
399399
let mut borrows_out_of_scope_at_location =
400400
calculate_borrows_out_of_scope_at_location(body, regioncx, borrow_set);
@@ -494,7 +494,7 @@ impl<'mir, 'tcx> Borrows<'mir, 'tcx> {
494494
}
495495
}
496496

497-
impl<'tcx> rustc_mir_dataflow::AnalysisDomain<'tcx> for Borrows<'_, 'tcx> {
497+
impl<'tcx> rustc_mir_dataflow::AnalysisDomain<'tcx> for Borrows<'_, '_, 'tcx> {
498498
type Domain = BitSet<BorrowIndex>;
499499

500500
const NAME: &'static str = "borrows";
@@ -517,7 +517,7 @@ impl<'tcx> rustc_mir_dataflow::AnalysisDomain<'tcx> for Borrows<'_, 'tcx> {
517517
/// region stops containing the CFG points reachable from the issuing location.
518518
/// - we also kill loans of conflicting places when overwriting a shared path: e.g. borrows of
519519
/// `a.b.c` when `a` is overwritten.
520-
impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
520+
impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, '_, 'tcx> {
521521
type Idx = BorrowIndex;
522522

523523
fn domain_size(&self, _: &mir::Body<'tcx>) -> usize {
@@ -617,8 +617,8 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
617617
}
618618
}
619619

620-
impl DebugWithContext<Borrows<'_, '_>> for BorrowIndex {
621-
fn fmt_with(&self, ctxt: &Borrows<'_, '_>, f: &mut fmt::Formatter<'_>) -> fmt::Result {
620+
impl DebugWithContext<Borrows<'_, '_, '_>> for BorrowIndex {
621+
fn fmt_with(&self, ctxt: &Borrows<'_, '_, '_>, f: &mut fmt::Formatter<'_>) -> fmt::Result {
622622
write!(f, "{:?}", ctxt.location(*self))
623623
}
624624
}

compiler/rustc_borrowck/src/lib.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -605,15 +605,15 @@ struct MirBorrowckCtxt<'a, 'mir, 'cx, 'tcx> {
605605
// 2. loans made in overlapping scopes do not conflict
606606
// 3. assignments do not affect things loaned out as immutable
607607
// 4. moves do not affect things loaned out in any way
608-
impl<'mir, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'mir, 'tcx, R>
609-
for MirBorrowckCtxt<'_, 'mir, '_, 'tcx>
608+
impl<'a, 'mir, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'mir, 'tcx, R>
609+
for MirBorrowckCtxt<'a, 'mir, '_, 'tcx>
610610
{
611-
type FlowState = Flows<'mir, 'tcx>;
611+
type FlowState = Flows<'a, 'mir, 'tcx>;
612612

613613
fn visit_statement_before_primary_effect(
614614
&mut self,
615615
_results: &mut R,
616-
flow_state: &Flows<'mir, 'tcx>,
616+
flow_state: &Flows<'_, 'mir, 'tcx>,
617617
stmt: &'mir Statement<'tcx>,
618618
location: Location,
619619
) {
@@ -683,7 +683,7 @@ impl<'mir, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'mir, 'tcx, R>
683683
fn visit_terminator_before_primary_effect(
684684
&mut self,
685685
_results: &mut R,
686-
flow_state: &Flows<'mir, 'tcx>,
686+
flow_state: &Flows<'_, 'mir, 'tcx>,
687687
term: &'mir Terminator<'tcx>,
688688
loc: Location,
689689
) {
@@ -794,7 +794,7 @@ impl<'mir, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'mir, 'tcx, R>
794794
fn visit_terminator_after_primary_effect(
795795
&mut self,
796796
_results: &mut R,
797-
flow_state: &Flows<'mir, 'tcx>,
797+
flow_state: &Flows<'_, 'mir, 'tcx>,
798798
term: &'mir Terminator<'tcx>,
799799
loc: Location,
800800
) {
@@ -988,7 +988,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
988988
place_span: (Place<'tcx>, Span),
989989
kind: (AccessDepth, ReadOrWrite),
990990
is_local_mutation_allowed: LocalMutationIsAllowed,
991-
flow_state: &Flows<'mir, 'tcx>,
991+
flow_state: &Flows<'_, 'mir, 'tcx>,
992992
) {
993993
let (sd, rw) = kind;
994994

@@ -1038,7 +1038,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
10381038
place_span: (Place<'tcx>, Span),
10391039
sd: AccessDepth,
10401040
rw: ReadOrWrite,
1041-
flow_state: &Flows<'mir, 'tcx>,
1041+
flow_state: &Flows<'_, 'mir, 'tcx>,
10421042
) -> bool {
10431043
let mut error_reported = false;
10441044
let borrow_set = Rc::clone(&self.borrow_set);
@@ -1179,7 +1179,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
11791179
location: Location,
11801180
place_span: (Place<'tcx>, Span),
11811181
kind: AccessDepth,
1182-
flow_state: &Flows<'mir, 'tcx>,
1182+
flow_state: &Flows<'_, 'mir, 'tcx>,
11831183
) {
11841184
// Write of P[i] or *P requires P init'd.
11851185
self.check_if_assigned_path_is_moved(location, place_span, flow_state);
@@ -1197,7 +1197,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
11971197
&mut self,
11981198
location: Location,
11991199
(rvalue, span): (&'mir Rvalue<'tcx>, Span),
1200-
flow_state: &Flows<'mir, 'tcx>,
1200+
flow_state: &Flows<'_, 'mir, 'tcx>,
12011201
) {
12021202
match rvalue {
12031203
&Rvalue::Ref(_ /*rgn*/, bk, place) => {
@@ -1455,7 +1455,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
14551455
&mut self,
14561456
location: Location,
14571457
(operand, span): (&'mir Operand<'tcx>, Span),
1458-
flow_state: &Flows<'mir, 'tcx>,
1458+
flow_state: &Flows<'_, 'mir, 'tcx>,
14591459
) {
14601460
match *operand {
14611461
Operand::Copy(place) => {
@@ -1579,7 +1579,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
15791579
&mut self,
15801580
location: Location,
15811581
span: Span,
1582-
flow_state: &Flows<'mir, 'tcx>,
1582+
flow_state: &Flows<'_, 'mir, 'tcx>,
15831583
) {
15841584
// Two-phase borrow support: For each activation that is newly
15851585
// generated at this statement, check if it interferes with
@@ -1743,7 +1743,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
17431743
location: Location,
17441744
desired_action: InitializationRequiringAction,
17451745
place_span: (PlaceRef<'tcx>, Span),
1746-
flow_state: &Flows<'mir, 'tcx>,
1746+
flow_state: &Flows<'_, 'mir, 'tcx>,
17471747
) {
17481748
let maybe_uninits = &flow_state.uninits;
17491749

@@ -1848,7 +1848,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
18481848
location: Location,
18491849
desired_action: InitializationRequiringAction,
18501850
place_span: (PlaceRef<'tcx>, Span),
1851-
flow_state: &Flows<'mir, 'tcx>,
1851+
flow_state: &Flows<'_, 'mir, 'tcx>,
18521852
) {
18531853
let maybe_uninits = &flow_state.uninits;
18541854

@@ -1947,7 +1947,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
19471947
&mut self,
19481948
location: Location,
19491949
(place, span): (Place<'tcx>, Span),
1950-
flow_state: &Flows<'mir, 'tcx>,
1950+
flow_state: &Flows<'_, 'mir, 'tcx>,
19511951
) {
19521952
debug!("check_if_assigned_path_is_moved place: {:?}", place);
19531953

@@ -2013,7 +2013,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
20132013
location: Location,
20142014
base: PlaceRef<'tcx>,
20152015
span: Span,
2016-
flow_state: &Flows<'mir, 'tcx>,
2016+
flow_state: &Flows<'_, 'mir, 'tcx>,
20172017
) {
20182018
// rust-lang/rust#21232: Until Rust allows reads from the
20192019
// initialized parts of partially initialized structs, we
@@ -2104,7 +2104,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
21042104
(place, span): (Place<'tcx>, Span),
21052105
kind: ReadOrWrite,
21062106
is_local_mutation_allowed: LocalMutationIsAllowed,
2107-
flow_state: &Flows<'mir, 'tcx>,
2107+
flow_state: &Flows<'_, 'mir, 'tcx>,
21082108
location: Location,
21092109
) -> bool {
21102110
debug!(
@@ -2220,15 +2220,15 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
22202220
fn is_local_ever_initialized(
22212221
&self,
22222222
local: Local,
2223-
flow_state: &Flows<'mir, 'tcx>,
2223+
flow_state: &Flows<'_, 'mir, 'tcx>,
22242224
) -> Option<InitIndex> {
22252225
let mpi = self.move_data.rev_lookup.find_local(local)?;
22262226
let ii = &self.move_data.init_path_map[mpi];
22272227
ii.into_iter().find(|&&index| flow_state.ever_inits.contains(index)).copied()
22282228
}
22292229

22302230
/// Adds the place into the used mutable variables set
2231-
fn add_used_mut(&mut self, root_place: RootPlace<'tcx>, flow_state: &Flows<'mir, 'tcx>) {
2231+
fn add_used_mut(&mut self, root_place: RootPlace<'tcx>, flow_state: &Flows<'_, 'mir, 'tcx>) {
22322232
match root_place {
22332233
RootPlace { place_local: local, place_projection: [], is_local_mutation_allowed } => {
22342234
// If the local may have been initialized, and it is now currently being

compiler/rustc_borrowck/src/nll.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
8181
promoted: &IndexSlice<Promoted, Body<'tcx>>,
8282
location_table: &LocationTable,
8383
param_env: ty::ParamEnv<'tcx>,
84-
flow_inits: &mut ResultsCursor<'cx, 'tcx, MaybeInitializedPlaces<'cx, 'tcx>>,
84+
flow_inits: &mut ResultsCursor<'cx, 'tcx, MaybeInitializedPlaces<'_, 'cx, 'tcx>>,
8585
move_data: &MoveData<'tcx>,
8686
borrow_set: &BorrowSet<'tcx>,
8787
upvars: &[&ty::CapturedPlace<'tcx>],

compiler/rustc_borrowck/src/type_check/liveness/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub(super) fn generate<'mir, 'tcx>(
3434
typeck: &mut TypeChecker<'_, 'tcx>,
3535
body: &Body<'tcx>,
3636
elements: &Rc<DenseLocationMap>,
37-
flow_inits: &mut ResultsCursor<'mir, 'tcx, MaybeInitializedPlaces<'mir, 'tcx>>,
37+
flow_inits: &mut ResultsCursor<'mir, 'tcx, MaybeInitializedPlaces<'_, 'mir, 'tcx>>,
3838
move_data: &MoveData<'tcx>,
3939
) {
4040
debug!("liveness::generate");

compiler/rustc_borrowck/src/type_check/liveness/trace.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub(super) fn trace<'mir, 'tcx>(
4343
typeck: &mut TypeChecker<'_, 'tcx>,
4444
body: &Body<'tcx>,
4545
elements: &Rc<DenseLocationMap>,
46-
flow_inits: &mut ResultsCursor<'mir, 'tcx, MaybeInitializedPlaces<'mir, 'tcx>>,
46+
flow_inits: &mut ResultsCursor<'mir, 'tcx, MaybeInitializedPlaces<'_, 'mir, 'tcx>>,
4747
move_data: &MoveData<'tcx>,
4848
relevant_live_locals: Vec<Local>,
4949
boring_locals: Vec<Local>,
@@ -101,7 +101,7 @@ pub(super) fn trace<'mir, 'tcx>(
101101
}
102102

103103
/// Contextual state for the type-liveness coroutine.
104-
struct LivenessContext<'me, 'typeck, 'flow, 'tcx> {
104+
struct LivenessContext<'a, 'me, 'typeck, 'flow, 'tcx> {
105105
/// Current type-checker, giving us our inference context etc.
106106
typeck: &'me mut TypeChecker<'typeck, 'tcx>,
107107

@@ -119,7 +119,7 @@ struct LivenessContext<'me, 'typeck, 'flow, 'tcx> {
119119

120120
/// Results of dataflow tracking which variables (and paths) have been
121121
/// initialized.
122-
flow_inits: &'me mut ResultsCursor<'flow, 'tcx, MaybeInitializedPlaces<'flow, 'tcx>>,
122+
flow_inits: &'me mut ResultsCursor<'flow, 'tcx, MaybeInitializedPlaces<'a, 'flow, 'tcx>>,
123123

124124
/// Index indicating where each variable is assigned, used, or
125125
/// dropped.
@@ -131,8 +131,8 @@ struct DropData<'tcx> {
131131
region_constraint_data: Option<&'tcx QueryRegionConstraints<'tcx>>,
132132
}
133133

134-
struct LivenessResults<'me, 'typeck, 'flow, 'tcx> {
135-
cx: LivenessContext<'me, 'typeck, 'flow, 'tcx>,
134+
struct LivenessResults<'a, 'me, 'typeck, 'flow, 'tcx> {
135+
cx: LivenessContext<'a, 'me, 'typeck, 'flow, 'tcx>,
136136

137137
/// Set of points that define the current local.
138138
defs: BitSet<PointIndex>,
@@ -153,8 +153,8 @@ struct LivenessResults<'me, 'typeck, 'flow, 'tcx> {
153153
stack: Vec<PointIndex>,
154154
}
155155

156-
impl<'me, 'typeck, 'flow, 'tcx> LivenessResults<'me, 'typeck, 'flow, 'tcx> {
157-
fn new(cx: LivenessContext<'me, 'typeck, 'flow, 'tcx>) -> Self {
156+
impl<'a, 'me, 'typeck, 'flow, 'tcx> LivenessResults<'a, 'me, 'typeck, 'flow, 'tcx> {
157+
fn new(cx: LivenessContext<'a, 'me, 'typeck, 'flow, 'tcx>) -> Self {
158158
let num_points = cx.elements.num_points();
159159
LivenessResults {
160160
cx,
@@ -507,7 +507,7 @@ impl<'me, 'typeck, 'flow, 'tcx> LivenessResults<'me, 'typeck, 'flow, 'tcx> {
507507
}
508508
}
509509

510-
impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
510+
impl<'tcx> LivenessContext<'_, '_, '_, '_, 'tcx> {
511511
/// Returns `true` if the local variable (or some part of it) is initialized at the current
512512
/// cursor position. Callers should call one of the `seek` methods immediately before to point
513513
/// the cursor to the desired location.

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
129129
location_table: &LocationTable,
130130
borrow_set: &BorrowSet<'tcx>,
131131
all_facts: &mut Option<AllFacts>,
132-
flow_inits: &mut ResultsCursor<'mir, 'tcx, MaybeInitializedPlaces<'mir, 'tcx>>,
132+
flow_inits: &mut ResultsCursor<'mir, 'tcx, MaybeInitializedPlaces<'_, 'mir, 'tcx>>,
133133
move_data: &MoveData<'tcx>,
134134
elements: &Rc<DenseLocationMap>,
135135
upvars: &[&ty::CapturedPlace<'tcx>],

0 commit comments

Comments
 (0)