2011/1/1 Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org">guido@python.org</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">On Sat, Jan 1, 2011 at 1:52 AM, Cesare Di Mauro<br>

<div class="im">> Do we consider local variable removing (due to internal optimizations) a<br>
> safe or unsafe operation?<br>
<br>
</div>I would consider it safe unless the function locals() is called<br>
directly in the function -- always assuming the compiler does not see<br>
obvious other evidence (like a local being used by a nested function).<br></blockquote><div><br></div><div>The problem here is that locals is a builtin function, not a keyword, so the compiler must resort to something like the "code fork" that I showed before, if we want to keep the correct language semantic.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Still, I wonder if it isn't much better to try to do this using a JIT<br> instead of messing with the bytecode.</blockquote>
<div><br></div><div>Ditto for me, if a good (and not resource hungry) JIT will come.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">You'll find that the current<br>

compiler just really doesn't have the datastructures needed to do<br> these kind of optimizations right.<br></blockquote><div><br></div><div>Right. Not now, but something can be made if and only if it makes sense. A JIT can make it non-sense, of course.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">
> Do we consider local variable values "untouchable"? Think about a locals()<br>
> call that return a list for a variable; lists are mutable objects, so they<br>
> can be changed by the caller, but the internally generated bytecode can work<br>
> on a "private" (on stack) copy which doesn't "see" the changes made due to<br>
> the locals() call.<br>
<br>
</div>Are you sure? locals() makes only a shallow copy, so changes to the<br>
list's contents made via the list returned by locals() should be<br>
completely visible by the bytecode.<br></blockquote><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im"><div><br></div>--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</blockquote> </div><div><br></div><div>Nice to know it. Reading from the doc ( <a href="http://docs.python.org/library/functions.html#locals">http://docs.python.org/library/functions.html#locals</a> ) it was not clear for me. Thanks.</div>
<div><br></div><div>Cesare<br></div>