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] Cython master crashes analysing division of int by float #6183
Comments
I suspect that this is a duplicate of #6004 but not absolutely sure |
Here is a simple reproducer: $ cat tmp.pyx
cdef inline long prec_to_dps(n):
return max(1, int(round(int(n)/3.3219280948873626)-1))
$ cython tmp.pyx
/home/oscar/.pyenv/versions/3.12.0/envs/sympy-3.12.git/lib/python3.12/site-packages/Cython/Compiler/Main.py:373: FutureWarning: Cython directive 'language_level' not set, using '3' (Py3). This has changed from earlier releases! File: /home/oscar/current/active/sympy/tmp.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
Error compiling Cython file:
------------------------------------------------------------
...
cdef inline long prec_to_dps(n):
return max(1, int(round(int(n)/3.3219280948873626)-1))
^
------------------------------------------------------------
tmp.pyx:2:34: Compiler crash in AnalyseExpressionsTransform
ModuleNode.body = StatListNode(tmp.pyx:1:5)
StatListNode.stats[0] = CFuncDefNode(tmp.pyx:1:5,
args = [...]/1,
modifiers = [...]/1,
outer_attrs = [...]/2,
visibility = 'private')
File 'Nodes.py', line 390, in analyse_expressions: StatListNode(tmp.pyx:2:4,
is_terminator = True)
File 'Nodes.py', line 6858, in analyse_expressions: ReturnStatNode(tmp.pyx:2:4,
is_terminator = True)
File 'UtilNodes.py', line 282, in analyse_types: EvalWithTempExprNode(tmp.pyx:2:21,
result_is_used = True,
use_managed_ref = True)
File 'ExprNodes.py', line 6155, in analyse_types: SimpleCallNode(tmp.pyx:2:21,
analysed = True,
result_is_used = True,
use_managed_ref = True)
File 'ExprNodes.py', line 8661, in analyse_types: TupleNode(tmp.pyx:2:21,
is_sequence_constructor = 1,
result_is_used = True,
use_managed_ref = True)
File 'ExprNodes.py', line 11831, in analyse_types: SubNode(tmp.pyx:2:54,
infix = True,
operator = '-',
result_is_used = True,
use_managed_ref = True)
File 'ExprNodes.py', line 6155, in analyse_types: SimpleCallNode(tmp.pyx:2:27,
analysed = True,
result_is_used = True,
use_managed_ref = True)
File 'ExprNodes.py', line 8661, in analyse_types: TupleNode(tmp.pyx:2:27,
is_sequence_constructor = 1,
result_is_used = True,
use_managed_ref = True)
File 'ExprNodes.py', line 11833, in analyse_types: DivNode(tmp.pyx:2:34,
ctruedivision = True,
infix = True,
operator = '/',
result_is_used = True,
truedivision = True,
use_managed_ref = True)
File 'ExprNodes.py', line 12417, in analyse_operation: DivNode(tmp.pyx:2:34,
ctruedivision = True,
infix = True,
operator = '/',
result_is_used = True,
truedivision = True,
use_managed_ref = True)
File 'ExprNodes.py', line 11846, in analyse_operation: DivNode(tmp.pyx:2:34,
ctruedivision = True,
infix = True,
operator = '/',
result_is_used = True,
truedivision = True,
use_managed_ref = True)
Compiler crash traceback from this point on:
File "/home/oscar/.pyenv/versions/3.12.0/envs/sympy-3.12.git/lib/python3.12/site-packages/Cython/Compiler/ExprNodes.py", line 11846, in analyse_operation
assert self.type.is_pyobject
AssertionError: |
In fact this is enough: def prec_to_dps(n):
return int(n) / 1.0 |
da-woods
added a commit
to da-woods/cython
that referenced
this issue
May 12, 2024
This was broken due to changes to type inference. It infers the type as a double, but "py_operations" for binops need to have a Python result. Therefore I've separated into a two step: * calculate Python result * coerce to known C type. In principle Optimize.c could take this back to 1 step. But at the moment it doesn't. Fixes cython#6183 Fixes cython#6004
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
I have bisected this problem to 0adbcde
I just tried to build python-flint using Cython master but it crashes with
Code to reproduce the behaviour:
I haven't tried distilling this down to a standalone reproducer but the code being complained about is:
Expected behaviour
This all builds fine with Cython 3.0.10 so I expected it to build fine.
OS
Linux
Python version
3.12
Cython version
master
Additional context
No response
The text was updated successfully, but these errors were encountered: