[gambit-list] object->u8vector as tree shaker?

Marc Feeley feeley at iro.umontreal.ca
Sat Apr 19 22:59:47 EDT 2014

On Apr 19, 2014, at 10:22 PM, Bradley Lucier <lucier at math.purdue.edu> wrote:

> On 04/19/2014 10:08 PM, Marc Feeley wrote:
>> On Apr 19, 2014, at 9:37 PM, Bradley Lucier <lucier at math.purdue.edu> wrote:
>>> Marc:
>>> It's not quite clear to me what object->u8vector does with procedures.
>>> I was thinking that if it pulled in all the functions not in system libraries, then it could be used as a tree-shaker.
>>> This is only a vague thought, but I find its interesting.
>>> Brad
>> Interpreted and compiled procedures are serialized differently.  The interpreter is rather lazy and procedures will close over all of the lexical environment at the site of the lambda.  The interpreter is smarter and will close over the non-global free variables.  Note that in both cases the global environment is never closed over.
> One of these behaviors must be for the compiler.
> How hard would it be to modify this to implement a tree-shaker?

What is it you expect from a tree-shaker?

The compiler already implements a tree-shaker, but it is experimental and not documented.

If you want to try it out do

gsc -c -e "(set! c#targ-tree-shake? #t)" shake.scm

Say shake.scm is the file

(declare (block))

(define (f x) (g (+ x 1)))

(define (g x) (* x x))

(define (h x) (f 11))

(f 22)

If you check the file shake.c that is generated, you will see that there is no code for function h and also no code for function g (because it is inlined in f).

With the declaration

(declare (block) (standard-bindings) (fixnum) (not safe))

even the definition of f is removed, because f (and g) are inlined at the call (f 22).


More information about the Gambit-list mailing list