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

0.60.0rc1 regression: NameError: name 'length_of_iterator' is not defined #9577

Open
2 tasks done
sk1p opened this issue May 16, 2024 · 2 comments
Open
2 tasks done
Assignees
Labels
bug - regression A regression against a previous version of Numba
Milestone

Comments

@sk1p
Copy link
Contributor

sk1p commented May 16, 2024

Reporting a bug

The following minimal example fails to compile with 0.60.0rc1 (works fine with 0.59.1):

import numpy as np
import numba


@numba.njit
def _inner():
    range_start = 0
    for _ in range(1):
        np.array([
            1 for _ in range(range_start, 7)
        ])
        range_start = 0

_inner()

Error message:

../numba/numba/core/dispatcher.py:423: in _compile_for_args
    error_rewrite(e, 'typing')
../numba/numba/core/dispatcher.py:362: in error_rewrite
    raise e
../numba/numba/core/dispatcher.py:375: in _compile_for_args
    return_val = self.compile(tuple(argtypes))
../numba/numba/core/dispatcher.py:905: in compile
    cres = self._compiler.compile(args, return_type)
../numba/numba/core/dispatcher.py:84: in compile
    raise retval
../numba/numba/core/dispatcher.py:94: in _compile_cached
    retval = self._compile_core(args, return_type)
../numba/numba/core/dispatcher.py:107: in _compile_core
    cres = compiler.compile_extra(self.targetdescr.typing_context,
../numba/numba/core/compiler.py:744: in compile_extra
    return pipeline.compile_extra(func)
../numba/numba/core/compiler.py:438: in compile_extra
    return self._compile_bytecode()
../numba/numba/core/compiler.py:506: in _compile_bytecode
    return self._compile_core()
../numba/numba/core/compiler.py:485: in _compile_core
    raise e
../numba/numba/core/compiler.py:472: in _compile_core
    pm.run(self.state)
../numba/numba/core/compiler_machinery.py:368: in run
    raise patched_exception
../numba/numba/core/compiler_machinery.py:356: in run
    self._runPass(idx, pass_inst, state)
../numba/numba/core/compiler_lock.py:35: in _acquire_compile_lock
    return func(*args, **kwargs)
../numba/numba/core/compiler_machinery.py:311: in _runPass
    mutated |= check(pss.run_pass, internal_state)
../numba/numba/core/compiler_machinery.py:273: in check
    mangled = func(compiler_state)
../numba/numba/core/typed_passes.py:112: in run_pass
    typemap, return_type, calltypes, errs = type_inference_stage(
../numba/numba/core/typed_passes.py:91: in type_inference_stage
    infer.build_constraint()
../numba/numba/core/typeinfer.py:1044: in build_constraint
    self.constrain_statement(inst)
../numba/numba/core/typeinfer.py:1406: in constrain_statement
    self.typeof_assign(inst)
../numba/numba/core/typeinfer.py:1481: in typeof_assign
    self.typeof_global(inst, inst.target, value)
../numba/numba/core/typeinfer.py:1581: in typeof_global
    typ = self.resolve_value_type(inst, gvar.value)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <numba.core.typeinfer.TypeInferer object at 0x7fb972830bc0>, inst = <numba.core.ir.Assign object at 0x7fb9727f3740>, val = <intrinsic length_of_iterator>

    def resolve_value_type(self, inst, val):
        """
        Resolve the type of a simple Python value, such as can be
        represented by literals.
        """
        try:
            return self.context.resolve_value_type(val)
        except ValueError as e:
            msg = str(e)
>       raise TypingError(msg, loc=inst.loc)
E       numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
E       NameError: name 'length_of_iterator' is not defined

../numba/numba/core/typeinfer.py:1502: TypingError

This seems to be some kind of "import order" problem - adding import numba.core.inline_closurecall before the _inner() call fixes the issue. Patching enable_inline_arraycall to False also fixes the issue. Thanks!

@gmarkall
Copy link
Member

Thanks for the report and reproducer! I can confirm that this reproduces with 0.60.0rc1, but not with 0.59.1.

@gmarkall gmarkall added the bug - regression A regression against a previous version of Numba label May 16, 2024
@gmarkall
Copy link
Member

The commit that caused this is: d184335 from #9437 (cc @kc611).

That commit moved length_of_iterator into inline_closurecall, so it is no longer registered when the CPU target is set up (it was moved from numba.cpython.rangeobj.py, which is imported in CPUContext.load_additional_registries() - this explains why importing inline_closurecall seems to resolve the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug - regression A regression against a previous version of Numba
Projects
None yet
Development

No branches or pull requests

3 participants