@@ -179,18 +179,11 @@ impl<'tcx> MirSource<'tcx> {
179
179
180
180
#[ derive( Clone , TyEncodable , TyDecodable , Debug , HashStable , TypeFoldable , TypeVisitable ) ]
181
181
pub struct GeneratorInfo < ' tcx > {
182
- /// The yield type of the function, if it is a generator.
183
- pub yield_ty : Option < Ty < ' tcx > > ,
184
-
185
182
/// Generator drop glue.
186
- pub generator_drop : Option < Body < ' tcx > > ,
183
+ pub generator_drop : Body < ' tcx > ,
187
184
188
185
/// The layout of a generator. Produced by the state transformation.
189
- pub generator_layout : Option < GeneratorLayout < ' tcx > > ,
190
-
191
- /// If this is a generator then record the type of source expression that caused this generator
192
- /// to be created.
193
- pub generator_kind : GeneratorKind ,
186
+ pub generator_layout : GeneratorLayout < ' tcx > ,
194
187
}
195
188
196
189
/// The lowered representation of a single function.
@@ -213,8 +206,6 @@ pub struct Body<'tcx> {
213
206
/// and used for debuginfo. Indexed by a `SourceScope`.
214
207
pub source_scopes : IndexVec < SourceScope , SourceScopeData < ' tcx > > ,
215
208
216
- pub generator : Option < Box < GeneratorInfo < ' tcx > > > ,
217
-
218
209
/// Declarations of locals.
219
210
///
220
211
/// The first local is the return value pointer, followed by `arg_count`
@@ -279,7 +270,6 @@ impl<'tcx> Body<'tcx> {
279
270
arg_count : usize ,
280
271
var_debug_info : Vec < VarDebugInfo < ' tcx > > ,
281
272
span : Span ,
282
- generator_kind : Option < GeneratorKind > ,
283
273
tainted_by_errors : Option < ErrorGuaranteed > ,
284
274
) -> Self {
285
275
// We need `arg_count` locals, and one for the return place.
@@ -295,14 +285,6 @@ impl<'tcx> Body<'tcx> {
295
285
source,
296
286
basic_blocks : BasicBlocks :: new ( basic_blocks) ,
297
287
source_scopes,
298
- generator : generator_kind. map ( |generator_kind| {
299
- Box :: new ( GeneratorInfo {
300
- yield_ty : None ,
301
- generator_drop : None ,
302
- generator_layout : None ,
303
- generator_kind,
304
- } )
305
- } ) ,
306
288
local_decls,
307
289
user_type_annotations,
308
290
arg_count,
@@ -328,7 +310,6 @@ impl<'tcx> Body<'tcx> {
328
310
source : MirSource :: item ( CRATE_DEF_ID . to_def_id ( ) ) ,
329
311
basic_blocks : BasicBlocks :: new ( basic_blocks) ,
330
312
source_scopes : IndexVec :: new ( ) ,
331
- generator : None ,
332
313
local_decls : IndexVec :: new ( ) ,
333
314
user_type_annotations : IndexVec :: new ( ) ,
334
315
arg_count : 0 ,
@@ -460,24 +441,15 @@ impl<'tcx> Body<'tcx> {
460
441
. unwrap_or_else ( || Either :: Right ( block_data. terminator ( ) ) )
461
442
}
462
443
463
- #[ inline]
464
- pub fn yield_ty ( & self ) -> Option < Ty < ' tcx > > {
465
- self . generator . as_ref ( ) . and_then ( |generator| generator. yield_ty )
466
- }
467
-
468
- #[ inline]
469
- pub fn generator_layout ( & self ) -> Option < & GeneratorLayout < ' tcx > > {
470
- self . generator . as_ref ( ) . and_then ( |generator| generator. generator_layout . as_ref ( ) )
471
- }
472
-
473
- #[ inline]
474
- pub fn generator_drop ( & self ) -> Option < & Body < ' tcx > > {
475
- self . generator . as_ref ( ) . and_then ( |generator| generator. generator_drop . as_ref ( ) )
476
- }
477
-
478
- #[ inline]
479
- pub fn generator_kind ( & self ) -> Option < GeneratorKind > {
480
- self . generator . as_ref ( ) . map ( |generator| generator. generator_kind )
444
+ pub fn yield_ty ( & self , tcx : TyCtxt < ' _ > ) -> Option < Ty < ' tcx > > {
445
+ if tcx. generator_kind ( self . source . def_id ( ) ) . is_none ( ) {
446
+ return None ;
447
+ } ;
448
+ let gen_ty = self . local_decls . raw [ 1 ] . ty ;
449
+ match * gen_ty. kind ( ) {
450
+ ty:: Generator ( _, substs, _) => Some ( substs. as_generator ( ) . sig ( ) . yield_ty ) ,
451
+ _ => None ,
452
+ }
481
453
}
482
454
}
483
455
0 commit comments