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

[BUG] Compiler crash with class method and memory view with default None value #4313

Closed
cphyc opened this issue Jul 27, 2021 · 3 comments
Closed

Comments

@cphyc
Copy link
Contributor

cphyc commented Jul 27, 2021

Describe the bug

The cython compiler crashes when analysing a class method that has a memory view with a default None value with the following traceback

analyse_types not implemented
Called from: CoerceToMemViewSliceNode.not_implemented 485
Called from: CoerceToMemViewSliceNode.analyse_types 719
Called from: TupleNode.analyse_types 8084
Called from: PyCFunctionNode.analyse_default_args 9493
Called from: PyCFunctionNode.analyse_types 9410
Called from: SingleAssignmentNode.analyse_types 5827
Called from: SingleAssignmentNode.analyse_expressions 5707
Called from: <listcomp> 396
Called from: StatListNode.analyse_expressions 396
Called from: CClassDefNode.analyse_expressions 5233
Called from: <listcomp> 396
Called from: StatListNode.analyse_expressions 396
Called from: AnalyseExpressionsTransform.visit_ModuleNode 2351
Called from: run 352
Called from: run_pipeline 372
Called from: run_pipeline 505
Called from: compile_multiple 607
Called from: compile 630
Called from: main 732
Called from: setuptools_main 714
Called from: <module> 8
----------------------------------------------------------------------

Error compiling Cython file:
------------------------------------------------------------
...
cdef class Foo:
    def test(self, int[:] bar = None):
                               ^
------------------------------------------------------------

test.pyx:2:32: Compiler crash in AnalyseExpressionsTransform

File 'Nodes.py', line 396, in analyse_expressions: StatListNode(test.pyx:1:5)
File 'Nodes.py', line 5233, in analyse_expressions: CClassDefNode(test.pyx:1:5,
    as_name = 'Foo',
    class_name = 'Foo',
    module_name = '',
    punycode_class_name = 'Foo',
    visibility = 'private')
File 'Nodes.py', line 396, in analyse_expressions: StatListNode(test.pyx:2:4)
File 'Nodes.py', line 5707, in analyse_expressions: SingleAssignmentNode(test.pyx:2:4)
File 'Nodes.py', line 5827, in analyse_types: SingleAssignmentNode(test.pyx:2:4)
File 'ExprNodes.py', line 9410, in analyse_types: PyCFunctionNode(test.pyx:2:4,
    binding = True,
    is_temp = 1,
    pymethdef_cname = '__pyx_mdef_4test_3Foo_1test',
    result_is_used = True,
    use_managed_ref = True)
File 'ExprNodes.py', line 9493, in analyse_default_args: PyCFunctionNode(test.pyx:2:4,
    binding = True,
    is_temp = 1,
    pymethdef_cname = '__pyx_mdef_4test_3Foo_1test',
    result_is_used = True,
    use_managed_ref = True)
File 'ExprNodes.py', line 8084, in analyse_types: TupleNode(test.pyx:2:4,
    is_sequence_constructor = 1,
    result_is_used = True,
    use_managed_ref = True)
File 'ExprNodes.py', line 719, in analyse_types: CoerceToMemViewSliceNode(test.pyx:2:32,
    is_temp = 1,
    result_is_used = True,
    use_managed_ref = True)
File 'ExprNodes.py', line 486, in not_implemented: CoerceToMemViewSliceNode(test.pyx:2:32,
    is_temp = 1,
    result_is_used = True,
    use_managed_ref = True)

Compiler crash traceback from this point on:
  File "/home/ccc/anaconda3/envs/py39/lib/python3.9/site-packages/Cython/Compiler/ExprNodes.py", line 486, in not_implemented
    raise InternalError(
InternalError: Internal compiler error: CoerceToMemViewSliceNode.analyse_types not implemented

To Reproduce
Minimal code to reproduce the behaviour:

# This results in a compiler crash
cdef class Foo:
    def test(self, int[:] bar = None):
        pass

Note that the compiler properly handles the following

# This compiles fine
def test(int[:] bar = None):
    pass

Expected behavior
The code should compile fine.

Environment (please complete the following information):

  • OS: Linux
  • Python version 3.7.11 and 3.9.5
  • Cython version 3.0a7, 3.0.0a8, 3.0.0a9 (works on any version <=3.0a6)

Additional information:
The traceback above is with Python 3.9.5 and Cython 3.0.0a9.

@cphyc
Copy link
Contributor Author

cphyc commented Jul 27, 2021

After a git bisection, it seems the crash appeared in ee7ae0b. Reverting the aforementioned commit fixes this specific issue (see attached patch).
patch.txt

cphyc added a commit to cphyc/cython that referenced this issue Jul 27, 2021
cphyc added a commit to cphyc/cython that referenced this issue Jul 27, 2021
@scoder
Copy link
Contributor

scoder commented Jul 29, 2021

Interesting. Thanks for reporting this. I was sure that default arguments are tested, but yeah, the usage in a method of an extension type might not be.

@neutrinoceros
Copy link
Contributor

Any chance this could be triaged into the 3.0 milestone ? I would also like to point out that #4315 isn't currently linked as a fix.

@scoder scoder closed this as completed in c36aa2f Dec 25, 2021
@scoder scoder added this to the 3.0 milestone Dec 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants