@@ -146,6 +146,22 @@ impl<'tcx> MirSource<'tcx> {
146
146
}
147
147
}
148
148
149
+ #[ derive( Clone , TyEncodable , TyDecodable , Debug , HashStable , TypeFoldable ) ]
150
+ pub struct GeneratorInfo < ' tcx > {
151
+ /// The yield type of the function, if it is a generator.
152
+ pub yield_ty : Option < Ty < ' tcx > > ,
153
+
154
+ /// Generator drop glue.
155
+ pub generator_drop : Option < Body < ' tcx > > ,
156
+
157
+ /// The layout of a generator. Produced by the state transformation.
158
+ pub generator_layout : Option < GeneratorLayout < ' tcx > > ,
159
+
160
+ /// If this is a generator then record the type of source expression that caused this generator
161
+ /// to be created.
162
+ pub generator_kind : GeneratorKind ,
163
+ }
164
+
149
165
/// The lowered representation of a single function.
150
166
#[ derive( Clone , TyEncodable , TyDecodable , Debug , HashStable , TypeFoldable ) ]
151
167
pub struct Body < ' tcx > {
@@ -166,18 +182,7 @@ pub struct Body<'tcx> {
166
182
/// and used for debuginfo. Indexed by a `SourceScope`.
167
183
pub source_scopes : IndexVec < SourceScope , SourceScopeData < ' tcx > > ,
168
184
169
- /// The yield type of the function, if it is a generator.
170
- pub yield_ty : Option < Ty < ' tcx > > ,
171
-
172
- /// Generator drop glue.
173
- pub generator_drop : Option < Box < Body < ' tcx > > > ,
174
-
175
- /// The layout of a generator. Produced by the state transformation.
176
- pub generator_layout : Option < GeneratorLayout < ' tcx > > ,
177
-
178
- /// If this is a generator then record the type of source expression that caused this generator
179
- /// to be created.
180
- pub generator_kind : Option < GeneratorKind > ,
185
+ pub generator : Option < Box < GeneratorInfo < ' tcx > > > ,
181
186
182
187
/// Declarations of locals.
183
188
///
@@ -259,10 +264,14 @@ impl<'tcx> Body<'tcx> {
259
264
source,
260
265
basic_blocks,
261
266
source_scopes,
262
- yield_ty : None ,
263
- generator_drop : None ,
264
- generator_layout : None ,
265
- generator_kind,
267
+ generator : generator_kind. map ( |generator_kind| {
268
+ Box :: new ( GeneratorInfo {
269
+ yield_ty : None ,
270
+ generator_drop : None ,
271
+ generator_layout : None ,
272
+ generator_kind,
273
+ } )
274
+ } ) ,
266
275
local_decls,
267
276
user_type_annotations,
268
277
arg_count,
@@ -289,16 +298,13 @@ impl<'tcx> Body<'tcx> {
289
298
source : MirSource :: item ( DefId :: local ( CRATE_DEF_INDEX ) ) ,
290
299
basic_blocks,
291
300
source_scopes : IndexVec :: new ( ) ,
292
- yield_ty : None ,
293
- generator_drop : None ,
294
- generator_layout : None ,
301
+ generator : None ,
295
302
local_decls : IndexVec :: new ( ) ,
296
303
user_type_annotations : IndexVec :: new ( ) ,
297
304
arg_count : 0 ,
298
305
spread_arg : None ,
299
306
span : DUMMY_SP ,
300
307
required_consts : Vec :: new ( ) ,
301
- generator_kind : None ,
302
308
var_debug_info : Vec :: new ( ) ,
303
309
is_polymorphic : false ,
304
310
predecessor_cache : PredecessorCache :: new ( ) ,
@@ -480,6 +486,26 @@ impl<'tcx> Body<'tcx> {
480
486
pub fn dominators ( & self ) -> Dominators < BasicBlock > {
481
487
dominators ( self )
482
488
}
489
+
490
+ #[ inline]
491
+ pub fn yield_ty ( & self ) -> Option < Ty < ' tcx > > {
492
+ self . generator . as_ref ( ) . and_then ( |generator| generator. yield_ty )
493
+ }
494
+
495
+ #[ inline]
496
+ pub fn generator_layout ( & self ) -> Option < & GeneratorLayout < ' tcx > > {
497
+ self . generator . as_ref ( ) . and_then ( |generator| generator. generator_layout . as_ref ( ) )
498
+ }
499
+
500
+ #[ inline]
501
+ pub fn generator_drop ( & self ) -> Option < & Body < ' tcx > > {
502
+ self . generator . as_ref ( ) . and_then ( |generator| generator. generator_drop . as_ref ( ) )
503
+ }
504
+
505
+ #[ inline]
506
+ pub fn generator_kind ( & self ) -> Option < GeneratorKind > {
507
+ self . generator . as_ref ( ) . map ( |generator| generator. generator_kind )
508
+ }
483
509
}
484
510
485
511
#[ derive( Copy , Clone , PartialEq , Eq , Debug , TyEncodable , TyDecodable , HashStable ) ]
0 commit comments