Skip to content

Commit 8c09f2f

Browse files
update the layout calculator to use relocated upvar info
1 parent 410e5b1 commit 8c09f2f

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

compiler/rustc_ty_utils/src/layout.rs

Lines changed: 13 additions & 11 deletions
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,
@@ -382,28 +383,25 @@ fn layout_of_uncached<'tcx>(
382383
return Err(error(cx, LayoutError::Unknown(ty)));
383384
};
384385

385-
let local_layouts = info
386+
let local_layouts: IndexVec<_, _> = info
386387
.field_tys
387388
.iter()
388389
.map(|local| {
389390
let field_ty = EarlyBinder::bind(local.ty);
390391
let uninit_ty = Ty::new_maybe_uninit(tcx, field_ty.instantiate(tcx, args));
391392
cx.spanned_layout_of(uninit_ty, local.source_info.span)
392393
})
393-
.try_collect::<IndexVec<_, _>>()?;
394-
395-
let prefix_layouts = args
396-
.as_coroutine()
397-
.prefix_tys()
398-
.iter()
399-
.map(|ty| cx.layout_of(ty))
400-
.try_collect::<IndexVec<_, _>>()?;
394+
.try_collect()?;
401395

396+
let relocated_upvars = IndexVec::from_fn_n(
397+
|local: CoroutineSavedLocal| info.relocated_upvars.get(&local).copied(),
398+
info.field_tys.len(),
399+
);
402400
let layout = cx
403401
.calc
404402
.coroutine(
405403
&local_layouts,
406-
prefix_layouts,
404+
&relocated_upvars,
407405
&info.variant_fields,
408406
&info.storage_conflicts,
409407
|tag| TyAndLayout {
@@ -798,7 +796,11 @@ fn variant_info_for_coroutine<'tcx>(
798796
.then(|| Symbol::intern(&field_layout.ty.to_string())),
799797
}
800798
})
801-
.chain(upvar_fields.iter().copied())
799+
.chain(
800+
if variant_idx == FIRST_VARIANT { &upvar_fields[..] } else { &[] }
801+
.iter()
802+
.copied(),
803+
)
802804
.collect();
803805

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

0 commit comments

Comments
 (0)