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-130415: Eliminate guards for constant CALL_BUILTIN_O/FAST by Fidget-Spinner · Pull Request #132708 · python/cpython

Conversation

@Fidget-Spinner

@Fidget-Spinner Fidget-Spinner commented Apr 18, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member
  • Issue: Better constant narrowing in the JIT optimizer #130415

Sorry, something went wrong.

Uh oh!

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

All reactions
@Fidget-Spinner
Eliminate guards for constant CALL_BUILTIN_O/FAST
385a663
@Fidget-Spinner
Fidget-Spinner requested a review from markshannon as a code owner April 18, 2025 21:03
@python-cla-bot

python-cla-bot Bot commented Apr 18, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot added the awaiting core review label Apr 18, 2025
@Fidget-Spinner
Fidget-Spinner requested review from brandtbucher and removed request for markshannon April 18, 2025 21:03
@bedevere-app bedevere-app Bot mentioned this pull request Apr 18, 2025
Better constant narrowing in the JIT optimizer #130415
Closed
13 of 17 tasks
@Fidget-Spinner
lint
e357d13
@Fidget-Spinner Fidget-Spinner added the skip news label Apr 18, 2025
brandtbucher
brandtbucher approved these changes Apr 24, 2025
View reviewed changes

@brandtbucher brandtbucher 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.

Some suggestions, but looks good!

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Python/optimizer_bytecodes.c
Comment on lines +690 to +701
int total_args = oparg;
if (sym_is_null(self_or_null) || sym_is_not_null(self_or_null)) {
total_args += sym_is_not_null(self_or_null);
// Constant propagate
if (total_args == 1 && sym_is_const(ctx, callable)) {
PyObject *callable_o = sym_get_const(ctx, callable);
if (PyCFunction_CheckExact(callable_o) &&
PyCFunction_GET_FLAGS(callable_o) == METH_O) {
REPLACE_OP(this_instr, _NOP, 0 ,0);
}
}
}

@brandtbucher brandtbucher Apr 24, 2025

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.

Not sure how much this helps in practice, but in theory we could infer a NULL/non-NULL here based on the oparg, and narrow the type of the callable:

Suggested change
int total_args = oparg;
if (sym_is_null(self_or_null) || sym_is_not_null(self_or_null)) {
total_args += sym_is_not_null(self_or_null);
// Constant propagate
if (total_args == 1 && sym_is_const(ctx, callable)) {
PyObject *callable_o = sym_get_const(ctx, callable);
if (PyCFunction_CheckExact(callable_o) &&
PyCFunction_GET_FLAGS(callable_o) == METH_O) {
REPLACE_OP(this_instr, _NOP, 0 ,0);
}
}
}
if (sym_is_null(self_or_null) || sym_is_not_null(self_or_null)) {
int total_args = oparg + sym_is_not_null(self_or_null);
// Constant propagate
if (total_args == 1 && sym_is_const(ctx, callable)) {
PyObject *callable_o = sym_get_const(ctx, callable);
if (PyCFunction_CheckExact(callable_o) &&
PyCFunction_GET_FLAGS(callable_o) == METH_O) {
REPLACE_OP(this_instr, _NOP, 0 ,0);
}
}
}
else if (oparg == 0) {
sym_set_non_null(ctx, self_or_null);
}
else {
assert(oparg == 1);
sym_set_null(ctx, self_or_null);
}
sym_set_type(callable, &PyCFunction_Type);

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Python/bytecodes.c
Comment on lines +4115 to +4121
op(_GUARD_CALL_BUILTIN_O, (callable, self_or_null, unused[oparg] -- callable, self_or_null, unused[oparg])) {
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable);

int total_args = oparg;
if (!PyStackRef_IsNull(self_or_null)) {
args--;
total_args++;
}
int total_args = oparg + (!PyStackRef_IsNull(self_or_null));
EXIT_IF(total_args != 1);
EXIT_IF(!PyCFunction_CheckExact(callable_o));
EXIT_IF(PyCFunction_GET_FLAGS(callable_o) != METH_O);
}

@brandtbucher brandtbucher Apr 24, 2025 •
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.

You might consider breaking this in two: one guard for the number of args, and one guard for callable type/flags. Could be there are situations where you could remove one but not the other.

Speaking of which, is it equally common to have NULL or self for these two instructions? Or is it more likely that it's always one or the other?

It might be worth tightening up the specialization for only one of the cases, since that makes the guards much simpler (and easier to remove). Maybe it's worth running stats.

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 core review labels Apr 24, 2025
@github-actions

github-actions Bot commented Apr 23, 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 Apr 23, 2026
@ambv

ambv commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

This PR is attached to gh-130415, which is already completed: the fix for that issue landed through other changes, and this PR's approach was not taken or has since become obsolete. 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.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@brandtbucher brandtbucher brandtbucher approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

awaiting merge skip news stale Stale PR or inactive for long period of time.

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

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