[Python-Dev] Second milestone of FAT Python (original) (raw)

Terry Reedy tjreedy at udel.edu
Wed Nov 4 17:20:49 EST 2015


On 11/4/2015 3:50 AM, Victor Stinner wrote:

Hi,

I'm writing a new "FAT Python" project to try to implement optimizations in CPython (inlining, constant folding, move invariants out of loops, etc.) using a "static" optimizer (not a JIT). For the background, see the thread on python-ideas: https://mail.python.org/pipermail/python-ideas/2015-October/036908.html See also the documentation: https://hg.python.org/sandbox/fatpython/file/tip/FATPYTHON.rst https://hg.python.org/sandbox/fatpython/file/tip/ASTOPTIMIZER.rst I implemented the most basic optimization to test my code: replace calls to builtin functions (with constant arguments) with the result. For example, len("abc") is replaced with 3. I reached the second milestone: it's now possible to run the full Python test suite with these optimizations enabled. It confirms that the optimizations don't break the Python semantic.

Is the test suite complete enough to say this? (see below)

Example: --- >>> def func(): ... return len("abc") ... >>> import dis >>> dis.dis(func) 2 0 LOADGLOBAL 0 (len) 3 LOADCONST 1 ('abc') 6 CALLFUNCTION 1 (1 positional, 0 keyword pair) 9 RETURNVALUE

>>> len(func.getspecialized()) 1 >>> specialized=func.getspecialized()[0] >>> dis.dis(specialized['code']) 2 0 LOADCONST 1 (3) 3 RETURNVALUE >>> len(specialized['guards']) 2 >>> func() 3 >>> len=lambda obj: "mock" >>> func() 'mock'

In particular, does the test suite have tests like this, to verify that over-riding builtins works?

>>> func.getspecialized() [] ---

-- Terry Jan Reedy



More information about the Python-Dev mailing list