GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-148871: extend and improve `LOAD_COMMON_CONSTANT` by NekoAsakura · Pull Request #148971 · python/cpython

Conversation

@NekoAsakura

@NekoAsakura NekoAsakura commented Apr 24, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Behaviour changes (Reverted)

Change main branch
1 all.__self__ / any.__self__ <module 'builtins'> None
2 gc.is_tracked(all) / gc.is_tracked(any) True False
  • Issue: Extend and improve LOAD_COMMON_CONSTANT #148871

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@NekoAsakura
pythongh-148871: extend and improve LOAD_COMMON_CONSTANT
fe39cfb
@NekoAsakura
NekoAsakura requested review from Eclips4, FFY00, Fidget-Spinner, ZeroIntensity, ericsnowcurrently, iritkatriel, markshannon, savannahostrowski and tomasr8 as code owners April 24, 2026 20:40
@bedevere-app bedevere-app Bot added the awaiting review label Apr 24, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Apr 24, 2026
Extend and improve LOAD_COMMON_CONSTANT #148871
Open
NekoAsakura added 2 commits April 24, 2026 17:08
@NekoAsakura
fix error
940932f
@NekoAsakura
update globals-to-fix.tsv
bec065a
markshannon
markshannon requested changes Apr 25, 2026
View reviewed changes

@markshannon markshannon left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Mostly looks good.

You need to take care distinguishing between process-wide data and per-interpreter data. See the comments below.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

NekoAsakura reacted with heart emoji
All reactions
  • ❤️ 1 reaction
Comment thread Objects/methodobject.c Outdated
meth_getsets, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */

@markshannon markshannon Apr 25, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Can you remove this list of zeros and use a named initializer: .tp_is_gc = cfunction_is_gc

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Python/flowgraph.c Outdated
return PyLong_FromLong(oparg);
}
if (opcode == LOAD_COMMON_CONSTANT) {
switch (oparg) {

@markshannon markshannon Apr 25, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Suggested change
switch (oparg) {
return load_common_const(oparg);

All these objects are immortal, so no need to worry about reference counts

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Python/optimizer_bytecodes.c Outdated
op(_LOAD_COMMON_CONSTANT, (-- value)) {
assert(oparg < NUM_COMMON_CONSTANTS);
PyObject *val = _PyInterpreterState_GET()->common_consts[oparg];
PyObject *val;

@markshannon markshannon Apr 25, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Why aren't you using the constants table?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Python/ceval_macros.h Outdated
static inline _PyStackRef
load_common_constant(unsigned int oparg)
{
switch (oparg) {

@markshannon markshannon Apr 25, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Why is this needed? These values should be in the table

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Python/bltinmodule.c Outdated
.vectorcall = _PyCFunction_vectorcall_O,
};

PyObject *_PyCommonConsts[NUM_COMMON_CONSTANTS];

@markshannon markshannon Apr 25, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

For this to be process-wide (not per-interpreter) PyExc_AssertionError and PyExc_NotImplementedError will need to be statically allocated.

Doing that might be complex, so maybe keep the constants per-interpreter for this PR, and make everything statically allocation in a later PR?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Python/pylifecycle.c Outdated
(PyObject *)&_PyLong_SMALL_INTS[_PY_NSMALLNEGINTS - 1];
for (int i = 0; i < NUM_COMMON_CONSTANTS; i++) {
assert(_PyCommonConsts[i] != NULL);
assert(_Py_IsImmortal(_PyCommonConsts[i]));

@markshannon markshannon Apr 25, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Suggested change
assert(_Py_IsImmortal(_PyCommonConsts[i]));
assert(_Py_IsStaticImmortal(_PyCommonConsts[i]));

If _PyCommonConsts is to be statically allocated.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Tools/c-analyzer/cpython/globals-to-fix.tsv Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting changes and removed awaiting review labels Apr 25, 2026
@bedevere-app

bedevere-app Bot commented Apr 25, 2026

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be poked with soft cushions!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@NekoAsakura
address requested changes
35592b1
@NekoAsakura

NekoAsakura commented Apr 25, 2026

Copy link
Copy Markdown
Member Author

Thanks for the review. Pushed the lot. :')

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

NekoAsakura added 3 commits April 27, 2026 06:36
@NekoAsakura
Merge branch 'main' into pythongh-148871/load-common-constant
22595cd
@NekoAsakura
fixup
926bd52
@NekoAsakura
retrigger CI
f654c71
@markshannon

markshannon commented May 1, 2026

Copy link
Copy Markdown
Member

This looks good, except the changes to any and all.

Sorry to go and forth on this, but I think we shouldn't make any and all static after all.

I'm worried that the changes to __self__ will break something. Maybe the GC change as well, but that seems less likely. Also, since the common constants table is still attached to the interpreter state, there is no performance advantage in doing so.

NekoAsakura reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

NekoAsakura added 2 commits May 1, 2026 13:29
@NekoAsakura
revert any/all static-ification
b4068b3
@NekoAsakura
Merge branch 'main' into pythongh-148871/load-common-constant
ebd1c28
@NekoAsakura

NekoAsakura commented May 1, 2026

Copy link
Copy Markdown
Member Author

Sound call. Reverted. Thanks again for the review.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

NekoAsakura added 3 commits May 1, 2026 14:24
@NekoAsakura
fixup: revert any/all static-ification
44dc084
@NekoAsakura
Merge branch 'main' into pythongh-148871/load-common-constant
558a5ac
@NekoAsakura
Merge branch 'main' into pythongh-148871/load-common-constant
b017ae9
@read-the-docs-community

read-the-docs-community Bot commented May 1, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #32502817 | 📁 Comparing b017ae9 against main (95559d2)

  🔍 Preview build  

61 files changed · + 1 added · ± 60 modified

+ Added

  • c-api/sentinel.html

± Modified

  • contents.html
  • download.html
  • genindex-B.html
  • genindex-C.html
  • genindex-D.html
  • genindex-E.html
  • genindex-F.html
  • genindex-G.html
  • genindex-H.html
  • genindex-I.html
  • and 50 more...
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@markshannon
markshannon self-requested a review May 2, 2026 18:57
markshannon
markshannon approved these changes May 2, 2026
View reviewed changes

@markshannon markshannon left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This fixes the compiler and selection of constants.

There are performance improvements to be made, but that can be done in another PR.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting changes labels May 2, 2026
@markshannon markshannon added the skip news label May 2, 2026
@markshannon
markshannon merged commit 7c9ad27 into python:main May 2, 2026
74 of 75 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label May 2, 2026
@markshannon

markshannon commented May 2, 2026

Copy link
Copy Markdown
Member

#148871 (comment)

NekoAsakura reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@NekoAsakura
NekoAsakura deleted the gh-148871/load-common-constant branch May 2, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@markshannon markshannon markshannon approved these changes
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner
@ZeroIntensity ZeroIntensity Awaiting requested review from ZeroIntensity ZeroIntensity is a code owner
@FFY00 FFY00 Awaiting requested review from FFY00 FFY00 is a code owner
@tomasr8 tomasr8 Awaiting requested review from tomasr8 tomasr8 is a code owner
@Fidget-Spinner Fidget-Spinner Awaiting requested review from Fidget-Spinner Fidget-Spinner is a code owner
@savannahostrowski savannahostrowski Awaiting requested review from savannahostrowski
@iritkatriel iritkatriel Awaiting requested review from iritkatriel iritkatriel is a code owner
@Eclips4 Eclips4 Awaiting requested review from Eclips4 Eclips4 is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@NekoAsakura @markshannon
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.