Skip to content

Commit 8144917

Browse files
committed
make the dataflow / mir-borrowck types carry a 'tcx lifetime
Also, factor out `do_mir_borrowck`, which is the code that actually performs the MIR borrowck from within the scope of an inference context. This change should be a pure refactoring.
1 parent 82b287a commit 8144917

File tree

8 files changed

+211
-201
lines changed

8 files changed

+211
-201
lines changed

src/librustc_mir/borrow_check.rs

Lines changed: 114 additions & 104 deletions
Large diffs are not rendered by default.

src/librustc_mir/dataflow/drop_flag_effects.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ pub fn move_path_children_matching<'tcx, F>(move_data: &MoveData<'tcx>,
5858
/// is no need to maintain separate drop flags to track such state.
5959
///
6060
/// FIXME: we have to do something for moving slice patterns.
61-
fn lvalue_contents_drop_state_cannot_differ<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
62-
mir: &Mir<'tcx>,
63-
lv: &mir::Lvalue<'tcx>) -> bool {
61+
fn lvalue_contents_drop_state_cannot_differ<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
62+
mir: &Mir<'tcx>,
63+
lv: &mir::Lvalue<'tcx>) -> bool {
6464
let ty = lv.ty(mir, tcx).to_ty(tcx);
6565
match ty.sty {
6666
ty::TyArray(..) | ty::TySlice(..) | ty::TyRef(..) | ty::TyRawPtr(..) => {
@@ -79,8 +79,8 @@ fn lvalue_contents_drop_state_cannot_differ<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx
7979
}
8080
}
8181

82-
pub(crate) fn on_lookup_result_bits<'a, 'tcx, F>(
83-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
82+
pub(crate) fn on_lookup_result_bits<'a, 'gcx, 'tcx, F>(
83+
tcx: TyCtxt<'a, 'gcx, 'tcx>,
8484
mir: &Mir<'tcx>,
8585
move_data: &MoveData<'tcx>,
8686
lookup_result: LookupResult,
@@ -97,16 +97,16 @@ pub(crate) fn on_lookup_result_bits<'a, 'tcx, F>(
9797
}
9898
}
9999

100-
pub(crate) fn on_all_children_bits<'a, 'tcx, F>(
101-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
100+
pub(crate) fn on_all_children_bits<'a, 'gcx, 'tcx, F>(
101+
tcx: TyCtxt<'a, 'gcx, 'tcx>,
102102
mir: &Mir<'tcx>,
103103
move_data: &MoveData<'tcx>,
104104
move_path_index: MovePathIndex,
105105
mut each_child: F)
106106
where F: FnMut(MovePathIndex)
107107
{
108-
fn is_terminal_path<'a, 'tcx>(
109-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
108+
fn is_terminal_path<'a, 'gcx, 'tcx>(
109+
tcx: TyCtxt<'a, 'gcx, 'tcx>,
110110
mir: &Mir<'tcx>,
111111
move_data: &MoveData<'tcx>,
112112
path: MovePathIndex) -> bool
@@ -115,8 +115,8 @@ pub(crate) fn on_all_children_bits<'a, 'tcx, F>(
115115
tcx, mir, &move_data.move_paths[path].lvalue)
116116
}
117117

118-
fn on_all_children_bits<'a, 'tcx, F>(
119-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
118+
fn on_all_children_bits<'a, 'gcx, 'tcx, F>(
119+
tcx: TyCtxt<'a, 'gcx, 'tcx>,
120120
mir: &Mir<'tcx>,
121121
move_data: &MoveData<'tcx>,
122122
move_path_index: MovePathIndex,
@@ -138,10 +138,10 @@ pub(crate) fn on_all_children_bits<'a, 'tcx, F>(
138138
on_all_children_bits(tcx, mir, move_data, move_path_index, &mut each_child);
139139
}
140140

141-
pub(crate) fn on_all_drop_children_bits<'a, 'tcx, F>(
142-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
141+
pub(crate) fn on_all_drop_children_bits<'a, 'gcx, 'tcx, F>(
142+
tcx: TyCtxt<'a, 'gcx, 'tcx>,
143143
mir: &Mir<'tcx>,
144-
ctxt: &MoveDataParamEnv<'tcx>,
144+
ctxt: &MoveDataParamEnv<'gcx, 'tcx>,
145145
path: MovePathIndex,
146146
mut each_child: F)
147147
where F: FnMut(MovePathIndex)
@@ -161,10 +161,10 @@ pub(crate) fn on_all_drop_children_bits<'a, 'tcx, F>(
161161
})
162162
}
163163

164-
pub(crate) fn drop_flag_effects_for_function_entry<'a, 'tcx, F>(
165-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
164+
pub(crate) fn drop_flag_effects_for_function_entry<'a, 'gcx, 'tcx, F>(
165+
tcx: TyCtxt<'a, 'gcx, 'tcx>,
166166
mir: &Mir<'tcx>,
167-
ctxt: &MoveDataParamEnv<'tcx>,
167+
ctxt: &MoveDataParamEnv<'gcx, 'tcx>,
168168
mut callback: F)
169169
where F: FnMut(MovePathIndex, DropFlagState)
170170
{
@@ -178,10 +178,10 @@ pub(crate) fn drop_flag_effects_for_function_entry<'a, 'tcx, F>(
178178
}
179179
}
180180

181-
pub(crate) fn drop_flag_effects_for_location<'a, 'tcx, F>(
182-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
181+
pub(crate) fn drop_flag_effects_for_location<'a, 'gcx, 'tcx, F>(
182+
tcx: TyCtxt<'a, 'gcx, 'tcx>,
183183
mir: &Mir<'tcx>,
184-
ctxt: &MoveDataParamEnv<'tcx>,
184+
ctxt: &MoveDataParamEnv<'gcx, 'tcx>,
185185
loc: Location,
186186
mut callback: F)
187187
where F: FnMut(MovePathIndex, DropFlagState)

src/librustc_mir/dataflow/impls/borrows.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ use std::fmt;
2929
// `Borrows` maps each dataflow bit to an `Rvalue::Ref`, which can be
3030
// uniquely identified in the MIR by the `Location` of the assigment
3131
// statement in which it appears on the right hand side.
32-
pub struct Borrows<'a, 'tcx: 'a> {
33-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
32+
pub struct Borrows<'a, 'gcx: 'tcx, 'tcx: 'a> {
33+
tcx: TyCtxt<'a, 'gcx, 'tcx>,
3434
mir: &'a Mir<'tcx>,
3535
borrows: IndexVec<BorrowIndex, BorrowData<'tcx>>,
3636
location_map: FxHashMap<Location, BorrowIndex>,
@@ -63,8 +63,8 @@ impl<'tcx> fmt::Display for BorrowData<'tcx> {
6363
}
6464
}
6565

66-
impl<'a, 'tcx> Borrows<'a, 'tcx> {
67-
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, mir: &'a Mir<'tcx>) -> Self {
66+
impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
67+
pub fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>, mir: &'a Mir<'tcx>) -> Self {
6868
let mut visitor = GatherBorrows { idx_vec: IndexVec::new(),
6969
location_map: FxHashMap(),
7070
region_map: FxHashMap(),
@@ -126,7 +126,7 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
126126
}
127127
}
128128

129-
impl<'a, 'tcx> BitDenotation for Borrows<'a, 'tcx> {
129+
impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
130130
type Idx = BorrowIndex;
131131
fn name() -> &'static str { "borrows" }
132132
fn bits_per_block(&self) -> usize {
@@ -191,14 +191,14 @@ impl<'a, 'tcx> BitDenotation for Borrows<'a, 'tcx> {
191191
}
192192
}
193193

194-
impl<'a, 'tcx> BitwiseOperator for Borrows<'a, 'tcx> {
194+
impl<'a, 'gcx, 'tcx> BitwiseOperator for Borrows<'a, 'gcx, 'tcx> {
195195
#[inline]
196196
fn join(&self, pred1: usize, pred2: usize) -> usize {
197197
pred1 | pred2 // union effects of preds when computing borrows
198198
}
199199
}
200200

201-
impl<'a, 'tcx> DataflowOperator for Borrows<'a, 'tcx> {
201+
impl<'a, 'gcx, 'tcx> DataflowOperator for Borrows<'a, 'gcx, 'tcx> {
202202
#[inline]
203203
fn bottom_value() -> bool {
204204
false // bottom = no Rvalue::Refs are active by default

src/librustc_mir/dataflow/impls/mod.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,23 @@ pub(super) mod borrows;
6969
/// Similarly, at a given `drop` statement, the set-intersection
7070
/// between this data and `MaybeUninitializedLvals` yields the set of
7171
/// l-values that would require a dynamic drop-flag at that statement.
72-
pub struct MaybeInitializedLvals<'a, 'tcx: 'a> {
73-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
72+
pub struct MaybeInitializedLvals<'a, 'gcx: 'tcx, 'tcx: 'a> {
73+
tcx: TyCtxt<'a, 'gcx, 'tcx>,
7474
mir: &'a Mir<'tcx>,
75-
mdpe: &'a MoveDataParamEnv<'tcx>,
75+
mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>,
7676
}
7777

78-
impl<'a, 'tcx: 'a> MaybeInitializedLvals<'a, 'tcx> {
79-
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
78+
impl<'a, 'gcx: 'tcx, 'tcx> MaybeInitializedLvals<'a, 'gcx, 'tcx> {
79+
pub fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>,
8080
mir: &'a Mir<'tcx>,
81-
mdpe: &'a MoveDataParamEnv<'tcx>)
81+
mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>)
8282
-> Self
8383
{
8484
MaybeInitializedLvals { tcx: tcx, mir: mir, mdpe: mdpe }
8585
}
8686
}
8787

88-
impl<'a, 'tcx: 'a> HasMoveData<'tcx> for MaybeInitializedLvals<'a, 'tcx> {
88+
impl<'a, 'gcx, 'tcx> HasMoveData<'tcx> for MaybeInitializedLvals<'a, 'gcx, 'tcx> {
8989
fn move_data(&self) -> &MoveData<'tcx> { &self.mdpe.move_data }
9090
}
9191

@@ -124,23 +124,23 @@ impl<'a, 'tcx: 'a> HasMoveData<'tcx> for MaybeInitializedLvals<'a, 'tcx> {
124124
/// Similarly, at a given `drop` statement, the set-intersection
125125
/// between this data and `MaybeInitializedLvals` yields the set of
126126
/// l-values that would require a dynamic drop-flag at that statement.
127-
pub struct MaybeUninitializedLvals<'a, 'tcx: 'a> {
128-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
127+
pub struct MaybeUninitializedLvals<'a, 'gcx: 'tcx, 'tcx: 'a> {
128+
tcx: TyCtxt<'a, 'gcx, 'tcx>,
129129
mir: &'a Mir<'tcx>,
130-
mdpe: &'a MoveDataParamEnv<'tcx>,
130+
mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>,
131131
}
132132

133-
impl<'a, 'tcx: 'a> MaybeUninitializedLvals<'a, 'tcx> {
134-
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
133+
impl<'a, 'gcx, 'tcx> MaybeUninitializedLvals<'a, 'gcx, 'tcx> {
134+
pub fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>,
135135
mir: &'a Mir<'tcx>,
136-
mdpe: &'a MoveDataParamEnv<'tcx>)
136+
mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>)
137137
-> Self
138138
{
139139
MaybeUninitializedLvals { tcx: tcx, mir: mir, mdpe: mdpe }
140140
}
141141
}
142142

143-
impl<'a, 'tcx: 'a> HasMoveData<'tcx> for MaybeUninitializedLvals<'a, 'tcx> {
143+
impl<'a, 'gcx, 'tcx> HasMoveData<'tcx> for MaybeUninitializedLvals<'a, 'gcx, 'tcx> {
144144
fn move_data(&self) -> &MoveData<'tcx> { &self.mdpe.move_data }
145145
}
146146

@@ -185,27 +185,27 @@ impl<'a, 'tcx: 'a> HasMoveData<'tcx> for MaybeUninitializedLvals<'a, 'tcx> {
185185
/// Similarly, at a given `drop` statement, the set-difference between
186186
/// this data and `MaybeInitializedLvals` yields the set of l-values
187187
/// that would require a dynamic drop-flag at that statement.
188-
pub struct DefinitelyInitializedLvals<'a, 'tcx: 'a> {
189-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
188+
pub struct DefinitelyInitializedLvals<'a, 'gcx: 'tcx, 'tcx: 'a> {
189+
tcx: TyCtxt<'a, 'gcx, 'tcx>,
190190
mir: &'a Mir<'tcx>,
191-
mdpe: &'a MoveDataParamEnv<'tcx>,
191+
mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>,
192192
}
193193

194-
impl<'a, 'tcx: 'a> DefinitelyInitializedLvals<'a, 'tcx> {
195-
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
194+
impl<'a, 'gcx, 'tcx: 'a> DefinitelyInitializedLvals<'a, 'gcx, 'tcx> {
195+
pub fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>,
196196
mir: &'a Mir<'tcx>,
197-
mdpe: &'a MoveDataParamEnv<'tcx>)
197+
mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>)
198198
-> Self
199199
{
200200
DefinitelyInitializedLvals { tcx: tcx, mir: mir, mdpe: mdpe }
201201
}
202202
}
203203

204-
impl<'a, 'tcx: 'a> HasMoveData<'tcx> for DefinitelyInitializedLvals<'a, 'tcx> {
204+
impl<'a, 'gcx, 'tcx: 'a> HasMoveData<'tcx> for DefinitelyInitializedLvals<'a, 'gcx, 'tcx> {
205205
fn move_data(&self) -> &MoveData<'tcx> { &self.mdpe.move_data }
206206
}
207207

208-
impl<'a, 'tcx> MaybeInitializedLvals<'a, 'tcx> {
208+
impl<'a, 'gcx, 'tcx> MaybeInitializedLvals<'a, 'gcx, 'tcx> {
209209
fn update_bits(sets: &mut BlockSets<MovePathIndex>, path: MovePathIndex,
210210
state: DropFlagState)
211211
{
@@ -216,7 +216,7 @@ impl<'a, 'tcx> MaybeInitializedLvals<'a, 'tcx> {
216216
}
217217
}
218218

219-
impl<'a, 'tcx> MaybeUninitializedLvals<'a, 'tcx> {
219+
impl<'a, 'gcx, 'tcx> MaybeUninitializedLvals<'a, 'gcx, 'tcx> {
220220
fn update_bits(sets: &mut BlockSets<MovePathIndex>, path: MovePathIndex,
221221
state: DropFlagState)
222222
{
@@ -227,7 +227,7 @@ impl<'a, 'tcx> MaybeUninitializedLvals<'a, 'tcx> {
227227
}
228228
}
229229

230-
impl<'a, 'tcx> DefinitelyInitializedLvals<'a, 'tcx> {
230+
impl<'a, 'gcx, 'tcx> DefinitelyInitializedLvals<'a, 'gcx, 'tcx> {
231231
fn update_bits(sets: &mut BlockSets<MovePathIndex>, path: MovePathIndex,
232232
state: DropFlagState)
233233
{
@@ -238,7 +238,7 @@ impl<'a, 'tcx> DefinitelyInitializedLvals<'a, 'tcx> {
238238
}
239239
}
240240

241-
impl<'a, 'tcx> BitDenotation for MaybeInitializedLvals<'a, 'tcx> {
241+
impl<'a, 'gcx, 'tcx> BitDenotation for MaybeInitializedLvals<'a, 'gcx, 'tcx> {
242242
type Idx = MovePathIndex;
243243
fn name() -> &'static str { "maybe_init" }
244244
fn bits_per_block(&self) -> usize {
@@ -290,7 +290,7 @@ impl<'a, 'tcx> BitDenotation for MaybeInitializedLvals<'a, 'tcx> {
290290
}
291291
}
292292

293-
impl<'a, 'tcx> BitDenotation for MaybeUninitializedLvals<'a, 'tcx> {
293+
impl<'a, 'gcx, 'tcx> BitDenotation for MaybeUninitializedLvals<'a, 'gcx, 'tcx> {
294294
type Idx = MovePathIndex;
295295
fn name() -> &'static str { "maybe_uninit" }
296296
fn bits_per_block(&self) -> usize {
@@ -345,7 +345,7 @@ impl<'a, 'tcx> BitDenotation for MaybeUninitializedLvals<'a, 'tcx> {
345345
}
346346
}
347347

348-
impl<'a, 'tcx> BitDenotation for DefinitelyInitializedLvals<'a, 'tcx> {
348+
impl<'a, 'gcx, 'tcx> BitDenotation for DefinitelyInitializedLvals<'a, 'gcx, 'tcx> {
349349
type Idx = MovePathIndex;
350350
fn name() -> &'static str { "definite_init" }
351351
fn bits_per_block(&self) -> usize {
@@ -399,21 +399,21 @@ impl<'a, 'tcx> BitDenotation for DefinitelyInitializedLvals<'a, 'tcx> {
399399
}
400400
}
401401

402-
impl<'a, 'tcx> BitwiseOperator for MaybeInitializedLvals<'a, 'tcx> {
402+
impl<'a, 'gcx, 'tcx> BitwiseOperator for MaybeInitializedLvals<'a, 'gcx, 'tcx> {
403403
#[inline]
404404
fn join(&self, pred1: usize, pred2: usize) -> usize {
405405
pred1 | pred2 // "maybe" means we union effects of both preds
406406
}
407407
}
408408

409-
impl<'a, 'tcx> BitwiseOperator for MaybeUninitializedLvals<'a, 'tcx> {
409+
impl<'a, 'gcx, 'tcx> BitwiseOperator for MaybeUninitializedLvals<'a, 'gcx, 'tcx> {
410410
#[inline]
411411
fn join(&self, pred1: usize, pred2: usize) -> usize {
412412
pred1 | pred2 // "maybe" means we union effects of both preds
413413
}
414414
}
415415

416-
impl<'a, 'tcx> BitwiseOperator for DefinitelyInitializedLvals<'a, 'tcx> {
416+
impl<'a, 'gcx, 'tcx> BitwiseOperator for DefinitelyInitializedLvals<'a, 'gcx, 'tcx> {
417417
#[inline]
418418
fn join(&self, pred1: usize, pred2: usize) -> usize {
419419
pred1 & pred2 // "definitely" means we intersect effects of both preds
@@ -430,21 +430,21 @@ impl<'a, 'tcx> BitwiseOperator for DefinitelyInitializedLvals<'a, 'tcx> {
430430
// propagating, or you start at all-ones and then use Intersect as
431431
// your merge when propagating.
432432

433-
impl<'a, 'tcx> DataflowOperator for MaybeInitializedLvals<'a, 'tcx> {
433+
impl<'a, 'gcx, 'tcx> DataflowOperator for MaybeInitializedLvals<'a, 'gcx, 'tcx> {
434434
#[inline]
435435
fn bottom_value() -> bool {
436436
false // bottom = uninitialized
437437
}
438438
}
439439

440-
impl<'a, 'tcx> DataflowOperator for MaybeUninitializedLvals<'a, 'tcx> {
440+
impl<'a, 'gcx, 'tcx> DataflowOperator for MaybeUninitializedLvals<'a, 'gcx, 'tcx> {
441441
#[inline]
442442
fn bottom_value() -> bool {
443443
false // bottom = initialized (start_block_effect counters this at outset)
444444
}
445445
}
446446

447-
impl<'a, 'tcx> DataflowOperator for DefinitelyInitializedLvals<'a, 'tcx> {
447+
impl<'a, 'gcx, 'tcx> DataflowOperator for DefinitelyInitializedLvals<'a, 'gcx, 'tcx> {
448448
#[inline]
449449
fn bottom_value() -> bool {
450450
true // bottom = initialized (start_block_effect counters this at outset)

src/librustc_mir/dataflow/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,19 @@ pub(crate) fn has_rustc_mir_with(attrs: &[ast::Attribute], name: &str) -> Option
9191
return None;
9292
}
9393

94-
pub struct MoveDataParamEnv<'tcx> {
94+
pub struct MoveDataParamEnv<'gcx, 'tcx> {
9595
pub(crate) move_data: MoveData<'tcx>,
96-
pub(crate) param_env: ty::ParamEnv<'tcx>,
96+
pub(crate) param_env: ty::ParamEnv<'gcx>,
9797
}
9898

99-
pub(crate) fn do_dataflow<'a, 'tcx, BD, P>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
100-
mir: &Mir<'tcx>,
101-
node_id: ast::NodeId,
102-
attributes: &[ast::Attribute],
103-
dead_unwinds: &IdxSet<BasicBlock>,
104-
bd: BD,
105-
p: P)
106-
-> DataflowResults<BD>
99+
pub(crate) fn do_dataflow<'a, 'gcx, 'tcx, BD, P>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
100+
mir: &Mir<'tcx>,
101+
node_id: ast::NodeId,
102+
attributes: &[ast::Attribute],
103+
dead_unwinds: &IdxSet<BasicBlock>,
104+
bd: BD,
105+
p: P)
106+
-> DataflowResults<BD>
107107
where BD: BitDenotation,
108108
P: Fn(&BD, BD::Idx) -> &fmt::Debug
109109
{
@@ -612,9 +612,9 @@ pub trait BitDenotation: DataflowOperator {
612612
dest_lval: &mir::Lvalue);
613613
}
614614

615-
impl<'a, 'tcx: 'a, D> DataflowAnalysis<'a, 'tcx, D> where D: BitDenotation
615+
impl<'a, 'gcx, 'tcx: 'a, D> DataflowAnalysis<'a, 'tcx, D> where D: BitDenotation
616616
{
617-
pub fn new(_tcx: TyCtxt<'a, 'tcx, 'tcx>,
617+
pub fn new(_tcx: TyCtxt<'a, 'gcx, 'tcx>,
618618
mir: &'a Mir<'tcx>,
619619
dead_unwinds: &'a IdxSet<mir::BasicBlock>,
620620
denotation: D) -> Self {

0 commit comments

Comments
 (0)