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

python compiler error, pure python mode #2705

Open
jpe opened this Issue Nov 8, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@jpe
Contributor

jpe commented Nov 8, 2018

I'm getting a traceback when compiling the following with Cython 0.29:

import cython

@cython.ccall
@cython.locals(a=dict)
def aa(a):
  
  try:
    alias = a
  except:
    alias = None
  for v in alias.values():
    pass
@scoder

This comment has been minimized.

Contributor

scoder commented Nov 9, 2018

Thanks for the report. First of all, I only get this in Py2 mode, where using d.values() is inefficient. You probably want to enable language_level=3.

As you probably noticed when cutting down the reproducer above, it's a combination of type inference and optimisations. The call to dict.values() normally gets optimised into a C-API call (PyDict_Values()) before type inference, and therefore does not apply here (it should!). Apparently, a later step in the pipeline still assumes that the optimisation has been applied and makes inconsistent changes to the parse tree, which then leads to the compiler crash during code generation.

When I remove the try-except, it works. I guess that's because a single assignment is handled differently from multiple alternative assignments here. That's clearly part of the issue. (Second thing to look into.)

I think the right fix is to make sure we have the correct symbol table entry for the alias variable after type inference/analysis, the one that knows that it's backed by a C-API function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment