1
Fork 0

Stop using a special inner body for the coroutine by-move body for async closures

This commit is contained in:
Michael Goulet 2024-08-01 13:05:17 -04:00
parent 515395af0e
commit 4609841c07
40 changed files with 295 additions and 315 deletions

View file

@ -169,39 +169,6 @@ fn fn_sig_for_fn_abi<'tcx>(
kind: ty::BoundRegionKind::BrEnv,
};
let mut ty = ty;
// When this `Closure` comes from a `CoroutineKindShim`,
// make sure we respect the `target_kind` in that shim.
// FIXME(async_closures): This shouldn't be needed, and we should be populating
// a separate def-id for these bodies.
if let InstanceKind::CoroutineKindShim { .. } = instance.def {
// Grab the parent coroutine-closure. It has the same args for the purposes
// of instantiation, so this will be okay to do.
let ty::CoroutineClosure(_, coroutine_closure_args) = *tcx
.instantiate_and_normalize_erasing_regions(
args,
param_env,
tcx.type_of(tcx.parent(did)),
)
.kind()
else {
bug!("CoroutineKindShim comes from calling a coroutine-closure");
};
let coroutine_closure_args = coroutine_closure_args.as_coroutine_closure();
ty = tcx.instantiate_bound_regions_with_erased(
coroutine_closure_args.coroutine_closure_sig().map_bound(|sig| {
sig.to_coroutine_given_kind_and_upvars(
tcx,
coroutine_closure_args.parent_args(),
did,
ty::ClosureKind::FnOnce,
tcx.lifetimes.re_erased,
coroutine_closure_args.tupled_upvars_ty(),
coroutine_closure_args.coroutine_captures_by_ref_ty(),
)
}),
);
}
let env_ty = Ty::new_mut_ref(tcx, ty::Region::new_bound(tcx, ty::INNERMOST, br), ty);
let pin_did = tcx.require_lang_item(LangItem::Pin, None);

View file

@ -144,7 +144,8 @@ fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx [(Ty<'
| DefKind::Field
| DefKind::LifetimeParam
| DefKind::GlobalAsm
| DefKind::Closure => ty::List::empty(),
| DefKind::Closure
| DefKind::SyntheticCoroutineBody => ty::List::empty(),
}
}

View file

@ -348,7 +348,8 @@ fn opaque_types_defined_by<'tcx>(
| DefKind::Field
| DefKind::LifetimeParam
| DefKind::GlobalAsm
| DefKind::Impl { .. } => {}
| DefKind::Impl { .. }
| DefKind::SyntheticCoroutineBody => {}
// Closures and coroutines are type checked with their parent, so we need to allow all
// opaques from the closure signature *and* from the parent body.
DefKind::Closure | DefKind::InlineConst => {

View file

@ -87,7 +87,7 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
// These are not part of a public API, they can only appear as hidden types, and there
// the interesting parts are solely in the signature of the containing item's opaque type
// or dyn type.
DefKind::InlineConst | DefKind::Closure => {}
DefKind::InlineConst | DefKind::Closure | DefKind::SyntheticCoroutineBody => {}
DefKind::Impl { of_trait } => {
if of_trait {
let span = tcx.hir_node_by_def_id(item).expect_item().expect_impl().of_trait.unwrap().path.span;