Implement async gen blocks
This commit is contained in:
@@ -119,9 +119,9 @@ fn fn_sig_for_fn_abi<'tcx>(
|
||||
// unlike for all other coroutine kinds.
|
||||
env_ty
|
||||
}
|
||||
hir::CoroutineKind::Async(_) | hir::CoroutineKind::Coroutine => {
|
||||
Ty::new_adt(tcx, pin_adt_ref, pin_args)
|
||||
}
|
||||
hir::CoroutineKind::Async(_)
|
||||
| hir::CoroutineKind::AsyncGen(_)
|
||||
| hir::CoroutineKind::Coroutine => Ty::new_adt(tcx, pin_adt_ref, pin_args),
|
||||
};
|
||||
|
||||
// The `FnSig` and the `ret_ty` here is for a coroutines main
|
||||
@@ -168,6 +168,30 @@ fn fn_sig_for_fn_abi<'tcx>(
|
||||
|
||||
(None, ret_ty)
|
||||
}
|
||||
hir::CoroutineKind::AsyncGen(_) => {
|
||||
// The signature should be
|
||||
// `AsyncIterator::poll_next(_, &mut Context<'_>) -> Poll<Option<Output>>`
|
||||
assert_eq!(sig.return_ty, tcx.types.unit);
|
||||
|
||||
// Yield type is already `Poll<Option<yield_ty>>`
|
||||
let ret_ty = sig.yield_ty;
|
||||
|
||||
// We have to replace the `ResumeTy` that is used for type and borrow checking
|
||||
// with `&mut Context<'_>` which is used in codegen.
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
if let ty::Adt(resume_ty_adt, _) = sig.resume_ty.kind() {
|
||||
let expected_adt =
|
||||
tcx.adt_def(tcx.require_lang_item(LangItem::ResumeTy, None));
|
||||
assert_eq!(*resume_ty_adt, expected_adt);
|
||||
} else {
|
||||
panic!("expected `ResumeTy`, found `{:?}`", sig.resume_ty);
|
||||
};
|
||||
}
|
||||
let context_mut_ref = Ty::new_task_context(tcx);
|
||||
|
||||
(Some(context_mut_ref), ret_ty)
|
||||
}
|
||||
hir::CoroutineKind::Coroutine => {
|
||||
// The signature should be `Coroutine::resume(_, Resume) -> CoroutineState<Yield, Return>`
|
||||
let state_did = tcx.require_lang_item(LangItem::CoroutineState, None);
|
||||
|
||||
Reference in New Issue
Block a user