diff options
author | Mark Shannon <mark@hotpy.org> | 2019-11-21 09:11:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-21 09:11:43 (GMT) |
commit | fee552669f21ca294f57fe0df826945edc779090 (patch) | |
tree | 13b461df5a1231220b8f72c197d2731e9cb88d85 /Python/peephole.c | |
parent | 5dcc06f6e0d7b5d6589085692b86c63e35e2325e (diff) | |
download | cpython-fee552669f21ca294f57fe0df826945edc779090.zip cpython-fee552669f21ca294f57fe0df826945edc779090.tar.gz cpython-fee552669f21ca294f57fe0df826945edc779090.tar.bz2 |
Produce cleaner bytecode for 'with' and 'async with' by generating separate code for normal and exceptional paths. (#6641)
Remove BEGIN_FINALLY, END_FINALLY, CALL_FINALLY and POP_FINALLY bytecodes. Implement finally blocks by code duplication.
Reimplement frame.lineno setter using line numbers rather than bytecode offsets.
Diffstat (limited to 'Python/peephole.c')
-rw-r--r-- | Python/peephole.c | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/Python/peephole.c b/Python/peephole.c index d859648..714a452 100644 --- a/Python/peephole.c +++ b/Python/peephole.c @@ -198,7 +198,6 @@ markblocks(_Py_CODEUNIT *code, Py_ssize_t len) case SETUP_FINALLY: case SETUP_WITH: case SETUP_ASYNC_WITH: - case CALL_FINALLY: j = GETJUMPTGT(code, i); assert(j < len); blocks[j] = 1; @@ -432,14 +431,10 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, /* Remove unreachable ops after RETURN */ case RETURN_VALUE: h = i + 1; - /* END_FINALLY should be kept since it denotes the end of - the 'finally' block in frame_setlineno() in frameobject.c. - SETUP_FINALLY should be kept for balancing. - */ - while (h < codelen && ISBASICBLOCK(blocks, i, h) && - _Py_OPCODE(codestr[h]) != END_FINALLY) + while (h < codelen && ISBASICBLOCK(blocks, i, h)) { - if (_Py_OPCODE(codestr[h]) == SETUP_FINALLY) { + /* Leave SETUP_FINALLY and RERAISE in place to help find block limits. */ + if (_Py_OPCODE(codestr[h]) == SETUP_FINALLY || _Py_OPCODE(codestr[h]) == RERAISE) { while (h > i + 1 && _Py_OPCODE(codestr[h - 1]) == EXTENDED_ARG) { @@ -506,7 +501,6 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, case SETUP_FINALLY: case SETUP_WITH: case SETUP_ASYNC_WITH: - case CALL_FINALLY: j = blocks[j / sizeof(_Py_CODEUNIT) + i + 1] - blocks[i] - 1; j *= sizeof(_Py_CODEUNIT); break; |