[issue42899] Is it legal to eliminate tests of a value, when that test has no effect on control flow?

Mark Shannon report at bugs.python.org
Wed Jan 13 11:47:49 EST 2021


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

The problem with using a specific syntax example, is that the optimizer doesn't work that way. It works on the CFG.

Any specification needs to be phrased in terms of general control flow, as other optimizations can enable this transformation.
e.g. 

if x or True:
    do_something()

is (in master) transformed to:

x
do_something()

I think your earlier suggestion of
"So I think dropping an *extra* call is fine, while dropping the *only* call is not."
is the best way to preserve 3.9 behavior.
It can be formalised as:
"The implementation is allowed to skip any boolean tests of a value, when it has effect on the flow of the program and at least one test has already been performed on that value."

----------

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


More information about the Python-bugs-list mailing list