Skip to content

Commit

Permalink
version __loop_cont__ variable
Browse files Browse the repository at this point in the history
While we expect that all `__loop_cont__` variables are used in the
correct scope, adding a version number to the variable will helpwhen
debugging nested loops.

The tests do not fail for this change, because we don't ever check the
trasnformed Python against a pre-recorded variant.
  • Loading branch information
esc committed Sep 30, 2024
1 parent 77a957a commit 2a96dc7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions numba_rvsdg/core/datastructures/ast_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ def transform(
body: MutableSequence[ast.AST] = []
self.region_stack = [scfg.region]
self.scfg = scfg
self.loop_cont_counter = 0
for name, block in scfg.concealed_region_view.items():
if type(block) is RegionBlock and block.kind == "branch":
continue
Expand Down Expand Up @@ -768,14 +769,16 @@ def codegen_view() -> list[Any]:
# A loop region gives rise to a Python while __scfg_loop_cont__
# loop. We recursively visit the body. The exiting latch will
# update __scfg_loop_continue__.
self.loop_cont_counter += 1
loop_continue = f"__scfg_loop_cont_{self.loop_cont_counter}__"
rval = [
ast.Assign(
[ast.Name("__scfg_loop_cont__")],
[ast.Name(loop_continue)],
ast.Constant(True),
lineno=0,
),
ast.While(
test=ast.Name("__scfg_loop_cont__"),
test=ast.Name(loop_continue),
body=codegen_view(),
orelse=[],
),
Expand Down Expand Up @@ -807,9 +810,11 @@ def codegen_view() -> list[Any]:
# the exit variable to '__scfg_loop_cont__'.
assert len(block.jump_targets) == 1
assert len(block.backedges) == 1
loop_continue = f"__scfg_loop_cont_{self.loop_cont_counter}__"
self.loop_cont_counter -= 1
return [
ast.Assign(
[ast.Name("__scfg_loop_cont__")],
[ast.Name(loop_continue)],
ast.UnaryOp(ast.Not(), ast.Name(block.variable)),
lineno=0,
)
Expand Down

0 comments on commit 2a96dc7

Please sign in to comment.