1
- // Copyright 2012-2016 The Rust Project Developers. See the COPYRIGHT
1
+ // Copyright 2012-2017 The Rust Project Developers. See the COPYRIGHT
2
2
// file at the top-level directory of this distribution and at
3
3
// http://rust-lang.org/COPYRIGHT.
4
4
//
8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- use borrowck:: BorrowckCtxt ;
12
-
13
11
use syntax:: ast:: { self , MetaItem } ;
14
12
use syntax_pos:: DUMMY_SP ;
15
13
16
- use rustc:: mir:: { self , BasicBlock , BasicBlockData , Mir , Statement , Terminator , Location } ;
14
+
15
+ use rustc:: mir:: { self , Mir , BasicBlock , Location } ;
17
16
use rustc:: session:: Session ;
18
17
use rustc:: ty:: { self , TyCtxt } ;
19
- use rustc_mir:: util:: elaborate_drops:: DropFlagState ;
20
- use rustc_data_structures:: indexed_set:: { IdxSet , IdxSetBuf } ;
21
-
22
- mod abs_domain;
23
- pub mod elaborate_drops;
24
- mod dataflow;
25
- mod gather_moves;
26
- // mod graphviz;
27
-
28
- use self :: dataflow:: { BitDenotation } ;
29
- use self :: dataflow:: { DataflowOperator } ;
30
- use self :: dataflow:: { Dataflow , DataflowAnalysis , DataflowResults } ;
31
- use self :: dataflow:: { MaybeInitializedLvals , MaybeUninitializedLvals } ;
32
- use self :: dataflow:: { DefinitelyInitializedLvals } ;
33
- use self :: gather_moves:: { HasMoveData , MoveData , MovePathIndex , LookupResult } ;
18
+ use util:: elaborate_drops:: DropFlagState ;
19
+ use rustc_data_structures:: indexed_set:: { IdxSet } ;
34
20
35
21
use std:: fmt;
36
22
37
- fn has_rustc_mir_with ( attrs : & [ ast:: Attribute ] , name : & str ) -> Option < MetaItem > {
23
+ use super :: { Dataflow , DataflowBuilder , DataflowAnalysis } ;
24
+ use super :: { BitDenotation , DataflowOperator , DataflowResults } ;
25
+ use super :: indexes:: MovePathIndex ;
26
+ use super :: move_paths:: { MoveData , LookupResult } ;
27
+
28
+ pub ( crate ) fn has_rustc_mir_with ( attrs : & [ ast:: Attribute ] , name : & str ) -> Option < MetaItem > {
38
29
for attr in attrs {
39
30
if attr. check_name ( "rustc_mir" ) {
40
31
let items = attr. meta_item_list ( ) ;
@@ -50,69 +41,11 @@ fn has_rustc_mir_with(attrs: &[ast::Attribute], name: &str) -> Option<MetaItem>
50
41
}
51
42
52
43
pub struct MoveDataParamEnv < ' tcx > {
53
- move_data : MoveData < ' tcx > ,
54
- param_env : ty:: ParamEnv < ' tcx > ,
44
+ pub ( crate ) move_data : MoveData < ' tcx > ,
45
+ pub ( crate ) param_env : ty:: ParamEnv < ' tcx > ,
55
46
}
56
47
57
- pub fn borrowck_mir ( bcx : & mut BorrowckCtxt ,
58
- id : ast:: NodeId ,
59
- attributes : & [ ast:: Attribute ] ) {
60
- let tcx = bcx. tcx ;
61
- let def_id = tcx. hir . local_def_id ( id) ;
62
- debug ! ( "borrowck_mir({:?}) UNIMPLEMENTED" , def_id) ;
63
-
64
- // It is safe for us to borrow `mir_validated()`: `optimized_mir`
65
- // steals it, but it forces the `borrowck` query.
66
- let mir = & tcx. mir_validated ( def_id) . borrow ( ) ;
67
-
68
- let param_env = tcx. param_env ( def_id) ;
69
- let move_data = MoveData :: gather_moves ( mir, tcx, param_env) ;
70
- let mdpe = MoveDataParamEnv { move_data : move_data, param_env : param_env } ;
71
- let dead_unwinds = IdxSetBuf :: new_empty ( mir. basic_blocks ( ) . len ( ) ) ;
72
- let flow_inits =
73
- do_dataflow ( tcx, mir, id, attributes, & dead_unwinds,
74
- MaybeInitializedLvals :: new ( tcx, mir, & mdpe) ,
75
- |bd, i| & bd. move_data ( ) . move_paths [ i] ) ;
76
- let flow_uninits =
77
- do_dataflow ( tcx, mir, id, attributes, & dead_unwinds,
78
- MaybeUninitializedLvals :: new ( tcx, mir, & mdpe) ,
79
- |bd, i| & bd. move_data ( ) . move_paths [ i] ) ;
80
- let flow_def_inits =
81
- do_dataflow ( tcx, mir, id, attributes, & dead_unwinds,
82
- DefinitelyInitializedLvals :: new ( tcx, mir, & mdpe) ,
83
- |bd, i| & bd. move_data ( ) . move_paths [ i] ) ;
84
-
85
- if has_rustc_mir_with ( attributes, "rustc_peek_maybe_init" ) . is_some ( ) {
86
- dataflow:: sanity_check_via_rustc_peek ( bcx. tcx , mir, id, attributes, & flow_inits) ;
87
- }
88
- if has_rustc_mir_with ( attributes, "rustc_peek_maybe_uninit" ) . is_some ( ) {
89
- dataflow:: sanity_check_via_rustc_peek ( bcx. tcx , mir, id, attributes, & flow_uninits) ;
90
- }
91
- if has_rustc_mir_with ( attributes, "rustc_peek_definite_init" ) . is_some ( ) {
92
- dataflow:: sanity_check_via_rustc_peek ( bcx. tcx , mir, id, attributes, & flow_def_inits) ;
93
- }
94
-
95
- if has_rustc_mir_with ( attributes, "stop_after_dataflow" ) . is_some ( ) {
96
- bcx. tcx . sess . fatal ( "stop_after_dataflow ended compilation" ) ;
97
- }
98
-
99
- let mut mbcx = MirBorrowckCtxt {
100
- bcx : bcx,
101
- mir : mir,
102
- node_id : id,
103
- move_data : & mdpe. move_data ,
104
- flow_inits : flow_inits,
105
- flow_uninits : flow_uninits,
106
- } ;
107
-
108
- for bb in mir. basic_blocks ( ) . indices ( ) {
109
- mbcx. process_basic_block ( bb) ;
110
- }
111
-
112
- debug ! ( "borrowck_mir done" ) ;
113
- }
114
-
115
- fn do_dataflow < ' a , ' tcx , BD , P > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
48
+ pub ( crate ) fn do_dataflow < ' a , ' tcx , BD , P > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
116
49
mir : & Mir < ' tcx > ,
117
50
node_id : ast:: NodeId ,
118
51
attributes : & [ ast:: Attribute ] ,
@@ -142,7 +75,7 @@ fn do_dataflow<'a, 'tcx, BD, P>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
142
75
let print_postflow_to =
143
76
name_found ( tcx. sess , attributes, "borrowck_graphviz_postflow" ) ;
144
77
145
- let mut mbcx = MirBorrowckCtxtPreDataflow {
78
+ let mut mbcx = DataflowBuilder {
146
79
node_id : node_id,
147
80
print_preflow_to : print_preflow_to,
148
81
print_postflow_to : print_postflow_to,
@@ -153,46 +86,7 @@ fn do_dataflow<'a, 'tcx, BD, P>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
153
86
mbcx. flow_state . results ( )
154
87
}
155
88
156
-
157
- pub struct MirBorrowckCtxtPreDataflow < ' a , ' tcx : ' a , BD > where BD : BitDenotation
158
- {
159
- node_id : ast:: NodeId ,
160
- flow_state : DataflowAnalysis < ' a , ' tcx , BD > ,
161
- print_preflow_to : Option < String > ,
162
- print_postflow_to : Option < String > ,
163
- }
164
-
165
- #[ allow( dead_code) ]
166
- pub struct MirBorrowckCtxt < ' b , ' a : ' b , ' tcx : ' a > {
167
- bcx : & ' b mut BorrowckCtxt < ' a , ' tcx > ,
168
- mir : & ' b Mir < ' tcx > ,
169
- node_id : ast:: NodeId ,
170
- move_data : & ' b MoveData < ' tcx > ,
171
- flow_inits : DataflowResults < MaybeInitializedLvals < ' b , ' tcx > > ,
172
- flow_uninits : DataflowResults < MaybeUninitializedLvals < ' b , ' tcx > >
173
- }
174
-
175
- impl < ' b , ' a : ' b , ' tcx : ' a > MirBorrowckCtxt < ' b , ' a , ' tcx > {
176
- fn process_basic_block ( & mut self , bb : BasicBlock ) {
177
- let BasicBlockData { ref statements, ref terminator, is_cleanup : _ } =
178
- self . mir [ bb] ;
179
- for stmt in statements {
180
- self . process_statement ( bb, stmt) ;
181
- }
182
-
183
- self . process_terminator ( bb, terminator) ;
184
- }
185
-
186
- fn process_statement ( & mut self , bb : BasicBlock , stmt : & Statement < ' tcx > ) {
187
- debug ! ( "MirBorrowckCtxt::process_statement({:?}, {:?}" , bb, stmt) ;
188
- }
189
-
190
- fn process_terminator ( & mut self , bb : BasicBlock , term : & Option < Terminator < ' tcx > > ) {
191
- debug ! ( "MirBorrowckCtxt::process_terminator({:?}, {:?})" , bb, term) ;
192
- }
193
- }
194
-
195
- fn move_path_children_matching < ' tcx , F > ( move_data : & MoveData < ' tcx > ,
89
+ pub fn move_path_children_matching < ' tcx , F > ( move_data : & MoveData < ' tcx > ,
196
90
path : MovePathIndex ,
197
91
mut cond : F )
198
92
-> Option < MovePathIndex >
@@ -253,7 +147,7 @@ fn lvalue_contents_drop_state_cannot_differ<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx
253
147
}
254
148
}
255
149
256
- fn on_lookup_result_bits < ' a , ' tcx , F > (
150
+ pub ( crate ) fn on_lookup_result_bits < ' a , ' tcx , F > (
257
151
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
258
152
mir : & Mir < ' tcx > ,
259
153
move_data : & MoveData < ' tcx > ,
@@ -271,7 +165,7 @@ fn on_lookup_result_bits<'a, 'tcx, F>(
271
165
}
272
166
}
273
167
274
- fn on_all_children_bits < ' a , ' tcx , F > (
168
+ pub ( crate ) fn on_all_children_bits < ' a , ' tcx , F > (
275
169
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
276
170
mir : & Mir < ' tcx > ,
277
171
move_data : & MoveData < ' tcx > ,
@@ -312,7 +206,7 @@ fn on_all_children_bits<'a, 'tcx, F>(
312
206
on_all_children_bits ( tcx, mir, move_data, move_path_index, & mut each_child) ;
313
207
}
314
208
315
- fn on_all_drop_children_bits < ' a , ' tcx , F > (
209
+ pub ( crate ) fn on_all_drop_children_bits < ' a , ' tcx , F > (
316
210
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
317
211
mir : & Mir < ' tcx > ,
318
212
ctxt : & MoveDataParamEnv < ' tcx > ,
@@ -333,7 +227,7 @@ fn on_all_drop_children_bits<'a, 'tcx, F>(
333
227
} )
334
228
}
335
229
336
- fn drop_flag_effects_for_function_entry < ' a , ' tcx , F > (
230
+ pub ( crate ) fn drop_flag_effects_for_function_entry < ' a , ' tcx , F > (
337
231
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
338
232
mir : & Mir < ' tcx > ,
339
233
ctxt : & MoveDataParamEnv < ' tcx > ,
@@ -350,7 +244,7 @@ fn drop_flag_effects_for_function_entry<'a, 'tcx, F>(
350
244
}
351
245
}
352
246
353
- fn drop_flag_effects_for_location < ' a , ' tcx , F > (
247
+ pub ( crate ) fn drop_flag_effects_for_location < ' a , ' tcx , F > (
354
248
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
355
249
mir : & Mir < ' tcx > ,
356
250
ctxt : & MoveDataParamEnv < ' tcx > ,
0 commit comments