[Python-ideas] Python-ideas Digest, Vol 90, Issue 30

Paul Moore p.f.moore at gmail.com
Thu May 22 00:47:24 CEST 2014


On 21 May 2014 23:30, Trip Volpe <trip at flowroute.com> wrote:
> On Wed, May 21, 2014 at 2:14 PM, Nathaniel Smith <njs at pobox.com> wrote:
>> Isn't the real problem here that the peephole optimizer violates the
>> first rule of optimization ("don't change semantics") by breaking
>> sys.settrace? Couldn't we fix this directly?
>
> I agree with this. Adding a command line flag to tinker with code generation
> may well be opening a can of worms, but "the peephole optimizer shouldn't
> change semantics" is a more compelling argument, although fixing it from
> that angle is obviously more involved. One problem is that functions like
> settrace() expose low-level details to the higher-level semantics. It's a
> fair question as to whether it should be considered kosher to expose
> implementation details like the peephole optimizer through such interfaces.

While I'm happy to be proved wrong with code, my instinct is that
"making sys.settrace work" would likely be too complex to be
practical.

In any case, as you say, it exposes low-level details, and I would
personally consider "glitches" like this as implementation details. To
put it another way, I don't consider the exact lines traced by
sys.settrace to be part of the semantics of a program, any more than I
consider the output of dis.dis to be. So in my view it is acceptable
for the optimiser to change the lines that get traced in the way that
coverage experienced.

Paul.


More information about the Python-ideas mailing list