Skip to content

Commit

Permalink
pythonGH-111485: Remove some special cases from the code generator an…
Browse files Browse the repository at this point in the history
…d bytecodes.c (pythonGH-111540)
  • Loading branch information
markshannon authored and Glyphack committed Jan 27, 2024
1 parent 6adcb62 commit 093ac60
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 55 deletions.
36 changes: 19 additions & 17 deletions Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Python/abstract_interp_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@ dummy_func(
}

inst(RAISE_VARARGS, (args[oparg] -- )) {
TIER_ONE_ONLY
PyObject *cause = NULL, *exc = NULL;
switch (oparg) {
case 2:
Expand Down Expand Up @@ -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];
Expand All @@ -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();
Expand All @@ -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)) {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -2247,13 +2251,15 @@ 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();
ERROR_IF(res == NULL, error);
}

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);
Expand All @@ -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 &&
Expand Down Expand Up @@ -2297,6 +2303,7 @@ dummy_func(
};

inst(ENTER_EXECUTOR, (--)) {
TIER_ONE_ONLY
CHECK_EVAL_BREAKER();

PyCodeObject *code = _PyFrame_GetCode(frame);
Expand Down Expand Up @@ -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__
*/
Expand Down Expand Up @@ -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 -- )) {
Expand Down
52 changes: 52 additions & 0 deletions Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 093ac60

Please sign in to comment.