Bytecode optimisation

M.-A. Lemburg mal at lemburg.com
Wed May 19 04:03:24 EDT 1999


Christian Tismer wrote:
> 
> "M.-A. Lemburg" wrote:
> ...
> > About adding type information to variables:
> >
> > Wouldn't it be possible to make the optimizer recognize
> > the following type of assert statement and then use the
> > implicit information contained in it...
> >
> > assert type(x) is types.IntegerType
> > x = x + 2
> >
> > There are many advantages to this construct, since it can
> > be used to debug *and* optimize code. It also is perfectly
> > valid Python and shows the programmers intent pretty well,
> > IMHO.
> 
> Sounds fine, although it doesn't give you a guarantee,
> just a hint. Faulty code could change x' type again
> somewhere, so either a flow analysis is needed, or
> the code must still be aware of any type, and can just
> optimize towards the promised one.

True, but since the above construct is about convention anyway,
this shouldn't hurt much: for one, the non-optimized code will
shout out loud whenever it sees a non integer type and second,
the intention is providing the programmer with an "inline"
way of telling the optimizer what to do: if his hints fail,
well, too bad :-) [will probably result in a segfault, I guess].
There should probably also be a way to lift the type restriction
again, say:

assert type(x) == types.AnyType

I'm not trying to invent some kind of static typing here...
this is all about dynamics and so stating that e.g.
a variable remains constant in the current scope is just
as reliable as any other assumption such as side effect
free function calls.

BTW, a few more specialized opcodes would be needed to
exploit the type information, plus, of course, a few
registers to hold basic values such as integers and
floats. Rattlesnake is VM experiment that goes in this
direction:

	http://www.egroups.com/group/rattlesnake/

Cheers,
-- 
Marc-Andre Lemburg
______________________________________________________________________
Y2000:                                                   226 days left
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/





More information about the Python-list mailing list