Skip to content

Commit cbc3cf7

Browse files
committed
Avoid computing layouts inside coroutines.
1 parent 4750dff commit cbc3cf7

File tree

1 file changed

+8
-1
lines changed
  • compiler/rustc_mir_transform/src

1 file changed

+8
-1
lines changed

‎compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ struct VnState<'body, 'tcx> {
216216
tcx: TyCtxt<'tcx>,
217217
ecx: InterpCx<'tcx, DummyMachine>,
218218
local_decls: &'body LocalDecls<'tcx>,
219+
is_coroutine: bool,
219220
/// Value stored in each local.
220221
locals: IndexVec<Local, Option<VnIndex>>,
221222
/// Locals that are assigned that value.
@@ -253,6 +254,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
253254
tcx,
254255
ecx: InterpCx::new(tcx, DUMMY_SP, typing_env, DummyMachine),
255256
local_decls,
257+
is_coroutine: body.coroutine.is_some(),
256258
locals: IndexVec::from_elem(None, local_decls),
257259
rev_locals: IndexVec::with_capacity(num_values),
258260
values: FxIndexSet::with_capacity_and_hasher(num_values, Default::default()),
@@ -380,7 +382,12 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
380382
fn eval_to_const(&mut self, value: VnIndex) -> Option<OpTy<'tcx>> {
381383
use Value::*;
382384
let ty = self.ty(value);
383-
let ty = self.ecx.layout_of(ty).ok()?;
385+
// Avoid computing layouts inside a coroutine, as that can cause cycles.
386+
let ty = if !self.is_coroutine || ty.is_scalar() {
387+
self.ecx.layout_of(ty).ok()?
388+
} else {
389+
return None;
390+
};
384391
let op = match *self.get(value) {
385392
_ if ty.is_zst() => ImmTy::uninit(ty).into(),
386393

0 commit comments

Comments
 (0)