Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Unpack args array into separate stack variables
  • Loading branch information
tomasr8 committed May 3, 2025
commit 8ba53c3db69cf9a640500ab6f2d53d0cd8dc1ace
4 changes: 2 additions & 2 deletions Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Include/internal/pycore_uop_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -4353,26 +4353,25 @@ dummy_func(
res = PyStackRef_FromPyObjectSteal(res_o);
}

op(_GUARD_CALLABLE_ISINSTANCE, (callable, unused, unused[oparg] -- callable, unused, unused[oparg])) {
op(_GUARD_CALLABLE_ISINSTANCE, (callable, unused, unused, unused -- callable, unused, unused, unused)) {
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable);
PyInterpreterState *interp = tstate->interp;
DEOPT_IF(callable_o != interp->callable_cache.isinstance);
}

op(_CALL_ISINSTANCE, (callable, null, args[oparg] -- res)) {
op(_CALL_ISINSTANCE, (callable, null, inst_, cls -- res)) {
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.

I don't love the trailing underscore. Not a huge deal, but maybe just rename to instance or obj or something ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I renamed it to instance in be50e24

/* isinstance(o, o2) */
assert(oparg == 2);
STAT_INC(CALL, hit);
PyObject *inst = PyStackRef_AsPyObjectBorrow(args[0]);
PyObject *cls = PyStackRef_AsPyObjectBorrow(args[1]);
int retval = PyObject_IsInstance(inst, cls);
PyObject *inst_o = PyStackRef_AsPyObjectBorrow(inst_);
PyObject *cls_o = PyStackRef_AsPyObjectBorrow(cls);
int retval = PyObject_IsInstance(inst_o, cls_o);
if (retval < 0) {
ERROR_NO_POP();
}
(void)null; // Silence compiler warnings about unused variables
PyStackRef_CLOSE(cls);
PyStackRef_CLOSE(inst_);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Interesting that with named stackrefs it won't let me do this:

DEAD(null);
PyStackRef_CLOSE(cls);
PyStackRef_CLOSE(inst_);

(the error is SyntaxError: Input 'null' is not live, but 'inst_' is)
While with the previous args version this was fine:

DEAD(null);
PyStackRef_CLOSE(args[0]);
PyStackRef_CLOSE(args[1]);

I guess the cases generator can't reason about arrays? Another reason to use named stackrefs instead :)

DEAD(null);
PyStackRef_CLOSE(args[0]);
PyStackRef_CLOSE(args[1]);
PyStackRef_CLOSE(callable);
res = retval ? PyStackRef_True : PyStackRef_False;
assert((!PyStackRef_IsNull(res)) ^ (_PyErr_Occurred(tstate) != NULL));
Expand Down
31 changes: 17 additions & 14 deletions Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 15 additions & 11 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Python/optimizer_bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ dummy_func(void) {
res = sym_new_type(ctx, &PyLong_Type);
}

op(_GUARD_CALLABLE_ISINSTANCE, (callable, unused, unused[oparg] -- callable, unused, unused[oparg])) {
op(_GUARD_CALLABLE_ISINSTANCE, (callable, unused, unused, unused -- callable, unused, unused, unused)) {
PyObject *isinstance = _PyInterpreterState_GET()->callable_cache.isinstance;
if (sym_get_const(ctx, callable) == isinstance) {
REPLACE_OP(this_instr, _NOP, 0, 0);
Expand Down
6 changes: 3 additions & 3 deletions Python/optimizer_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading