Skip to content

gh-157468: Validate correct builtins used under JIT - #157766

Merged
markshannon merged 14 commits into
python:mainfrom
johng:gh-builtit-bug
Oct 1, 2026
Merged

markshannon merged 14 commits into
python:mainfrom
johng:gh-builtit-bug

Conversation

@johng

@johng johng commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

This adds the two checks at tracing and at JIT runtime that the builtin dict is the original interpreter's builtins

- Test 1: verifying the traceguard is correctly activating

- Test 2: verifying the runtime guard is activating

@cocolato cocolato left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please don't force push PRs. We‘ll squash merge commits at the end. And some comments:

Comment thread Python/optimizer_analysis.c Outdated
Comment thread Python/optimizer_bytecodes.c Outdated
@johng
johng requested a review from cocolato September 20, 2026 12:20

@cocolato cocolato left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for doing this, there are also a few comments

Comment thread Lib/test/test_capi/test_opt.py Outdated
Comment thread Lib/test/test_capi/test_opt.py Outdated
Co-authored-by: Hai Zhu <haiizhu@outlook.com>
@johng
johng requested a review from cocolato September 21, 2026 07:13

@cocolato cocolato left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, and let's wait a core dev to review this

@markshannon markshannon left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should be able to remove repeated checks in much the same way as do with ctx->frame->globals_checked_version by adding a ctx->frame->builtins_checked flag.

Comment thread Python/optimizer_bytecodes.c Outdated
if (ctx->frame->globals_checked_version != 0 && ctx->frame->globals_watched) {
if (ctx->frame->globals_checked_version != 0 &&
ctx->frame->globals_watched &&
uop_buffer_remaining_space(&ctx->out_buffer) >= 2)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We always allow enough headroom for small changes like this. No need to check here.

Comment thread Python/optimizer_bytecodes.c
@johng

johng commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor Author

I reverted the last commit against my fork and the same test failed so don't think it's related (and didn't seem to be anyway)

1 test failed:
test.test_gdb.test_jit

Edit: Saying that main appears to be in a good state although confused about the failure here

@johng

johng commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor Author

The failing test is now passing after latest merge to main @cocolato @markshannon I did some analysis and looks to be related to the code layout generated and whether a veneer is generated. I raised a separate issue above tracking it.

Comment thread Python/optimizer_bytecodes.c Outdated
Comment thread Python/optimizer_bytecodes.c Outdated
@methane

methane commented Sep 23, 2026

Copy link
Copy Markdown
Member

Isn't keys->dk_version = 0; needed in clone_combined_dict_keys()? @markshannon

johng and others added 2 commits September 23, 2026 07:18
@johng
johng requested a review from cocolato September 25, 2026 06:27
@cocolato

Copy link
Copy Markdown
Member

Isn't keys->dk_version = 0; needed in clone_combined_dict_keys()?

@johng refer: #157468 (comment)
We also need to reset keys->dk_version = 0 here, because a copied globals dict can otherwise pass the original dict’s version guard and reuse its folded constants even after the copy’s values change.

@johng
johng requested a review from methane as a code owner September 28, 2026 07:08

@markshannon markshannon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One small nit, otherwise looks good

/* Do nothing */
}
else if (ctx->frame->func == NULL ||
ctx->frame->func->func_builtins != builtins) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Empty clause. Can you put a /* Do nothing */ comment here for clarity

@bedevere-app

bedevere-app Bot commented Sep 30, 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.

@johng
johng requested a review from markshannon September 30, 2026 17:40

@markshannon markshannon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good now. Thanks

@markshannon markshannon added the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Oct 1, 2026
@markshannon
markshannon merged commit 0906d2a into python:main Oct 1, 2026
83 of 84 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @johng for the PR, and @markshannon for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Sorry, @johng and @markshannon, I could not cleanly backport this to 3.15 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 0906d2ab93fc9f4c7e0db031c965e7d8a0db7d37 3.15

@johng

johng commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews!

@bedevere-bot

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot s390x RHEL9 Refleaks 3.x (tier-3) has failed when building commit 0906d2a.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1589/builds/3974) and take a look at the build logs.
  4. Check if the failure is related to this commit (0906d2a) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1589/builds/3974

Summary of the results of the build (if available):

==

Click to see traceback logs
Note: switching to '0906d2ab93fc9f4c7e0db031c965e7d8a0db7d37'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 0906d2ab93f gh-157468: Validate correct builtins used under JIT (GH-157766)
Switched to and reset branch 'main'

Kill <WorkerThread #1 running test=test_regrtest pid=3678827 time=2 min 11 sec> process group
Kill <WorkerThread #3 running test=test.test_concurrent_futures.test_process_pool pid=3655369 time=5 min 16 sec> process group
Kill <WorkerThread #4 running test=test.test_concurrent_futures.test_future pid=3689330 time=3.7 sec> process group
Kill <WorkerThread #5 running test=test.test_multiprocessing_forkserver.test_misc pid=3688887 time=7.2 sec> process group
Kill <WorkerThread #6 running test=test.test_gdb.test_pretty_print pid=3687892 time=19.8 sec> process group
Kill <WorkerThread #7 running test=test_zipfile pid=3673953 time=3 min 5 sec> process group
Kill <WorkerThread #8 running test=test_tarfile pid=3681066 time=1 min 48 sec> process group
Kill <WorkerThread #9 running test=test_imaplib pid=3676017 time=2 min 45 sec> process group
Kill <WorkerThread #10 running test=test_socket pid=3688888 time=7.2 sec> process group
make: *** [Makefile:2487: buildbottest] Error 130

@bedevere-bot

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 FreeBSD Refleaks 3.x (tier-3) has failed when building commit 0906d2a.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1613/builds/3909) and take a look at the build logs.
  4. Check if the failure is related to this commit (0906d2a) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1613/builds/3909

Failed tests:

  • test.test_asyncio.test_ssl

Failed subtests:

  • test_remote_shutdown_receives_trailing_data - test.test_asyncio.test_ssl.TestSSL.test_remote_shutdown_receives_trailing_data

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.opsec-fbsd14.refleak/build/Lib/test/test_asyncio/test_ssl.py", line 1422, in test_remote_shutdown_receives_trailing_data
    self.loop.run_until_complete(client(srv.addr))
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.x.opsec-fbsd14.refleak/build/Lib/asyncio/base_events.py", line 725, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/home/buildbot/buildarea/3.x.opsec-fbsd14.refleak/build/Lib/test/test_asyncio/test_ssl.py", line 1406, in client
    await future
  File "/home/buildbot/buildarea/3.x.opsec-fbsd14.refleak/build/Lib/test/test_asyncio/test_ssl.py", line 1414, in wrapper
    meth(sock)
    ~~~~^^^^^^
  File "/home/buildbot/buildarea/3.x.opsec-fbsd14.refleak/build/Lib/test/test_asyncio/test_ssl.py", line 1360, in server
    self.assertEqual(data_len, CHUNK * SIZE)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 0 != 4194304

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs backport to 3.15 pre-release feature fixes, bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants