Skip to content

Commit e7a9937

Browse files
committed
Support Yield in ops.
1 parent ed85b96 commit e7a9937

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
@@ -237,9 +243,8 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> {
237243
TerminatorKind::Drop { place, .. } => {
238244
state.flood_with(place.as_ref(), &self.map, FlatSet::<Scalar>::BOTTOM);
239245
}
240-
TerminatorKind::Yield { .. } => {
241-
// They would have an effect, but are not allowed in this phase.
242-
bug!("encountered disallowed terminator");
246+
TerminatorKind::Yield { resume_arg, .. } => {
247+
state.flood_with(resume_arg.as_ref(), &self.map, FlatSet::<Scalar>::BOTTOM);
243248
}
244249
TerminatorKind::SwitchInt { discr, targets } => {
245250
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
@@ -1912,14 +1912,18 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, '_, 'tcx> {
19121912
}
19131913

19141914
fn visit_terminator(&mut self, terminator: &mut Terminator<'tcx>, location: Location) {
1915-
if let Terminator { kind: TerminatorKind::Call { destination, .. }, .. } = terminator {
1916-
if let Some(local) = destination.as_local()
1917-
&& self.ssa.is_ssa(local)
1918-
{
1919-
let ty = self.local_decls[local].ty;
1920-
let opaque = self.new_opaque(ty);
1921-
self.assign(local, opaque);
1922-
}
1915+
let destination = match terminator.kind {
1916+
TerminatorKind::Call { destination, .. } => Some(destination),
1917+
TerminatorKind::Yield { resume_arg, .. } => Some(resume_arg),
1918+
_ => None,
1919+
};
1920+
if let Some(destination) = destination
1921+
&& let Some(local) = destination.as_local()
1922+
&& self.ssa.is_ssa(local)
1923+
{
1924+
let ty = self.local_decls[local].ty;
1925+
let opaque = self.new_opaque(ty);
1926+
self.assign(local, opaque);
19231927
}
19241928
// Terminators that can write to memory may invalidate (nested) derefs.
19251929
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
@@ -610,9 +610,9 @@ impl<'a, 'tcx> TOFinder<'a, 'tcx> {
610610
| TerminatorKind::Unreachable
611611
| TerminatorKind::CoroutineDrop => bug!("{term:?} has no terminators"),
612612
// Disallowed during optimizations.
613-
TerminatorKind::FalseEdge { .. }
614-
| TerminatorKind::FalseUnwind { .. }
615-
| TerminatorKind::Yield { .. } => bug!("{term:?} invalid"),
613+
TerminatorKind::FalseEdge { .. } | TerminatorKind::FalseUnwind { .. } => {
614+
bug!("{term:?} invalid")
615+
}
616616
// Cannot reason about inline asm.
617617
TerminatorKind::InlineAsm { .. } => return,
618618
// `SwitchInt` is handled specially.
@@ -621,6 +621,7 @@ impl<'a, 'tcx> TOFinder<'a, 'tcx> {
621621
TerminatorKind::Goto { .. } => None,
622622
// Flood the overwritten place, and progress through.
623623
TerminatorKind::Drop { place: destination, .. }
624+
| TerminatorKind::Yield { resume_arg: destination, .. }
624625
| TerminatorKind::Call { destination, .. } => Some(destination),
625626
// Ignore, as this can be a no-op at codegen time.
626627
TerminatorKind::Assert { .. } => None,

0 commit comments

Comments
 (0)