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
Remove redundant macros used for stack manipulation in interpreter #85097
Comments
Currently, there are fourteen macros provided for stack manipulation. TOP()
SECOND()
THIRD()
FOURTH()
SET_TOP(v)
SET_SECOND(v)
SET_THIRD(v)
SET_FOURTH(v)
SET_VALUE(n, v)
STACK_GROW(n)
STACK_SHRINK(n) These are unnecessary as compilers have long understood the sequences of pointer increments and decrements that is generated by using POPs and PUSHes. See https://godbolt.org/z/Htw-2k which shows GCC generating exactly the same code from just POP, PUSH and PEEK as from direct access to items on the stack. Removing the redundant macros would make the code easier to reason about and analyze. Notes: I'm ignoring the stack debugging macros here, they aren't a problem. |
What type of changes are you proposing to make? |
I'm proposing that we remove the nine macros above; the eleven listed, except TOP() and SECOND(). |
AFAIK, SET_VALUE is not used in CPython master codebase. |
I don't see any advantage to making this change. The current code is readable and the macros have an obvious interpretation. We also know that they generate clean code on every compiler we've come across and on 32 bits. Also, this should be marked as type, "performance". If performance changes at all, it will likely be a net detriment. |
I could understand wanting to replace TOP,...,FOURTH with PEEK(n) and the SET_XYZs with the now deleted SET(_VALUE)(n, v), but to me, replacing PEEK-SET with POPs and PUSHes (in different orders) that directly mean something different but that compilers (all?) optimize to mean the same thing makes the code initially harder to read. In particular, the old version of TARGET(ROT_FOUR) is initially clearer without thinking through the effect of the particular order of pushes in the new version. It depends on what one is accustomed to. |
Dennis, thanks for doing the benchmarking. Since this may have a negative effect on performance and doesn't seem to be popular, let's drop it. For the record, my motivation for this change is for tooling. Such "nice to have" features aren't worth the slowdown. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: