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

Fix PyInteger / float division #6195

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

da-woods
Copy link
Contributor

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 #6183
Fixes #6004

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
@da-woods da-woods added this to the 3.1 milestone May 12, 2024
@@ -187,6 +187,8 @@ def arithmetic():
assert typeof(f) == "long", typeof(f)
g = 4 // <int>2
assert typeof(g) == "long", typeof(g)
h = int(2) / 3.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR changes also other operators (e.g. *). They are not tested here. Should not be added here?

@matusvalo
Copy link
Contributor

Implementation seems OK (but I cannot tell for 100%). I added just one comment regarding tests.

@scoder
Copy link
Contributor

scoder commented May 12, 2024

In principle Optimize.c could take this back to 1 step.

Did you mean the transforms in Optimize.py instead of Optimize.c? There are certainly cases where we drop "to py - from py" cycles. It's just not always safe since there may be actual type coercions along that way. Doing these with a C cast might not always work or do the exact same thing.

@da-woods
Copy link
Contributor Author

da-woods commented May 12, 2024

Yes I do mean the transforms in Optimize.py.

PR changes also other operators (e.g. *). They are not tested here. Should not be added here?

Yes I think you're probably right. We've only had complaints about / for some reason. But more tests might spot the next breakage before it happens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants