@@ -15,7 +15,7 @@ use crate::dataflow::MaybeMutBorrowedLocals;
15
15
use crate :: dataflow:: MoveDataParamEnv ;
16
16
use crate :: dataflow:: { Analysis , Results , ResultsCursor } ;
17
17
use crate :: dataflow:: {
18
- DefinitelyInitializedPlaces , MaybeInitializedPlaces , MaybeUninitializedPlaces ,
18
+ DefinitelyInitializedPlaces , MaybeInitializedPlaces , MaybeLiveLocals , MaybeUninitializedPlaces ,
19
19
} ;
20
20
21
21
pub struct SanityCheck ;
@@ -36,31 +36,45 @@ impl<'tcx> MirPass<'tcx> for SanityCheck {
36
36
let move_data = MoveData :: gather_moves ( body, tcx, param_env) . unwrap ( ) ;
37
37
let mdpe = MoveDataParamEnv { move_data, param_env } ;
38
38
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
-
52
39
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
+
53
44
sanity_check_via_rustc_peek ( tcx, body, def_id, & attributes, & flow_inits) ;
54
45
}
46
+
55
47
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
+
56
52
sanity_check_via_rustc_peek ( tcx, body, def_id, & attributes, & flow_uninits) ;
57
53
}
54
+
58
55
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
+
59
60
sanity_check_via_rustc_peek ( tcx, body, def_id, & attributes, & flow_def_inits) ;
60
61
}
62
+
61
63
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
+
62
68
sanity_check_via_rustc_peek ( tcx, body, def_id, & attributes, & flow_mut_borrowed) ;
63
69
}
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
+
64
78
if has_rustc_mir_with ( & attributes, sym:: stop_after_dataflow) . is_some ( ) {
65
79
tcx. sess . fatal ( "stop_after_dataflow ended compilation" ) ;
66
80
}
@@ -286,3 +300,25 @@ impl<'tcx> RustcPeekAt<'tcx> for MaybeMutBorrowedLocals<'_, 'tcx> {
286
300
}
287
301
}
288
302
}
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