Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-130415: Eliminate guards for constant CALL_BUILTIN_O/FAST#132708

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Fidget-Spinner wants to merge2 commits intopython:main
base:main
Choose a base branch
Loading
fromFidget-Spinner:constant-prop-builtins

Conversation

Fidget-Spinner
Copy link
Member

@Fidget-SpinnerFidget-Spinner commentedApr 18, 2025
edited by bedevere-appbot
Loading

@python-cla-bot
Copy link

python-cla-botbot commentedApr 18, 2025
edited
Loading

All commit authors signed the Contributor License Agreement.

CLA signed

Copy link
Member

@brandtbucherbrandtbucher left a 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!

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);
}
}
}
Copy link
Member

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 aNULL/non-NULL here based on the oparg, and narrow the type of the callable:

Suggested change
inttotal_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)) {
inttotal_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);
}
}
}
elseif (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);

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);
}
Copy link
Member

@brandtbucherbrandtbucherApr 24, 2025
edited
Loading

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 haveNULL orself 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.

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

@brandtbucherbrandtbucherbrandtbucher approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@Fidget-Spinner@brandtbucher

[8]ページ先頭

©2009-2025 Movatter.jp