@@ -352,11 +352,31 @@ pub struct CoroutineClosureArgs<'tcx> {
352
352
}
353
353
354
354
pub struct CoroutineClosureArgsParts < ' tcx > {
355
+ /// This is the args of the typeck root.
355
356
pub parent_args : & ' tcx [ GenericArg < ' tcx > ] ,
357
+ /// Represents the maximum calling capability of the closure.
356
358
pub closure_kind_ty : Ty < ' tcx > ,
359
+ /// Represents all of the relevant parts of the coroutine returned by this
360
+ /// coroutine-closure. This signature parts type will have the general
361
+ /// shape of `fn(tupled_inputs, resume_ty) -> (return_ty, yield_ty)`, where
362
+ /// `resume_ty`, `return_ty`, and `yield_ty` are the respective types for the
363
+ /// coroutine returned by the coroutine-closure.
364
+ ///
365
+ /// Use `coroutine_closure_sig` to break up this type rather than using it
366
+ /// yourself.
357
367
pub signature_parts_ty : Ty < ' tcx > ,
368
+ /// The upvars captured by the closure. Remains an inference variable
369
+ /// until the upvar analysis, which happens late in HIR typeck.
358
370
pub tupled_upvars_ty : Ty < ' tcx > ,
371
+ /// a function pointer that has the shape `for<'env> fn() -> (&'env T, ...)`.
372
+ /// This allows us to represent the binder of the self-captures of the closure.
373
+ ///
374
+ /// For example, if the coroutine returned by the closure borrows `String`
375
+ /// from the closure's upvars, this will be `for<'env> fn() -> (&'env String,)`,
376
+ /// while the `tupled_upvars_ty`, representing the by-move version of the same
377
+ /// captures, will be `(String,)`.
359
378
pub coroutine_captures_by_ref_ty : Ty < ' tcx > ,
379
+ /// Witness type returned by the generator produced by this coroutine-closure.
360
380
pub coroutine_witness_ty : Ty < ' tcx > ,
361
381
}
362
382
@@ -572,15 +592,27 @@ pub struct CoroutineArgs<'tcx> {
572
592
pub struct CoroutineArgsParts < ' tcx > {
573
593
/// This is the args of the typeck root.
574
594
pub parent_args : & ' tcx [ GenericArg < ' tcx > ] ,
575
- // TODO: why
595
+
596
+ /// The coroutines returned by a coroutine-closure's `AsyncFnOnce`/`AsyncFnMut`
597
+ /// implementations must be distinguished since the former takes the closure's
598
+ /// upvars by move, and the latter takes the closure's upvars by ref.
599
+ ///
600
+ /// This field distinguishes these fields so that codegen can select the right
601
+ /// body for the coroutine. This has the same type representation as the closure
602
+ /// kind: `i8`/`i16`/`i32`.
603
+ ///
604
+ /// For regular coroutines, this field will always just be `()`.
576
605
pub kind_ty : Ty < ' tcx > ,
606
+
577
607
pub resume_ty : Ty < ' tcx > ,
578
608
pub yield_ty : Ty < ' tcx > ,
579
609
pub return_ty : Ty < ' tcx > ,
610
+
580
611
/// The interior type of the coroutine.
581
612
/// Represents all types that are stored in locals
582
613
/// in the coroutine's body.
583
614
pub witness : Ty < ' tcx > ,
615
+
584
616
/// The upvars captured by the closure. Remains an inference variable
585
617
/// until the upvar analysis, which happens late in HIR typeck.
586
618
pub tupled_upvars_ty : Ty < ' tcx > ,
@@ -632,7 +664,7 @@ impl<'tcx> CoroutineArgs<'tcx> {
632
664
self . split ( ) . parent_args
633
665
}
634
666
635
- // TODO:
667
+ // Returns the kind of the coroutine. See docs on the `kind_ty` field.
636
668
pub fn kind_ty ( self ) -> Ty < ' tcx > {
637
669
self . split ( ) . kind_ty
638
670
}
0 commit comments