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

Give better error when there are incompatible return types #1248

Closed
hargup opened this issue Jun 20, 2015 · 1 comment
Closed

Give better error when there are incompatible return types #1248

hargup opened this issue Jun 20, 2015 · 1 comment

Comments

@hargup
Copy link
Contributor

hargup commented Jun 20, 2015

numba in nopython mode fails expected fails on functions which can possibly return two different types of result, but the error message given is hard to understand and if possible we should which tell the programmer exactly why his/her code cannot be compiled in the nopython mode. Here is the example code and error message I got:

In [3]: @numba.jit(nopython=True)
   ...: def example(x):
   ...:     if x > 0:
   ...:         return "Hello"
   ...:     else:
   ...:         return 1
   ...:     

In [4]: example(2)
---------------------------------------------------------------------------
LoweringError                             Traceback (most recent call last)
<ipython-input-4-390f115c7a56> in <module>()
----> 1 example(2)

/home/hargup/anaconda/lib/python2.7/site-packages/numba/dispatcher.pyc in _compile_for_args(self, *args, **kws)
    163         assert not kws
    164         sig = tuple([self.typeof_pyval(a) for a in args])
--> 165         return self.compile(sig)
    166 
    167     def inspect_llvm(self, signature=None):

/home/hargup/anaconda/lib/python2.7/site-packages/numba/dispatcher.pyc in compile(self, sig)
    301                                           self.py_func,
    302                                           args=args, return_type=return_type,
--> 303                                           flags=flags, locals=self.locals)
    304 
    305             # Check typing error if object mode is used

/home/hargup/anaconda/lib/python2.7/site-packages/numba/compiler.pyc in compile_extra(typingctx, targetctx, func, args, return_type, flags, locals, library)
    592     pipeline = Pipeline(typingctx, targetctx, library,
    593                         args, return_type, flags, locals)
--> 594     return pipeline.compile_extra(func)
    595 
    596 

/home/hargup/anaconda/lib/python2.7/site-packages/numba/compiler.pyc in compile_extra(self, func)
    315                 raise e
    316 
--> 317         return self.compile_bytecode(bc, func_attr=self.func_attr)
    318 
    319     def compile_bytecode(self, bc, lifted=(), lifted_from=None,

/home/hargup/anaconda/lib/python2.7/site-packages/numba/compiler.pyc in compile_bytecode(self, bc, lifted, lifted_from, func_attr)
    324         self.lifted_from = lifted_from
    325         self.func_attr = func_attr
--> 326         return self._compile_bytecode()
    327 
    328     def compile_internal(self, bc, func_attr=DEFAULT_FUNCTION_ATTRIBUTES):

/home/hargup/anaconda/lib/python2.7/site-packages/numba/compiler.pyc in _compile_bytecode(self)
    579 
    580         pm.finalize()
--> 581         return pm.run(self.status)
    582 
    583 

/home/hargup/anaconda/lib/python2.7/site-packages/numba/compiler.pyc in run(self, status)
    207                     # No more fallback pipelines?
    208                     if is_final_pipeline:
--> 209                         raise patched_exception
    210                     # Go to next fallback pipeline
    211                     else:

LoweringError: Caused By:
Traceback (most recent call last):
  File "/home/hargup/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 201, in run
    res = stage()
  File "/home/hargup/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 537, in stage_nopython_backend
    return self._backend(lowerfn, objectmode=False)
  File "/home/hargup/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 492, in _backend
    lowered = lowerfn()
  File "/home/hargup/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 483, in backend_nopython_mode
    self.flags)
  File "/home/hargup/anaconda/lib/python2.7/site-packages/numba/compiler.py", line 728, in native_lowering_stage
    lower.lower()
  File "/home/hargup/anaconda/lib/python2.7/site-packages/numba/lowering.py", line 99, in lower
    self.lower_normal_function(self.fndesc)
  File "/home/hargup/anaconda/lib/python2.7/site-packages/numba/lowering.py", line 131, in lower_normal_function
    entry_block_tail = self.lower_function_body()
  File "/home/hargup/anaconda/lib/python2.7/site-packages/numba/lowering.py", line 157, in lower_function_body
    self.lower_block(block)
  File "/home/hargup/anaconda/lib/python2.7/site-packages/numba/lowering.py", line 175, in lower_block
    raise LoweringError(msg, inst.loc)
LoweringError: Internal error:
NotImplementedError: ('cast', <llvmlite.ir.instructions.LoadInstr object at 0x7f0807c859d0>, str, pyobject)
File "<ipython-input-3-b1eef8320bc7>", line 4

Failed at nopython (nopython mode backend)
Internal error:
NotImplementedError: ('cast', <llvmlite.ir.instructions.LoadInstr object at 0x7f0807c859d0>, str, pyobject)
File "<ipython-input-3-b1eef8320bc7>", line 4
@pitrou
Copy link
Contributor

pitrou commented Jun 23, 2015

I'm surprised type inference succeeds on this piece of code.

@pitrou pitrou closed this as completed in c75a791 Jun 30, 2015
sklam added a commit that referenced this issue Jun 30, 2015
Fix #1248: detect type unification failure for function return type
pitrou added a commit that referenced this issue Jun 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants