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

Fixes issue reported under #7217 #7228

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions numba/core/untyped_passes.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,17 @@ def inject_loop_body(self, switch_ir, loop_ir, caller_max_label,
new_var_dict[name] = mk_unique_var(name)
replace_var_names(loop_blocks, new_var_dict)

# Patch up the scope with the new variable names, this is horrible
new_var_table = get_name_var_table(loop_blocks)
for blk in loop_blocks.values():
scope = blk.scope
real_con = scope.localvars._con
for name, var in dict(scope.localvars._con).items():
if name in new_var_dict:
new_name = new_var_dict[name]
del real_con[name]
real_con[new_name] = new_var_table[new_name]
Comment on lines +914 to +922
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably will make a follow up PR to refactor it with ir_utils.fixup_var_define_in_scope

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I think the issue is that the versioned loop bodied have versions of some of the original variables and potentially replace the original.


# clobber the sentinel body and then stuff in the rest
switch_ir.blocks[lbl] = deepcopy(loop_blocks[loop_start_lbl])
remaining_keys = [y for y in loop_blocks.keys()]
Expand Down
13 changes: 13 additions & 0 deletions numba/tests/test_mixed_tuple_unroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1818,6 +1818,19 @@ def foo():

self.assertEqual(foo(), foo.py_func())

def test_unroller_with_scope_update(self):
# See issue #7217
@njit
def foo():
i = 0
for _ in literal_unroll((1, 2)):
for i in range(1):
i += 1
return i

foo()
self.assertEqual(foo(), foo.py_func())


def capture(real_pass):
""" Returns a compiler pass that captures the mutation state reported
Expand Down