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

Compiler crash with cython.view.array: 'NoneType' object has no attribute 'lookup' #1598

Closed
mdickinson opened this issue Feb 3, 2017 · 2 comments

Comments

@mdickinson
Copy link

mdickinson commented Feb 3, 2017

Since Cython 0.24, I'm seeing a compilation failure on code that's using cython.view.array to dynamically create typed memoryviews. Here's the end of the traceback I get (full code to reproduce and full traceback are at the end of this report):

Compiler crash traceback from this point on:
  File "/Users/mdickinson/.edm/envs/test/lib/python2.7/site-packages/Cython/Compiler/ExprNodes.py", line 1783, in compile_time_value
    return denv.lookup(self.name)
AttributeError: 'NoneType' object has no attribute 'lookup'

The failure seems very similar to that reported in April 2016 on the cython-devel mailing list, in a message entitled "Cython compiler crash in 0.24": https://mail.python.org/pipermail/cython-devel/2016-April/004771.html

Versions in use: Cython 0.25.2-1, Python 2.7.12, OS X 10.9.5.


Here's a cut-down version of the original code (and yes, the original code made more sense than this):

(test)bash-3.2$ cat view_array_compile_failure.pyx 
cimport cython
cimport numpy as np
import numpy as np

cdef double _safe_interp(
        double x,
        double[::1] xp,
        double[::1] fp,
        size_t n,
    ):
    return 1.3

def convert(object depth_to_time):
    sample_count = 16

    native_trace = cython.view.array(
        shape=(sample_count,),
        itemsize=sizeof(double),
        format='d',
    )

    return np.zeros(16, dtype=np.float64)

Under Cython < 0.24, this compiles without error. Under Cython 0.24 and later, I get a traceback like the following:

(test)bash-3.2$ cythonize view_array_compile_failure.pyx 
Compiling /Users/mdickinson/Desktop/view_array_compile_failure.pyx because it changed.
[1/1] Cythonizing /Users/mdickinson/Desktop/view_array_compile_failure.pyx

Error compiling Cython file:
------------------------------------------------------------
...

def convert(object depth_to_time):
    sample_count = 16

    native_trace = cython.view.array(
        shape=(sample_count,),
                          ^
------------------------------------------------------------

view_array_compile_failure.pyx:17:27: Compiler crash in TransformBuiltinMethods

ModuleNode.body = StatListNode(view_array_compile_failure.pyx:1:0)
StatListNode.stats[4] = StatListNode(view_array_compile_failure.pyx:13:0)
StatListNode.stats[0] = DefNode(view_array_compile_failure.pyx:13:0,
    modifiers = [...]/0,
    name = u'convert',
    num_required_args = 1,
    py_wrapper_required = True,
    reqd_kw_flags_cname = '0')
DefNode.body = StatListNode(view_array_compile_failure.pyx:14:4,
    is_terminator = True)
StatListNode.stats[1] = SingleAssignmentNode(view_array_compile_failure.pyx:16:36)
SingleAssignmentNode.rhs = GeneralCallNode(view_array_compile_failure.pyx:16:36,
    result_is_used = True,
    use_managed_ref = True)
File 'ExprNodes.py', line 8158, in compile_time_value: DictNode(view_array_compile_failure.pyx:17:13,
    is_dict_literal = True,
    is_temp = 1,
    obj_conversion_errors = [...]/0,
    reject_duplicates = True,
    result_is_used = True,
    use_managed_ref = True)
File 'ExprNodes.py', line 7457, in compile_time_value: TupleNode(view_array_compile_failure.pyx:17:15,
    is_sequence_constructor = 1,
    result_is_used = True,
    use_managed_ref = True)
File 'ExprNodes.py', line 6853, in compile_time_value_list: TupleNode(view_array_compile_failure.pyx:17:15,
    is_sequence_constructor = 1,
    result_is_used = True,
    use_managed_ref = True)
File 'ExprNodes.py', line 1785, in compile_time_value: NameNode(view_array_compile_failure.pyx:17:27,
    cf_maybe_null = True,
    is_name = True,
    name = u'sample_count',
    result_is_used = True,
    use_managed_ref = True)

Compiler crash traceback from this point on:
  File "/Users/mdickinson/.edm/envs/test/lib/python2.7/site-packages/Cython/Compiler/ExprNodes.py", line 1783, in compile_time_value
    return denv.lookup(self.name)
AttributeError: 'NoneType' object has no attribute 'lookup'
Traceback (most recent call last):
  File "/Users/mdickinson/.edm/envs/test/bin/cythonize", line 10, in <module>
    sys.exit(main())
  File "/Users/mdickinson/.edm/envs/test/lib/python2.7/site-packages/Cython/Build/Cythonize.py", line 196, in main
    cython_compile(path, options)
  File "/Users/mdickinson/.edm/envs/test/lib/python2.7/site-packages/Cython/Build/Cythonize.py", line 90, in cython_compile
    **options.options)
  File "/Users/mdickinson/.edm/envs/test/lib/python2.7/site-packages/Cython/Build/Dependencies.py", line 934, in cythonize
    cythonize_one(*args)
  File "/Users/mdickinson/.edm/envs/test/lib/python2.7/site-packages/Cython/Build/Dependencies.py", line 1056, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: /Users/mdickinson/Desktop/view_array_compile_failure.pyx
@mdickinson
Copy link
Author

Still an issue with Cython 0.26. Is there any other information I can provide to help move this forward?

@scoder scoder closed this as completed in 91f2c2e Jul 31, 2017
@scoder
Copy link
Contributor

scoder commented Jul 31, 2017

Thank you for your very detailed report and sorry it took us so long to fix the issue.

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