8000 bpo-44800: rename _PyInterpreterFrame to _Py_frame by ncoghlan · Pull Request #31987 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-44800: rename _PyInterpreterFrame to _Py_frame #31987

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

10000

Conversation

ncoghlan
Copy link
Contributor
@ncoghlan ncoghlan commented Mar 19, 2022
  • rename _PyInterpreterFrame to _Py_frame to help indicate that _Py_frame
    is an implementation optimisation for frame objects rather than a distinct concept
  • remove f_ prefix from _Py_frame fields that currently have it so presence or
    absence of the prefix disambiguates PyFrameObject and _Py_frame pointers
    when reading code snippets without their type declarations in code diffs
  • rename f_frame to f_fdata to avoid the odd frame->f_frame construct
  • rename _f_frame_data to _f_owned_fdata to avoid confusion with f_fdata
  • convert a potentially confusing use of cframe as a variable name to just frame
  • add a block comment to pycore_frame.h covering the naming conventions

https://bugs.python.org/issue44800

@ncoghlan
Copy link
Contributor Author

Significantly scaled back from the original proposal in #27525, as per the Discourse thread at https://discuss.python.org/t/proposal-rename-pyinterpreterframe-struct-as-py-framedata/14213

Copy link
Member
@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

Honestly, I'm not convinced by the value of this large rename changes. I renamed _PyInterpreterFrame and _PyCFrame just before Python 3.11 alpha6 release which moves the PyFrameObject structure to the pycore_frame.h internal header file. The plan is now to updated 3rd party code projects to make them compatible with these changes (compatible with Python 3.11 alpha6): https://bugs.python.org/issue46836#msg414283

If we change this internal C API once more time (Python 3.11 alpha7 or another release), it would require one more compatibility layer to the compatibility sandwich of projects like Cython, greenlet and gevent which currently require to access to these members until faster-cpython/ideas#309 is implemented.

IMO investing time on implementing faster-cpython/ideas#309 first would make more sense, since right now there are still too many 3rd party code which require to access PyFrameObject members.

Once 3rd party code will no longer consume this internal C API, we will have more freedom to change it without annoying users. As I wrote, core devs are directly impacted since these changes often break pyperformance: https://bugs.python.org/issue46836#msg414279

cc @markshannon @brandtbucher

@bedevere-bot
Copy link

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@vstinner
Copy link
Member

I'm not saying that these changes should not be done. The current API can be enhanced as you do. The problem is really a practical problem impacting users right now.

@ncoghlan
Copy link
Contributor Author
ncoghlan commented Mar 19, 2022

@vstinner If you're willing to volunteer to sync the PEP 558 working branch with CPython's main branch for me without these changes being made first, then I'll drop the proposal.

I didn't file the issue out of idle whim, I filed it as a result of trying to do that merge and failing abjectly because I couldn't easily tell which conflicting snippets were using full frame objects and needed to add a level of indirection to get to the frame data object and which should now be using the lower level frame data struct and should hence change their type declarations.

I know this code pretty well (both the old and the new versions), so if I can't follow it well enough to merge it with other code, that doesn't bode well for future maintainability.

If you want to make the case that it's already too late to fix this and we're now stuck with it forever just because I broke my arm last November and didn't push the point until I'd recovered, then the Discourse thread is the place to do it: https://discuss.python.org/t/proposal-rename-pyinterpreterframe-struct-as-py-framedata/14213

@vstinner
Copy link
Member

PEP 558 is still a draft, no? Is it important to have an up to date implementation? There is also PEP 667. What's the status of these PEPs?

it's already too late to fix this and we're now stuck with it forever

That's not what I wrote. Once Cython, greenlet and gevent will be able to use a sane public C API, changing PyFrameObject internals will impact less projects.

@ncoghlan
Copy link
Contributor Author

And as I wrote on Discourse, if we don't change this internal layout for 3.11, we won't be able to change it in the future due to the problems it would create for bqckports.

@ncoghlan
Copy link
Contributor Author

PEP 558 is supposed to be in 3.11. The 3 months lost to my broken arm means it is likely that it isn't going to make it, but the readability problem revealed by attempting a merge of that magnitude is a separate issue (hence why I filed it as one)

@ncoghlan
Copy link
Contributor Author

I realised there's a macro hack we can use to keep code written for 3.11a6 compiling until a proper frame stack access API is available (presumably before 3.11b1).

The old field and type names aren't used anywhere else, so the C preprocessor can be used to automatically translate them at compile time.

@ncoghlan ncoghlan dismissed vstinner’s stale review March 20, 2022 03:50

Added a workaround that keeps 3.11a6 API compatibility by default

@ncoghlan
Copy link
Contributor Author

Thanks to C11, we're able to use static_assert now, so I was not only able to add a workaround that keeps code written against the 3.11a6 API working, but also compile time checks that those aliases were in place.

Temporarily adding #define _PY_FRAME_API_DISABLE_INTERIM_COMPAT_3_11a6 to frameobject.c also confirmed that that declaration turns off the compatibility aliases as expected (although rather than the static_asserts failing as such, they just fail to compile due to the missing type and field names referenced).

@ncoghlan
Copy link
Contributor Author

I'm going to scale back the proposal again to just the struct rename (keeping the old name around as a compatibility alias until there's a proper public API), and documenting the 7 frame data struct fields that have the "f_" prefix.

@ncoghlan ncoghlan closed this Mar 21, 2022
@ncoghlan
Copy link
Contributor Author

Scaled back PR is at #32024

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.

4 participants
0