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 using ufunc with multiple, fused return types #6068

Open
cgohlke opened this issue Mar 11, 2024 · 1 comment · May be fixed by #6086
Open

[BUG] Compiler crash using ufunc with multiple, fused return types #6068

cgohlke opened this issue Mar 11, 2024 · 1 comment · May be fixed by #6086

Comments

@cgohlke
Copy link
Contributor

cgohlke commented Mar 11, 2024

Describe the bug

Thanks again for fixing #6064.

The Cython compiler crashes with the following code using cython.ufunc with multiple, fused return types (single, fused return types work, as do multiple, non-fused return types):

cimport cython
from cython cimport floating

@cython.ufunc
cdef (floating, floating) add_one(floating x):
    return x, x+1
[1/1] Cythonizing ufunc_fused.pyx
D:\ufunc\Cython\Compiler\Main.py:373: FutureWarning: Cython directive 'language_level' not set, using '3' (Py3). This has changed from earlier releases! File: D:\ufunc\ufunc_fused.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)

Error compiling Cython file:
------------------------------------------------------------
...
cimport cython
from cython cimport floating

@cython.ufunc
cdef (floating, floating) add_one(floating x):
     ^
------------------------------------------------------------

ufunc_fused.pyx:5:5: Compiler crash in AnalyseDeclarationsTransform

File 'ModuleNode.py', line 202, in analyse_declarations: ModuleNode(ufunc_fused.pyx:1:0,
    full_module_name = 'ufunc_fused')
File 'Nodes.py', line 386, in analyse_declarations: StatListNode(ufunc_fused.pyx:1:0)
File 'Nodes.py', line 386, in analyse_declarations: StatListNode(ufunc_fused.pyx:5:5)
File 'Nodes.py', line 328, in analyse_declarations: CompilerDirectivesNode(ufunc_fused.pyx:5:5)
File 'Nodes.py', line 386, in analyse_declarations: StatListNode(ufunc_fused.pyx:5:5)
File 'Nodes.py', line 2620, in analyse_declarations: CFuncDefNode(ufunc_fused.pyx:5:5,
    modifiers = [...]/0,
    outer_attrs = [...]/2,
    visibility = 'private')
File 'Nodes.py', line 1356, in analyse: CTupleBaseTypeNode(ufunc_fused.pyx:5:5)

Compiler crash traceback from this point on:
  File "D:\ufunc\Cython\Compiler\Nodes.py", line 1356, in analyse
    entry = env.declare_tuple_type(self.pos, component_types)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\ufunc\Cython\Compiler\Symtab.py", line 1343, in declare_tuple_type
    ttype = self._cached_tuple_types[components] = PyrexTypes.c_tuple_type(components)
                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\ufunc\Cython\Compiler\PyrexTypes.py", line 4652, in c_tuple_type
    cname = Naming.ctuple_type_prefix + type_list_identifier(components)
                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\ufunc\Cython\Compiler\PyrexTypes.py", line 5440, in type_list_identifier
    return cap_length('__and_'.join(type_identifier(type) for type in types))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\ufunc\Cython\Compiler\PyrexTypes.py", line 5440, in <genexpr>
    return cap_length('__and_'.join(type_identifier(type) for type in types))
                                    ^^^^^^^^^^^^^^^^^^^^^
  File "D:\ufunc\Cython\Compiler\PyrexTypes.py", line 5468, in type_identifier
    decl = type.empty_declaration_code(pyrex=pyrex)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\ufunc\Cython\Compiler\PyrexTypes.py", line 50, in empty_declaration_code
    self._empty_declaration = self.declaration_code('')
                              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\ufunc\Cython\Compiler\PyrexTypes.py", line 1924, in declaration_code
    raise Exception("This may never happen, please report a bug")
Exception: This may never happen, please report a bug
Traceback (most recent call last):
  File "D:\ufunc\setup.py", line 4, in <module>
    setup(
  File "X:\Python311\Lib\site-packages\setuptools\__init__.py", line 103, in setup
    return distutils.core.setup(**attrs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "X:\Python311\Lib\site-packages\setuptools\_distutils\core.py", line 185, in setup
    return run_commands(dist)
           ^^^^^^^^^^^^^^^^^^
  File "X:\Python311\Lib\site-packages\setuptools\_distutils\core.py", line 201, in run_commands
    dist.run_commands()
  File "X:\Python311\Lib\site-packages\setuptools\_distutils\dist.py", line 969, in run_commands
    self.run_command(cmd)
  File "X:\Python311\Lib\site-packages\setuptools\dist.py", line 963, in run_command
    super().run_command(command)
  File "X:\Python311\Lib\site-packages\setuptools\_distutils\dist.py", line 988, in run_command
    cmd_obj.run()
  File "X:\Python311\Lib\site-packages\setuptools\command\build_ext.py", line 89, in run
    _build_ext.run(self)
  File "X:\Python311\Lib\site-packages\setuptools\_distutils\command\build_ext.py", line 345, in run
    self.build_extensions()
  File "X:\Python311\Lib\site-packages\setuptools\_distutils\command\build_ext.py", line 467, in build_extensions
    self._build_extensions_serial()
  File "X:\Python311\Lib\site-packages\setuptools\_distutils\command\build_ext.py", line 493, in _build_extensions_serial
    self.build_extension(ext)
  File "X:\Python311\Lib\site-packages\setuptools\command\build_ext.py", line 250, in build_extension
    _build_ext.build_extension(self, ext)
  File "D:\ufunc\Cython\Distutils\build_ext.py", line 129, in build_extension
    new_ext = cythonize(
              ^^^^^^^^^^
  File "D:\ufunc\Cython\Build\Dependencies.py", line 1168, in cythonize
    cythonize_one(*args)
  File "D:\ufunc\Cython\Build\Dependencies.py", line 1331, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: ufunc_fused.pyx

Code to reproduce the behaviour:

cimport cython
from cython cimport floating

@cython.ufunc
cdef (floating, floating) add_one(floating x):
    return x, x+1

Expected behaviour

No compiler crash

OS

Windows 11

Python version

3.11, 3.12

Cython version

3.0.9 and current main branch (f3cad15)

Additional context

No response

@da-woods
Copy link
Contributor

Thanks. I'll try to have a look in the fairly near future. The ufunc stuff is all fairly new so I'm sure there's plenty of bugs there.

da-woods added a commit to da-woods/cython that referenced this issue Mar 16, 2024
Fixes cython#6068.

Ideally should go in 3.0.x.
da-woods added a commit to da-woods/cython that referenced this issue Mar 16, 2024
Fixes cython#6068.

Ideally should go in 3.0.x.
@da-woods da-woods linked a pull request Mar 16, 2024 that will close this 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

Successfully merging a pull request may close this issue.

2 participants