@@ -74,13 +74,19 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeLiveLocals {
74
74
_block : mir:: BasicBlock ,
75
75
return_places : CallReturnPlaces < ' _ , ' tcx > ,
76
76
) {
77
- return_places . for_each ( |place| {
78
- CallReturnEffect ( trans) . visit_place (
79
- & place ,
80
- PlaceContext :: MutatingUse ( MutatingUseContext :: Store ) ,
77
+ if let CallReturnPlaces :: Yield ( resume_place ) = return_places {
78
+ YieldResumeEffect ( trans) . visit_place (
79
+ & resume_place ,
80
+ PlaceContext :: MutatingUse ( MutatingUseContext :: Yield ) ,
81
81
Location :: START ,
82
82
)
83
- } ) ;
83
+ } else {
84
+ return_places. for_each ( |place| {
85
+ if let Some ( local) = place. as_local ( ) {
86
+ trans. kill ( local) ;
87
+ }
88
+ } ) ;
89
+ }
84
90
}
85
91
}
86
92
@@ -91,12 +97,16 @@ where
91
97
T : GenKill < Local > ,
92
98
{
93
99
fn visit_place ( & mut self , place : & mir:: Place < ' tcx > , context : PlaceContext , location : Location ) {
100
+ if let PlaceContext :: MutatingUse ( MutatingUseContext :: Yield ) = context {
101
+ // The resume place is evaluated and assigned to only after generator resumes, so its
102
+ // effect is handled separately in `call_resume_effect`.
103
+ return ;
104
+ }
105
+
94
106
match DefUse :: for_place ( * place, context) {
95
107
Some ( DefUse :: Def ) => {
96
108
if let PlaceContext :: MutatingUse (
97
- MutatingUseContext :: Yield
98
- | MutatingUseContext :: Call
99
- | MutatingUseContext :: AsmOutput ,
109
+ MutatingUseContext :: Call | MutatingUseContext :: AsmOutput ,
100
110
) = context
101
111
{
102
112
// For the associated terminators, this is only a `Def` when the terminator returns
@@ -119,9 +129,9 @@ where
119
129
}
120
130
}
121
131
122
- struct CallReturnEffect < ' a , T > ( & ' a mut T ) ;
132
+ struct YieldResumeEffect < ' a , T > ( & ' a mut T ) ;
123
133
124
- impl < ' tcx , T > Visitor < ' tcx > for CallReturnEffect < ' _ , T >
134
+ impl < ' tcx , T > Visitor < ' tcx > for YieldResumeEffect < ' _ , T >
125
135
where
126
136
T : GenKill < Local > ,
127
137
{
@@ -291,12 +301,18 @@ impl<'a, 'tcx> Analysis<'tcx> for MaybeTransitiveLiveLocals<'a> {
291
301
_block : mir:: BasicBlock ,
292
302
return_places : CallReturnPlaces < ' _ , ' tcx > ,
293
303
) {
294
- return_places . for_each ( |place| {
295
- CallReturnEffect ( trans) . visit_place (
296
- & place ,
297
- PlaceContext :: MutatingUse ( MutatingUseContext :: Store ) ,
304
+ if let CallReturnPlaces :: Yield ( resume_place ) = return_places {
305
+ YieldResumeEffect ( trans) . visit_place (
306
+ & resume_place ,
307
+ PlaceContext :: MutatingUse ( MutatingUseContext :: Yield ) ,
298
308
Location :: START ,
299
309
)
300
- } ) ;
310
+ } else {
311
+ return_places. for_each ( |place| {
312
+ if let Some ( local) = place. as_local ( ) {
313
+ trans. remove ( local) ;
314
+ }
315
+ } ) ;
316
+ }
301
317
}
302
318
}
0 commit comments