Skip to content

Commit d054fcd

Browse files
committed
vm runtime debug prints
1 parent f6d8804 commit d054fcd

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

vm/src/frame.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@ impl ExecutingFrame<'_> {
351351
let mut arg_state = bytecode::OpArgState::default();
352352
loop {
353353
let idx = self.lasti() as usize;
354+
// eprintln!(
355+
// "location: {:?} {}",
356+
// self.code.locations[idx], self.code.source_path
357+
// );
354358
self.update_lasti(|i| *i += 1);
355359
let bytecode::CodeUnit { op, arg } = instrs[idx];
356360
let arg = arg_state.extend(arg);
@@ -993,6 +997,8 @@ impl ExecutingFrame<'_> {
993997
Ok(None)
994998
}
995999
bytecode::Instruction::GetANext => {
1000+
#[cfg(debug_assertions)] // remove when async bugs are all fixed
1001+
let orig_stack_len = self.state.stack.len();
9961002
let aiter = self.top_value();
9971003
let awaitable = if aiter.class().is(vm.ctx.types.async_generator) {
9981004
vm.call_special_method(aiter, identifier!(vm, __anext__), ())?
@@ -1030,6 +1036,7 @@ impl ExecutingFrame<'_> {
10301036
})?
10311037
};
10321038
self.push_value(awaitable);
1039+
debug_assert_eq!(orig_stack_len + 1, self.state.stack.len());
10331040
Ok(None)
10341041
}
10351042
bytecode::Instruction::EndAsyncFor => {
@@ -1238,6 +1245,7 @@ impl ExecutingFrame<'_> {
12381245
fn unwind_blocks(&mut self, vm: &VirtualMachine, reason: UnwindReason) -> FrameResult {
12391246
// First unwind all existing blocks on the block stack:
12401247
while let Some(block) = self.current_block() {
1248+
// eprintln!("unwinding block: {:.60?} {:.60?}", block.typ, reason);
12411249
match block.typ {
12421250
BlockType::Loop => match reason {
12431251
UnwindReason::Break { target } => {
@@ -1935,6 +1943,7 @@ impl ExecutingFrame<'_> {
19351943
}
19361944

19371945
fn push_block(&mut self, typ: BlockType) {
1946+
// eprintln!("block pushed: {:.60?} {}", typ, self.state.stack.len());
19381947
self.state.blocks.push(Block {
19391948
typ,
19401949
level: self.state.stack.len(),
@@ -1944,7 +1953,12 @@ impl ExecutingFrame<'_> {
19441953
#[track_caller]
19451954
fn pop_block(&mut self) -> Block {
19461955
let block = self.state.blocks.pop().expect("No more blocks to pop!");
1947-
// eprintln!("popped block: {:?} stack: {} truncate to {}", block.typ, self.state.stack.len(), block.level);
1956+
// eprintln!(
1957+
// "block popped: {:.60?} {} -> {} ",
1958+
// block.typ,
1959+
// self.state.stack.len(),
1960+
// block.level
1961+
// );
19481962
#[cfg(debug_assertions)]
19491963
if self.state.stack.len() < block.level {
19501964
dbg!(&self);
@@ -1966,6 +1980,11 @@ impl ExecutingFrame<'_> {
19661980
#[inline]
19671981
#[track_caller] // not a real track_caller but push_value is not very useful
19681982
fn push_value(&mut self, obj: PyObjectRef) {
1983+
// eprintln!(
1984+
// "push_value {} / len: {} +1",
1985+
// obj.class().name(),
1986+
// self.state.stack.len()
1987+
// );
19691988
match self.state.stack.try_push(obj) {
19701989
Ok(()) => {}
19711990
Err(_e) => self.fatal("tried to push value onto stack but overflowed max_stackdepth"),
@@ -1976,7 +1995,14 @@ impl ExecutingFrame<'_> {
19761995
#[track_caller] // not a real track_caller but pop_value is not very useful
19771996
fn pop_value(&mut self) -> PyObjectRef {
19781997
match self.state.stack.pop() {
1979-
Some(x) => x,
1998+
Some(x) => {
1999+
// eprintln!(
2000+
// "pop_value {} / len: {}",
2001+
// x.class().name(),
2002+
// self.state.stack.len()
2003+
// );
2004+
x
2005+
}
19802006
None => self.fatal("tried to pop value but there was nothing on the stack"),
19812007
}
19822008
}

0 commit comments

Comments
 (0)