[New-bugs-announce] [issue42246] Implement PEP 626

Mark Shannon report at bugs.python.org
Mon Nov 2 10:32:42 EST 2020


New submission from Mark Shannon <mark at hotpy.org>:

Implementation of PEP 626 requires:

1. Implementation of the new line number table and associated APIs.
2. Removal of BEGIN_DO_NOT_EMIT_BYTECODE and END_DO_NOT_EMIT_BYTECODE from the compiler as they do not understand line numbers and may remove lines from the bytecode that they shouldn't.
3. Enhance compiler front-end and CFG optimizer to avoid the negative performance impact of PEP.
 a) Duplicate the tests in while blocks to avoid the extra jump instruction at the end of the loop.
 b) Duplicate and renumber terminator blocks that have no line numbers.

Guaranteeing that f_lineno is correct without hurting performance
-----------------------------------------------------------------

PEP 626 mandates that the f_lineno attribute of a frame is always correct, even after a return or raise, but we don't want to hurt performance.
Since the interpreter ensures that the f_lasti attribute of a frame is always correct, we can ensure correctness of f_lineno at zero cost, by ensuring that all RETURN_VALUE, RAISE_VARARGS and RERAISE instruction have a non-negative line number. Then f_lineno can always be lazily computed from f_lasti.

The front-end generates artificial RERAISEs and RETURN_VALUE that have no line number. To give these instructions a valid line number we can take advantage of the fact that such terminator blocks (blocks with no successors) can be freely duplicated. Once duplicated, each terminator block will have only one predecessor and can acquire the line number of the preceding block, without causing false line events.

----------
assignee: Mark.Shannon
messages: 380231
nosy: Mark.Shannon, pablogsal
priority: normal
severity: normal
status: open
title: Implement PEP 626
type: enhancement
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42246>
_______________________________________


More information about the New-bugs-announce mailing list