Compiling a subset of Python

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Tue Sep 11 05:37:39 EDT 2001


10 Sep 2001 23:55:58 GMT, Martijn Faassen <m.faassen at vet.uu.nl> pisze:

> Compiling a dynamically typed language like Python is a lot harder than
> compiling a statically typed language.

I think another reason of problems with compiling python efficiently
is that many things are mutable.

When any bit of statically unknown code is executed, a compiler must
in principle assume that it could change objects in __builtins__,
attributes of any object or class, global variables of the current
module or other modules, superclass relationships, code of functions,
classes of objects etc.

All objects looked up in dictionaries must be reloaded using whatever
lookups are specified in the language, and any static information
about their properties is lost. There isn't much advantage of the
fact inferred by a compiler that open(filename).readline() returns
a string if __builtins__.open doesn't need to refer to the original
open function.

A statically unknown code can be executed from just anywhere. For
example decrementing a reference count of an unknown object can cause
__del__ and thus arbitrary code to be executed. It's very unlikely
that such code would replace sys.modules['sre'] with something else,
but in principle it's possible, so objects bound to names qualified
with sre must not be cached across deletions of unknown objects
(unless a clever scheme would detect these changes at runtime, but
it looks hard) and having static information about functions in this
module doesn't help with optimization.

-- 
 __("<  Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK



More information about the Python-list mailing list