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 #6551

Open
user202729 opened this issue Dec 8, 2024 · 4 comments
Open

[BUG] Compiler crash #6551

user202729 opened this issue Dec 8, 2024 · 4 comments

Comments

@user202729
Copy link

user202729 commented Dec 8, 2024

Describe the bug

cimport libc.math

cdef object eat(double x):
	return 1

def call(double x):
	y = eat(libc.math.sqrt(x))

Encountered while trying to build SageMath with the latest Cython.


Compiling a.pyx because it changed.
[1/1] Cythonizing a.pyx
/home/user202729/miniforge3/envs/sage-dev/lib/python3.11/site-packages/Cython/Compiler/Main.py:373: FutureWarning: Cython directive 'language_level' not set, using '3' (Py3). This has changed from earlier releases! File: /tmp/a.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)

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

cdef object eat(double x):
        return 1

def call(double x):
        y = eat(libc.math.sqrt(x))
             ^
------------------------------------------------------------

a.pyx:8:13: cimported module has no attribute 'math'

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

cdef object eat(double x):
        return 1

def call(double x):
        y = eat(libc.math.sqrt(x))
             ^
------------------------------------------------------------

a.pyx:8:13: Compiler crash in AnalyseExpressionsTransform

ModuleNode.body = StatListNode(a.pyx:2:0)
StatListNode.stats[2] = StatListNode(a.pyx:7:0)
StatListNode.stats[0] = DefNode(a.pyx:7:0,
    is_cyfunction = True,
    modifiers = [...]/0,
    name = 'call',
    np_args_idx = [...]/0,
    num_required_args = 1,
    outer_attrs = [...]/2,
    py_wrapper_required = True,
    reqd_kw_flags_cname = '0',
    used = True)
File 'ExprNodes.py', line 5945, in infer_type: SimpleCallNode(a.pyx:8:8,
    result_is_used = True,
    use_managed_ref = True)
File 'ExprNodes.py', line 5924, in infer_type: SimpleCallNode(a.pyx:8:23,
    result_is_used = True,
    use_managed_ref = True)
File 'ExprNodes.py', line 7552, in infer_type: AttributeNode(a.pyx:8:13,
    attribute = 'math',
    is_attribute = 1,
    needs_none_check = True,
    result_is_used = True,
    use_managed_ref = True)

Compiler crash traceback from this point on:
  File "/home/user202729/miniforge3/envs/sage-dev/lib/python3.11/site-packages/Cython/Compiler/ExprNodes.py", line 7552, in infer_type
    if node.entry.type and node.entry.type.is_cfunction:
       ^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'type'
Traceback (most recent call last):
  File "/tmp/setup.py", line 4, in <module>
    setup(ext_modules = cythonize("a.pyx", include_path=[
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user202729/miniforge3/envs/sage-dev/lib/python3.11/site-packages/Cython/Build/Dependencies.py", line 1111, in cythonize
    cythonize_one(*args)
  File "/home/user202729/miniforge3/envs/sage-dev/lib/python3.11/site-packages/Cython/Build/Dependencies.py", line 1254, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: a.pyx

Code to reproduce the behaviour:

No response

Expected behaviour

No response

OS

Linux

Python version

3.11

Cython version

Latest master

Additional context

No response

@matusvalo
Copy link
Contributor

Present in master and 3.1.0a1 too. 3.0.11-1 works OK.

@matusvalo
Copy link
Contributor

Bisected commit causing the issue is: 4847429

@scoder scoder added this to the 3.1 milestone Dec 9, 2024
@scoder
Copy link
Contributor

scoder commented Dec 9, 2024

Thanks for the report. It's unclear to me right now how this needs to be handled between AttributeNode.infer_type() and AttributeNode.analyse_as_cimported_attribute_node(). I think the problem is that the latter behaves helpfully when called (and failing) in analyse_types() but not when called (and failing) in infer_types(). 1) it shouldn't fail in this case but correctly handle submodules, and 2) if it fails, infer_type() should understand that and handle it.

@user202729
Copy link
Author

I think we can just handle (1) first, (2) is less of a priority now (i.e. it's not as problematic if the compiler crash instead of giving helpful diagnostic on erroneous code, as long as it compiles correctly on well-formed code)

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