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

[3.13] gh-117482: Simplify the Fix For Builtin Types Slot Wrappers #121932

Conversation

ericsnowcurrently
Copy link
Member

@ericsnowcurrently ericsnowcurrently commented Jul 17, 2024

In gh-121602, I applied a fix to a builtin types initialization bug. That fix made sense in the context of some broader future changes, but introduced a little bit of extra complexity. For earlier versions those future changes are not relevant; we can avoid the extra complexity. Thus we can revert that earlier change and replace it with one that is more focused and conceptually simpler.

That's this PR. It's essentially the implementation of an idea that @markshannon pointed out to me. Note that this change would be much smaller if we didn't have to deal with compatibility for builtin types that explicitly inherit tp slots (see expect_manually_inherited()).

Copy link
Member

@markshannon markshannon left a comment

Choose a reason for hiding this comment

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

Would it make sense to set a flag for each slot that is explicitly overridden when we first see the PyTypeObject struct. That way, we can refer to that during subsequent calls to know whether the field was set by the author or by the VM?

We only need about 80 bits per type

Objects/typeobject.c Show resolved Hide resolved
@markshannon
Copy link
Member

Thinking about this so more, I think the problem is that we are attempting to initial static builtin types more than once.
We should only do it once, pre process. Then this problem goes away.

@ericsnowcurrently
Copy link
Member Author

Thinking about this so more, I think the problem is that we are attempting to initial static builtin types more than once. We should only do it once, pre process. Then this problem goes away.

I agree, but this would probably be too much of a change for 3.13 and 3.12.

@markshannon
Copy link
Member

Does this fix the issue?
If it does, could you add a test?

The change itself is a bit ad-hoc, but it looks fine.

@ericsnowcurrently
Copy link
Member Author

If it does, could you add a test?

The existing test does verify that the underlying is still fixed. I'll add a test for the embedding case.

@ericsnowcurrently ericsnowcurrently merged commit 716c677 into python:3.13 Jul 24, 2024
32 checks passed
@miss-islington-app
Copy link

Thanks @ericsnowcurrently for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@ericsnowcurrently ericsnowcurrently deleted the simplify-builtin-static-type-add-operators-3.13 branch July 24, 2024 18:02
ericsnowcurrently added a commit to ericsnowcurrently/cpython that referenced this pull request Jul 24, 2024
…ers (pythongh-121932)

In pythongh-121602, I applied a fix to a builtin types initialization bug.
That fix made sense in the context of some broader future changes,
but introduced a little bit of extra complexity.  For earlier versions
those future changes are not relevant; we can avoid the extra complexity.
Thus we can revert that earlier change and replace it with this one,
which is more focused and conceptually simpler.  This is essentially
the implementation of an idea that @markshannon pointed out to me.

Note that this change would be much smaller if we didn't have to deal
with repr compatibility for builtin types that explicitly inherit tp slots
(see expect_manually_inherited()).  The alternative is to stop
*explicitly* inheriting tp slots in static PyTypeObject values,
which is churn that we can do separately.

(cherry picked from commit 716c677, AKA pythongh-121932)
@ericsnowcurrently ericsnowcurrently removed the needs backport to 3.12 bug and security fixes label Jul 24, 2024
ericsnowcurrently added a commit that referenced this pull request Jul 24, 2024
…h-122241)

In gh-121602, I applied a fix to a builtin types initialization bug.
That fix made sense in the context of some broader future changes,
but introduced a little bit of extra complexity.  For earlier versions
those future changes are not relevant; we can avoid the extra complexity.
Thus we can revert that earlier change and replace it with this one,
which is more focused and conceptually simpler.  This is essentially
the implementation of an idea that @markshannon pointed out to me.

Note that this change would be much smaller if we didn't have to deal
with repr compatibility for builtin types that explicitly inherit tp slots
(see expect_manually_inherited()).  The alternative is to stop
*explicitly* inheriting tp slots in static PyTypeObject values,
which is churn that we can do separately.

(cherry picked from commit 716c677, AKA gh-121932)
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.

2 participants