8000 gh-132097: remove unnecessary clinic casts to `PyCFunction` and others by picnixz · Pull Request #131665 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-132097: remove unnecessary clinic casts to PyCFunction and others #131665

New issue 10000

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

Closed

Conversation

picnixz
Copy link
Member
@picnixz picnixz commented Mar 24, 2025

@picnixz
Copy link
Member Author
picnixz commented Apr 4, 2025

@vstinner This one is purely cosmetic but it affects lots of files. It's about removing redundant casts. I've removed some redundant casts with non-clinic files but this one just removes the casts generated by clinic.

I'm not entirely sure I want to merge this for the following reason:

  • let's say clinic incorrectly generates a signature, and the signature then becomes incompatible. With this change, this would affect the PR with a bad clinic signature. However, this means that we need to fix clinic in the meantime.
  • Without removing the explicit casts, we can at least make other PRs relying on clinic not affected by subtle UBs that may or may not be impactful.
  • For WASM, UBs are strictly checked: "Bad fpcasts are an issue in WebAssembly. WASM's indirect_call has strict function signature checks. Argument count, types, and return type must match." (this is a comment for _PyCFunction_TrampolineCall in pycore_object.h (which is also duplicated in pycore_emscripten_trampoline.h).
  • So technically, while it's a UB for all platforms, it's much more annoying on Emscripten. So maybe it's better that UBs are always detected at compile time.

I'm going to first address the fastcall issue before continuing here so take your time. I won't commit if you're not happy with this change or if you prefer that we hold it until we see a real issue.

@picnixz picnixz changed the title gh-111178: remove unnecessary clinic casts to PyCFunction gh-111178: remove unnecessary clinic casts to PyCFunction and others Apr 5, 2025
@picnixz picnixz changed the title gh-111178: remove unnecessary clinic casts to PyCFunction and others gh-131665: remove unnecessary clinic casts to PyCFunction and others Apr 5, 2025
@picnixz picnixz changed the title gh-131665: remove unnecessary clinic casts to PyCFunction and others gh-132097: remove unnecessary clinic casts to PyCFunction and others Apr 5, 2025
@picnixz
Copy link
Member Author
picnixz commented Apr 20, 2025

I more or less added explicit casts for WASM in #132406 so what's left here is just removing redundant casts. If someone wants to push for that, we'll do it but it will create conflicts in many generated files (which, thankfully, are easy to fix with make clinic). That being said, it's not that useful for now. If I were to be alone on the project, I would have pushed this one. But I'm not and I eventually don't see a real value that this PR brings. So I will close this.

@picnixz picnixz closed this Apr 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0