Record coroutine kind in generics

This commit is contained in:
Michael Goulet 2024-02-07 16:06:52 +00:00
parent d6c46a23ce
commit dcca9a12cd
3 changed files with 35 additions and 4 deletions

View File

@ -344,11 +344,18 @@ enum Defaults {
kind: hir::ExprKind::Closure(hir::Closure { kind, .. }), .. kind: hir::ExprKind::Closure(hir::Closure { kind, .. }), ..
}) = node }) = node
{ {
// See `ClosureArgsParts`, `CoroutineArgsParts`, and `CoroutineClosureArgsParts`
// for info on the usage of each of these fields.
let dummy_args = match kind { let dummy_args = match kind {
ClosureKind::Closure => &["<closure_kind>", "<closure_signature>", "<upvars>"][..], ClosureKind::Closure => &["<closure_kind>", "<closure_signature>", "<upvars>"][..],
ClosureKind::Coroutine(_) => { ClosureKind::Coroutine(_) => &[
&["<resume_ty>", "<yield_ty>", "<return_ty>", "<witness>", "<upvars>"][..] "<coroutine_kind>",
} "<resume_ty>",
"<yield_ty>",
"<return_ty>",
"<witness>",
"<upvars>",
][..],
ClosureKind::CoroutineClosure(_) => &[ ClosureKind::CoroutineClosure(_) => &[
"<closure_kind>", "<closure_kind>",
"<closure_signature_parts>", "<closure_signature_parts>",

View File

@ -765,7 +765,14 @@ fn polymorphize<'tcx>(
let def_id = instance.def_id(); let def_id = instance.def_id();
let upvars_ty = match tcx.type_of(def_id).skip_binder().kind() { let upvars_ty = match tcx.type_of(def_id).skip_binder().kind() {
ty::Closure(..) => Some(args.as_closure().tupled_upvars_ty()), ty::Closure(..) => Some(args.as_closure().tupled_upvars_ty()),
ty::Coroutine(..) => Some(args.as_coroutine().tupled_upvars_ty()), ty::Coroutine(..) => {
assert_eq!(
args.as_coroutine().kind_ty(),
tcx.types.unit,
"polymorphization does not support coroutines from async closures"
);
Some(args.as_coroutine().tupled_upvars_ty())
}
_ => None, _ => None,
}; };
let has_upvars = upvars_ty.is_some_and(|ty| !ty.tuple_fields().is_empty()); let has_upvars = upvars_ty.is_some_and(|ty| !ty.tuple_fields().is_empty());

View File

@ -0,0 +1,17 @@
// compile-flags: -Zpolymorphize=on
// build-pass
#![feature(coroutines, coroutine_trait)]
use std::ops::Coroutine;
use std::pin::Pin;
use std::thread;
fn main() {
let mut foo = || yield;
thread::spawn(move || match Pin::new(&mut foo).resume(()) {
s => panic!("bad state: {:?}", s),
})
.join()
.unwrap();
}