Movability doesn't need to be a query anymore

This commit is contained in:
Michael Goulet 2023-12-26 22:43:11 +00:00
parent 15ccf2e7bd
commit e24da8ea19
21 changed files with 29 additions and 56 deletions

View file

@ -1565,7 +1565,7 @@ pub(crate) fn mir_coroutine_witnesses<'tcx>(
let coroutine_ty = body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty;
let movable = match *coroutine_ty.kind() {
ty::Coroutine(def_id, _) => tcx.movability(def_id) == hir::Movability::Movable,
ty::Coroutine(def_id, _) => tcx.coroutine_movability(def_id) == hir::Movability::Movable,
ty::Error(_) => return None,
_ => span_bug!(body.span, "unexpected coroutine type {}", coroutine_ty),
};
@ -1597,12 +1597,13 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
// The first argument is the coroutine type passed by value
let coroutine_ty = body.local_decls.raw[1].ty;
let coroutine_kind = body.coroutine_kind().unwrap();
// Get the discriminant type and args which typeck computed
let (discr_ty, movable) = match *coroutine_ty.kind() {
ty::Coroutine(def_id, args) => {
ty::Coroutine(_, args) => {
let args = args.as_coroutine();
(args.discr_ty(tcx), tcx.movability(def_id) == hir::Movability::Movable)
(args.discr_ty(tcx), coroutine_kind.movability() == hir::Movability::Movable)
}
_ => {
tcx.dcx().span_delayed_bug(
@ -1613,19 +1614,13 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
}
};
let is_async_kind = matches!(
body.coroutine_kind(),
Some(CoroutineKind::Desugared(CoroutineDesugaring::Async, _))
);
let is_async_gen_kind = matches!(
body.coroutine_kind(),
Some(CoroutineKind::Desugared(CoroutineDesugaring::AsyncGen, _))
);
let is_gen_kind = matches!(
body.coroutine_kind(),
Some(CoroutineKind::Desugared(CoroutineDesugaring::Gen, _))
);
let new_ret_ty = match body.coroutine_kind().unwrap() {
let is_async_kind =
matches!(coroutine_kind, CoroutineKind::Desugared(CoroutineDesugaring::Async, _));
let is_async_gen_kind =
matches!(coroutine_kind, CoroutineKind::Desugared(CoroutineDesugaring::AsyncGen, _));
let is_gen_kind =
matches!(coroutine_kind, CoroutineKind::Desugared(CoroutineDesugaring::Gen, _));
let new_ret_ty = match coroutine_kind {
CoroutineKind::Desugared(CoroutineDesugaring::Async, _) => {
// Compute Poll<return_ty>
let poll_did = tcx.require_lang_item(LangItem::Poll, None);

View file

@ -395,7 +395,7 @@ fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) -
ty::Closure(_, args) => builder.tuple_like_shim(dest, src, args.as_closure().upvar_tys()),
ty::Tuple(..) => builder.tuple_like_shim(dest, src, self_ty.tuple_fields()),
ty::Coroutine(coroutine_def_id, args) => {
assert_eq!(tcx.movability(coroutine_def_id), hir::Movability::Movable);
assert_eq!(tcx.coroutine_movability(*coroutine_def_id), hir::Movability::Movable);
builder.coroutine_shim(dest, src, *coroutine_def_id, args.as_coroutine())
}
_ => bug!("clone shim for `{:?}` which is not `Copy` and is not an aggregate", self_ty),