[Python-Dev] Possible optimization for LOAD_FAST ?

Guido van Rossum guido at python.org
Mon Jan 3 04:18:09 CET 2011


On Sun, Jan 2, 2011 at 5:50 PM, Alex Gaynor <alex.gaynor at gmail.com> wrote:
> No, it's singularly impossible to prove that any global load will be any given
> value at compile time.  Any optimization based on this premise is wrong.

True.

My proposed way out of this conundrum has been to change the language
semantics slightly so that global names which (a) coincide with a
builtin, and (b) have no explicit assignment to them in the current
module, would be fair game for such optimizations, with the
understanding that the presence of e.g. "len = len" anywhere in the
module (even in dead code!) would be sufficient to disable the
optimization.

But barring someone interested in implementing something based on this
rule, the proposal has languished for many years.

FWIW, this is reminiscent of Fortran's rules for "intrinsics" (its
name for builtins), which have a similar optimization behavior (except
there the potential overrides that the compiler doesn't need to take
into account are load-time definitions).

-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-Dev mailing list