Skip to content

Commit a5a2d8f

Browse files
committed
DSL cleanup
1 parent fd6607f commit a5a2d8f

File tree

4 files changed

+123
-127
lines changed

4 files changed

+123
-127
lines changed

Include/internal/pycore_opcode_metadata.h

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

Python/bytecodes.c

Lines changed: 39 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,8 +1598,7 @@ dummy_func(
15981598
ERROR_IF(map == NULL, error);
15991599
}
16001600

1601-
inst(DICT_UPDATE, (update --)) {
1602-
PyObject *dict = PEEK(oparg + 1); // update is still on the stack
1601+
inst(DICT_UPDATE, (dict, unused[oparg - 1], update -- dict, unused[oparg - 1])) {
16031602
if (PyDict_Update(dict, update) < 0) {
16041603
if (_PyErr_ExceptionMatches(tstate, PyExc_AttributeError)) {
16051604
_PyErr_Format(tstate, PyExc_TypeError,
@@ -1612,19 +1611,16 @@ dummy_func(
16121611
DECREF_INPUTS();
16131612
}
16141613

1615-
inst(DICT_MERGE, (update --)) {
1616-
PyObject *dict = PEEK(oparg + 1); // update is still on the stack
1617-
1614+
inst(DICT_MERGE, (callable, unused, unused, dict, unused[oparg - 1], update -- callable, unused, unused, dict, unused[oparg - 1])) {
16181615
if (_PyDict_MergeEx(dict, update, 2) < 0) {
1619-
_PyEval_FormatKwargsError(tstate, PEEK(4 + oparg), update);
1616+
_PyEval_FormatKwargsError(tstate, callable, update);
16201617
DECREF_INPUTS();
16211618
ERROR_IF(true, error);
16221619
}
16231620
DECREF_INPUTS();
16241621
}
16251622

1626-
inst(MAP_ADD, (key, value --)) {
1627-
PyObject *dict = PEEK(oparg + 2); // key, value are still on the stack
1623+
inst(MAP_ADD, (dict, unused[oparg - 1], key, value -- dict, unused[oparg - 1])) {
16281624
assert(PyDict_CheckExact(dict));
16291625
/* dict[key] = value */
16301626
// Do not DECREF INPUTS because the function steals the references
@@ -1644,7 +1640,7 @@ dummy_func(
16441640
LOAD_SUPER_ATTR_METHOD,
16451641
};
16461642

1647-
inst(LOAD_SUPER_ATTR, (unused/1, global_super, class, self -- attr, self_or_null if (oparg & 1))) {
1643+
inst(LOAD_SUPER_ATTR, (unused/1, global_super, class, self -- attr, null if (oparg & 1))) {
16481644
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg >> 2);
16491645
int load_method = oparg & 1;
16501646
#if ENABLE_SPECIALIZATION
@@ -1691,6 +1687,7 @@ dummy_func(
16911687
attr = PyObject_GetAttr(super, name);
16921688
Py_DECREF(super);
16931689
ERROR_IF(attr == NULL, error);
1690+
null = NULL;
16941691
}
16951692

16961693
pseudo(LOAD_SUPER_METHOD) = {
@@ -1705,7 +1702,7 @@ dummy_func(
17051702
LOAD_SUPER_ATTR,
17061703
};
17071704

1708-
inst(LOAD_SUPER_ATTR_ATTR, (unused/1, global_super, class, self -- attr, self_or_null if (oparg & 1))) {
1705+
inst(LOAD_SUPER_ATTR_ATTR, (unused/1, global_super, class, self -- attr, unused if (oparg & 1))) {
17091706
assert(!(oparg & 1));
17101707
DEOPT_IF(global_super != (PyObject *)&PySuper_Type, LOAD_SUPER_ATTR);
17111708
DEOPT_IF(!PyType_Check(class), LOAD_SUPER_ATTR);
@@ -1770,15 +1767,14 @@ dummy_func(
17701767
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg >> 1);
17711768
if (oparg & 1) {
17721769
/* Designed to work in tandem with CALL, pushes two values. */
1773-
PyObject* meth = NULL;
1774-
if (_PyObject_GetMethod(owner, name, &meth)) {
1770+
attr = NULL;
1771+
if (_PyObject_GetMethod(owner, name, &attr)) {
17751772
/* We can bypass temporary bound method object.
17761773
meth is unbound method and obj is self.
17771774
17781775
meth | self | arg1 | ... | argN
17791776
*/
1780-
assert(meth != NULL); // No errors on this branch
1781-
attr = meth;
1777+
assert(attr != NULL); // No errors on this branch
17821778
self_or_null = owner; // Transfer ownership
17831779
}
17841780
else {
@@ -1790,8 +1786,7 @@ dummy_func(
17901786
NULL | meth | arg1 | ... | argN
17911787
*/
17921788
DECREF_INPUTS();
1793-
ERROR_IF(meth == NULL, error);
1794-
attr = meth;
1789+
ERROR_IF(attr == NULL, error);
17951790
self_or_null = NULL;
17961791
}
17971792
}
@@ -1820,13 +1815,13 @@ dummy_func(
18201815
DEOPT_IF(!_PyDictOrValues_IsValues(dorv), LOAD_ATTR);
18211816
}
18221817

1823-
op(_LOAD_ATTR_INSTANCE_VALUE, (index/1, owner -- attr, self_or_null if (oparg & 1))) {
1818+
op(_LOAD_ATTR_INSTANCE_VALUE, (index/1, owner -- attr, null if (oparg & 1))) {
18241819
PyDictOrValues dorv = *_PyObject_DictOrValuesPointer(owner);
18251820
attr = _PyDictOrValues_GetValues(dorv)->values[index];
18261821
DEOPT_IF(attr == NULL, LOAD_ATTR);
18271822
STAT_INC(LOAD_ATTR, hit);
18281823
Py_INCREF(attr);
1829-
self_or_null = NULL;
1824+
null = NULL;
18301825
DECREF_INPUTS();
18311826
}
18321827

@@ -1837,7 +1832,7 @@ dummy_func(
18371832
_LOAD_ATTR_INSTANCE_VALUE +
18381833
unused/5; // Skip over rest of cache
18391834

1840-
inst(LOAD_ATTR_MODULE, (unused/1, type_version/2, index/1, unused/5, owner -- attr, self_or_null if (oparg & 1))) {
1835+
inst(LOAD_ATTR_MODULE, (unused/1, type_version/2, index/1, unused/5, owner -- attr, null if (oparg & 1))) {
18411836
DEOPT_IF(!PyModule_CheckExact(owner), LOAD_ATTR);
18421837
PyDictObject *dict = (PyDictObject *)((PyModuleObject *)owner)->md_dict;
18431838
assert(dict != NULL);
@@ -1849,11 +1844,11 @@ dummy_func(
18491844
DEOPT_IF(attr == NULL, LOAD_ATTR);
18501845
STAT_INC(LOAD_ATTR, hit);
18511846
Py_INCREF(attr);
1852-
self_or_null = NULL;
1847+
null = NULL;
18531848
DECREF_INPUTS();
18541849
}
18551850

1856-
inst(LOAD_ATTR_WITH_HINT, (unused/1, type_version/2, index/1, unused/5, owner -- attr, self_or_null if (oparg & 1))) {
1851+
inst(LOAD_ATTR_WITH_HINT, (unused/1, type_version/2, index/1, unused/5, owner -- attr, null if (oparg & 1))) {
18571852
PyTypeObject *tp = Py_TYPE(owner);
18581853
assert(type_version != 0);
18591854
DEOPT_IF(tp->tp_version_tag != type_version, LOAD_ATTR);
@@ -1879,11 +1874,11 @@ dummy_func(
18791874
DEOPT_IF(attr == NULL, LOAD_ATTR);
18801875
STAT_INC(LOAD_ATTR, hit);
18811876
Py_INCREF(attr);
1882-
self_or_null = NULL;
1877+
null = NULL;
18831878
DECREF_INPUTS();
18841879
}
18851880

1886-
inst(LOAD_ATTR_SLOT, (unused/1, type_version/2, index/1, unused/5, owner -- attr, self_or_null if (oparg & 1))) {
1881+
inst(LOAD_ATTR_SLOT, (unused/1, type_version/2, index/1, unused/5, owner -- attr, null if (oparg & 1))) {
18871882
PyTypeObject *tp = Py_TYPE(owner);
18881883
assert(type_version != 0);
18891884
DEOPT_IF(tp->tp_version_tag != type_version, LOAD_ATTR);
@@ -1892,19 +1887,19 @@ dummy_func(
18921887
DEOPT_IF(attr == NULL, LOAD_ATTR);
18931888
STAT_INC(LOAD_ATTR, hit);
18941889
Py_INCREF(attr);
1895-
self_or_null = NULL;
1890+
null = NULL;
18961891
DECREF_INPUTS();
18971892
}
18981893

1899-
inst(LOAD_ATTR_CLASS, (unused/1, type_version/2, unused/2, descr/4, cls -- attr, self_or_null if (oparg & 1))) {
1894+
inst(LOAD_ATTR_CLASS, (unused/1, type_version/2, unused/2, descr/4, cls -- attr, null if (oparg & 1))) {
19001895

19011896
DEOPT_IF(!PyType_Check(cls), LOAD_ATTR);
19021897
DEOPT_IF(((PyTypeObject *)cls)->tp_version_tag != type_version,
19031898
LOAD_ATTR);
19041899
assert(type_version != 0);
19051900

19061901
STAT_INC(LOAD_ATTR, hit);
1907-
self_or_null = NULL;
1902+
null = NULL;
19081903
attr = descr;
19091904
assert(attr != NULL);
19101905
Py_INCREF(attr);
@@ -2740,7 +2735,7 @@ dummy_func(
27402735
self_or_null = self;
27412736
}
27422737

2743-
inst(LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES, (unused/1, type_version/2, keys_version/2, descr/4, self -- attr, self_or_null if (0))) {
2738+
inst(LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES, (unused/1, type_version/2, keys_version/2, descr/4, self -- attr, unused if (0))) {
27442739
assert((oparg & 1) == 0);
27452740
PyTypeObject *self_cls = Py_TYPE(self);
27462741
assert(type_version != 0);
@@ -2757,7 +2752,7 @@ dummy_func(
27572752
attr = Py_NewRef(descr);
27582753
}
27592754

2760-
inst(LOAD_ATTR_NONDESCRIPTOR_NO_DICT, (unused/1, type_version/2, unused/2, descr/4, self -- attr, self_or_null if (0))) {
2755+
inst(LOAD_ATTR_NONDESCRIPTOR_NO_DICT, (unused/1, type_version/2, unused/2, descr/4, self -- attr, unused if (0))) {
27612756
assert((oparg & 1) == 0);
27622757
PyTypeObject *self_cls = Py_TYPE(self);
27632758
assert(type_version != 0);
@@ -2893,7 +2888,7 @@ dummy_func(
28932888
kwnames);
28942889
if (opcode == INSTRUMENTED_CALL) {
28952890
PyObject *arg = total_args == 0 ?
2896-
&_PyInstrumentation_MISSING : PEEK(total_args);
2891+
&_PyInstrumentation_MISSING : args[0];
28972892
if (res == NULL) {
28982893
_Py_call_instrumentation_exc2(
28992894
tstate, PY_MONITORING_EVENT_C_RAISE,
@@ -2921,8 +2916,8 @@ dummy_func(
29212916
// Start out with [NULL, bound_method, arg1, arg2, ...]
29222917
// Transform to [callable, self, arg1, arg2, ...]
29232918
// Then fall through to CALL_PY_EXACT_ARGS
2924-
inst(CALL_BOUND_METHOD_EXACT_ARGS, (unused/1, unused/2, callable, self_or_null, unused[oparg] -- unused)) {
2925-
DEOPT_IF(self_or_null != NULL, CALL);
2919+
inst(CALL_BOUND_METHOD_EXACT_ARGS, (unused/1, unused/2, callable, null, unused[oparg] -- unused)) {
2920+
DEOPT_IF(null != NULL, CALL);
29262921
DEOPT_IF(Py_TYPE(callable) != &PyMethod_Type, CALL);
29272922
STAT_INC(CALL, hit);
29282923
PyObject *self = ((PyMethodObject *)callable)->im_self;
@@ -2995,10 +2990,10 @@ dummy_func(
29952990
DISPATCH_INLINED(new_frame);
29962991
}
29972992

2998-
inst(CALL_NO_KW_TYPE_1, (unused/1, unused/2, callable, self_or_null, args[oparg] -- res)) {
2993+
inst(CALL_NO_KW_TYPE_1, (unused/1, unused/2, callable, null, args[oparg] -- res)) {
29992994
ASSERT_KWNAMES_IS_NULL();
30002995
assert(oparg == 1);
3001-
DEOPT_IF(self_or_null != NULL, CALL);
2996+
DEOPT_IF(null != NULL, CALL);
30022997
PyObject *obj = args[0];
30032998
DEOPT_IF(callable != (PyObject *)&PyType_Type, CALL);
30042999
STAT_INC(CALL, hit);
@@ -3007,10 +3002,10 @@ dummy_func(
30073002
Py_DECREF(&PyType_Type); // I.e., callable
30083003
}
30093004

3010-
inst(CALL_NO_KW_STR_1, (unused/1, unused/2, callable, self_or_null, args[oparg] -- res)) {
3005+
inst(CALL_NO_KW_STR_1, (unused/1, unused/2, callable, null, args[oparg] -- res)) {
30113006
ASSERT_KWNAMES_IS_NULL();
30123007
assert(oparg == 1);
3013-
DEOPT_IF(self_or_null != NULL, CALL);
3008+
DEOPT_IF(null != NULL, CALL);
30143009
DEOPT_IF(callable != (PyObject *)&PyUnicode_Type, CALL);
30153010
STAT_INC(CALL, hit);
30163011
PyObject *arg = args[0];
@@ -3021,10 +3016,10 @@ dummy_func(
30213016
CHECK_EVAL_BREAKER();
30223017
}
30233018

3024-
inst(CALL_NO_KW_TUPLE_1, (unused/1, unused/2, callable, self_or_null, args[oparg] -- res)) {
3019+
inst(CALL_NO_KW_TUPLE_1, (unused/1, unused/2, callable, null, args[oparg] -- res)) {
30253020
ASSERT_KWNAMES_IS_NULL();
30263021
assert(oparg == 1);
3027-
DEOPT_IF(self_or_null != NULL, CALL);
3022+
DEOPT_IF(null != NULL, CALL);
30283023
DEOPT_IF(callable != (PyObject *)&PyTuple_Type, CALL);
30293024
STAT_INC(CALL, hit);
30303025
PyObject *arg = args[0];
@@ -3035,15 +3030,15 @@ dummy_func(
30353030
CHECK_EVAL_BREAKER();
30363031
}
30373032

3038-
inst(CALL_NO_KW_ALLOC_AND_ENTER_INIT, (unused/1, unused/2, callable, self_or_null, args[oparg] -- unused)) {
3033+
inst(CALL_NO_KW_ALLOC_AND_ENTER_INIT, (unused/1, unused/2, callable, null, args[oparg] -- unused)) {
30393034
/* This instruction does the following:
30403035
* 1. Creates the object (by calling ``object.__new__``)
30413036
* 2. Pushes a shim frame to the frame stack (to cleanup after ``__init__``)
30423037
* 3. Pushes the frame for ``__init__`` to the frame stack
30433038
* */
30443039
ASSERT_KWNAMES_IS_NULL();
30453040
_PyCallCache *cache = (_PyCallCache *)next_instr;
3046-
DEOPT_IF(self_or_null != NULL, CALL);
3041+
DEOPT_IF(null != NULL, CALL);
30473042
DEOPT_IF(!PyType_Check(callable), CALL);
30483043
PyTypeObject *tp = (PyTypeObject *)callable;
30493044
DEOPT_IF(tp->tp_version_tag != read_u32(cache->func_version), CALL);
@@ -3269,18 +3264,18 @@ dummy_func(
32693264
}
32703265

32713266
// This is secretly a super-instruction
3272-
inst(CALL_NO_KW_LIST_APPEND, (unused/1, unused/2, callable, self_or_null, args[oparg] -- unused)) {
3267+
inst(CALL_NO_KW_LIST_APPEND, (unused/1, unused/2, callable, self, args[oparg] -- unused)) {
32733268
ASSERT_KWNAMES_IS_NULL();
32743269
assert(oparg == 1);
3275-
assert(self_or_null != NULL);
3270+
assert(self != NULL);
32763271
PyInterpreterState *interp = tstate->interp;
32773272
DEOPT_IF(callable != interp->callable_cache.list_append, CALL);
3278-
DEOPT_IF(!PyList_Check(self_or_null), CALL);
3273+
DEOPT_IF(!PyList_Check(self), CALL);
32793274
STAT_INC(CALL, hit);
3280-
if (_PyList_AppendTakeRef((PyListObject *)self_or_null, args[0]) < 0) {
3275+
if (_PyList_AppendTakeRef((PyListObject *)self, args[0]) < 0) {
32813276
goto pop_1_error; // Since arg is DECREF'ed already
32823277
}
3283-
Py_DECREF(self_or_null);
3278+
Py_DECREF(self);
32843279
Py_DECREF(callable);
32853280
STACK_SHRINK(3);
32863281
// CALL + POP_TOP

0 commit comments

Comments
 (0)