Skip to content

Commit f6ea185

Browse files
Address review
1 parent 769cef6 commit f6ea185

12 files changed

Lines changed: 71 additions & 111 deletions

File tree

Include/internal/pycore_magic_number.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ Known values:
294294
Python 3.15a4 3661 (Lazy imports IMPORT_NAME opcode changes)
295295
Python 3.15a8 3662 (Add counter to RESUME)
296296
Python 3.15a8 3663 (Merge GET_ITER and GET_YIELD_FROM_ITER. Modify SEND to make it a bit more like FOR_ITER)
297-
Python 3.15b1 3664 (All code objects now have 1 extra stack slot space)
298297
299298
300299
Python 3.16 will start with 3700
@@ -308,7 +307,7 @@ PC/launcher.c must also be updated.
308307
309308
*/
310309

311-
#define PYC_MAGIC_NUMBER 3664
310+
#define PYC_MAGIC_NUMBER 3663
312311
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
313312
(little-endian) and then appending b'\r\n'. */
314313
#define PYC_MAGIC_NUMBER_TOKEN \

Include/internal/pycore_opcode_metadata.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/test/test_capi/test_opt.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2732,6 +2732,7 @@ def testfunc(n):
27322732
uops = get_opnames(ex)
27332733
self.assertIn("_CALL_BUILTIN_FAST", uops)
27342734
self.assertNotIn("_GUARD_CALLABLE_BUILTIN_FAST", uops)
2735+
self.assertGreaterEqual(count_ops(ex, "_POP_TOP_NOP"), 6)
27352736

27362737
def test_call_builtin_fast_with_keywords(self):
27372738
def testfunc(n):

Lib/test/test_sys.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,9 +1686,9 @@ def func():
16861686
return sys._getframe()
16871687
x = func()
16881688
if support.Py_GIL_DISABLED:
1689-
INTERPRETER_FRAME = '9PihcPP'
1689+
INTERPRETER_FRAME = '9PihcP'
16901690
else:
1691-
INTERPRETER_FRAME = '9PhcPP'
1691+
INTERPRETER_FRAME = '9PhcP'
16921692
check(x, size('3PiccPPP' + INTERPRETER_FRAME + 'P'))
16931693
# function
16941694
def func(): pass

Modules/_testinternalcapi/test_cases.c.h

Lines changed: 9 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/bytecodes.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,6 @@ dummy_func(
386386
PyStackRef_CLOSE(nos);
387387
}
388388

389-
// This is expanded to POP_TOP + POP_TOP + POP_TOP + ... (oparg times) in the JIT trace.
390389
op(_POP_TOP_OPARG, (args[oparg] -- )) {
391390
_PyStackRef_CloseStack(args, oparg);
392391
DEAD(args);
@@ -4635,7 +4634,7 @@ dummy_func(
46354634
EXIT_IF(PyCFunction_GET_FLAGS(callable_o) != METH_FASTCALL);
46364635
}
46374636

4638-
op(_CALL_BUILTIN_FAST, (callable, self_or_null, args[oparg] -- res, c, s, a[oparg])) {
4637+
op(_CALL_BUILTIN_FAST, (callable, self_or_null, args[oparg] -- res, s, a[oparg])) {
46394638
/* Builtin METH_FASTCALL functions, without keywords */
46404639
int total_args = oparg;
46414640
_PyStackRef *arguments = args;
@@ -4649,13 +4648,15 @@ dummy_func(
46494648
arguments,
46504649
total_args
46514650
);
4652-
c = callable;
4651+
// To maintain a consistent view of the stack in the GC, callable's stack location
4652+
// must be overwritten before we close it.
4653+
_PyStackRef *callable_ptr = args - 2;
4654+
PyStackRef_XSETREF(*callable_ptr, PyStackRef_NULL);
4655+
DEAD(callable);
46534656
s = self_or_null;
4654-
// Swap the first argument with the first empty slot after args to allows space for res.
4655-
// We are guaranteed by the bytecode compiler to have a spare stack slot.
4656-
args[oparg] = args[0];
46574657
DEAD(self_or_null);
46584658
DEAD(callable);
4659+
(void)a;
46594660
DEAD(args);
46604661
res = res_o == NULL ? PyStackRef_NULL : PyStackRef_FromPyObjectSteal(res_o);
46614662
}
@@ -4672,7 +4673,6 @@ dummy_func(
46724673
_CALL_BUILTIN_FAST +
46734674
_POP_TOP_OPARG +
46744675
POP_TOP +
4675-
POP_TOP +
46764676
_ERROR_IF_TOS_NULL +
46774677
_CHECK_PERIODIC_AT_END;
46784678

Python/executor_cases.c.h

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 9 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -945,12 +945,6 @@ _PyJit_translate_single_bytecode_to_trace(
945945
assert(next->op.code == STORE_FAST);
946946
operand = next->op.arg;
947947
}
948-
else if (uop == _POP_TOP_OPARG) {
949-
for (int i = 0; i < oparg; i++) {
950-
ADD_TO_TRACE(_POP_TOP, 0, operand, target);
951-
}
952-
continue;
953-
}
954948
else if (_PyUop_Flags[uop] & HAS_RECORDS_VALUE_FLAG) {
955949
PyObject *recorded_value = tracer->prev_state.recorded_value;
956950
tracer->prev_state.recorded_value = NULL;

Python/optimizer_analysis.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,29 @@ lookup_attr(JitOptContext *ctx, _PyBloomFilter *dependencies, _PyUOpInstruction
410410
return sym_new_not_null(ctx);
411411
}
412412

413+
static void
414+
optimize_pop_top(JitOptContext *ctx, _PyUOpInstruction *this_instr, JitOptRef value)
415+
{
416+
PyTypeObject *typ = sym_get_type(value);
417+
if (PyJitRef_IsBorrowed(value) ||
418+
sym_is_immortal(PyJitRef_Unwrap(value)) ||
419+
sym_is_null(value)) {
420+
ADD_OP(_POP_TOP_NOP, 0, 0);
421+
}
422+
else if (typ == &PyLong_Type) {
423+
ADD_OP(_POP_TOP_INT, 0, 0);
424+
}
425+
else if (typ == &PyFloat_Type) {
426+
ADD_OP(_POP_TOP_FLOAT, 0, 0);
427+
}
428+
else if (typ == &PyUnicode_Type) {
429+
ADD_OP(_POP_TOP_UNICODE, 0, 0);
430+
}
431+
else {
432+
ADD_OP(_POP_TOP, 0, 0);
433+
}
434+
}
435+
413436
static
414437
PyCodeObject *
415438
get_current_code_object(JitOptContext *ctx)

0 commit comments

Comments
 (0)