2010/12/29 "Martin v. L÷wis" <martin@v.loewis.de>
Am 28.12.2010 18:08, schrieb Lukas Lueg:
> Also, the
> load_fast in lne 22 to reference x could be taken out of the loop as x
> will always point to the same object....

That's not true; a debugger may change the value of x.


OK, but is it mandatory? For example, in the above code, I can unroll the loop because I found that range is the usual built-in, 5 is a low-enough constant, and the body is made by a simple statement.

Another example. I can totally remove the variable i, just using the stack, so a debugger (or, in general, having the tracing enabled) cannot even find something to change about it.

And so on with other optimization examples that can be possible.

Are they "legal" with Python? I think that we need to make it clear what happens in such cases.

My idea is that it should be made implementation-specific. What happens with local variables and the generated code must depend on the specific compiler & virtual machine, in order to have a greater flexibility.

IMHO the most important thing should be that, under normal conditions, the executed code have the expected behavior.