Skip to content

Commit 881b6b5

Browse files
Bless tests, add comments
1 parent 427896d commit 881b6b5

File tree

28 files changed

+201
-126
lines changed

28 files changed

+201
-126
lines changed

compiler/rustc_borrowck/src/type_check/input_output.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
4747
user_provided_sig,
4848
);
4949

50-
// FIXME(async_closures): We must apply the same transformation to our
51-
// signature here as we do during closure checking.
50+
// FIXME(async_closures): It's kind of wacky that we must apply this
51+
// transformation here, since we do the same thing in HIR typeck.
52+
// Maybe we could just fix up the canonicalized signature during HIR typeck?
5253
if let DefiningTy::CoroutineClosure(_, args) =
5354
self.borrowck_context.universal_regions.defining_ty
5455
{

compiler/rustc_borrowck/src/universal_regions.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ pub enum DefiningTy<'tcx> {
9898
Coroutine(DefId, GenericArgsRef<'tcx>),
9999

100100
/// The MIR is a special kind of closure that returns coroutines.
101-
/// TODO: describe how to make the sig...
101+
///
102+
/// See the documentation on `CoroutineClosureSignature` for details
103+
/// on how to construct the callable signature of the coroutine from
104+
/// its args.
102105
CoroutineClosure(DefId, GenericArgsRef<'tcx>),
103106

104107
/// The MIR is a fn item with the given `DefId` and args. The signature

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
335335
continue;
336336
}
337337

338-
// For this check, we do *not* want to treat async coroutine closures (async blocks)
338+
// For this check, we do *not* want to treat async coroutine-closures (async blocks)
339339
// as proper closures. Doing so would regress type inference when feeding
340340
// the return value of an argument-position async block to an argument-position
341341
// closure wrapped in a block.

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,16 @@ pub struct CoroutineInfo<'tcx> {
262262
/// Coroutine drop glue. This field is populated after the state transform pass.
263263
pub coroutine_drop: Option<Body<'tcx>>,
264264

265-
/// The body of the coroutine, modified to take its upvars by move.
266-
/// TODO:
265+
/// The body of the coroutine, modified to take its upvars by move rather than by ref.
266+
///
267+
/// This is used by coroutine-closures, which must return a different flavor of coroutine
268+
/// when called using `AsyncFnOnce::call_once`. It is produced by the `ByMoveBody` which
269+
/// is run right after building the initial MIR, and will only be populated for coroutines
270+
/// which come out of the async closure desugaring.
271+
///
272+
/// This body should be processed in lockstep with the containing body -- any optimization
273+
/// passes, etc, should be applied to this body as well. This is done automatically if
274+
/// using `run_passes`.
267275
pub by_move_body: Option<Body<'tcx>>,
268276

269277
/// The layout of a coroutine. This field is populated after the state transform pass.

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ rustc_queries! {
756756
}
757757

758758
query coroutine_for_closure(def_id: DefId) -> DefId {
759-
desc { |_tcx| "TODO" }
759+
desc { |_tcx| "Given a coroutine-closure def id, return the def id of the coroutine returned by it" }
760760
separate_provide_extern
761761
}
762762

compiler/rustc_middle/src/traits/select.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ pub enum SelectionCandidate<'tcx> {
138138
/// generated for an `async ||` expression.
139139
AsyncClosureCandidate,
140140

141-
// TODO:
141+
/// Implementation of the the `AsyncFnKindHelper` helper trait, which
142+
/// is used internally to delay computation for async closures until after
143+
/// upvar analysis is performed in HIR typeck.
142144
AsyncFnKindHelperCandidate,
143145

144146
/// Implementation of a `Coroutine` trait by one of the anonymous types

compiler/rustc_middle/src/ty/instance.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ pub enum InstanceDef<'tcx> {
101101
target_kind: ty::ClosureKind,
102102
},
103103

104-
/// TODO:
104+
/// `<[coroutine] as Future>::poll`, but for coroutines produced when `AsyncFnOnce`
105+
/// is called on a coroutine-closure whose closure kind is not `FnOnce`. This
106+
/// will select the body that is produced by the `ByMoveBody` transform, and thus
107+
/// take and use all of its upvars by-move rather than by-ref.
105108
CoroutineByMoveShim { coroutine_def_id: DefId },
106109

107110
/// Compiler-generated accessor for thread locals which returns a reference to the thread local

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
877877
ty::CoroutineClosure(did, args) => {
878878
p!(write("{{"));
879879
if !self.should_print_verbose() {
880-
p!(write("coroutine closure"));
880+
p!(write("coroutine-closure"));
881881
// FIXME(eddyb) should use `def_span`.
882882
if let Some(did) = did.as_local() {
883883
if self.tcx().sess.opts.unstable_opts.span_free_formats {

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,31 @@ pub struct CoroutineClosureArgs<'tcx> {
276276
}
277277

278278
pub struct CoroutineClosureArgsParts<'tcx> {
279+
/// This is the args of the typeck root.
279280
pub parent_args: &'tcx [GenericArg<'tcx>],
281+
/// Represents the maximum calling capability of the closure.
280282
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.
281291
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.
282294
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,)`.
283302
pub coroutine_captures_by_ref_ty: Ty<'tcx>,
303+
/// Witness type returned by the generator produced by this coroutine-closure.
284304
pub coroutine_witness_ty: Ty<'tcx>,
285305
}
286306

@@ -496,15 +516,27 @@ pub struct CoroutineArgs<'tcx> {
496516
pub struct CoroutineArgsParts<'tcx> {
497517
/// This is the args of the typeck root.
498518
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 `()`.
500529
pub kind_ty: Ty<'tcx>,
530+
501531
pub resume_ty: Ty<'tcx>,
502532
pub yield_ty: Ty<'tcx>,
503533
pub return_ty: Ty<'tcx>,
534+
504535
/// The interior type of the coroutine.
505536
/// Represents all types that are stored in locals
506537
/// in the coroutine's body.
507538
pub witness: Ty<'tcx>,
539+
508540
/// The upvars captured by the closure. Remains an inference variable
509541
/// until the upvar analysis, which happens late in HIR typeck.
510542
pub tupled_upvars_ty: Ty<'tcx>,
@@ -556,7 +588,7 @@ impl<'tcx> CoroutineArgs<'tcx> {
556588
self.split().parent_args
557589
}
558590

559-
// TODO:
591+
// Returns the kind of the coroutine. See docs on the `kind_ty` field.
560592
pub fn kind_ty(self) -> Ty<'tcx> {
561593
self.split().kind_ty
562594
}

compiler/rustc_smir/src/rustc_smir/convert/mir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ impl<'tcx> Stable<'tcx> for mir::AggregateKind<'tcx> {
539539
)
540540
}
541541
mir::AggregateKind::CoroutineClosure(..) => {
542-
todo!("FIXME(async_closure): Lower these to SMIR")
542+
todo!("FIXME(async_closures): Lower these to SMIR")
543543
}
544544
}
545545
}

0 commit comments

Comments
 (0)