@@ -203,18 +203,11 @@ impl<'tcx> MirSource<'tcx> {
203
203
204
204
#[ derive( Clone , TyEncodable , TyDecodable , Debug , HashStable , TypeFoldable , TypeVisitable ) ]
205
205
pub struct GeneratorInfo < ' tcx > {
206
- /// The yield type of the function, if it is a generator.
207
- pub yield_ty : Option < Ty < ' tcx > > ,
208
-
209
206
/// Generator drop glue.
210
- pub generator_drop : Option < Body < ' tcx > > ,
207
+ pub generator_drop : Body < ' tcx > ,
211
208
212
209
/// The layout of a generator. Produced by the state transformation.
213
- pub generator_layout : Option < GeneratorLayout < ' tcx > > ,
214
-
215
- /// If this is a generator then record the type of source expression that caused this generator
216
- /// to be created.
217
- pub generator_kind : GeneratorKind ,
210
+ pub generator_layout : GeneratorLayout < ' tcx > ,
218
211
}
219
212
220
213
/// The lowered representation of a single function.
@@ -240,8 +233,6 @@ pub struct Body<'tcx> {
240
233
/// and used for debuginfo. Indexed by a `SourceScope`.
241
234
pub source_scopes : IndexVec < SourceScope , SourceScopeData < ' tcx > > ,
242
235
243
- pub generator : Option < Box < GeneratorInfo < ' tcx > > > ,
244
-
245
236
/// Declarations of locals.
246
237
///
247
238
/// The first local is the return value pointer, followed by `arg_count`
@@ -306,7 +297,6 @@ impl<'tcx> Body<'tcx> {
306
297
arg_count : usize ,
307
298
var_debug_info : Vec < VarDebugInfo < ' tcx > > ,
308
299
span : Span ,
309
- generator_kind : Option < GeneratorKind > ,
310
300
tainted_by_errors : Option < ErrorGuaranteed > ,
311
301
) -> Self {
312
302
// We need `arg_count` locals, and one for the return place.
@@ -323,14 +313,6 @@ impl<'tcx> Body<'tcx> {
323
313
source,
324
314
basic_blocks : BasicBlocks :: new ( basic_blocks) ,
325
315
source_scopes,
326
- generator : generator_kind. map ( |generator_kind| {
327
- Box :: new ( GeneratorInfo {
328
- yield_ty : None ,
329
- generator_drop : None ,
330
- generator_layout : None ,
331
- generator_kind,
332
- } )
333
- } ) ,
334
316
local_decls,
335
317
user_type_annotations,
336
318
arg_count,
@@ -357,7 +339,6 @@ impl<'tcx> Body<'tcx> {
357
339
source : MirSource :: item ( CRATE_DEF_ID . to_def_id ( ) ) ,
358
340
basic_blocks : BasicBlocks :: new ( basic_blocks) ,
359
341
source_scopes : IndexVec :: new ( ) ,
360
- generator : None ,
361
342
local_decls : IndexVec :: new ( ) ,
362
343
user_type_annotations : IndexVec :: new ( ) ,
363
344
arg_count : 0 ,
@@ -489,24 +470,15 @@ impl<'tcx> Body<'tcx> {
489
470
. unwrap_or_else ( || Either :: Right ( block_data. terminator ( ) ) )
490
471
}
491
472
492
- #[ inline]
493
- pub fn yield_ty ( & self ) -> Option < Ty < ' tcx > > {
494
- self . generator . as_ref ( ) . and_then ( |generator| generator. yield_ty )
495
- }
496
-
497
- #[ inline]
498
- pub fn generator_layout ( & self ) -> Option < & GeneratorLayout < ' tcx > > {
499
- self . generator . as_ref ( ) . and_then ( |generator| generator. generator_layout . as_ref ( ) )
500
- }
501
-
502
- #[ inline]
503
- pub fn generator_drop ( & self ) -> Option < & Body < ' tcx > > {
504
- self . generator . as_ref ( ) . and_then ( |generator| generator. generator_drop . as_ref ( ) )
505
- }
506
-
507
- #[ inline]
508
- pub fn generator_kind ( & self ) -> Option < GeneratorKind > {
509
- self . generator . as_ref ( ) . map ( |generator| generator. generator_kind )
473
+ pub fn yield_ty ( & self , tcx : TyCtxt < ' _ > ) -> Option < Ty < ' tcx > > {
474
+ if tcx. generator_kind ( self . source . def_id ( ) ) . is_none ( ) {
475
+ return None ;
476
+ } ;
477
+ let gen_ty = self . local_decls . raw [ 1 ] . ty ;
478
+ match * gen_ty. kind ( ) {
479
+ ty:: Generator ( _, substs, _) => Some ( substs. as_generator ( ) . sig ( ) . yield_ty ) ,
480
+ _ => None ,
481
+ }
510
482
}
511
483
}
512
484
0 commit comments