Skip to content

Commit

Permalink
fix stack depth problem
Browse files Browse the repository at this point in the history
  • Loading branch information
cfbolz committed Sep 25, 2024
1 parent 22d1dd9 commit 3fef457
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
6 changes: 3 additions & 3 deletions pypy/interpreter/astcompiler/assemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ def _stacksize_error_pos(self, depth, blocks, block, instr):
self._stack_depth_debug_print(blocks, block, instr)
os.write(2, "StackDepthComputationError(POS) in %s at %s:%s depth %s\n"
% (self.compile_info.filename, self.name, self.first_lineno, depth))
#raise StackDepthComputationError # would-be-nice-not-to-have
raise StackDepthComputationError # would-be-nice-not-to-have

def _stack_depth_debug_print(self, blocks, errorblock, errorinstr):
print "\n" * 5
Expand Down Expand Up @@ -569,6 +569,8 @@ def _do_stack_depth_walk(self, block, blocks):
for instr in block.instructions:
orig_depth = depth
depth += _opcode_stack_effect(instr.opcode, instr.arg)
if not we_are_translated():
instr._stack_depth_after = depth
if depth < 0:
# This is really a fatal error, don't comment out this
# 'raise'. It means that the stack depth computation
Expand Down Expand Up @@ -601,8 +603,6 @@ def _do_stack_depth_walk(self, block, blocks):
break
elif jump_op == ops.RERAISE:
break
if not we_are_translated():
instr._stack_depth_after = depth
else:
if block.next_block:
self._next_stack_depth_walk(block.next_block, depth, (block, None))
Expand Down
8 changes: 7 additions & 1 deletion pypy/interpreter/astcompiler/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,6 @@ def visit_TryStar(self, tr):
[] L0: <next statement>
"""
import pdb; pdb.set_trace()
body = self.new_block()
exc = self.new_block() # L1 in comment above
otherwise = self.new_block() # L0 in comment above
Expand Down Expand Up @@ -1141,6 +1140,7 @@ def visit_TryStar(self, tr):
self.emit_jump(ops.POP_JUMP_IF_FALSE, reraise_block)
self.emit_op(ops.POP_TOP)
self.emit_op(ops.POP_EXCEPT)
self.emit_op(ops.POP_TOP) # pypy difference: get rid of unroller
self.emit_jump(ops.JUMP_FORWARD, otherwise)

self.use_next_block(reraise_block)
Expand Down Expand Up @@ -2978,6 +2978,8 @@ def view(startblock):
for i, block in enumerate(blocks):
name = blocknames[block]
label = ["pos in blocks: %s/%s\\n" % (i + 1, len(blocks))]
if hasattr(block, 'initial_depth'):
label.append('initial stack depth: %s' % (block.initial_depth, ))
if block.marked != 0:
label.append("marked: %s\\n" % block.marked)

Expand All @@ -2990,6 +2992,10 @@ def view(startblock):
str_instr = "%5s: %s" % (instr.position_info[0], ops.opname[instr.opcode])
if instr.opcode >= ops.HAVE_ARGUMENT and instr.jump is None:
str_instr += " %s" % (instr.arg, )
if hasattr(instr, '_stack_depth_after'):
str_instr += " stack depth after: %s" % instr._stack_depth_after
if instr._stack_depth_after < 0 and instr._stack_depth_after != -99:
fillcolor = "red"
label.append(str_instr)
if instr.jump is not None:
graph.emit_node(name, shape="box", label="\\l".join(label), fillcolor=fillcolor, color=color)
Expand Down
2 changes: 2 additions & 0 deletions pypy/interpreter/astcompiler/test/apptest_exceptiongroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,5 @@ def test_try_star_name_raise_in_except_handler():
assert "ZeroDivisionError" in repr(e)
with raises(UnboundLocalError):
e1


6 changes: 0 additions & 6 deletions pypy/interpreter/pyopcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ def dispatch_bytecode(self, co_code, next_instr, ec):
opcode = ord(co_code[next_instr])
oparg = ord(co_code[next_instr + 1])
next_instr += 2
if self.pycode.co_name =='raises_one' and next_instr == 76:
import pdb;pdb.set_trace()

# note: the structure of the code here is such that it makes
# (after translation) a big "if/elif" chain, which is then
Expand Down Expand Up @@ -1301,8 +1299,6 @@ def WITH_EXCEPT_START(self, oparg, next_instr):
self.pushvalue(w_res)

def RERAISE(self, reset_last_instr, next_instr):
if self.pycode.co_name == "raises_one":
import pdb;pdb.set_trace()
unroller = self.popvalue()
if not isinstance(unroller, SApplicationException):
assert 0
Expand Down Expand Up @@ -1792,7 +1788,6 @@ def CHECK_EG_MATCH(self, oparg, next_instr):
w_typ = self.popvalue()
check_except_star_type_valid(self, w_typ)
w_eg = self.peekvalue()
import pdb; pdb.set_trace()
w_match, w_rest = exception_group_match(space, w_eg, w_typ)
if space.is_w(w_match, space.w_None):
self.pushvalue(w_match)
Expand All @@ -1805,7 +1800,6 @@ def PREP_RERAISE_STAR(self, oparg, next_instr):
w_res = self.popvalue()
w_orig = self.popvalue()
w_mod = space.call_method(space.builtin, '__import__', space.newtext('_pypy_exceptiongroups'))
import pdb; pdb.set_trace()
w_eg_or_None = space.call_method(w_mod, "_prep_reraise_star", w_orig, w_res)
if space.is_w(w_eg_or_None, space.w_None):
w_push = space.w_None
Expand Down

0 comments on commit 3fef457

Please sign in to comment.