From 75e790836a5f6ed08841a2abf8c2806893e5c61d Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Wed, 24 Apr 2024 05:23:46 +0900 Subject: [PATCH] debuggable --- compiler/codegen/src/ir.rs | 18 +++++++++--------- vm/src/frame.rs | 12 ++++++++++-- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/compiler/codegen/src/ir.rs b/compiler/codegen/src/ir.rs index de7055e0d..9f1a86e51 100644 --- a/compiler/codegen/src/ir.rs +++ b/compiler/codegen/src/ir.rs @@ -234,14 +234,14 @@ impl CodeInfo { eprintln!("===BLOCK {}===", block.0); } let block = &self.blocks[block]; - for i in &block.instructions { - let instr = &i.instr; - let effect = instr.stack_effect(i.arg, false); + for ins in &block.instructions { + let instr = &ins.instr; + let effect = instr.stack_effect(ins.arg, false); if DEBUG { - let display_arg = if i.target == BlockIdx::NULL { - i.arg + let display_arg = if ins.target == BlockIdx::NULL { + ins.arg } else { - OpArg(i.target.0) + OpArg(ins.target.0) }; let instr_display = instr.display(display_arg, self); eprint!("{instr_display}: {depth} {effect:+} => "); @@ -256,18 +256,18 @@ impl CodeInfo { // we don't want to worry about Break/Continue, they use unwinding to jump to // their targets and as such the stack size is taken care of in frame.rs by setting // it back to the level it was at when SetupLoop was run - if i.target != BlockIdx::NULL + if ins.target != BlockIdx::NULL && !matches!( instr, Instruction::Continue { .. } | Instruction::Break { .. } ) { - let effect = instr.stack_effect(i.arg, true); + let effect = instr.stack_effect(ins.arg, true); let target_depth = depth.checked_add_signed(effect).unwrap(); if target_depth > maxdepth { maxdepth = target_depth } - stackdepth_push(&mut stack, &mut start_depths, i.target, target_depth); + stackdepth_push(&mut stack, &mut start_depths, ins.target, target_depth); } depth = new_depth; if instr.unconditional_branch() { diff --git a/vm/src/frame.rs b/vm/src/frame.rs index 49307541f..55081257b 100644 --- a/vm/src/frame.rs +++ b/vm/src/frame.rs @@ -486,7 +486,10 @@ impl ExecutingFrame<'_> { ) -> FrameResult { vm.check_signals()?; - flame_guard!(format!("Frame::execute_instruction({:?})", instruction)); + flame_guard!(format!( + "Frame::execute_instruction({})", + instruction.display(arg, &self.code.code).to_string() + )); #[cfg(feature = "vm-tracing-logging")] { @@ -497,7 +500,10 @@ impl ExecutingFrame<'_> { } */ trace!(" {:#?}", self); - trace!(" Executing op code: {:?}", instruction); + trace!( + " Executing op code: {}", + instruction.display(arg, &self.code.code).to_string() + ); trace!("======="); } @@ -1926,6 +1932,7 @@ impl ExecutingFrame<'_> { } #[inline] + #[track_caller] // not a real track_caller but pop_value is not very useful fn pop_value(&mut self) -> PyObjectRef { match self.state.stack.pop() { Some(x) => x, @@ -1959,6 +1966,7 @@ impl ExecutingFrame<'_> { #[cold] #[inline(never)] + #[track_caller] fn fatal(&self, msg: &'static str) -> ! { dbg!(self); panic!("{}", msg)