@@ -74,6 +74,72 @@ impl<'tcx, 'a> crate::GenKillAnalysis<'tcx> for MaybeStorageLive<'a> {
7474 }
7575}
7676
77+ #[ derive( Clone ) ]
78+ pub struct MaybeStorageDead {
79+ always_live_locals : BitSet < Local > ,
80+ }
81+
82+ impl MaybeStorageDead {
83+ pub fn new ( always_live_locals : BitSet < Local > ) -> Self {
84+ MaybeStorageDead { always_live_locals }
85+ }
86+ }
87+
88+ impl < ' tcx > crate :: AnalysisDomain < ' tcx > for MaybeStorageDead {
89+ type Domain = BitSet < Local > ;
90+
91+ const NAME : & ' static str = "maybe_storage_dead" ;
92+
93+ fn bottom_value ( & self , body : & mir:: Body < ' tcx > ) -> Self :: Domain {
94+ // bottom = live
95+ BitSet :: new_empty ( body. local_decls . len ( ) )
96+ }
97+
98+ fn initialize_start_block ( & self , body : & mir:: Body < ' tcx > , on_entry : & mut Self :: Domain ) {
99+ assert_eq ! ( body. local_decls. len( ) , self . always_live_locals. domain_size( ) ) ;
100+ for local in body. vars_and_temps_iter ( ) {
101+ if !self . always_live_locals . contains ( local) {
102+ on_entry. insert ( local) ;
103+ }
104+ }
105+ }
106+ }
107+
108+ impl < ' tcx > crate :: GenKillAnalysis < ' tcx > for MaybeStorageDead {
109+ type Idx = Local ;
110+
111+ fn statement_effect (
112+ & self ,
113+ trans : & mut impl GenKill < Self :: Idx > ,
114+ stmt : & mir:: Statement < ' tcx > ,
115+ _: Location ,
116+ ) {
117+ match stmt. kind {
118+ StatementKind :: StorageLive ( l) => trans. kill ( l) ,
119+ StatementKind :: StorageDead ( l) => trans. gen ( l) ,
120+ _ => ( ) ,
121+ }
122+ }
123+
124+ fn terminator_effect (
125+ & self ,
126+ _trans : & mut impl GenKill < Self :: Idx > ,
127+ _: & mir:: Terminator < ' tcx > ,
128+ _: Location ,
129+ ) {
130+ // Terminators have no effect
131+ }
132+
133+ fn call_return_effect (
134+ & self ,
135+ _trans : & mut impl GenKill < Self :: Idx > ,
136+ _block : BasicBlock ,
137+ _return_places : CallReturnPlaces < ' _ , ' tcx > ,
138+ ) {
139+ // Nothing to do when a call returns successfully
140+ }
141+ }
142+
77143type BorrowedLocalsResults < ' a , ' tcx > = ResultsRefCursor < ' a , ' a , ' tcx , MaybeBorrowedLocals > ;
78144
79145/// Dataflow analysis that determines whether each local requires storage at a
0 commit comments