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-131798: Split `CHECK_FUNCTION_VERSION` into two guards in the JIT by Sacul0457 · Pull Request #145080 · python/cpython

Conversation

@Sacul0457

@Sacul0457 Sacul0457 commented Feb 21, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

This PR splits up _CHECK_FUNCTION_VERSION into _GUARD_CALLABLE_FUNCTION and itself. This allows the optimizer to remove the PyFunction_Check check if we know the type. I think the naming can be improved but this is just what I went for.

This can be done for _CHECK_FUNCTION_VERSION_KW too but I left that out to keep the change smaller.

  • Issue: Better uop coverage in the JIT optimizer #131798

Sorry, something went wrong.

Uh oh!

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

All reactions
@Sacul0457
Sacul0457 requested review from Fidget-Spinner, markshannon, savannahostrowski and tomasr8 as code owners February 21, 2026 14:04
@bedevere-app bedevere-app Bot added the awaiting review label Feb 21, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Feb 21, 2026
Better uop coverage in the JIT optimizer #131798
Open
@Sacul0457
Sacul0457 marked this pull request as draft February 21, 2026 14:04
@bedevere-app bedevere-app Bot removed the awaiting review label Feb 21, 2026
Sacul0457
Sacul0457 commented Feb 22, 2026
View reviewed changes
Comment thread Python/optimizer_bytecodes.c Resolved

Uh oh!

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

Fidget-Spinner
Fidget-Spinner reviewed Feb 24, 2026
View reviewed changes
Comment thread Python/bytecodes.c Resolved

Uh oh!

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

Sacul0457 added 3 commits February 25, 2026 16:45
@Sacul0457
Split CHECK_FUNCTION_VERSION into two guards
ebcc043
@Sacul0457
address review and add assert
481ad4b
@Sacul0457
Attempting to fix merge conflicts...
e775a6b
@Sacul0457
Sacul0457 force-pushed the Split-up-CHECK_FUNCTION_VERSION branch from 37e58ef to e775a6b Compare February 25, 2026 09:08
Sacul0457 and others added 4 commits March 13, 2026 21:09
@Sacul0457
Merge branch 'main' into Split-up-CHECK_FUNCTION_VERSION
7c62059
@blurb-it
📜🤖 Added by blurb_it.
86c929d
@Sacul0457
regen files
99cbd72
@Sacul0457
Merge branch 'Split-up-CHECK_FUNCTION_VERSION' of https://github.com/…
0a3a178
…Sacul0457/cpython into Split-up-CHECK_FUNCTION_VERSION
@Sacul0457
Sacul0457 marked this pull request as ready for review March 13, 2026 13:24
@bedevere-app bedevere-app Bot added the awaiting review label Mar 13, 2026
@Sacul0457
fix lint
f58adeb
Fidget-Spinner
Fidget-Spinner approved these changes Mar 13, 2026
View reviewed changes

@Fidget-Spinner Fidget-Spinner 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.

Thanks.

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 review labels Mar 13, 2026
Sacul0457 added 3 commits March 14, 2026 00:17
@Sacul0457
change to assert
aa03bc0
@Sacul0457
Merge branch 'main' into Split-up-CHECK_FUNCTION_VERSION
40d2eaa
@Sacul0457
regen files
f7a5f30
@Sacul0457

Sacul0457 commented Mar 21, 2026

Copy link
Copy Markdown
Contributor Author

Is this optimization still correct/sound after #146101?

All reactions

Sorry, something went wrong.

Uh oh!

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

Fidget-Spinner
Fidget-Spinner reviewed Mar 21, 2026
View reviewed changes
Comment thread Python/optimizer_bytecodes.c
op(_CHECK_FUNCTION_VERSION, (func_version/2, callable, self_or_null, unused[oparg] -- callable, self_or_null, unused[oparg])) {
assert(sym_matches_type(callable, &PyFunction_Type));
if (sym_get_func_version(callable) == func_version) {
REPLACE_OP(this_instr, _NOP, 0, 0);

@Fidget-Spinner Fidget-Spinner Mar 21, 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.

I just realised this existing code I wrote might be wrong

The idea is that it's possible to modify a function version midway in a trace, so we need to recheck it or at least add a watcher at the first check.

Sorry, something went wrong.

Uh oh!

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

All reactions

@Fidget-Spinner Fidget-Spinner Mar 21, 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.

@Sacul0457 would you be willing to help me fix this (please open a separate issue if so)? Basically you'd need to add a PyFunction_AddWatcher in the else case of this branch. (See what we do in _GUARD_TYPE_VERSION). It's just a callback that invalidates the executors (see type_watcher_callback).

Sorry, something went wrong.

Uh oh!

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

All reactions

@Sacul0457 Sacul0457 Mar 21, 2026

Copy link
Copy Markdown
Contributor Author

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.

Sure, Ill open an issue and the PR in a bit

Sorry, something went wrong.

Uh oh!

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

Fidget-Spinner reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@Sacul0457 Sacul0457 Mar 21, 2026

Copy link
Copy Markdown
Contributor Author

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.

Hi, I was just taking a look at this issue and I've got a few questions:

  • We add a PyFunction_AddWatcher only if the func_version was set properly, like what _GUARD_TYPE_VERSION version does?
  • If so, what PyFunction_WatchCallback do I add to PyFunction_AddWatcher or am I suppose to create one similar to type_watcher_callback

I'll continue to look into this in the meantime, thx! :)

Sorry, something went wrong.

Uh oh!

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

All reactions

@Fidget-Spinner Fidget-Spinner Mar 21, 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.

We add a PyFunction_AddWatcher only if the func_version was set properly, like what _GUARD_TYPE_VERSION version does?

Yup!

If so, what PyFunction_WatchCallback do I add to PyFunction_AddWatcher or am I suppose to create one similar to type_watcher_callback

Yes you need to create your own one with its own ID similar to type_watcher_callback.

Sorry, something went wrong.

Uh oh!

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

All reactions

@Fidget-Spinner Fidget-Spinner Mar 21, 2026 •
edited
Loading

Uh oh!

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

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.

The function watcher needs to be more specific though: we want to invalidate for everything except for PyFunction_EVENT_DESTROY. As that doesn't actually invalidate any of our assumptions.

Sorry, something went wrong.

Uh oh!

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

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

@Sacul0457 Sacul0457 Mar 21, 2026

Copy link
Copy Markdown
Contributor Author

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.

Ah ok ty!

Yes you need to create your own one with its own ID similar to type_watcher_callback.

Just one more thing on the callback (sorry!),
type_watcher_callback calls PyType_Unwatch, and so I'm guessing I also need to create some sort of PyFunc_Unwatch?

Sorry, something went wrong.

Uh oh!

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

All reactions

@Fidget-Spinner Fidget-Spinner Mar 21, 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.

It should be PyFunction_ClearWatcher (check Objects/funcobject.c)

Sorry, something went wrong.

Uh oh!

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

All reactions

@Sacul0457 Sacul0457 Mar 21, 2026

Copy link
Copy Markdown
Contributor Author

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.

Found it thx!

Sorry, something went wrong.

Uh oh!

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

All reactions
@Sacul0457 Sacul0457 mentioned this pull request Mar 21, 2026
JIT: Optimization in _CHECK_FUNCTION_VERSION is wrong #146261
Closed
@Sacul0457

Sacul0457 commented Apr 9, 2026

Copy link
Copy Markdown
Contributor Author

Is this optimization still possible/correct with #146300?

All reactions

Sorry, something went wrong.

Uh oh!

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

@github-actions

github-actions Bot commented May 17, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

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

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label May 17, 2026
@ambv

ambv commented Oct 20, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

This PR is superseded by #157011, a newer open pull request for the same issue (gh-131798), and it no longer merges cleanly. Closing to cull the number of open pull requests. Do not reopen this pull request without getting a go-ahead from a triager or core developer.

Incorrectly marked as duplicate.

All reactions

Sorry, something went wrong.

Uh oh!

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

@ambv ambv closed this Oct 20, 2026
@ambv ambv reopened this Oct 21, 2026
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Oct 21, 2026
@read-the-docs-community

read-the-docs-community Bot commented Oct 21, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35284819 | 📁 Comparing f7a5f30 against main (1277a5e)

  🔍 Preview build  

353 files changed · + 1 added · ± 333 modified · - 19 deleted

+ Added

  • library/asyncio-policy.html

± Modified

  • glossary.html
  • index.html
  • license.html
  • py-modindex.html
  • _static/tachyon-example-heatmap.html
  • c-api/allocation.html
  • c-api/arg.html
  • c-api/buffer.html
  • c-api/bytearray.html
  • c-api/bytes.html
  • and 323 more...

- Deleted

  • builtins/constants.html
  • builtins/exceptions.html
  • builtins/functions.html
  • builtins/index.html
  • builtins/stdtypes.html
  • builtins/threadsafety.html
  • builtins/time-complexity.html
  • c-api/sentinel.html
  • c-api/slots.html
  • deprecations/pending-removal-in-3.21.html
  • and 9 more...
All reactions

Sorry, something went wrong.

Uh oh!

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

@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Fidget-Spinner Fidget-Spinner Fidget-Spinner approved these changes
@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner
@tomasr8 tomasr8 Awaiting requested review from tomasr8 tomasr8 is a code owner
@savannahostrowski savannahostrowski Awaiting requested review from savannahostrowski

Uh oh!

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

Assignees

No one assigned

Labels

awaiting merge type-feature A feature request or enhancement

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.

3 participants

@Sacul0457 @ambv @Fidget-Spinner
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.