Skip to content

Commit 020d7af

Browse files
authored
Rollup merge of #105082 - Swatinem:async-abi, r=compiler-errors
Fix Async Generator ABI This change was missed when making async generators implement `Future` directly. It did not cause any problems in codegen so far, as `GeneratorState<(), Output>` happens to have the same ABI as `Poll<Output>`.
2 parents eb1159c + ecf8127 commit 020d7af

File tree

1 file changed

+17
-5
lines changed
  • compiler/rustc_ty_utils/src

1 file changed

+17
-5
lines changed

compiler/rustc_ty_utils/src/abi.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn fn_sig_for_fn_abi<'tcx>(
8585
bound_vars,
8686
)
8787
}
88-
ty::Generator(_, substs, _) => {
88+
ty::Generator(did, substs, _) => {
8989
let sig = substs.as_generator().poly_sig();
9090

9191
let bound_vars = tcx.mk_bound_variable_kinds(
@@ -104,10 +104,22 @@ fn fn_sig_for_fn_abi<'tcx>(
104104
let env_ty = tcx.mk_adt(pin_adt_ref, pin_substs);
105105

106106
let sig = sig.skip_binder();
107-
let state_did = tcx.require_lang_item(LangItem::GeneratorState, None);
108-
let state_adt_ref = tcx.adt_def(state_did);
109-
let state_substs = tcx.intern_substs(&[sig.yield_ty.into(), sig.return_ty.into()]);
110-
let ret_ty = tcx.mk_adt(state_adt_ref, state_substs);
107+
// The `FnSig` and the `ret_ty` here is for a generators main
108+
// `Generator::resume(...) -> GeneratorState` function in case we
109+
// have an ordinary generator, or the `Future::poll(...) -> Poll`
110+
// function in case this is a special generator backing an async construct.
111+
let ret_ty = if tcx.generator_is_async(did) {
112+
let state_did = tcx.require_lang_item(LangItem::Poll, None);
113+
let state_adt_ref = tcx.adt_def(state_did);
114+
let state_substs = tcx.intern_substs(&[sig.return_ty.into()]);
115+
tcx.mk_adt(state_adt_ref, state_substs)
116+
} else {
117+
let state_did = tcx.require_lang_item(LangItem::GeneratorState, None);
118+
let state_adt_ref = tcx.adt_def(state_did);
119+
let state_substs = tcx.intern_substs(&[sig.yield_ty.into(), sig.return_ty.into()]);
120+
tcx.mk_adt(state_adt_ref, state_substs)
121+
};
122+
111123
ty::Binder::bind_with_vars(
112124
tcx.mk_fn_sig(
113125
[env_ty, sig.resume_ty].iter(),

0 commit comments

Comments
 (0)