[Python-ideas] Re: A “big picture” question.

2022-06-11 Thread Stephen J. Turnbull
Steven D'Aprano writes:
 > On Wed, Jun 08, 2022 at 06:51:54AM -0500, James Johnson wrote:
 > 
 > > When an amateur develops code incorrectly, s/he sometimes ends up with a
 > > code object that doesn’t run because of intermediate compiler
 > > optimizations.
 > 
 > If that happens, that's a bug in the compiler. Optimizations should 
 > never change the meaning of code.

This isn't quite true.  Languages (mostly low-level) frequently leave
behavior of legal syntax partly undefined in order to allow efficient
implementation on various architectures, or because it's unclear how
it will be used in the future (function annotations, I be lookin' at
you!)

 > If you have an example of this, where the compiler optimization changes
 > the meaning of Python code beyond what is documented, please raise a bug 
 > report for it.

OK, you've mostly taken care of the letter of my comment.  But I still
think it's worth pointing out that the documentation is frequently
incomplete for various reasons.

 > But I doubt you will find any, because Python performs very, very few 
 > optimizations of the sort you are referring to.

True, although it might in the future.

___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/QEHF3IDM24LVD6PZY7OF4YJFM3FU75T3/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: A “big picture” question.

2022-06-11 Thread Dennis Sweeney
I would note that the accepted [PEP 626](https://peps.python.org/pep-0626/) 
explicitly constrains line-tracing behavior: """Python should guarantee that 
when tracing is turned on, “line” tracing events are generated for all lines of 
code executed and only for lines of code that are executed."""

So even peephole optimizations should now theoretically follow PEP 626 and 
produce the expected line-tracing events. For example, the line "try:" 
typically emits a "NOP" instruction that is kept around just for the sake of 
tracing. If I recall correctly, there might not be 100% compliance with PEP 626 
so far, but in general, things have recently gotten more well-specified and 
predictable in this regard, not less.

The interpreter is still allowed to go wild by, e.g., executing 
type-specialized versions of different opcodes (PEP 659), but just not in such 
a way as to change language semantics, including the semantics of tracing when 
tracing is enabled.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/EK2HDVLAVC7B3EY7RDZTMXIGL5RYQI6J/
Code of Conduct: http://python.org/psf/codeofconduct/