Skip to content

Commit 0648920

Browse files
update the layout calculator to use relocated upvar info
1 parent b8dfe07 commit 0648920

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

compiler/rustc_ty_utils/src/layout.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_abi::{
99
use rustc_hashes::Hash64;
1010
use rustc_index::IndexVec;
1111
use rustc_middle::bug;
12+
use rustc_middle::mir::CoroutineSavedLocal;
1213
use rustc_middle::query::Providers;
1314
use rustc_middle::ty::layout::{
1415
FloatExt, HasTyCtxt, IntegerExt, LayoutCx, LayoutError, LayoutOf, TyAndLayout,
@@ -410,28 +411,25 @@ fn layout_of_uncached<'tcx>(
410411
return Err(error(cx, LayoutError::Unknown(ty)));
411412
};
412413

413-
let local_layouts = info
414+
let local_layouts: IndexVec<_, _> = info
414415
.field_tys
415416
.iter()
416417
.map(|local| {
417418
let field_ty = EarlyBinder::bind(local.ty);
418419
let uninit_ty = Ty::new_maybe_uninit(tcx, field_ty.instantiate(tcx, args));
419420
cx.spanned_layout_of(uninit_ty, local.source_info.span)
420421
})
421-
.try_collect::<IndexVec<_, _>>()?;
422-
423-
let prefix_layouts = args
424-
.as_coroutine()
425-
.prefix_tys()
426-
.iter()
427-
.map(|ty| cx.layout_of(ty))
428-
.try_collect::<IndexVec<_, _>>()?;
422+
.try_collect()?;
429423

424+
let relocated_upvars = IndexVec::from_fn_n(
425+
|local: CoroutineSavedLocal| info.relocated_upvars.get(&local).copied(),
426+
info.field_tys.len(),
427+
);
430428
let layout = cx
431429
.calc
432430
.coroutine(
433431
&local_layouts,
434-
prefix_layouts,
432+
&relocated_upvars,
435433
&info.variant_fields,
436434
&info.storage_conflicts,
437435
|tag| TyAndLayout {
@@ -826,7 +824,11 @@ fn variant_info_for_coroutine<'tcx>(
826824
.then(|| Symbol::intern(&field_layout.ty.to_string())),
827825
}
828826
})
829-
.chain(upvar_fields.iter().copied())
827+
.chain(
828+
if variant_idx == FIRST_VARIANT { &upvar_fields[..] } else { &[] }
829+
.iter()
830+
.copied(),
831+
)
830832
.collect();
831833

832834
// If the variant has no state-specific fields, then it's the size of the upvars.

0 commit comments

Comments
 (0)