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

gh-119311: Fix name mangling with PEP 695 generic classes #119464

Merged
merged 5 commits into from
May 28, 2024

Conversation

JelleZijlstra
Copy link
Member

@JelleZijlstra JelleZijlstra commented May 23, 2024

Fixes #119311. Fixes #119395.

There are two related bugs with name mangling in generic classes: it incorrectly gets applied to names that appear in the class's type param scope (#119311) and it leaks into code after the generic class (#119395). This PR fixes both by introducing a new mechanism where in a type param scope, only type param names are mangled.

Unfortunately, I'm not sure we can backport this to 3.12, as it changes some internal C APIs and the magic number.

Copy link
Member

@carljm carljm left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@carljm
Copy link
Member

carljm commented May 28, 2024

I'm not sure I see why this can't be backported to 3.12.

I don't know if we usually bump bytecode magic number in patch releases, but surely that doesn't prevent us from backporting any compiler fixes at all. This change doesn't break execution of previously-compiled bytecode (any more than it was already buggy), so the worst case if backported without magic number bump is that some buggy bytecode wouldn't get the fix immediately. That's strictly better than nobody getting the fix at all in 3.12. (I'm not sure how else we can fix the issue of mangling type param names but not other names in class bases list.)

And I don't see where this changes existing C API. It adds a new function, but only internal/pycore. And it changes the symtable entry struct, but again that's not part of the public API.

@JelleZijlstra JelleZijlstra merged commit a9a74da into python:main May 28, 2024
36 checks passed
@miss-islington-app
Copy link

Thanks @JelleZijlstra for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@JelleZijlstra JelleZijlstra added the needs backport to 3.12 bug and security fixes label May 28, 2024
@miss-islington-app
Copy link

Sorry, @JelleZijlstra, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker a9a74da4a0ca0645f049e67b6434a95e30592c32 3.13

@miss-islington-app
Copy link

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

@JelleZijlstra JelleZijlstra deleted the pep695-mangle2 branch May 28, 2024 02:50
@miss-islington-app
Copy link

Sorry, @JelleZijlstra, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker a9a74da4a0ca0645f049e67b6434a95e30592c32 3.12

JelleZijlstra added a commit to JelleZijlstra/cpython that referenced this pull request May 28, 2024
@bedevere-app
Copy link

bedevere-app bot commented May 28, 2024

GH-119643 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label May 28, 2024
JelleZijlstra added a commit to JelleZijlstra/cpython that referenced this pull request May 28, 2024
@bedevere-app
Copy link

bedevere-app bot commented May 28, 2024

GH-119644 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 bug and security fixes label May 28, 2024
JelleZijlstra added a commit that referenced this pull request May 28, 2024
Yhg1s pushed a commit that referenced this pull request Jun 4, 2024
…9464) (#119644)

* [3.12] gh-119311: Fix name mangling with PEP 695 generic classes (#119464)

Fixes #119311. Fixes #119395.

(cherry picked from commit a9a74da)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PEP 695: Name mangling leaks to surrounding scope Unexpected name mangling behavior with generics
2 participants