[cvs-nhc98] Added the application-of-function-of-known-arity optimisat

Olaf Chitil olaf@sparud.net
Thu, 16 Jan 2003 15:31:36 +0100 (CET)


olaf: Thu Jan 16 15:31:35 CET 2003

Update of /usr/src/master/nhc/src/hat/lib/Hat
In directory hinken:/tmp/cvs-serv20926/src/hat/lib/Hat

Modified Files:
	Hat.hs 
Log Message:
Added the application-of-function-of-known-arity optimisation to Hat.

If a function of known arity n is applied to n arguments, then instead of the apn/uapn combinators the new appn/uappn combinators are used (0 < n <= 5). If function and application are trusted, then even only a uWrapForward combinator is used. All these combinators do not use the wrapper of a function, but directly the worker. Thus time for some wrapping and unwrapping is saved.

With optimisation the same *.hat file is produced as without. A speedup of 15-20% was measured for adjoxo edgecorner1.in and mate ellerman.

A hack is used to avoid ambiguous type variables in the transformed program: a type declaration of a function is transformed into type declarations for the wrapper function. There are no type declarations for worker functions, type inference might yield a rather general type and then direct use of a worker by the new combinators may yield to an ambiguous type variable error. Constructing a type declaration for a worker would be hard; in general it would be necessary to expand type synonyms. Hence the transformation adds a bogus last equation to the worker definition (because of "| False =" it can never be taken) which contains a call of the wrapper. Thus the worker inherits the type of its wrapper.

A worker definition used to be local to its wrapper definition. Because workers may now be called directly, they are now defined in the same scope. The exceptions are class/instance methods, because no additional definitions are allowed there. However, workers of methods are never directly called anyway, because methods do not have a fixed arity.

Corrected that the arity of the predefined function composition (.) had wrongly been set to 2 instead of 3.