@@ -15,7 +15,7 @@ use crate::dataflow::MaybeMutBorrowedLocals;
1515use crate :: dataflow:: MoveDataParamEnv ;
1616use crate :: dataflow:: { Analysis , Results , ResultsCursor } ;
1717use crate :: dataflow:: {
18- DefinitelyInitializedPlaces , MaybeInitializedPlaces , MaybeUninitializedPlaces ,
18+ DefinitelyInitializedPlaces , MaybeInitializedPlaces , MaybeLiveLocals , MaybeUninitializedPlaces ,
1919} ;
2020
2121pub struct SanityCheck ;
@@ -36,31 +36,45 @@ impl<'tcx> MirPass<'tcx> for SanityCheck {
3636 let move_data = MoveData :: gather_moves ( body, tcx, param_env) . unwrap ( ) ;
3737 let mdpe = MoveDataParamEnv { move_data, param_env } ;
3838
39- let flow_inits = MaybeInitializedPlaces :: new ( tcx, body, & mdpe)
40- . into_engine ( tcx, body, def_id)
41- . iterate_to_fixpoint ( ) ;
42- let flow_uninits = MaybeUninitializedPlaces :: new ( tcx, body, & mdpe)
43- . into_engine ( tcx, body, def_id)
44- . iterate_to_fixpoint ( ) ;
45- let flow_def_inits = DefinitelyInitializedPlaces :: new ( tcx, body, & mdpe)
46- . into_engine ( tcx, body, def_id)
47- . iterate_to_fixpoint ( ) ;
48- let flow_mut_borrowed = MaybeMutBorrowedLocals :: mut_borrows_only ( tcx, body, param_env)
49- . into_engine ( tcx, body, def_id)
50- . iterate_to_fixpoint ( ) ;
51-
5239 if has_rustc_mir_with ( & attributes, sym:: rustc_peek_maybe_init) . is_some ( ) {
40+ let flow_inits = MaybeInitializedPlaces :: new ( tcx, body, & mdpe)
41+ . into_engine ( tcx, body, def_id)
42+ . iterate_to_fixpoint ( ) ;
43+
5344 sanity_check_via_rustc_peek ( tcx, body, def_id, & attributes, & flow_inits) ;
5445 }
46+
5547 if has_rustc_mir_with ( & attributes, sym:: rustc_peek_maybe_uninit) . is_some ( ) {
48+ let flow_uninits = MaybeUninitializedPlaces :: new ( tcx, body, & mdpe)
49+ . into_engine ( tcx, body, def_id)
50+ . iterate_to_fixpoint ( ) ;
51+
5652 sanity_check_via_rustc_peek ( tcx, body, def_id, & attributes, & flow_uninits) ;
5753 }
54+
5855 if has_rustc_mir_with ( & attributes, sym:: rustc_peek_definite_init) . is_some ( ) {
56+ let flow_def_inits = DefinitelyInitializedPlaces :: new ( tcx, body, & mdpe)
57+ . into_engine ( tcx, body, def_id)
58+ . iterate_to_fixpoint ( ) ;
59+
5960 sanity_check_via_rustc_peek ( tcx, body, def_id, & attributes, & flow_def_inits) ;
6061 }
62+
6163 if has_rustc_mir_with ( & attributes, sym:: rustc_peek_indirectly_mutable) . is_some ( ) {
64+ let flow_mut_borrowed = MaybeMutBorrowedLocals :: mut_borrows_only ( tcx, body, param_env)
65+ . into_engine ( tcx, body, def_id)
66+ . iterate_to_fixpoint ( ) ;
67+
6268 sanity_check_via_rustc_peek ( tcx, body, def_id, & attributes, & flow_mut_borrowed) ;
6369 }
70+
71+ if has_rustc_mir_with ( & attributes, sym:: rustc_peek_liveness) . is_some ( ) {
72+ let flow_liveness =
73+ MaybeLiveLocals . into_engine ( tcx, body, def_id) . iterate_to_fixpoint ( ) ;
74+
75+ sanity_check_via_rustc_peek ( tcx, body, def_id, & attributes, & flow_liveness) ;
76+ }
77+
6478 if has_rustc_mir_with ( & attributes, sym:: stop_after_dataflow) . is_some ( ) {
6579 tcx. sess . fatal ( "stop_after_dataflow ended compilation" ) ;
6680 }
@@ -286,3 +300,25 @@ impl<'tcx> RustcPeekAt<'tcx> for MaybeMutBorrowedLocals<'_, 'tcx> {
286300 }
287301 }
288302}
303+
304+ impl < ' tcx > RustcPeekAt < ' tcx > for MaybeLiveLocals {
305+ fn peek_at (
306+ & self ,
307+ tcx : TyCtxt < ' tcx > ,
308+ place : mir:: Place < ' tcx > ,
309+ flow_state : & BitSet < Local > ,
310+ call : PeekCall ,
311+ ) {
312+ warn ! ( "peek_at: place={:?}" , place) ;
313+ let local = if let Some ( l) = place. as_local ( ) {
314+ l
315+ } else {
316+ tcx. sess . span_err ( call. span , "rustc_peek: argument was not a local" ) ;
317+ return ;
318+ } ;
319+
320+ if !flow_state. contains ( local) {
321+ tcx. sess . span_err ( call. span , "rustc_peek: bit not set" ) ;
322+ }
323+ }
324+ }
0 commit comments