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

Regression with literally and overloads with inline='always' #5887

Closed
2 tasks done
kozlov-alexey opened this issue Jun 18, 2020 · 6 comments · Fixed by #5889
Closed
2 tasks done

Regression with literally and overloads with inline='always' #5887

kozlov-alexey opened this issue Jun 18, 2020 · 6 comments · Fixed by #5889
Labels
Milestone

Comments

@kozlov-alexey
Copy link
Contributor

Hi,

While trying to migrate to Numba 0.50 we encountered the following problem with literally that may now fail if called from overloads compiled with inline='always'. The error itself looks like this:

DEBUG: dtype= unicode_type
Traceback (most recent call last):
  File "test_inline_literally.py", line 36, in <module>
    res = test_impl(data, dtype)
  File "C:\Users\akozlov\AppData\Local\Continuum\anaconda3\numba_master\numba\numba\core\dispatcher.py", line 401, in _compile_for_args
    error_rewrite(e, 'typing')
  File "C:\Users\akozlov\AppData\Local\Continuum\anaconda3\numba_master\numba\numba\core\dispatcher.py", line 344, in error_rewrite
    reraise(type(e), e, None)
  File "C:\Users\akozlov\AppData\Local\Continuum\anaconda3\numba_master\numba\numba\core\utils.py", line 79, in reraise
    raise value.with_traceback(tb)
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Internal error at <numba.core.typeinfer.CallConstraint object at 0x0000023CF5AA24F0>.
'NoneType' object is not callable
[1] During: resolving callee type: Function(<function foo at 0x0000023CF24E5280>)
[2] During: typing of call at test_inline_literally.py (32)

Enable logging at debug level for details.

File "test_inline_literally.py", line 32:
def test_impl(arr, dtype):
    return foo(arr, dtype)
    ^

And below is the reproducer:

import numba
import numpy as np
from numba.extending import overload
from numba import types
from numba import literally


def foo(val, dtype):
    pass

@overload(foo, inline='always')    # seen with inline='always' only
def foo_ovld(arr, dtype):

    print("DEBUG: dtype=", dtype)
    if not isinstance(dtype, types.StringLiteral):
        def foo_noop(arr, dtype):
            return literally(dtype)
        return foo_noop

    if dtype.literal_value == 'str':
        def foo_as_str_impl(arr, dtype):
            return [str(x) for x in arr]
        return foo_as_str_impl

    if dtype.literal_value in ('int64', 'float64'):
        def foo_as_num_impl(arr, dtype):
            return list(arr.astype(np.dtype(dtype)))
        return foo_as_num_impl

@numba.njit
def test_impl(arr, dtype):
    return foo(arr, dtype)

data = np.asarray([1, 2, 3, 2, 4], dtype=np.int32)
dtype = 'int64'
print(test_impl(data, dtype))

The issue was found on 0.50.0rc1 but still remains in 0.51.0.dev0+56.g92df8df57
It seems it is somehow related to #5673 as it's not observed before it, but please note that even though test from our code base always passes on 0.49.1 the above script which is just simplified version might occasionally fail with 'Repeated literal typing request' as below:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test_inline_literally_2.py", line 20, in <module>
    res = test_impl(data, dtype)
  File "c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\numba\core\dispatcher.py", line 376, in _compile_for_args
    return self._compile_for_args(*args)
  File "c:\users\akozlov\appdata\local\continuum\anaconda3\numba_master\numba\numba\core\dispatcher.py", line 369, in _compile_for_args
    raise errors.CompilerError(m.format(info))
numba.core.errors.CompilerError: Repeated literal typing request.
Arg #1 is Literal[str](int64).
This is likely caused by an error in typing. Please see nested and suppressed exceptions.

Not sure if this latter is a known issue and wasn't fixed already (please confirm if it's so).
But the main issue is of course new one 'NoneType' object is not callable problem.

Best Regards,
Alexey.

@stuartarchibald
Copy link
Contributor

Thanks for the report. Is this the same problem as discussed, where literally wasn't forcing re-dispatch or is this just the error seen in use with cause unknown?

stuartarchibald added a commit to stuartarchibald/numba that referenced this issue Jun 19, 2020
stuartarchibald added a commit to stuartarchibald/numba that referenced this issue Jun 19, 2020
@stuartarchibald
Copy link
Contributor

Think #5889 should fix.

@stuartarchibald stuartarchibald added this to the Numba 0.50.1 milestone Jun 19, 2020
@kozlov-alexey
Copy link
Contributor Author

@stuartarchibald Thank you for a quick solution, but it solves the problem partly and while the test added is OK, the reproducer it seems still fails (seems _OverloadFunctionTemplate.generic is not called at all). Do you have any thoughts why?

@stuartarchibald
Copy link
Contributor

@kozlov-alexey From the above reproducer using the #5889 PR I get:

$ python test_5887.py 
DEBUG: dtype= unicode_type
DEBUG: dtype= Literal[str](int64)
DEBUG: dtype= Literal[str](int64)
[1, 2, 3, 2, 4]

I'm not sure what you are expecting to happen, any chance you could expand please? Thanks.

@kozlov-alexey
Copy link
Contributor Author

@stuartarchibald I just didn't get same results at first, but now after cleaning conda env properly it seems sdc tests also pass with this fix. Sorry for confusing.

@stuartarchibald
Copy link
Contributor

@kozlov-alexey no worries, thank you for double checking, glad it is working as expected now. I think the only change we're likely to make subsequent to what's in #5889 at present is to do this #5889 (comment), but I'll check again that the original reproducer is still fixed if that change is made. Thanks for helping to test this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants