Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 150 #151

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion numba_rvsdg/core/datastructures/ast_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def prune_empty(self) -> set[WritableASTBlock]:
"""Prune empty blocks from the CFG."""
empty = set()
for name, block in list(self.items()):
if not block.instructions:
if not block.instructions and name != "0":
empty.add(self.pop(name))
# Empty blocks can only have a single jump target.
it = block.jump_targets[0]
Expand Down Expand Up @@ -724,6 +724,9 @@ def codegen(self, block: Any) -> MutableSequence[ast.AST]:
)
if_node = ast.If(test, body, orelse)
return block.tree[:-1] + [if_node]
elif block.fallthrough and len(block.tree) == 0:
# Am empty block, do nothing.
return [ast.Pass()]
elif block.fallthrough and type(block.tree[-1]) is ast.Return:
# The value of the ast.Return could be either None or an
# ast.AST type. In the case of None, this refers to a plain
Expand Down
28 changes: 27 additions & 1 deletion numba_rvsdg/tests/test_ast_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,33 @@ def function() -> int:
"name": "6",
},
}
self.compare(function, expected, empty={"4", "7"})
self.compare(function, expected, empty={"7", "4"})

def test_if_in_while_without_else(self):
def function(i) -> int:
while i < 10:
i += 1
return i

expected = {
"0": {"instructions": [], "jump_targets": ["1"], "name": "0"},
"1": {
"instructions": ["i < 10"],
"jump_targets": ["2", "3"],
"name": "1",
},
"2": {
"instructions": ["i += 1"],
"jump_targets": ["1"],
"name": "2",
},
"3": {
"instructions": ["return i"],
"jump_targets": [],
"name": "3",
},
}
self.compare(function, expected, empty={"4"}, arguments=[(0,)])

def test_while_in_if(self):
def function(y: int) -> int:
Expand Down