I have implemented a simple quick-and-dirty tree-shaker for those interested in experimenting with such a thing.
To try it out, update your Gambit to the latest sources. The tree- shaker is disabled by default. To use it you must compile your program this way:
% gsc -e '(set! c#targ-tree-shake? #t)' test.scm
The tree-shaker will only remove from a compiled file the procedures which are not reachable *and* defined in the scope of a (declare (block)). So if you compile this program:
(declare (block))
(define (f x) (+ (* x x) (- x 1)))
(define (g y) (f (f y)))
(pp 123)
both f and g are eliminated. If the (pp 123) is changed to (pp (g 123)) then there is code generated for f, but ***not for g*** because the compiler has inlined g so that the main call is really (pp (f (f 123))).
For the experimenter... implement a Scheme library in lib.scm and compile your program like so:
(declare (block)) (include "lib.scm") ...your program here...
The last step is to link with a minimal Gambit runtime library containing only _kernel.scm .
Marc
Afficher les réponses par date