Skip to content

Commit d88dab2

Browse files
committed
Support Yield in ops.
1 parent c1bda59 commit d88dab2

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
@@ -46,6 +46,12 @@ impl<'tcx> crate::MirPass<'tcx> for DataflowConstProp {
4646
return;
4747
}
4848

49+
// Avoid computing layout inside coroutines, since their `optimized_mir` is used for layout
50+
// computation, which can create a cycle.
51+
if body.coroutine.is_some() {
52+
return;
53+
}
54+
4955
// We want to have a somewhat linear runtime w.r.t. the number of statements/terminators.
5056
// Let's call this number `n`. Dataflow analysis has `O(h*n)` transfer function
5157
// applications, where `h` is the height of the lattice. Because the height of our lattice
@@ -241,9 +247,8 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> {
241247
TerminatorKind::Drop { place, .. } => {
242248
state.flood_with(place.as_ref(), &self.map, FlatSet::<Scalar>::BOTTOM);
243249
}
244-
TerminatorKind::Yield { .. } => {
245-
// They would have an effect, but are not allowed in this phase.
246-
bug!("encountered disallowed terminator");
250+
TerminatorKind::Yield { resume_arg, .. } => {
251+
state.flood_with(resume_arg.as_ref(), &self.map, FlatSet::<Scalar>::BOTTOM);
247252
}
248253
TerminatorKind::SwitchInt { discr, targets } => {
249254
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
@@ -1730,14 +1730,18 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, 'tcx> {
17301730
}
17311731

17321732
fn visit_terminator(&mut self, terminator: &mut Terminator<'tcx>, location: Location) {
1733-
if let Terminator { kind: TerminatorKind::Call { destination, .. }, .. } = terminator {
1734-
if let Some(local) = destination.as_local()
1735-
&& self.ssa.is_ssa(local)
1736-
{
1737-
let ty = self.local_decls[local].ty;
1738-
let opaque = self.new_opaque(ty);
1739-
self.assign(local, opaque);
1740-
}
1733+
let destination = match terminator.kind {
1734+
TerminatorKind::Call { destination, .. } => Some(destination),
1735+
TerminatorKind::Yield { resume_arg, .. } => Some(resume_arg),
1736+
_ => None,
1737+
};
1738+
if let Some(destination) = destination
1739+
&& let Some(local) = destination.as_local()
1740+
&& self.ssa.is_ssa(local)
1741+
{
1742+
let ty = self.local_decls[local].ty;
1743+
let opaque = self.new_opaque(ty);
1744+
self.assign(local, opaque);
17411745
}
17421746
// Function calls and ASM may invalidate (nested) derefs. We must handle them carefully.
17431747
// Currently, only preserving derefs for trivial terminators like SwitchInt and Goto.

compiler/rustc_mir_transform/src/jump_threading.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,9 +612,9 @@ impl<'a, 'tcx> TOFinder<'a, 'tcx> {
612612
| TerminatorKind::Unreachable
613613
| TerminatorKind::CoroutineDrop => bug!("{term:?} has no terminators"),
614614
// Disallowed during optimizations.
615-
TerminatorKind::FalseEdge { .. }
616-
| TerminatorKind::FalseUnwind { .. }
617-
| TerminatorKind::Yield { .. } => bug!("{term:?} invalid"),
615+
TerminatorKind::FalseEdge { .. } | TerminatorKind::FalseUnwind { .. } => {
616+
bug!("{term:?} invalid")
617+
}
618618
// Cannot reason about inline asm.
619619
TerminatorKind::InlineAsm { .. } => return,
620620
// `SwitchInt` is handled specially.
@@ -623,6 +623,7 @@ impl<'a, 'tcx> TOFinder<'a, 'tcx> {
623623
TerminatorKind::Goto { .. } => None,
624624
// Flood the overwritten place, and progress through.
625625
TerminatorKind::Drop { place: destination, .. }
626+
| TerminatorKind::Yield { resume_arg: destination, .. }
626627
| TerminatorKind::Call { destination, .. } => Some(destination),
627628
// Ignore, as this can be a no-op at codegen time.
628629
TerminatorKind::Assert { .. } => None,

0 commit comments

Comments
 (0)