[issue42693] "if 0:" lines are traced; they didn't use to be

Mark Shannon report at bugs.python.org
Mon Dec 21 08:55:22 EST 2020


Mark Shannon <mark at hotpy.org> added the comment:

You should never have to disable optimizations.

Let's be clear about what an optimization is.

An optimization (CS not math) is a change to the program such that it has the same effect, according to the language spec, but improves some aspect of the behavior, such as run time or memory use.

Any transformation that changes the effect of the program is not an optimization.

You shouldn't be able to tell, without timing the program (or measuring memory use, observing race conditions, etc.) whether optimizations are turned on or not.

Removing bytecodes for dead code is a legal optimization. It can never run, so we can't tell by observation whether it is there or not.

PEP 626 makes the lines number traced part of the language specification.
So the optimizer *must* respect line numbers.

Thus, removing all trace of `if 0:` is not legal since we could observe that change.
Hypothetically, we could change the line number table to allow multiple lines per bytecode and remove the NOP. The important point is that is coverage.py shouldn't care, or even know, if we do so.

----------

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


More information about the Python-bugs-list mailing list