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

Steve Stagg report at bugs.python.org
Wed Jan 13 12:33:59 EST 2021


Steve Stagg <stestagg at gmail.com> added the comment:

Sounds great to me (with my approximately zero optimizer experience)

At risk of taking this too far, you /could/ add something like:

"skip any boolean test of a value _immediately_ following another boolean test, when it has no ..."

to this spec/guidance/whatever it is.

Just to prevent the risk of the `if` block being removed in future in ridiculous code like the following:

try:
  while True:
    a = x or y
    a.pop()
    if a:
      pass
except XIsEmptyError:
  ...

(I'm guessing we're pretty far from being able to rewrite enough for this to be a remotely credible optimization candidate anytime soon anyway)

----------

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


More information about the Python-bugs-list mailing list