Skip to content

Commit 6d3d384

Browse files
committed
Support Yield in ops.
1 parent 99b9a88 commit 6d3d384

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
@@ -1830,14 +1830,18 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, 'tcx> {
18301830
}
18311831

18321832
fn visit_terminator(&mut self, terminator: &mut Terminator<'tcx>, location: Location) {
1833-
if let Terminator { kind: TerminatorKind::Call { destination, .. }, .. } = terminator {
1834-
if let Some(local) = destination.as_local()
1835-
&& self.ssa.is_ssa(local)
1836-
{
1837-
let ty = self.local_decls[local].ty;
1838-
let opaque = self.new_opaque(ty);
1839-
self.assign(local, opaque);
1840-
}
1833+
let destination = match terminator.kind {
1834+
TerminatorKind::Call { destination, .. } => Some(destination),
1835+
TerminatorKind::Yield { resume_arg, .. } => Some(resume_arg),
1836+
_ => None,
1837+
};
1838+
if let Some(destination) = destination
1839+
&& let Some(local) = destination.as_local()
1840+
&& self.ssa.is_ssa(local)
1841+
{
1842+
let ty = self.local_decls[local].ty;
1843+
let opaque = self.new_opaque(ty);
1844+
self.assign(local, opaque);
18411845
}
18421846
// Function calls and ASM may invalidate (nested) derefs. We must handle them carefully.
18431847
// 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)