aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2023-10-31 13:21:07 +0000
committerGitHub <noreply@github.com>2023-10-31 13:21:07 +0000
commit2904d99839cd4620818fd0556a1c0b0229944abc (patch)
tree39a1a91ac415017441f0c5c6859f6226f0a5332c /Python
parentd27acd4461ee603bcf6f4a81ca6afccc9fc87331 (diff)
downloadcpython-2904d99839cd4620818fd0556a1c0b0229944abc.tar.gz
cpython-2904d99839cd4620818fd0556a1c0b0229944abc.zip
GH-111485: Remove some special cases from the code generator and bytecodes.c (GH-111540)
Diffstat (limited to 'Python')
-rw-r--r--Python/abstract_interp_cases.c.h11
-rw-r--r--Python/bytecodes.c18
-rw-r--r--Python/executor_cases.c.h52
-rw-r--r--Python/generated_cases.c.h18
4 files changed, 89 insertions, 10 deletions
diff --git a/Python/abstract_interp_cases.c.h b/Python/abstract_interp_cases.c.h
index 232c569a3dd..11090ee4dba 100644
--- a/Python/abstract_interp_cases.c.h
+++ b/Python/abstract_interp_cases.c.h
@@ -344,6 +344,10 @@
break;
}
+ case MAKE_CELL: {
+ break;
+ }
+
case DELETE_DEREF: {
break;
}
@@ -668,6 +672,13 @@
break;
}
+ case BEFORE_ASYNC_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: {
STACK_GROW(1);
PARTITIONNODE_OVERWRITE((_Py_PARTITIONNODE_t *)PARTITIONNODE_NULLROOT, PEEK(-(-1)), true);
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index d33ee3265d2..bb2d491523c 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -742,6 +742,7 @@ dummy_func(
}
inst(RAISE_VARARGS, (args[oparg] -- )) {
+ TIER_ONE_ONLY
PyObject *cause = NULL, *exc = NULL;
switch (oparg) {
case 2:
@@ -1073,6 +1074,7 @@ dummy_func(
}
inst(RERAISE, (values[oparg], exc -- values[oparg])) {
+ TIER_ONE_ONLY
assert(oparg >= 0 && oparg <= 2);
if (oparg) {
PyObject *lasti = values[0];
@@ -1094,6 +1096,7 @@ dummy_func(
}
inst(END_ASYNC_FOR, (awaitable, exc -- )) {
+ TIER_ONE_ONLY
assert(exc && PyExceptionInstance_Check(exc));
if (PyErr_GivenExceptionMatches(exc, PyExc_StopAsyncIteration)) {
DECREF_INPUTS();
@@ -1107,6 +1110,7 @@ dummy_func(
}
inst(CLEANUP_THROW, (sub_iter, last_sent_val, exc_value -- none, value)) {
+ TIER_ONE_ONLY
assert(throwflag);
assert(exc_value && PyExceptionInstance_Check(exc_value));
if (PyErr_GivenExceptionMatches(exc_value, PyExc_StopIteration)) {
@@ -1467,7 +1471,7 @@ dummy_func(
PyObject *initial = GETLOCAL(oparg);
PyObject *cell = PyCell_New(initial);
if (cell == NULL) {
- goto resume_with_error;
+ goto error;
}
SETLOCAL(oparg, cell);
}
@@ -2247,6 +2251,7 @@ dummy_func(
}
inst(IMPORT_NAME, (level, fromlist -- res)) {
+ TIER_ONE_ONLY
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
res = import_name(tstate, frame, name, fromlist, level);
DECREF_INPUTS();
@@ -2254,6 +2259,7 @@ dummy_func(
}
inst(IMPORT_FROM, (from -- from, res)) {
+ TIER_ONE_ONLY
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
res = import_from(tstate, from, name);
ERROR_IF(res == NULL, error);
@@ -2263,10 +2269,10 @@ dummy_func(
JUMPBY(oparg);
}
- inst(JUMP_BACKWARD, (--)) {
+ inst(JUMP_BACKWARD, (unused/1 --)) {
CHECK_EVAL_BREAKER();
assert(oparg <= INSTR_OFFSET());
- JUMPBY(1-oparg);
+ JUMPBY(-oparg);
#if ENABLE_SPECIALIZATION
this_instr[1].cache += (1 << OPTIMIZER_BITS_IN_COUNTER);
if (this_instr[1].cache > tstate->interp->optimizer_backedge_threshold &&
@@ -2297,6 +2303,7 @@ dummy_func(
};
inst(ENTER_EXECUTOR, (--)) {
+ TIER_ONE_ONLY
CHECK_EVAL_BREAKER();
PyCodeObject *code = _PyFrame_GetCode(frame);
@@ -2703,6 +2710,7 @@ dummy_func(
}
inst(BEFORE_WITH, (mgr -- exit, res)) {
+ TIER_ONE_ONLY
/* pop the context manager, push its __exit__ and the
* value returned from calling its __enter__
*/
@@ -3831,9 +3839,9 @@ dummy_func(
INSTRUMENTED_JUMP(this_instr, next_instr + oparg, PY_MONITORING_EVENT_JUMP);
}
- inst(INSTRUMENTED_JUMP_BACKWARD, ( -- )) {
+ inst(INSTRUMENTED_JUMP_BACKWARD, (unused/1 -- )) {
CHECK_EVAL_BREAKER();
- INSTRUMENTED_JUMP(this_instr, next_instr + 1 - oparg, PY_MONITORING_EVENT_JUMP);
+ INSTRUMENTED_JUMP(this_instr, next_instr - oparg, PY_MONITORING_EVENT_JUMP);
}
inst(INSTRUMENTED_POP_JUMP_IF_TRUE, (unused/1 -- )) {
diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h
index 24de9eadf59..4d5b6dc7f01 100644
--- a/Python/executor_cases.c.h
+++ b/Python/executor_cases.c.h
@@ -1240,6 +1240,18 @@
break;
}
+ case MAKE_CELL: {
+ // "initial" is probably NULL but not if it's an arg (or set
+ // via PyFrame_LocalsToFast() before MAKE_CELL has run).
+ PyObject *initial = GETLOCAL(oparg);
+ PyObject *cell = PyCell_New(initial);
+ if (cell == NULL) {
+ goto error;
+ }
+ SETLOCAL(oparg, cell);
+ break;
+ }
+
case DELETE_DEREF: {
PyObject *cell = GETLOCAL(oparg);
PyObject *oldobj = PyCell_GET(cell);
@@ -2320,6 +2332,46 @@
break;
}
+ case BEFORE_ASYNC_WITH: {
+ PyObject *mgr;
+ PyObject *exit;
+ PyObject *res;
+ mgr = stack_pointer[-1];
+ PyObject *enter = _PyObject_LookupSpecial(mgr, &_Py_ID(__aenter__));
+ if (enter == NULL) {
+ if (!_PyErr_Occurred(tstate)) {
+ _PyErr_Format(tstate, PyExc_TypeError,
+ "'%.200s' object does not support the "
+ "asynchronous context manager protocol",
+ Py_TYPE(mgr)->tp_name);
+ }
+ goto error;
+ }
+ exit = _PyObject_LookupSpecial(mgr, &_Py_ID(__aexit__));
+ if (exit == NULL) {
+ if (!_PyErr_Occurred(tstate)) {
+ _PyErr_Format(tstate, PyExc_TypeError,
+ "'%.200s' object does not support the "
+ "asynchronous context manager protocol "
+ "(missed __aexit__ method)",
+ Py_TYPE(mgr)->tp_name);
+ }
+ Py_DECREF(enter);
+ goto error;
+ }
+ Py_DECREF(mgr);
+ res = _PyObject_CallNoArgs(enter);
+ Py_DECREF(enter);
+ if (res == NULL) {
+ Py_DECREF(exit);
+ if (true) goto pop_1_error;
+ }
+ STACK_GROW(1);
+ stack_pointer[-2] = exit;
+ stack_pointer[-1] = res;
+ break;
+ }
+
case WITH_EXCEPT_START: {
PyObject *val;
PyObject *lasti;
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index 40c8cd8798c..8b6ebe4f8ab 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -1090,6 +1090,7 @@
INSTRUCTION_STATS(RAISE_VARARGS);
PyObject **args;
args = stack_pointer - oparg;
+ TIER_ONE_ONLY
PyObject *cause = NULL, *exc = NULL;
switch (oparg) {
case 2:
@@ -1532,6 +1533,7 @@
PyObject **values;
exc = stack_pointer[-1];
values = stack_pointer - 1 - oparg;
+ TIER_ONE_ONLY
assert(oparg >= 0 && oparg <= 2);
if (oparg) {
PyObject *lasti = values[0];
@@ -1560,6 +1562,7 @@
PyObject *awaitable;
exc = stack_pointer[-1];
awaitable = stack_pointer[-2];
+ TIER_ONE_ONLY
assert(exc && PyExceptionInstance_Check(exc));
if (PyErr_GivenExceptionMatches(exc, PyExc_StopAsyncIteration)) {
Py_DECREF(awaitable);
@@ -1587,6 +1590,7 @@
exc_value = stack_pointer[-1];
last_sent_val = stack_pointer[-2];
sub_iter = stack_pointer[-3];
+ TIER_ONE_ONLY
assert(throwflag);
assert(exc_value && PyExceptionInstance_Check(exc_value));
if (PyErr_GivenExceptionMatches(exc_value, PyExc_StopIteration)) {
@@ -2107,7 +2111,7 @@
PyObject *initial = GETLOCAL(oparg);
PyObject *cell = PyCell_New(initial);
if (cell == NULL) {
- goto resume_with_error;
+ goto error;
}
SETLOCAL(oparg, cell);
DISPATCH();
@@ -3282,6 +3286,7 @@
PyObject *res;
fromlist = stack_pointer[-1];
level = stack_pointer[-2];
+ TIER_ONE_ONLY
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
res = import_name(tstate, frame, name, fromlist, level);
Py_DECREF(level);
@@ -3299,6 +3304,7 @@
PyObject *from;
PyObject *res;
from = stack_pointer[-1];
+ TIER_ONE_ONLY
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
res = import_from(tstate, from, name);
if (res == NULL) goto error;
@@ -3317,11 +3323,11 @@
TARGET(JUMP_BACKWARD) {
_Py_CODEUNIT *this_instr = frame->instr_ptr = next_instr;
- next_instr += 1;
+ next_instr += 2;
INSTRUCTION_STATS(JUMP_BACKWARD);
CHECK_EVAL_BREAKER();
assert(oparg <= INSTR_OFFSET());
- JUMPBY(1-oparg);
+ JUMPBY(-oparg);
#if ENABLE_SPECIALIZATION
this_instr[1].cache += (1 << OPTIMIZER_BITS_IN_COUNTER);
if (this_instr[1].cache > tstate->interp->optimizer_backedge_threshold &&
@@ -3346,6 +3352,7 @@
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(ENTER_EXECUTOR);
+ TIER_ONE_ONLY
CHECK_EVAL_BREAKER();
PyCodeObject *code = _PyFrame_GetCode(frame);
@@ -3890,6 +3897,7 @@
PyObject *exit;
PyObject *res;
mgr = stack_pointer[-1];
+ TIER_ONE_ONLY
/* pop the context manager, push its __exit__ and the
* value returned from calling its __enter__
*/
@@ -5560,10 +5568,10 @@
TARGET(INSTRUMENTED_JUMP_BACKWARD) {
_Py_CODEUNIT *this_instr = frame->instr_ptr = next_instr;
- next_instr += 1;
+ next_instr += 2;
INSTRUCTION_STATS(INSTRUMENTED_JUMP_BACKWARD);
CHECK_EVAL_BREAKER();
- INSTRUMENTED_JUMP(this_instr, next_instr + 1 - oparg, PY_MONITORING_EVENT_JUMP);
+ INSTRUMENTED_JUMP(this_instr, next_instr - oparg, PY_MONITORING_EVENT_JUMP);
DISPATCH();
}