On 21.05.2014 14:13, Steven D'Aprano wrote:
> On Wed, May 21, 2014 at 07:05:49AM -0400, Ned Batchelder wrote:
>> ** The problem
>>
>> A long-standing problem with CPython is that the peephole optimizer
>> cannot be completely disabled. Normally, peephole optimization is a
>> good thing, it improves execution speed. But in some situations, like
>> coverage testing, it's more important to be able to reason about the
>> code's execution. I propose that we add a way to completely disable the
>> optimizer.
>
> I'm not sure whether this is an argument for or against your proposal,
> but the continue statement shown below is *not* dead code and should not
> be optimized out. The assert fails if you remove the continue statement.
>
> I don't have 3.4 on this machine to test with, but using 3.3, I can see
> no evidence that `continue` is optimized away.
The logical continue is still there -- what happens is that the
optimizer rewrites the `else` jump at the preceding `if` condition,
which would normally point at the `continue` statement, to the beginning
of the loop, because it would be a jump (to the continue) to a jump (to
the for loop header).
Thus, the actual continue statement is not reached, but logically the
code does the same, because the only way continue would have been
reached was transformed to a continue itself.
To make the details more explicit, here is the source again, and the
disassembled code, with the original source interspersed: