Skip to content

Commit 029f844

Browse files
committed
Remove support for conditional stack effects from code generators
1 parent 053327a commit 029f844

18 files changed

+83
-192
lines changed

Include/internal/pycore_opcode_metadata.h

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

Include/internal/pycore_uop_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_opcache.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1352,8 +1352,9 @@ def __init__(self):
13521352
A()
13531353

13541354
self.assert_specialized(A.__init__, "LOAD_SUPER_ATTR_ATTR")
1355-
self.assert_specialized(A.__init__, "LOAD_SUPER_ATTR_METHOD")
1355+
self.assert_specialized(A.__init__, "LOAD_SUPER_METHOD_METHOD")
13561356
self.assert_no_opcode(A.__init__, "LOAD_SUPER_ATTR")
1357+
self.assert_no_opcode(A.__init__, "LOAD_SUPER_METHOD")
13571358

13581359
# Temporarily replace super() with something else.
13591360
real_super = super

Python/bytecodes.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2429,7 +2429,7 @@ dummy_func(
24292429
_SAVE_RETURN_OFFSET +
24302430
_PUSH_FRAME;
24312431

2432-
inst(LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN, (unused/1, type_version/2, func_version/2, getattribute/4, owner -- unused, unused if (0))) {
2432+
inst(LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN, (unused/1, type_version/2, func_version/2, getattribute/4, owner -- unused)) {
24332433
PyObject *owner_o = PyStackRef_AsPyObjectBorrow(owner);
24342434

24352435
assert((oparg & 1) == 0);
@@ -3365,7 +3365,7 @@ dummy_func(
33653365
DEOPT_IF(FT_ATOMIC_LOAD_UINT32_RELAXED(keys->dk_version) != keys_version);
33663366
}
33673367

3368-
split op(_LOAD_METHOD_WITH_VALUES, (descr/4, owner -- attr, self if (1))) {
3368+
split op(_LOAD_METHOD_WITH_VALUES, (descr/4, owner -- attr, self)) {
33693369
assert(oparg & 1);
33703370
/* Cached method object */
33713371
STAT_INC(LOAD_ATTR, hit);
@@ -3383,7 +3383,7 @@ dummy_func(
33833383
_GUARD_KEYS_VERSION +
33843384
_LOAD_METHOD_WITH_VALUES;
33853385

3386-
op(_LOAD_METHOD_NO_DICT, (descr/4, owner -- attr, self if (1))) {
3386+
op(_LOAD_METHOD_NO_DICT, (descr/4, owner -- attr, self)) {
33873387
assert(oparg & 1);
33883388
assert(Py_TYPE(PyStackRef_AsPyObjectBorrow(owner))->tp_dictoffset == 0);
33893389
STAT_INC(LOAD_ATTR, hit);
@@ -4712,11 +4712,16 @@ dummy_func(
47124712
LLTRACE_RESUME_FRAME();
47134713
}
47144714

4715-
inst(BUILD_SLICE, (start, stop, step if (oparg == 3) -- slice)) {
4715+
inst(BUILD_SLICE, (args[oparg] -- slice)) {
4716+
assert(oparg == 2 || oparg == 3);
4717+
_PyStackRef start = args[0];
4718+
_PyStackRef stop = args[1];
47164719
PyObject *start_o = PyStackRef_AsPyObjectBorrow(start);
47174720
PyObject *stop_o = PyStackRef_AsPyObjectBorrow(stop);
4718-
PyObject *step_o = PyStackRef_AsPyObjectBorrow(step);
4719-
4721+
PyObject * step_o = NULL;
4722+
if (oparg == 3) {
4723+
step_o = PyStackRef_AsPyObjectBorrow(args[2]);
4724+
}
47204725
PyObject *slice_o = PySlice_New(start_o, stop_o, step_o);
47214726
DECREF_INPUTS();
47224727
ERROR_IF(slice_o == NULL, error);

Python/executor_cases.c.h

Lines changed: 16 additions & 14 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: 17 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,10 +1283,7 @@ uop_optimize(
12831283
for (int pc = 0; pc < length; pc++) {
12841284
int opcode = buffer[pc].opcode;
12851285
int oparg = buffer[pc].oparg;
1286-
if (_PyUop_Flags[opcode] & HAS_OPARG_AND_1_FLAG) {
1287-
buffer[pc].opcode = opcode + 1 + (oparg & 1);
1288-
}
1289-
else if (oparg < _PyUop_Replication[opcode]) {
1286+
if (oparg < _PyUop_Replication[opcode]) {
12901287
buffer[pc].opcode = opcode + oparg + 1;
12911288
}
12921289
else if (is_terminator(&buffer[pc])) {

Python/optimizer_bytecodes.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,12 @@ dummy_func(void) {
550550
}
551551
}
552552

553-
op(_LOAD_ATTR, (owner -- attr, self_or_null if (oparg & 1))) {
553+
op(_LOAD_ATTR, (owner -- attr)) {
554+
(void)owner;
555+
attr = sym_new_not_null(ctx);
556+
}
557+
558+
op(_LOAD_METHOD, (owner -- attr, self_or_null)) {
554559
(void)owner;
555560
attr = sym_new_not_null(ctx);
556561
self_or_null = sym_new_unknown(ctx);
@@ -812,7 +817,7 @@ dummy_func(void) {
812817
Py_UNREACHABLE();
813818
}
814819

815-
op(_PUSH_FRAME, (new_frame: _Py_UOpsAbstractFrame * -- unused if (0))) {
820+
op(_PUSH_FRAME, (new_frame: _Py_UOpsAbstractFrame * -- )) {
816821
SYNC_SP();
817822
ctx->frame->stack_pointer = stack_pointer;
818823
ctx->frame = new_frame;

Python/optimizer_cases.c.h

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

Python/specialize.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,6 @@ do_specialize_instance_load_attr(PyObject* owner, _Py_CODEUNIT* instr, PyObject*
11171117
SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_OUT_OF_VERSIONS);
11181118
return -1;
11191119
}
1120-
uint8_t oparg = FT_ATOMIC_LOAD_UINT8_RELAXED(instr->op.arg);
11211120
switch(kind) {
11221121
case OVERRIDING:
11231122
SPECIALIZATION_FAIL(load_method ? LOAD_METHOD : LOAD_ATTR, SPEC_FAIL_ATTR_OVERRIDING_DESCRIPTOR);
@@ -1245,10 +1244,6 @@ do_specialize_instance_load_attr(PyObject* owner, _Py_CODEUNIT* instr, PyObject*
12451244
if (!function_check_args(descr, 2, LOAD_ATTR)) {
12461245
return -1;
12471246
}
1248-
if (oparg & 1) {
1249-
SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_ATTR_METHOD);
1250-
return -1;
1251-
}
12521247
uint32_t version = function_get_version(descr, LOAD_ATTR);
12531248
if (version == 0) {
12541249
return -1;
@@ -1375,11 +1370,11 @@ _Py_Specialize_LoadMethod(_PyStackRef owner_st, _Py_CODEUNIT *instr, PyObject *n
13751370
}
13761371
else if (Py_TYPE(owner)->tp_getattro == PyModule_Type.tp_getattro) {
13771372
SPECIALIZATION_FAIL(LOAD_METHOD, SPEC_FAIL_OTHER);
1378-
unspecialize(instr);
1373+
fail = true;
13791374
}
13801375
else if (PyType_Check(owner)) {
13811376
SPECIALIZATION_FAIL(LOAD_METHOD, SPEC_FAIL_OTHER);
1382-
unspecialize(instr);
1377+
fail = true;
13831378
}
13841379
else {
13851380
fail = specialize_instance_load_attr(owner, instr, name, true);

0 commit comments

Comments
 (0)