From 7a39500aed49d70a6c82fbd5f40484da8e47ac4e Mon Sep 17 00:00:00 2001 From: Noah <33094578+coolreader18@users.noreply.github.com> Date: Sat, 26 Sep 2020 22:48:16 -0500 Subject: [PATCH] Fix vm-tracing-logging build --- extra_tests/.gitignore | 2 +- vm/src/frame.rs | 16 ++++++++++++++-- vm/src/obj/objbuiltinfunc.rs | 7 ++++++- vm/src/vm.rs | 8 +------- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/extra_tests/.gitignore b/extra_tests/.gitignore index 933f9259e..776e3b786 100644 --- a/extra_tests/.gitignore +++ b/extra_tests/.gitignore @@ -1,4 +1,4 @@ snippets/whats_left_*.py .cache/ cpython_tests_results.json - +cpython_generated_slices.py diff --git a/vm/src/frame.rs b/vm/src/frame.rs index f78d95f9d..c17adcd95 100644 --- a/vm/src/frame.rs +++ b/vm/src/frame.rs @@ -78,6 +78,7 @@ enum UnwindReason { Continue, } +#[derive(Debug)] struct FrameState { // We need 1 stack per frame /// The main data frame of the stack machine @@ -237,6 +238,17 @@ struct ExecutingFrame<'a> { state: &'a mut FrameState, } +impl fmt::Debug for ExecutingFrame<'_> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("ExecutingFrame") + .field("code", self.code) + .field("scope", self.scope) + .field("lasti", self.lasti) + .field("state", self.state) + .finish() + } +} + impl ExecutingFrame<'_> { fn run(&mut self, vm: &VirtualMachine) -> PyResult { flame_guard!(format!("Frame::run({})", self.code.obj_name)); @@ -259,8 +271,8 @@ impl ExecutingFrame<'_> { let new_traceback = PyTraceback::new(next, self.object.clone(), self.lasti(), loc.row()); + vm_trace!("Adding to traceback: {:?} {:?}", new_traceback, loc.row()); exception.set_traceback(Some(new_traceback.into_ref(vm))); - vm_trace!("Adding to traceback: {:?} {:?}", new_traceback, loc.row); match self.unwind_blocks(vm, UnwindReason::Raising { exception }) { Ok(None) => {} @@ -331,7 +343,7 @@ impl ExecutingFrame<'_> { trace!(" {:?}", frame); } */ - trace!(" {:?}", self); + trace!(" {:#?}", self); trace!(" Executing op code: {:?}", instruction); trace!("======="); } diff --git a/vm/src/obj/objbuiltinfunc.rs b/vm/src/obj/objbuiltinfunc.rs index d117f57f0..20b5c0acf 100644 --- a/vm/src/obj/objbuiltinfunc.rs +++ b/vm/src/obj/objbuiltinfunc.rs @@ -1,6 +1,7 @@ use std::fmt; use super::objclassmethod::PyClassMethod; +use crate::common::borrow::BorrowValue; use crate::function::{PyFuncArgs, PyNativeFunc}; use crate::obj::objstr::PyStrRef; use crate::obj::objtype::PyTypeRef; @@ -69,7 +70,11 @@ impl PyValue for PyBuiltinFunction { impl fmt::Debug for PyBuiltinFunction { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "builtin function") + let name = match &self.value.name { + Some(s) => s.borrow_value(), + None => "", + }; + write!(f, "builtin function {}", name) } } diff --git a/vm/src/vm.rs b/vm/src/vm.rs index f0ab9b8c2..0866398c4 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -862,13 +862,7 @@ impl VirtualMachine { // This is only used in the vm for magic methods, which use a greatly simplified attribute lookup. match obj.get_class_attr(method_name) { Some(func) => { - vm_trace!( - "vm.call_method {:?} {:?} {:?} -> {:?}", - obj, - cls, - method_name, - func - ); + vm_trace!("vm.call_method {:?} {:?} -> {:?}", obj, method_name, func); let wrapped = self.call_if_get_descriptor(func, obj.clone())?; self.invoke(&wrapped, args) }