Skip to content

Commit 2ec7085

Browse files
committed
make exception cold
1 parent 3379ea2 commit 2ec7085

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

vm/src/frame.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -335,22 +335,25 @@ impl ExecutingFrame<'_> {
335335
}
336336
// Instruction raised an exception
337337
Err(exception) => {
338-
// 1. Extract traceback from exception's '__traceback__' attr.
339-
// 2. Add new entry with current execution position (filename, lineno, code_object) to traceback.
340-
// 3. Unwind block stack till appropriate handler is found.
338+
#[cold]
339+
fn handle_exception(frame: &mut ExecutingFrame, exception: PyBaseExceptionRef, idx: usize, vm: &VirtualMachine) -> FrameResult {
340+
// 1. Extract traceback from exception's '__traceback__' attr.
341+
// 2. Add new entry with current execution position (filename, lineno, code_object) to traceback.
342+
// 3. Unwind block stack till appropriate handler is found.
343+
344+
let loc = frame.code.locations[idx];
345+
let next = exception.traceback();
346+
let new_traceback =
347+
PyTraceback::new(next, frame.object.clone(), frame.lasti(), loc.row());
348+
vm_trace!("Adding to traceback: {:?} {:?}", new_traceback, loc.row());
349+
exception.set_traceback(Some(new_traceback.into_ref(vm)));
341350

342-
let loc = self.code.locations[idx];
343-
344-
let next = exception.traceback();
345-
346-
let new_traceback =
347-
PyTraceback::new(next, self.object.clone(), self.lasti(), loc.row());
348-
vm_trace!("Adding to traceback: {:?} {:?}", new_traceback, loc.row());
349-
exception.set_traceback(Some(new_traceback.into_ref(vm)));
351+
vm.contextualize_exception(&exception);
350352

351-
vm.contextualize_exception(&exception);
353+
frame.unwind_blocks(vm, UnwindReason::Raising { exception })
354+
}
352355

353-
match self.unwind_blocks(vm, UnwindReason::Raising { exception }) {
356+
match handle_exception(self, exception, idx, vm) {
354357
Ok(None) => continue,
355358
Ok(Some(result)) => {
356359
break Ok(result);

0 commit comments

Comments
 (0)