On 06.07.2019 0:28, Pablo Galindo Salgado wrote:
Hi,

Recently, we moved the optimization for the removal of dead code of the form

if 0:
....

to the ast so we use JUMP bytecodes instead (being completed in PR14116). The 
reason is that
currently, any syntax error in the block will never be reported. For example:

if 0:
return

if 1:
     pass
else:
     return

while 0:
     return

at module level do not raise any syntax error (just some examples), In 
https://bugs.python.org/issue37500 it was reported
that after that, code coverage will decrease as coverage.py sees these new 
bytecodes (even if they are not executed). In general,
the code object is a bit bigger and the optimization now it requires an JUMP 
instruction to be executed, but syntax errors are reported.

The discussion on issue 37500 is about if we should prioritize the optimization 
or the correctness of reporting syntax errors. In my opinion,
SyntaxErrors should be reported with independence of the value of variables 
(__debug__) or constant as is a property of the code being written
not of the code being executed. Also, as CPython is the reference implementation of Python, the danger here is that it could be interpreted that
this optimization is part of the language and its behavior should be mirrored 
in every other Python implementation. Elsewhere we have always
prioritize correctness over speed or optimizations.

I am writing this email to know what other people think. Should we revert the 
change and not report Syntax Errors on optimized blocks? Someone
sees a viable way of reporting the errors and not emitting the bytecode for 
these block?


"Correctness over speed" is Python's core value, so any syntax errors must be 
reported.

Is this optimization so important anyway? `if 0:' seems a niche use case (yes, it's in site.py which is in every installation but the gain there is pretty small)

If it is, why not kill two birds with one stone and discard the subtree, but 
_after_ it has passed scrunity?

AFAIK the standard approach to optimization is to construct a raw tree first 
and only then apply any equivalence transformations to it.

--
Regards,
Ivan

_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/Q3HT6IRKC4X6UUYRZVANPJI4AJZNQQHM/

Reply via email to