Skip to content

Commit cfb31e4

Browse files
committed
Support Yield in ops.
1 parent b7e26ac commit cfb31e4

4 files changed

Lines changed: 23 additions & 19 deletions

File tree

compiler/rustc_mir_transform/src/cost_checker.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> {
107107
}
108108
}
109109
}
110+
TerminatorKind::Yield { .. } => self.penalty += CALL_PENALTY,
110111
TerminatorKind::Call { func, unwind, .. } => {
111112
self.penalty += if let Some((def_id, ..)) = func.const_fn_def()
112113
&& self.tcx.intrinsic(def_id).is_some()
@@ -163,12 +164,11 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> {
163164
TerminatorKind::Unreachable => {
164165
self.bonus += INSTR_COST;
165166
}
166-
TerminatorKind::Goto { .. } | TerminatorKind::Return => {}
167+
TerminatorKind::Goto { .. }
168+
| TerminatorKind::Return
169+
| TerminatorKind::CoroutineDrop => {}
167170
TerminatorKind::UnwindTerminate(..) => {}
168-
kind @ (TerminatorKind::FalseUnwind { .. }
169-
| TerminatorKind::FalseEdge { .. }
170-
| TerminatorKind::Yield { .. }
171-
| TerminatorKind::CoroutineDrop) => {
171+
kind @ (TerminatorKind::FalseUnwind { .. } | TerminatorKind::FalseEdge { .. }) => {
172172
bug!("{kind:?} should not be in runtime MIR");
173173
}
174174
}

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,8 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> {
239239
TerminatorKind::Drop { place, .. } => {
240240
state.flood_with(place.as_ref(), &self.map, FlatSet::<Scalar>::BOTTOM);
241241
}
242-
TerminatorKind::Yield { .. } => {
243-
// They would have an effect, but are not allowed in this phase.
244-
bug!("encountered disallowed terminator");
242+
TerminatorKind::Yield { resume_arg, .. } => {
243+
state.flood_with(resume_arg.as_ref(), &self.map, FlatSet::<Scalar>::BOTTOM);
245244
}
246245
TerminatorKind::SwitchInt { discr, targets } => {
247246
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
@@ -2062,14 +2062,18 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, '_, 'tcx> {
20622062
}
20632063

20642064
fn visit_terminator(&mut self, terminator: &mut Terminator<'tcx>, location: Location) {
2065-
if let Terminator { kind: TerminatorKind::Call { destination, .. }, .. } = terminator {
2066-
if let Some(local) = destination.as_local()
2067-
&& self.ssa.is_ssa(local)
2068-
{
2069-
let ty = self.local_decls[local].ty;
2070-
let opaque = self.new_opaque(ty);
2071-
self.assign(local, opaque);
2072-
}
2065+
let destination = match terminator.kind {
2066+
TerminatorKind::Call { destination, .. } => Some(destination),
2067+
TerminatorKind::Yield { resume_arg, .. } => Some(resume_arg),
2068+
_ => None,
2069+
};
2070+
if let Some(destination) = destination
2071+
&& let Some(local) = destination.as_local()
2072+
&& self.ssa.is_ssa(local)
2073+
{
2074+
let ty = self.local_decls[local].ty;
2075+
let opaque = self.new_opaque(ty);
2076+
self.assign(local, opaque);
20732077
}
20742078
self.super_terminator(terminator, location);
20752079
}

compiler/rustc_mir_transform/src/jump_threading.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,9 +650,9 @@ impl<'a, 'tcx> TOFinder<'a, 'tcx> {
650650
let term = self.body.basic_blocks[bb].terminator();
651651
let place_to_flood = match term.kind {
652652
// Disallowed during optimizations.
653-
TerminatorKind::FalseEdge { .. }
654-
| TerminatorKind::FalseUnwind { .. }
655-
| TerminatorKind::Yield { .. } => bug!("{term:?} invalid"),
653+
TerminatorKind::FalseEdge { .. } | TerminatorKind::FalseUnwind { .. } => {
654+
bug!("{term:?} invalid")
655+
}
656656
// Cannot reason about inline asm.
657657
TerminatorKind::InlineAsm { .. } => {
658658
state.active.clear();
@@ -673,6 +673,7 @@ impl<'a, 'tcx> TOFinder<'a, 'tcx> {
673673
| TerminatorKind::Goto { .. } => None,
674674
// Flood the overwritten place, and progress through.
675675
TerminatorKind::Drop { place: destination, .. }
676+
| TerminatorKind::Yield { resume_arg: destination, .. }
676677
| TerminatorKind::Call { destination, .. } => Some(destination),
677678
TerminatorKind::TailCall { .. } => Some(RETURN_PLACE.into()),
678679
};

0 commit comments

Comments
 (0)