Skip to content

Commit 8cf95cd

Browse files
committedApr 8, 2023
Fix major regression in the MIR related to the introduction of the UnwindAction enum.
This is the relevant PR that introduced the changes to rustc rust-lang/rust#102906 Now there a new enum called `UnwindAction`, which may contain in some cases a basic block for the cleanup that we need to handle. This change requires some renaming to keep some consistency when using the words "unwind" and "cleanup" All tests are passing again. Updated the README
1 parent e2ca279 commit 8cf95cd

File tree

7 files changed

+28
-27
lines changed

7 files changed

+28
-27
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ This proves extremely useful to get feedback on the types, compiler errors, etc.
4848

4949
As time goes on and the compiler internals change, the code will inevitably need changes to work again.
5050

51-
**The current state of the repository compiled without warnings and with all tests passing with** `rustc 1.70.0-nightly (700938c07 2023-04-04)`
51+
**The current state of the repository compiled without warnings and with all tests passing with** `rustc 1.70.0-nightly (23ee2af2f 2023-04-07)`
5252

5353
### Installation
5454

‎src/naming/basic_block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub fn drop_transition_label(function_name: &str, index: usize) -> String {
5050

5151
/// Label of the transition that represents the (optional) unwind path of a drop terminator.
5252
#[inline]
53-
pub fn drop_unwind_transition_label(function_name: &str, index: usize) -> String {
53+
pub fn drop_cleanup_transition_label(function_name: &str, index: usize) -> String {
5454
format!("{}_DROP_UNWIND_{index}", sanitize(function_name))
5555
}
5656

‎src/translator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl<'tcx> Translator<'tcx> {
178178
args: &[rustc_middle::mir::Operand<'tcx>],
179179
destination: rustc_middle::mir::Place<'tcx>,
180180
target: Option<rustc_middle::mir::BasicBlock>,
181-
cleanup: Option<rustc_middle::mir::BasicBlock>,
181+
unwind: rustc_middle::mir::UnwindAction,
182182
) {
183183
let current_function = self.call_stack.peek_mut();
184184
let function_def_id =
@@ -208,7 +208,7 @@ impl<'tcx> Translator<'tcx> {
208208
};
209209

210210
let place_refs_for_function_call =
211-
current_function.get_place_refs_for_function_call(return_block, cleanup, &mut self.net);
211+
current_function.get_place_refs_for_function_call(return_block, unwind, &mut self.net);
212212

213213
let function_call = FunctionCall::new(function_def_id, self.tcx);
214214
self.start_function_call(

‎src/translator/mir_function.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl<'tcx> MirFunction<'tcx> {
209209
pub fn get_place_refs_for_function_call(
210210
&mut self,
211211
block_number: rustc_middle::mir::BasicBlock,
212-
cleanup_block_number: Option<rustc_middle::mir::BasicBlock>,
212+
unwind: rustc_middle::mir::UnwindAction,
213213
net: &mut PetriNet,
214214
) -> FunctionPlaces {
215215
let active_block = self.get_active_block();
@@ -219,7 +219,7 @@ impl<'tcx> MirFunction<'tcx> {
219219
let end_place = return_block.start_place.clone();
220220

221221
let mut cleanup_place = None;
222-
if let Some(cleanup_block_number) = cleanup_block_number {
222+
if let rustc_middle::mir::UnwindAction::Cleanup(cleanup_block_number) = unwind {
223223
let cleanup_block = self.get_or_add_basic_block(cleanup_block_number, net);
224224
cleanup_place = Some(cleanup_block.start_place.clone());
225225
}

‎src/translator/mir_function/basic_block.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use crate::data_structures::petri_net_interface::{
1111
};
1212
use crate::data_structures::petri_net_interface::{PetriNet, PlaceRef, TransitionRef};
1313
use crate::naming::basic_block::{
14-
assert_cleanup_transition_label, assert_transition_label, drop_transition_label,
15-
drop_unwind_transition_label, end_place_label, goto_transition_label, start_place_label,
14+
assert_cleanup_transition_label, assert_transition_label, drop_cleanup_transition_label,
15+
drop_transition_label, end_place_label, goto_transition_label, start_place_label,
1616
switch_int_transition_label, unreachable_transition_label, unwind_transition_label,
1717
};
1818

@@ -113,12 +113,12 @@ impl BasicBlock {
113113
transition
114114
}
115115

116-
/// Connects the end place of this block to the start place of the `unwind` basic block.
117-
pub fn drop_unwind(&self, unwind: &Self, net: &mut PetriNet) {
116+
/// Connects the end place of this block to the start place of the `cleanup` basic block.
117+
pub fn drop_cleanup(&self, cleanup: &Self, net: &mut PetriNet) {
118118
self.connect_end_to_next_place(
119-
&unwind.start_place,
119+
&cleanup.start_place,
120120
net,
121-
&drop_unwind_transition_label(&self.function_name, self.index),
121+
&drop_cleanup_transition_label(&self.function_name, self.index),
122122
);
123123
}
124124

‎src/translator/mir_function/terminator.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -49,46 +49,47 @@ impl<'tcx> MirFunction<'tcx> {
4949
/// of the drop terminator.
5050
/// Returns the transition that represents dropping the variable.
5151
///
52-
/// Optionally, if an unwind block is present, connects the active basic block to the next basic
53-
/// block identified as the argument `unwind` of the drop terminator.
52+
/// Optionally, if the unwind action contains a cleanup block, connects the active basic block to the next basic
53+
/// block contained in the argument `unwind` of the drop terminator.
5454
///
5555
/// # Panics
5656
///
5757
/// If there is no active basic block set, then the function panics.
5858
pub fn drop(
5959
&mut self,
6060
target: rustc_middle::mir::BasicBlock,
61-
unwind: Option<rustc_middle::mir::BasicBlock>,
61+
unwind: rustc_middle::mir::UnwindAction,
6262
net: &mut PetriNet,
6363
) -> TransitionRef {
6464
let (active_block, target_block) = self.get_pair_active_block_target_block(target, net);
6565
let transition_drop = active_block.drop(target_block, net);
6666

67-
if let Some(unwind) = unwind {
68-
let (active_block, unwind_block) = self.get_pair_active_block_target_block(unwind, net);
69-
active_block.drop_unwind(unwind_block, net);
67+
if let rustc_middle::mir::UnwindAction::Cleanup(cleanup) = unwind {
68+
let (active_block, cleanup_block) =
69+
self.get_pair_active_block_target_block(cleanup, net);
70+
active_block.drop_cleanup(cleanup_block, net);
7071
};
7172
transition_drop
7273
}
7374

7475
/// Connects the active basic block to the next basic block identified as the argument `target`
7576
/// of the assert terminator.
76-
/// Optionally, if a cleanup block is present, connects the active basic block to the next basic
77-
/// block identified as the argument `cleanup` of the assert terminator.
77+
/// Optionally, if the unwind action contains a cleanup block, connects the active basic block to the next basic
78+
/// block contained in the argument `unwind` of the assert terminator.
7879
///
7980
/// # Panics
8081
///
8182
/// If there is no active basic block set, then the function panics.
8283
pub fn assert(
8384
&mut self,
8485
target: rustc_middle::mir::BasicBlock,
85-
cleanup: Option<rustc_middle::mir::BasicBlock>,
86+
unwind: rustc_middle::mir::UnwindAction,
8687
net: &mut PetriNet,
8788
) {
8889
let (active_block, target_block) = self.get_pair_active_block_target_block(target, net);
8990
active_block.assert(target_block, net);
9091

91-
if let Some(cleanup) = cleanup {
92+
if let rustc_middle::mir::UnwindAction::Cleanup(cleanup) = unwind {
9293
let (active_block, cleanup_block) =
9394
self.get_pair_active_block_target_block(cleanup, net);
9495
active_block.assert_cleanup(cleanup_block, net);

‎src/translator/mir_visitor.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl<'tcx> Visitor<'tcx> for Translator<'tcx> {
8181
// <rustc_middle::mir::terminator::SwitchTargets>
8282
function.switch_int(targets.all_targets().to_vec(), &mut self.net);
8383
}
84-
TerminatorKind::Resume | TerminatorKind::Abort => {
84+
TerminatorKind::Resume | TerminatorKind::Terminate => {
8585
function.unwind(&self.program_panic, &mut self.net);
8686
}
8787
TerminatorKind::Return => {
@@ -108,20 +108,20 @@ impl<'tcx> Visitor<'tcx> for Translator<'tcx> {
108108
ref args,
109109
destination,
110110
target,
111-
cleanup,
111+
unwind,
112112
from_hir_call: _,
113113
fn_span: _,
114114
} => {
115-
self.call_function(func, args, destination, target, cleanup);
115+
self.call_function(func, args, destination, target, unwind);
116116
}
117117
TerminatorKind::Assert {
118118
cond: _,
119119
expected: _,
120120
msg: _,
121121
target,
122-
cleanup,
122+
unwind,
123123
} => {
124-
function.assert(target, cleanup, &mut self.net);
124+
function.assert(target, unwind, &mut self.net);
125125
}
126126
TerminatorKind::Yield { .. } => {
127127
unimplemented!("TerminatorKind::Yield not implemented yet")

0 commit comments

Comments
 (0)