@@ -276,11 +276,31 @@ pub struct CoroutineClosureArgs<'tcx> {
276
276
}
277
277
278
278
pub struct CoroutineClosureArgsParts < ' tcx > {
279
+ /// This is the args of the typeck root.
279
280
pub parent_args : & ' tcx [ GenericArg < ' tcx > ] ,
281
+ /// Represents the maximum calling capability of the closure.
280
282
pub closure_kind_ty : Ty < ' tcx > ,
283
+ /// Represents all of the relevant parts of the coroutine returned by this
284
+ /// coroutine-closure. This signature parts type will have the general
285
+ /// shape of `fn(tupled_inputs, resume_ty) -> (return_ty, yield_ty)`, where
286
+ /// `resume_ty`, `return_ty`, and `yield_ty` are the respective types for the
287
+ /// coroutine returned by the coroutine-closure.
288
+ ///
289
+ /// Use `coroutine_closure_sig` to break up this type rather than using it
290
+ /// yourself.
281
291
pub signature_parts_ty : Ty < ' tcx > ,
292
+ /// The upvars captured by the closure. Remains an inference variable
293
+ /// until the upvar analysis, which happens late in HIR typeck.
282
294
pub tupled_upvars_ty : Ty < ' tcx > ,
295
+ /// a function pointer that has the shape `for<'env> fn() -> (&'env T, ...)`.
296
+ /// This allows us to represent the binder of the self-captures of the closure.
297
+ ///
298
+ /// For example, if the coroutine returned by the closure borrows `String`
299
+ /// from the closure's upvars, this will be `for<'env> fn() -> (&'env String,)`,
300
+ /// while the `tupled_upvars_ty`, representing the by-move version of the same
301
+ /// captures, will be `(String,)`.
283
302
pub coroutine_captures_by_ref_ty : Ty < ' tcx > ,
303
+ /// Witness type returned by the generator produced by this coroutine-closure.
284
304
pub coroutine_witness_ty : Ty < ' tcx > ,
285
305
}
286
306
@@ -496,15 +516,27 @@ pub struct CoroutineArgs<'tcx> {
496
516
pub struct CoroutineArgsParts < ' tcx > {
497
517
/// This is the args of the typeck root.
498
518
pub parent_args : & ' tcx [ GenericArg < ' tcx > ] ,
499
- // TODO: why
519
+
520
+ /// The coroutines returned by a coroutine-closure's `AsyncFnOnce`/`AsyncFnMut`
521
+ /// implementations must be distinguished since the former takes the closure's
522
+ /// upvars by move, and the latter takes the closure's upvars by ref.
523
+ ///
524
+ /// This field distinguishes these fields so that codegen can select the right
525
+ /// body for the coroutine. This has the same type representation as the closure
526
+ /// kind: `i8`/`i16`/`i32`.
527
+ ///
528
+ /// For regular coroutines, this field will always just be `()`.
500
529
pub kind_ty : Ty < ' tcx > ,
530
+
501
531
pub resume_ty : Ty < ' tcx > ,
502
532
pub yield_ty : Ty < ' tcx > ,
503
533
pub return_ty : Ty < ' tcx > ,
534
+
504
535
/// The interior type of the coroutine.
505
536
/// Represents all types that are stored in locals
506
537
/// in the coroutine's body.
507
538
pub witness : Ty < ' tcx > ,
539
+
508
540
/// The upvars captured by the closure. Remains an inference variable
509
541
/// until the upvar analysis, which happens late in HIR typeck.
510
542
pub tupled_upvars_ty : Ty < ' tcx > ,
@@ -556,7 +588,7 @@ impl<'tcx> CoroutineArgs<'tcx> {
556
588
self . split ( ) . parent_args
557
589
}
558
590
559
- // TODO:
591
+ // Returns the kind of the coroutine. See docs on the `kind_ty` field.
560
592
pub fn kind_ty ( self ) -> Ty < ' tcx > {
561
593
self . split ( ) . kind_ty
562
594
}
0 commit comments