Skip to content

Commit 1a79c49

Browse files
committed
Support Yield in ops.
1 parent 0208ee0 commit 1a79c49

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ impl<'tcx> crate::MirPass<'tcx> for DataflowConstProp {
4747
return;
4848
}
4949

50+
// Avoid computing layout inside coroutines, since their `optimized_mir` is used for layout
51+
// computation, which can create a cycle.
52+
if body.coroutine.is_some() {
53+
return;
54+
}
55+
5056
// We want to have a somewhat linear runtime w.r.t. the number of statements/terminators.
5157
// Let's call this number `n`. Dataflow analysis has `O(h*n)` transfer function
5258
// applications, where `h` is the height of the lattice. Because the height of our lattice
@@ -236,9 +242,8 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> {
236242
TerminatorKind::Drop { place, .. } => {
237243
state.flood_with(place.as_ref(), &self.map, FlatSet::<Scalar>::BOTTOM);
238244
}
239-
TerminatorKind::Yield { .. } => {
240-
// They would have an effect, but are not allowed in this phase.
241-
bug!("encountered disallowed terminator");
245+
TerminatorKind::Yield { resume_arg, .. } => {
246+
state.flood_with(resume_arg.as_ref(), &self.map, FlatSet::<Scalar>::BOTTOM);
242247
}
243248
TerminatorKind::SwitchInt { discr, targets } => {
244249
return self.handle_switch_int(discr, targets, state);

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,14 +1918,18 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, '_, 'tcx> {
19181918
}
19191919

19201920
fn visit_terminator(&mut self, terminator: &mut Terminator<'tcx>, location: Location) {
1921-
if let Terminator { kind: TerminatorKind::Call { destination, .. }, .. } = terminator {
1922-
if let Some(local) = destination.as_local()
1923-
&& self.ssa.is_ssa(local)
1924-
{
1925-
let ty = self.local_decls[local].ty;
1926-
let opaque = self.new_opaque(ty);
1927-
self.assign(local, opaque);
1928-
}
1921+
let destination = match terminator.kind {
1922+
TerminatorKind::Call { destination, .. } => Some(destination),
1923+
TerminatorKind::Yield { resume_arg, .. } => Some(resume_arg),
1924+
_ => None,
1925+
};
1926+
if let Some(destination) = destination
1927+
&& let Some(local) = destination.as_local()
1928+
&& self.ssa.is_ssa(local)
1929+
{
1930+
let ty = self.local_decls[local].ty;
1931+
let opaque = self.new_opaque(ty);
1932+
self.assign(local, opaque);
19291933
}
19301934
// Terminators that can write to memory may invalidate (nested) derefs.
19311935
if terminator.kind.can_write_to_memory() {

compiler/rustc_mir_transform/src/jump_threading.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -624,9 +624,9 @@ impl<'a, 'tcx> TOFinder<'a, 'tcx> {
624624
let term = self.body.basic_blocks[bb].terminator();
625625
let place_to_flood = match term.kind {
626626
// Disallowed during optimizations.
627-
TerminatorKind::FalseEdge { .. }
628-
| TerminatorKind::FalseUnwind { .. }
629-
| TerminatorKind::Yield { .. } => bug!("{term:?} invalid"),
627+
TerminatorKind::FalseEdge { .. } | TerminatorKind::FalseUnwind { .. } => {
628+
bug!("{term:?} invalid")
629+
}
630630
// Cannot reason about inline asm.
631631
TerminatorKind::InlineAsm { .. } => {
632632
state.active.clear();
@@ -647,6 +647,7 @@ impl<'a, 'tcx> TOFinder<'a, 'tcx> {
647647
| TerminatorKind::Goto { .. } => None,
648648
// Flood the overwritten place, and progress through.
649649
TerminatorKind::Drop { place: destination, .. }
650+
| TerminatorKind::Yield { resume_arg: destination, .. }
650651
| TerminatorKind::Call { destination, .. } => Some(destination),
651652
TerminatorKind::TailCall { .. } => Some(RETURN_PLACE.into()),
652653
};

0 commit comments

Comments
 (0)