Repository navigation
Conversation
| try: | ||
| scope.get_exact(name) | ||
| except errors.NotDefinedError: | ||
| # is this correct? In case the scope doesn't have the | ||
| # variable, we need to define it prior creating new | ||
| # copies of it! | ||
| scope.define(name, var.loc) | ||
| new_var_dict[name] = scope.redefine(name, var.loc).name |
There was a problem hiding this comment.
This needs a careful look. Previously, mk_unique_var would return a unique identifier, whereas scope.redefine might just return the original identifier if it is the first time defining it.
There was a problem hiding this comment.
@guilhermeleobas which tests are failing due to this?
There was a problem hiding this comment.
Change this line to
for name, var in var_table.items():
scope = switch_ir.blocks[lbl].scope
scope.define(name, var.loc)
new_var_dict[name] = scope.redefine(name, var.loc).nameAnd run the tests python -m runtests numba.tests.test_mixed_tuple_unroller.TestMixedTupleUnroll.test_08
$ python -m runtests numba.tests.test_mixed_tuple_unroller.TestMixedTupleUnroll.test_08
/home/guilhermeleobas/git/numba/numba/core/utils.py:612: NumbaExperimentalFeatureWarning: First-class function type feature is experimental
warnings.warn("First-class function type feature is experimental",
/home/guilhermeleobas/git/numba/numba/tests/test_mixed_tuple_unroller.py:603: NumbaExperimentalFeatureWarning: First-class function type feature is experimental
acc += tup2[0]()
/home/guilhermeleobas/git/numba/numba/tests/test_mixed_tuple_unroller.py:605: NumbaExperimentalFeatureWarning: First-class function type feature is experimental
acc += tup2[1]()
/home/guilhermeleobas/git/numba/numba/tests/test_mixed_tuple_unroller.py:607: NumbaExperimentalFeatureWarning: First-class function type feature is experimental
acc += tup2[2]()
/home/guilhermeleobas/git/numba/numba/tests/test_mixed_tuple_unroller.py:603: NumbaExperimentalFeatureWarning: First-class function type feature is experimental
acc += tup2[0]()
/home/guilhermeleobas/git/numba/numba/tests/test_mixed_tuple_unroller.py:605: NumbaExperimentalFeatureWarning: First-class function type feature is experimental
acc += tup2[1]()
/home/guilhermeleobas/git/numba/numba/tests/test_mixed_tuple_unroller.py:607: NumbaExperimentalFeatureWarning: First-class function type feature is experimental
acc += tup2[2]()
E
======================================================================
ERROR: test_08 (numba.tests.test_mixed_tuple_unroller.TestMixedTupleUnroll)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/guilhermeleobas/git/numba/numba/tests/test_mixed_tuple_unroller.py", line 617, in test_08
self.assertEqual(foo(tup1, tup2), foo.py_func(tup1, tup2))
File "/home/guilhermeleobas/git/numba/numba/core/dispatcher.py", line 476, in _compile_for_args
error_rewrite(e, 'interpreter')
File "/home/guilhermeleobas/git/numba/numba/core/dispatcher.py", line 407, in error_rewrite
raise e
File "/home/guilhermeleobas/git/numba/numba/core/dispatcher.py", line 420, in _compile_for_args
return_val = self.compile(tuple(argtypes))
File "/home/guilhermeleobas/git/numba/numba/core/dispatcher.py", line 965, in compile
cres = self._compiler.compile(args, return_type)
File "/home/guilhermeleobas/git/numba/numba/core/dispatcher.py", line 125, in compile
status, retval = self._compile_cached(args, return_type)
File "/home/guilhermeleobas/git/numba/numba/core/dispatcher.py", line 139, in _compile_cached
retval = self._compile_core(args, return_type)
File "/home/guilhermeleobas/git/numba/numba/core/dispatcher.py", line 152, in _compile_core
cres = compiler.compile_extra(self.targetdescr.typing_context,
File "/home/guilhermeleobas/git/numba/numba/core/compiler.py", line 716, in compile_extra
return pipeline.compile_extra(func)
File "/home/guilhermeleobas/git/numba/numba/core/compiler.py", line 452, in compile_extra
return self._compile_bytecode()
File "/home/guilhermeleobas/git/numba/numba/core/compiler.py", line 520, in _compile_bytecode
return self._compile_core()
File "/home/guilhermeleobas/git/numba/numba/core/compiler.py", line 499, in _compile_core
raise e
File "/home/guilhermeleobas/git/numba/numba/core/compiler.py", line 486, in _compile_core
pm.run(self.state)
File "/home/guilhermeleobas/git/numba/numba/core/compiler_machinery.py", line 368, in run
raise patched_exception
File "/home/guilhermeleobas/git/numba/numba/core/compiler_machinery.py", line 356, in run
self._runPass(idx, pass_inst, state)
File "/home/guilhermeleobas/git/numba/numba/core/compiler_lock.py", line 35, in _acquire_compile_lock
return func(*args, **kwargs)
File "/home/guilhermeleobas/git/numba/numba/core/compiler_machinery.py", line 311, in _runPass
mutated |= check(pss.run_pass, internal_state)
File "/home/guilhermeleobas/git/numba/numba/core/compiler_machinery.py", line 273, in check
mangled = func(compiler_state)
File "/home/guilhermeleobas/git/numba/numba/core/untyped_passes.py", line 1667, in run_pass
pm.run(state)
File "/home/guilhermeleobas/git/numba/numba/core/compiler_machinery.py", line 368, in run
raise patched_exception
File "/home/guilhermeleobas/git/numba/numba/core/compiler_machinery.py", line 356, in run
self._runPass(idx, pass_inst, state)
File "/home/guilhermeleobas/git/numba/numba/core/compiler_lock.py", line 35, in _acquire_compile_lock
return func(*args, **kwargs)
File "/home/guilhermeleobas/git/numba/numba/core/compiler_machinery.py", line 311, in _runPass
mutated |= check(pss.run_pass, internal_state)
File "/home/guilhermeleobas/git/numba/numba/core/compiler_machinery.py", line 273, in check
mangled = func(compiler_state)
File "/home/guilhermeleobas/git/numba/numba/core/untyped_passes.py", line 1296, in run_pass
stat = self.apply_transform(state)
File "/home/guilhermeleobas/git/numba/numba/core/untyped_passes.py", line 1160, in apply_transform
self.unroll_loop(state, info)
File "/home/guilhermeleobas/git/numba/numba/core/untyped_passes.py", line 1259, in unroll_loop
unrolled_body = self.inject_loop_body(
File "/home/guilhermeleobas/git/numba/numba/core/untyped_passes.py", line 916, in inject_loop_body
scope.define(name, var.loc)
File "/home/guilhermeleobas/git/numba/numba/core/ir.py", line 1107, in define
self.localvars.define(v.name, v)
File "/home/guilhermeleobas/git/numba/numba/core/ir.py", line 261, in define
raise RedefinedError(name)
numba.core.errors.RedefinedError: Failed in nopython mode pipeline (step: handles literal_unroll)
Failed in literal_unroll_subpipeline mode pipeline (step: performs mixed container unroll)
$const78.3
----------------------------------------------------------------------
Ran 1 test in 0.203s
FAILED (errors=1)
(numba)
There was a problem hiding this comment.
Thanks for the example, I think I understand what's happening. The switch_ir is some IR containing the switch table to jump to a type specific loop body version, it initially won't contain any of the variables present in the loop blocks scheduled for versioning. This part of the code is essentially wiring these versioned blocks into the switch table, which means the switch table need to "know" about the loops' variables as they are now in scope. Occasionally there are collisions, like in the case above, whereby the switch table happens to have the same name for a constant as a versioned loop body and the proposed change works around this.
I think another way to "fix" it would be to version the inlined variable names with the branch version from which they were derived, e.g.
diff --git a/numba/core/untyped_passes.py b/numba/core/untyped_passes.py
--- a/numba/core/untyped_passes.py
+++ b/numba/core/untyped_passes.py
@@ -906,14 +906,7 @@ class MixedContainerUnroller(FunctionPass):
new_var_dict = {}
for name, var in var_table.items():
scope = switch_ir.blocks[lbl].scope
- try:
- scope.get_exact(name)
- except errors.NotDefinedError:
- # is this correct? In case the scope doesn't have the
- # variable, we need to define it prior creating new
- # copies of it!
- scope.define(name, var.loc)
- new_var_dict[name] = scope.redefine(name, var.loc).name
+ new_var_dict[name] = scope.define(f"v{branch_ty}_{name}", var.loc).name
replace_var_names(loop_blocks, new_var_dict)which might be a strategy worth employing as it makes it easier to track the origin of the variable.
Either way, I think the proposed code change is correct.
stuartarchibald
left a comment
There was a problem hiding this comment.
Thanks for the patch and fixes!
xref: #8230