numba
numba copied to clipboard
presence of while loop breaks literal_unroll compilation
I reproduce this issue by running on numba 0.56.0 on google colab.
I cannot understand why the presence of a while loop later in the block creates a getitem problem for literal_unroll on heterogenous tuples.
from numba import njit,literal_unroll
@njit
def f1( t ):
for t_i in literal_unroll(t):
print('.')
return 0
@njit
def f2( t ):
for t_i in literal_unroll(t):
print('.')
x=0
while x>0:
x= x-1
return 0
print('f1')
f1( (0,0.0) ) # works
print('f2')
f2( (0,0.0) ) # fails
The unexpected compile fail for f2 is the following:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<built-in function getitem>) found for signature:
>>> getitem(Tuple(int64, float64), int64)
There are 22 candidate implementations:
- Of which 22 did not match due to:
Overload of function 'getitem': File: <numerous>: Line N/A.
With argument(s): '(Tuple(int64, float64), int64)':
No match.
During: typing of intrinsic-call at C:\Users\pconlon\AppData\Local\Temp/ipykernel_18736/1219060107.py (11)
File "..\..\..\..\..\AppData\Local\Temp\ipykernel_18736\1219060107.py", line 11:
<source missing, REPL/exec in use?>
- [X] I have tried using the latest released version of Numba (most recent is visible in the change log (https://github.com/numba/numba/blob/main/CHANGE_LOG).
- [X] I have included a self contained code sample to reproduce the problem. i.e. it's possible to run as 'python bug.py'.
What I expect to happen:
- the f2 should compiles just like f1 and does not have a compilation failure
Thanks for the report - I can reproduce the compilation failure.
A smaller reproducer:
from numba import njit, literal_unroll
@njit('(Tuple((int64, float64)),)')
def f2(t):
for t_i in literal_unroll(t):
pass
while True:
x = 0
#8321 fixes.