> < ^ Date: Fri, 30 Aug 1996 13:02:00 +0100 (MET)
> < ^ From: Martin Schoenert <martin.schoenert@math.rwth-aachen.de >
< ^ Subject: Re: Compiler; Collected
Julian Gilbey wrote in his mail message of 1996/08/27

However, if we want to have an optimising compiler, then compilation
of g should take into account the definition of f and not simply call
f. This gets even hairier if a function has a recursive definition,
but somewhere in the recursion (perhaps at a lower level?) the
function definition might be changed.

This process of replacing the function call with the body of the called
function is usually called inlining. One advantage is that the function call
overhead is avoided. The other advantage is that the other parts of the
compiler have large code blocks to work with and thus more opportunities for
optimizations.

As you note, this would be difficult for a GAP compiler, because the compiler
cannot know which function should be called. The compiler could do the
optimistic optimization, and assume that the function that would be called at
the time of the compilation will also be the one that should be called later
and inline that. But it would be necessary to have a fallback in case this
assumption is no longer true (as in your example).

Rather than develop such a mechanism, we have invested effort to make the
function call faster for GAP 4.

Julian Gilbey continued

Having looked at the code for Collected (in list.g), may I suggest the
following as a possible alternative, which might well be faster in
many cases?

Indeed, it should be faster for almost all cases. With your permission
we shall be using this function in the next version of GAP.

Martin.

-- .- .-. - .. -.  .-.. --- ...- . ...  .- -. -. .. -.- .-
Martin Sch"onert,   Martin.Schoenert@Math.RWTH-Aachen.DE,   +49 241 804551
Lehrstuhl D f"ur Mathematik, Templergraben 64, RWTH, 52056 Aachen, Germany

> < [top]