mirror of
https://github.com/python/cpython
synced 2024-09-16 04:09:56 +00:00
GH-111485: Make BEFORE_WITH a uop (GH-111812)
This commit is contained in:
parent
d4426e8d00
commit
3e99c9cbf6
1
Include/internal/pycore_opcode_metadata.h
generated
1
Include/internal/pycore_opcode_metadata.h
generated
|
@ -1864,6 +1864,7 @@ const struct opcode_macro_expansion _PyOpcode_macro_expansion[OPCODE_MACRO_EXPAN
|
||||||
[GET_ITER] = { .nuops = 1, .uops = { { GET_ITER, 0, 0 } } },
|
[GET_ITER] = { .nuops = 1, .uops = { { GET_ITER, 0, 0 } } },
|
||||||
[GET_YIELD_FROM_ITER] = { .nuops = 1, .uops = { { GET_YIELD_FROM_ITER, 0, 0 } } },
|
[GET_YIELD_FROM_ITER] = { .nuops = 1, .uops = { { GET_YIELD_FROM_ITER, 0, 0 } } },
|
||||||
[BEFORE_ASYNC_WITH] = { .nuops = 1, .uops = { { BEFORE_ASYNC_WITH, 0, 0 } } },
|
[BEFORE_ASYNC_WITH] = { .nuops = 1, .uops = { { BEFORE_ASYNC_WITH, 0, 0 } } },
|
||||||
|
[BEFORE_WITH] = { .nuops = 1, .uops = { { BEFORE_WITH, 0, 0 } } },
|
||||||
[WITH_EXCEPT_START] = { .nuops = 1, .uops = { { WITH_EXCEPT_START, 0, 0 } } },
|
[WITH_EXCEPT_START] = { .nuops = 1, .uops = { { WITH_EXCEPT_START, 0, 0 } } },
|
||||||
[PUSH_EXC_INFO] = { .nuops = 1, .uops = { { PUSH_EXC_INFO, 0, 0 } } },
|
[PUSH_EXC_INFO] = { .nuops = 1, .uops = { { PUSH_EXC_INFO, 0, 0 } } },
|
||||||
[LOAD_ATTR_METHOD_WITH_VALUES] = { .nuops = 4, .uops = { { _GUARD_TYPE_VERSION, 2, 1 }, { _GUARD_DORV_VALUES_INST_ATTR_FROM_DICT, 0, 0 }, { _GUARD_KEYS_VERSION, 2, 3 }, { _LOAD_ATTR_METHOD_WITH_VALUES, 4, 5 } } },
|
[LOAD_ATTR_METHOD_WITH_VALUES] = { .nuops = 4, .uops = { { _GUARD_TYPE_VERSION, 2, 1 }, { _GUARD_DORV_VALUES_INST_ATTR_FROM_DICT, 0, 0 }, { _GUARD_KEYS_VERSION, 2, 3 }, { _LOAD_ATTR_METHOD_WITH_VALUES, 4, 5 } } },
|
||||||
|
|
7
Python/abstract_interp_cases.c.h
generated
7
Python/abstract_interp_cases.c.h
generated
|
@ -683,6 +683,13 @@
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case BEFORE_WITH: {
|
||||||
|
STACK_GROW(1);
|
||||||
|
PARTITIONNODE_OVERWRITE((_Py_PARTITIONNODE_t *)PARTITIONNODE_NULLROOT, PEEK(-(-2)), true);
|
||||||
|
PARTITIONNODE_OVERWRITE((_Py_PARTITIONNODE_t *)PARTITIONNODE_NULLROOT, PEEK(-(-1)), true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case WITH_EXCEPT_START: {
|
case WITH_EXCEPT_START: {
|
||||||
STACK_GROW(1);
|
STACK_GROW(1);
|
||||||
PARTITIONNODE_OVERWRITE((_Py_PARTITIONNODE_t *)PARTITIONNODE_NULLROOT, PEEK(-(-1)), true);
|
PARTITIONNODE_OVERWRITE((_Py_PARTITIONNODE_t *)PARTITIONNODE_NULLROOT, PEEK(-(-1)), true);
|
||||||
|
|
|
@ -2765,7 +2765,7 @@ dummy_func(
|
||||||
GOTO_ERROR(error);
|
GOTO_ERROR(error);
|
||||||
}
|
}
|
||||||
DECREF_INPUTS();
|
DECREF_INPUTS();
|
||||||
res = _PyObject_CallNoArgs(enter);
|
res = _PyObject_CallNoArgsTstate(tstate, enter);
|
||||||
Py_DECREF(enter);
|
Py_DECREF(enter);
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
Py_DECREF(exit);
|
Py_DECREF(exit);
|
||||||
|
@ -2774,7 +2774,6 @@ dummy_func(
|
||||||
}
|
}
|
||||||
|
|
||||||
inst(BEFORE_WITH, (mgr -- exit, res)) {
|
inst(BEFORE_WITH, (mgr -- exit, res)) {
|
||||||
TIER_ONE_ONLY
|
|
||||||
/* pop the context manager, push its __exit__ and the
|
/* pop the context manager, push its __exit__ and the
|
||||||
* value returned from calling its __enter__
|
* value returned from calling its __enter__
|
||||||
*/
|
*/
|
||||||
|
@ -2801,7 +2800,7 @@ dummy_func(
|
||||||
GOTO_ERROR(error);
|
GOTO_ERROR(error);
|
||||||
}
|
}
|
||||||
DECREF_INPUTS();
|
DECREF_INPUTS();
|
||||||
res = _PyObject_CallNoArgs(enter);
|
res = _PyObject_CallNoArgsTstate(tstate, enter);
|
||||||
Py_DECREF(enter);
|
Py_DECREF(enter);
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
Py_DECREF(exit);
|
Py_DECREF(exit);
|
||||||
|
|
45
Python/executor_cases.c.h
generated
45
Python/executor_cases.c.h
generated
|
@ -2304,7 +2304,50 @@
|
||||||
GOTO_ERROR(error);
|
GOTO_ERROR(error);
|
||||||
}
|
}
|
||||||
Py_DECREF(mgr);
|
Py_DECREF(mgr);
|
||||||
res = _PyObject_CallNoArgs(enter);
|
res = _PyObject_CallNoArgsTstate(tstate, enter);
|
||||||
|
Py_DECREF(enter);
|
||||||
|
if (res == NULL) {
|
||||||
|
Py_DECREF(exit);
|
||||||
|
if (true) goto pop_1_error_tier_two;
|
||||||
|
}
|
||||||
|
STACK_GROW(1);
|
||||||
|
stack_pointer[-2] = exit;
|
||||||
|
stack_pointer[-1] = res;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case BEFORE_WITH: {
|
||||||
|
PyObject *mgr;
|
||||||
|
PyObject *exit;
|
||||||
|
PyObject *res;
|
||||||
|
mgr = stack_pointer[-1];
|
||||||
|
/* pop the context manager, push its __exit__ and the
|
||||||
|
* value returned from calling its __enter__
|
||||||
|
*/
|
||||||
|
PyObject *enter = _PyObject_LookupSpecial(mgr, &_Py_ID(__enter__));
|
||||||
|
if (enter == NULL) {
|
||||||
|
if (!_PyErr_Occurred(tstate)) {
|
||||||
|
_PyErr_Format(tstate, PyExc_TypeError,
|
||||||
|
"'%.200s' object does not support the "
|
||||||
|
"context manager protocol",
|
||||||
|
Py_TYPE(mgr)->tp_name);
|
||||||
|
}
|
||||||
|
GOTO_ERROR(error);
|
||||||
|
}
|
||||||
|
exit = _PyObject_LookupSpecial(mgr, &_Py_ID(__exit__));
|
||||||
|
if (exit == NULL) {
|
||||||
|
if (!_PyErr_Occurred(tstate)) {
|
||||||
|
_PyErr_Format(tstate, PyExc_TypeError,
|
||||||
|
"'%.200s' object does not support the "
|
||||||
|
"context manager protocol "
|
||||||
|
"(missed __exit__ method)",
|
||||||
|
Py_TYPE(mgr)->tp_name);
|
||||||
|
}
|
||||||
|
Py_DECREF(enter);
|
||||||
|
GOTO_ERROR(error);
|
||||||
|
}
|
||||||
|
Py_DECREF(mgr);
|
||||||
|
res = _PyObject_CallNoArgsTstate(tstate, enter);
|
||||||
Py_DECREF(enter);
|
Py_DECREF(enter);
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
Py_DECREF(exit);
|
Py_DECREF(exit);
|
||||||
|
|
5
Python/generated_cases.c.h
generated
5
Python/generated_cases.c.h
generated
|
@ -3967,7 +3967,7 @@
|
||||||
GOTO_ERROR(error);
|
GOTO_ERROR(error);
|
||||||
}
|
}
|
||||||
Py_DECREF(mgr);
|
Py_DECREF(mgr);
|
||||||
res = _PyObject_CallNoArgs(enter);
|
res = _PyObject_CallNoArgsTstate(tstate, enter);
|
||||||
Py_DECREF(enter);
|
Py_DECREF(enter);
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
Py_DECREF(exit);
|
Py_DECREF(exit);
|
||||||
|
@ -3987,7 +3987,6 @@
|
||||||
PyObject *exit;
|
PyObject *exit;
|
||||||
PyObject *res;
|
PyObject *res;
|
||||||
mgr = stack_pointer[-1];
|
mgr = stack_pointer[-1];
|
||||||
TIER_ONE_ONLY
|
|
||||||
/* pop the context manager, push its __exit__ and the
|
/* pop the context manager, push its __exit__ and the
|
||||||
* value returned from calling its __enter__
|
* value returned from calling its __enter__
|
||||||
*/
|
*/
|
||||||
|
@ -4014,7 +4013,7 @@
|
||||||
GOTO_ERROR(error);
|
GOTO_ERROR(error);
|
||||||
}
|
}
|
||||||
Py_DECREF(mgr);
|
Py_DECREF(mgr);
|
||||||
res = _PyObject_CallNoArgs(enter);
|
res = _PyObject_CallNoArgsTstate(tstate, enter);
|
||||||
Py_DECREF(enter);
|
Py_DECREF(enter);
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
Py_DECREF(exit);
|
Py_DECREF(exit);
|
||||||
|
|
Loading…
Reference in a new issue