1
Fork 0

Bless tests, add comments

This commit is contained in:
Michael Goulet 2024-01-25 03:50:23 +00:00
parent 427896dd7e
commit 881b6b5149
28 changed files with 202 additions and 127 deletions

View file

@ -262,8 +262,16 @@ pub struct CoroutineInfo<'tcx> {
/// Coroutine drop glue. This field is populated after the state transform pass.
pub coroutine_drop: Option<Body<'tcx>>,
/// The body of the coroutine, modified to take its upvars by move.
/// TODO:
/// The body of the coroutine, modified to take its upvars by move rather than by ref.
///
/// This is used by coroutine-closures, which must return a different flavor of coroutine
/// when called using `AsyncFnOnce::call_once`. It is produced by the `ByMoveBody` which
/// is run right after building the initial MIR, and will only be populated for coroutines
/// which come out of the async closure desugaring.
///
/// This body should be processed in lockstep with the containing body -- any optimization
/// passes, etc, should be applied to this body as well. This is done automatically if
/// using `run_passes`.
pub by_move_body: Option<Body<'tcx>>,
/// The layout of a coroutine. This field is populated after the state transform pass.

View file

@ -756,7 +756,7 @@ rustc_queries! {
}
query coroutine_for_closure(def_id: DefId) -> DefId {
desc { |_tcx| "TODO" }
desc { |_tcx| "Given a coroutine-closure def id, return the def id of the coroutine returned by it" }
separate_provide_extern
}

View file

@ -138,7 +138,9 @@ pub enum SelectionCandidate<'tcx> {
/// generated for an `async ||` expression.
AsyncClosureCandidate,
// TODO:
/// Implementation of the the `AsyncFnKindHelper` helper trait, which
/// is used internally to delay computation for async closures until after
/// upvar analysis is performed in HIR typeck.
AsyncFnKindHelperCandidate,
/// Implementation of a `Coroutine` trait by one of the anonymous types

View file

@ -101,7 +101,10 @@ pub enum InstanceDef<'tcx> {
target_kind: ty::ClosureKind,
},
/// TODO:
/// `<[coroutine] as Future>::poll`, but for coroutines produced when `AsyncFnOnce`
/// is called on a coroutine-closure whose closure kind is not `FnOnce`. This
/// will select the body that is produced by the `ByMoveBody` transform, and thus
/// take and use all of its upvars by-move rather than by-ref.
CoroutineByMoveShim { coroutine_def_id: DefId },
/// Compiler-generated accessor for thread locals which returns a reference to the thread local

View file

@ -877,7 +877,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
ty::CoroutineClosure(did, args) => {
p!(write("{{"));
if !self.should_print_verbose() {
p!(write("coroutine closure"));
p!(write("coroutine-closure"));
// FIXME(eddyb) should use `def_span`.
if let Some(did) = did.as_local() {
if self.tcx().sess.opts.unstable_opts.span_free_formats {

View file

@ -276,11 +276,31 @@ pub struct CoroutineClosureArgs<'tcx> {
}
pub struct CoroutineClosureArgsParts<'tcx> {
/// This is the args of the typeck root.
pub parent_args: &'tcx [GenericArg<'tcx>],
/// Represents the maximum calling capability of the closure.
pub closure_kind_ty: Ty<'tcx>,
/// Represents all of the relevant parts of the coroutine returned by this
/// coroutine-closure. This signature parts type will have the general
/// shape of `fn(tupled_inputs, resume_ty) -> (return_ty, yield_ty)`, where
/// `resume_ty`, `return_ty`, and `yield_ty` are the respective types for the
/// coroutine returned by the coroutine-closure.
///
/// Use `coroutine_closure_sig` to break up this type rather than using it
/// yourself.
pub signature_parts_ty: Ty<'tcx>,
/// The upvars captured by the closure. Remains an inference variable
/// until the upvar analysis, which happens late in HIR typeck.
pub tupled_upvars_ty: Ty<'tcx>,
/// a function pointer that has the shape `for<'env> fn() -> (&'env T, ...)`.
/// This allows us to represent the binder of the self-captures of the closure.
///
/// For example, if the coroutine returned by the closure borrows `String`
/// from the closure's upvars, this will be `for<'env> fn() -> (&'env String,)`,
/// while the `tupled_upvars_ty`, representing the by-move version of the same
/// captures, will be `(String,)`.
pub coroutine_captures_by_ref_ty: Ty<'tcx>,
/// Witness type returned by the generator produced by this coroutine-closure.
pub coroutine_witness_ty: Ty<'tcx>,
}
@ -496,15 +516,27 @@ pub struct CoroutineArgs<'tcx> {
pub struct CoroutineArgsParts<'tcx> {
/// This is the args of the typeck root.
pub parent_args: &'tcx [GenericArg<'tcx>],
// TODO: why
/// The coroutines returned by a coroutine-closure's `AsyncFnOnce`/`AsyncFnMut`
/// implementations must be distinguished since the former takes the closure's
/// upvars by move, and the latter takes the closure's upvars by ref.
///
/// This field distinguishes these fields so that codegen can select the right
/// body for the coroutine. This has the same type representation as the closure
/// kind: `i8`/`i16`/`i32`.
///
/// For regular coroutines, this field will always just be `()`.
pub kind_ty: Ty<'tcx>,
pub resume_ty: Ty<'tcx>,
pub yield_ty: Ty<'tcx>,
pub return_ty: Ty<'tcx>,
/// The interior type of the coroutine.
/// Represents all types that are stored in locals
/// in the coroutine's body.
pub witness: Ty<'tcx>,
/// The upvars captured by the closure. Remains an inference variable
/// until the upvar analysis, which happens late in HIR typeck.
pub tupled_upvars_ty: Ty<'tcx>,
@ -556,7 +588,7 @@ impl<'tcx> CoroutineArgs<'tcx> {
self.split().parent_args
}
// TODO:
// Returns the kind of the coroutine. See docs on the `kind_ty` field.
pub fn kind_ty(self) -> Ty<'tcx> {
self.split().kind_ty
}