From 2a96dc7a6f6487208bcdcb2c65552c064694ded6 Mon Sep 17 00:00:00 2001 From: esc Date: Mon, 30 Sep 2024 18:14:06 +0200 Subject: [PATCH] version __loop_cont__ variable 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. --- numba_rvsdg/core/datastructures/ast_transforms.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/numba_rvsdg/core/datastructures/ast_transforms.py b/numba_rvsdg/core/datastructures/ast_transforms.py index f5fd1c4..e87ef39 100644 --- a/numba_rvsdg/core/datastructures/ast_transforms.py +++ b/numba_rvsdg/core/datastructures/ast_transforms.py @@ -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 @@ -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=[], ), @@ -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, )