1- // Copyright 2012-2016 The Rust Project Developers. See the COPYRIGHT
1+ // Copyright 2012-2017 The Rust Project Developers. See the COPYRIGHT
22// file at the top-level directory of this distribution and at
33// http://rust-lang.org/COPYRIGHT.
44//
88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
11- use borrowck:: BorrowckCtxt ;
12-
1311use syntax:: ast:: { self , MetaItem } ;
1412use syntax_pos:: DUMMY_SP ;
1513
16- use rustc:: mir:: { self , BasicBlock , BasicBlockData , Mir , Statement , Terminator , Location } ;
14+
15+ use rustc:: mir:: { self , Mir , BasicBlock , Location } ;
1716use rustc:: session:: Session ;
1817use 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 } ;
3420
3521use std:: fmt;
3622
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 > {
3829 for attr in attrs {
3930 if attr. check_name ( "rustc_mir" ) {
4031 let items = attr. meta_item_list ( ) ;
@@ -50,69 +41,11 @@ fn has_rustc_mir_with(attrs: &[ast::Attribute], name: &str) -> Option<MetaItem>
5041}
5142
5243pub 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 > ,
5546}
5647
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 > ,
11649 mir : & Mir < ' tcx > ,
11750 node_id : ast:: NodeId ,
11851 attributes : & [ ast:: Attribute ] ,
@@ -142,7 +75,7 @@ fn do_dataflow<'a, 'tcx, BD, P>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
14275 let print_postflow_to =
14376 name_found ( tcx. sess , attributes, "borrowck_graphviz_postflow" ) ;
14477
145- let mut mbcx = MirBorrowckCtxtPreDataflow {
78+ let mut mbcx = DataflowBuilder {
14679 node_id : node_id,
14780 print_preflow_to : print_preflow_to,
14881 print_postflow_to : print_postflow_to,
@@ -153,46 +86,7 @@ fn do_dataflow<'a, 'tcx, BD, P>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
15386 mbcx. flow_state . results ( )
15487}
15588
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 > ,
19690 path : MovePathIndex ,
19791 mut cond : F )
19892 -> Option < MovePathIndex >
@@ -253,7 +147,7 @@ fn lvalue_contents_drop_state_cannot_differ<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx
253147 }
254148}
255149
256- fn on_lookup_result_bits < ' a , ' tcx , F > (
150+ pub ( crate ) fn on_lookup_result_bits < ' a , ' tcx , F > (
257151 tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
258152 mir : & Mir < ' tcx > ,
259153 move_data : & MoveData < ' tcx > ,
@@ -271,7 +165,7 @@ fn on_lookup_result_bits<'a, 'tcx, F>(
271165 }
272166}
273167
274- fn on_all_children_bits < ' a , ' tcx , F > (
168+ pub ( crate ) fn on_all_children_bits < ' a , ' tcx , F > (
275169 tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
276170 mir : & Mir < ' tcx > ,
277171 move_data : & MoveData < ' tcx > ,
@@ -312,7 +206,7 @@ fn on_all_children_bits<'a, 'tcx, F>(
312206 on_all_children_bits ( tcx, mir, move_data, move_path_index, & mut each_child) ;
313207}
314208
315- fn on_all_drop_children_bits < ' a , ' tcx , F > (
209+ pub ( crate ) fn on_all_drop_children_bits < ' a , ' tcx , F > (
316210 tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
317211 mir : & Mir < ' tcx > ,
318212 ctxt : & MoveDataParamEnv < ' tcx > ,
@@ -333,7 +227,7 @@ fn on_all_drop_children_bits<'a, 'tcx, F>(
333227 } )
334228}
335229
336- fn drop_flag_effects_for_function_entry < ' a , ' tcx , F > (
230+ pub ( crate ) fn drop_flag_effects_for_function_entry < ' a , ' tcx , F > (
337231 tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
338232 mir : & Mir < ' tcx > ,
339233 ctxt : & MoveDataParamEnv < ' tcx > ,
@@ -350,7 +244,7 @@ fn drop_flag_effects_for_function_entry<'a, 'tcx, F>(
350244 }
351245}
352246
353- fn drop_flag_effects_for_location < ' a , ' tcx , F > (
247+ pub ( crate ) fn drop_flag_effects_for_location < ' a , ' tcx , F > (
354248 tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
355249 mir : & Mir < ' tcx > ,
356250 ctxt : & MoveDataParamEnv < ' tcx > ,
0 commit comments