[Types-sig] Low-hanging fruit: recognizing builtins

Guido van Rossum guido@CNRI.Reston.VA.US
Thu, 16 Dec 1999 10:38:24 -0500

>     Guido> A first approximation would be to go hunt through all existing
>     Guido> code objects in a module for LOAD_GLOBAL and STORE_GLOBAL opcodes
>     Guido> with built-in names; for all such built-in names that have no
>     Guido> STORE_GLOBAL anywhere, it's "safe enough" to use the special
>     Guido> opcode.  Then of course you will have to hunt through the
>     Guido> bytecode for sequences of LOAD_GLOBAL(<name>), followed by
>     Guido> arbitrary code to load an object, followed by CALL_FUNCTION(1).
> Don't you also have to watch out for the dreaded
>     from my_rewritten_builtins import *

A module using "from whatever import *" loses the benefits of this
optimization.  Serves them right.

--Guido van Rossum (home page: http://www.python.org/~guido/)