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
Afficher les réponses par date
On Apr 19, 2014, at 9:37 PM, Bradley Lucier lucier@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. In the following code:
(define (f x) (g (+ x 1)))
(define (g x) (* x x))
two procedures are created, one bound to f and the other to g. The procedure bound to f will not contain a reference to the procedure bound to g. The procedure bound to f will only refer to the global variable g, and this global variable will be dereferenced when the body of f is executed.
So serializing the procedure bound to f will not magically collect all of the code that is needed to run f. In fact, if the deserialization happens in a context where g is not bound, calling the deserialized procedure will give an “unbound variable g” error.
Marc
On 04/19/2014 10:08 PM, Marc Feeley wrote:
On Apr 19, 2014, at 9:37 PM, Bradley Lucier lucier@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?
Brad
On Apr 19, 2014, at 10:22 PM, Bradley Lucier lucier@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@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).
Marc
On 04/19/2014 10:59 PM, Marc Feeley wrote:
On Apr 19, 2014, at 10:22 PM, Bradley Lucier lucier@math.purdue.edu wrote:
On 04/19/2014 10:08 PM, Marc Feeley wrote:
What is it you expect from a tree-shaker?
That's interesting, but I was thinking more of a runtime thing. E.g., load a bunch of compiled libraries, the Gambit run-time system (of course), the files (either compiled or interpreted) specific to my project, with a call to (main), and then have
(object->u8vector main)
output all the current globals, etc., that can be called by running main, so that calling u8vector->object would give you a runnable object with minimal overhead.
Perhaps it's impossible, now that I think about it.
Brad
On 04/19/2014 10:59 PM, Marc Feeley wrote:
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).
This is an old thread, but it's interesting.
When I compiled Meroon recently with the tree-shaker, I got
-rwxrwxr-x 1 lucier lucier 800496 Mar 28 23:39 _meroon.o1*
while without the tree-shaker, I get
-rwxrwxr-x 1 lucier lucier 1111768 Mar 28 23:40 _meroon.o2*
That's not a trivial difference.
And there are unused, redundant things in Meroon (experimental dispatchers, etc.).
But when I load Meroon I get
(load "_meroon.o1")
*** WARNING -- Variable "Class-add-subclass" used in module "_meroon" is undefined *** WARNING -- Variable "Class-generate-accessors" used in module "_meroon" is undefined *** WARNING -- Variable "Class-generate-accompanying-functions" used in module "_meroon" is undefined *** WARNING -- Variable "Class-is-a?" used in module "_meroon" is undefined *** WARNING -- Variable "Class-super-class" used in module "_meroon" is undefined *** WARNING -- Variable "Class?" used in module "_meroon" is undefined *** WARNING -- Variable "Field?" used in module "_meroon" is undefined *** WARNING -- Variable "Generic-1-update!" used in module "_meroon" is undefined *** WARNING -- Variable "Generic-1?" used in module "_meroon" is undefined *** WARNING -- Variable "Generic-N-update!" used in module "_meroon" is undefined *** WARNING -- Variable "Generic-N?" used in module "_meroon" is undefined *** WARNING -- Variable "Global-Dispatcher-augment-dispatcher!" used in module "_meroon" is undefined *** WARNING -- Variable "Global-Dispatcher-compress-dispatcher!" used in module "_meroon" is undefined *** WARNING -- Variable "Global-Dispatcher-enlarge-dispatcher!" used in module "_meroon" is undefined *** WARNING -- Variable "Global-Dispatcher-find-method" used in module "_meroon" is undefined *** WARNING -- Variable "Global-Dispatcher-rebalance-dispatcher!" used in module "_meroon" is undefined *** WARNING -- Variable "Global-Dispatcher-update-dispatcher!" used in module "_meroon" is undefined *** WARNING -- Variable "Global-Dispatcher?" used in module "_meroon" is undefined *** WARNING -- Variable "Handy-Class-generate-accessors" used in module "_meroon" is undefined *** WARNING -- Variable "Handy-Class-generate-accompanying-functions" used in module "_meroon" is undefined *** WARNING -- Variable "Handy-Class-generate-allocator" used in module "_meroon" is undefined *** WARNING -- Variable "Handy-Class-generate-coercer" used in module "_meroon" is undefined *** WARNING -- Variable "Handy-Class-generate-maker" used in module "_meroon" is undefined *** WARNING -- Variable "Handy-Class-generate-predicate" used in module "_meroon" is undefined *** WARNING -- Variable "Handy-Class?" used in module "_meroon" is undefined *** WARNING -- Variable "Immediate-Dispatcher-augment-dispatcher!" used in module "_meroon" is undefined *** WARNING -- Variable "Immediate-Dispatcher-compress-dispatcher!" used in module "_meroon" is undefined *** WARNING -- Variable "Immediate-Dispatcher-find-method" used in module "_meroon" is undefined *** WARNING -- Variable "Immediate-Dispatcher-rebalance-dispatcher!" used in module "_meroon" is undefined *** WARNING -- Variable "Immediate-Dispatcher-update-dispatcher!" used in module "_meroon" is undefined *** WARNING -- Variable "Immediate-Dispatcher?" used in module "_meroon" is undefined *** WARNING -- Variable "Indexed-Dispatcher-augment-dispatcher!" used in module "_meroon" is undefined *** WARNING -- Variable "Indexed-Dispatcher-compress-dispatcher!" used in module "_meroon" is undefined *** WARNING -- Variable "Indexed-Dispatcher-find-method" used in module "_meroon" is undefined *** WARNING -- Variable "Indexed-Dispatcher-rebalance-dispatcher!" used in module "_meroon" is undefined *** WARNING -- Variable "Indexed-Dispatcher-update-dispatcher!" used in module "_meroon" is undefined *** WARNING -- Variable "Indexed-Dispatcher?" used in module "_meroon" is undefined *** WARNING -- Variable "Linear-Dispatcher-find-multi-method" used in module "_meroon" is undefined *** WARNING -- Variable "Linear-Dispatcher?" used in module "_meroon" is undefined *** WARNING -- Variable "MeroonV2-Class-generate-accessors" used in module "_meroon" is undefined *** WARNING -- Variable "MeroonV2-Class?" used in module "_meroon" is undefined *** WARNING -- Variable "Mono-Field-compute-value-offset" used in module "_meroon" is undefined *** WARNING -- Variable "Mono-Field-create-careful-reader" used in module "_meroon" is undefined *** WARNING -- Variable "Mono-Field-create-careful-writer" used in module "_meroon" is undefined *** WARNING -- Variable "Mono-Field-field-defined?" used in module "_meroon" is undefined *** WARNING -- Variable "Mono-Field-field-value" used in module "_meroon" is undefined *** WARNING -- Variable "Mono-Field-generate-Handy-accessors" used in module "_meroon" is undefined *** WARNING -- Variable "Mono-Field-generate-MeroonV2-accessors" used in module "_meroon" is undefined *** WARNING -- Variable "Mono-Field-generate-fast-careful-reader" used in module "_meroon" is undefined *** WARNING -- Variable "Mono-Field-generate-fast-careful-writer" used in module "_meroon" is undefined *** WARNING -- Variable "Mono-Field-generate-next-offset!" used in module "_meroon" is undefined *** WARNING -- Variable "Mono-Field-generate-offset" used in module "_meroon" is undefined *** WARNING -- Variable "Mono-Field-initialize-field-value!" used in module "_meroon" is undefined *** WARNING -- Variable "Mono-Field-set-field-value!" used in module "_meroon" is undefined *** WARNING -- Variable "Mono-Field?" used in module "_meroon" is undefined *** WARNING -- Variable "Poly-Field-compute-value-offset" used in module "_meroon" is undefined *** WARNING -- Variable "Poly-Field-create-careful-lengther" used in module "_meroon" is undefined *** WARNING -- Variable "Poly-Field-create-careful-reader" used in module "_meroon" is undefined *** WARNING -- Variable "Poly-Field-create-careful-writer" used in module "_meroon" is undefined *** WARNING -- Variable "Poly-Field-field-defined?" used in module "_meroon" is undefined *** WARNING -- Variable "Poly-Field-field-length" used in module "_meroon" is undefined *** WARNING -- Variable "Poly-Field-field-value" used in module "_meroon" is undefined *** WARNING -- Variable "Poly-Field-generate-Handy-accessors" used in module "_meroon" is undefined *** WARNING -- Variable "Poly-Field-generate-MeroonV2-accessors" used in module "_meroon" is undefined *** WARNING -- Variable "Poly-Field-generate-fast-careful-lengther" used in module "_meroon" is undefined *** WARNING -- Variable "Poly-Field-generate-fast-careful-reader" used in module "_meroon" is undefined *** WARNING -- Variable "Poly-Field-generate-fast-careful-writer" used in module "_meroon" is undefined *** WARNING -- Variable "Poly-Field-generate-next-offset!" used in module "_meroon" is undefined *** WARNING -- Variable "Poly-Field-generate-offset" used in module "_meroon" is undefined *** WARNING -- Variable "Poly-Field-initialize-field-value!" used in module "_meroon" is undefined *** WARNING -- Variable "Poly-Field-set-field-value!" used in module "_meroon" is undefined *** WARNING -- Variable "Poly-Field?" used in module "_meroon" is undefined *** WARNING -- Variable "Subclass-Dispatcher-augment-dispatcher!" used in module "_meroon" is undefined *** WARNING -- Variable "Subclass-Dispatcher-compress-dispatcher!" used in module "_meroon" is undefined *** WARNING -- Variable "Subclass-Dispatcher-find-method" used in module "_meroon" is undefined *** WARNING -- Variable "Subclass-Dispatcher-rebalance-dispatcher!" used in module "_meroon" is undefined *** WARNING -- Variable "Subclass-Dispatcher-update-dispatcher!" used in module "_meroon" is undefined *** WARNING -- Variable "Subclass-Dispatcher?" used in module "_meroon" is undefined *** WARNING -- Variable "Tracing-Dispatcher-augment-dispatcher!" used in module "_meroon" is undefined *** WARNING -- Variable "Tracing-Dispatcher-compress-dispatcher!" used in module "_meroon" is undefined *** WARNING -- Variable "Tracing-Dispatcher-rebalance-dispatcher!" used in module "_meroon" is undefined *** WARNING -- Variable "Tracing-Dispatcher-update-dispatcher!" used in module "_meroon" is undefined *** WARNING -- Variable "Tracing-Dispatcher?" used in module "_meroon" is undefined *** WARNING -- Variable "View-generate-accessors" used in module "_meroon" is undefined *** WARNING -- Variable "View-generate-accompanying-functions" used in module "_meroon" is undefined *** WARNING -- Variable "View-generate-predicate" used in module "_meroon" is undefined *** WARNING -- Variable "View-is-a?" used in module "_meroon" is undefined *** WARNING -- Variable "View?" used in module "_meroon" is undefined *** WARNING -- Variable "Virtual-Field-compute-value-offset" used in module "_meroon" is undefined *** WARNING -- Variable "Virtual-Field-field-defined?" used in module "_meroon" is undefined *** WARNING -- Variable "Virtual-Field-field-length" used in module "_meroon" is undefined *** WARNING -- Variable "Virtual-Field-field-value" used in module "_meroon" is undefined *** WARNING -- Variable "Virtual-Field-generate-Handy-accessors" used in module "_meroon" is undefined *** WARNING -- Variable "Virtual-Field-generate-MeroonV2-accessors" used in module "_meroon" is undefined *** WARNING -- Variable "Virtual-Field-initialize-field-value!" used in module "_meroon" is undefined *** WARNING -- Variable "Virtual-Field-set-field-value!" used in module "_meroon" is undefined *** WARNING -- Variable "Virtual-Field?" used in module "_meroon" is undefined> (show Object-class)
*** WARNING -- Variable "add-1-method!" used in module "_meroon" is undefined *** WARNING -- Variable "add-N-method!" used in module "_meroon" is undefined *** WARNING -- Variable "adjust-index" used in module "_meroon" is undefined *** WARNING -- Variable "already-unveiled?" used in module "_meroon" is undefined *** WARNING -- Variable "barfing-method" used in module "_meroon" is undefined *** WARNING -- Variable "careless-determine-method1" used in module "_meroon" is undefined *** WARNING -- Variable "careless-subclass?" used in module "_meroon" is undefined *** WARNING -- Variable "check-appropriate-size" used in module "_meroon" is undefined *** WARNING -- Variable "check-class" used in module "_meroon" is undefined *** WARNING -- Variable "check-conformity" used in module "_meroon" is undefined *** WARNING -- Variable "check-index" used in module "_meroon" is undefined *** WARNING -- Variable "check-revision" used in module "_meroon" is undefined *** WARNING -- Variable "check-size" used in module "_meroon" is undefined *** WARNING -- Variable "coherent-variables?" used in module "_meroon" is undefined *** WARNING -- Variable "collect-super-class-numbers" used in module "_meroon" is undefined *** WARNING -- Variable "combine" used in module "_meroon" is undefined *** WARNING -- Variable "compare-signatures" used in module "_meroon" is undefined *** WARNING -- Variable "compare4egal" used in module "_meroon" is undefined *** WARNING -- Variable "compute-offset" used in module "_meroon" is undefined *** WARNING -- Variable "copy-vector-slice!" used in module "_meroon" is undefined *** WARNING -- Variable "count-Poly-Fields" used in module "_meroon" is undefined *** WARNING -- Variable "create-Indexed-Dispatcher" used in module "_meroon" is undefined *** WARNING -- Variable "create-Mono-Field" used in module "_meroon" is undefined *** WARNING -- Variable "create-Poly-Field" used in module "_meroon" is undefined *** WARNING -- Variable "create-allocator" used in module "_meroon" is undefined *** WARNING -- Variable "create-default-generic-method" used in module "_meroon" is undefined *** WARNING -- Variable "create-one-final-poly-maker" used in module "_meroon" is undefined *** WARNING -- Variable "create-some-field" used in module "_meroon" is undefined *** WARNING -- Variable "create-zero-poly-maker" used in module "_meroon" is undefined *** WARNING -- Variable "display-meroon-anomaly" used in module "_meroon" is undefined *** WARNING -- Variable "display-meroon-banner" used in module "_meroon" is undefined *** WARNING -- Variable "every?" used in module "_meroon" is undefined *** WARNING -- Variable "extend-Indexed-Dispatcher" used in module "_meroon" is undefined *** WARNING -- Variable "extend-classes-number!" used in module "_meroon" is undefined *** WARNING -- Variable "fill-instance!" used in module "_meroon" is undefined *** WARNING -- Variable "find-method1" used in module "_meroon" is undefined *** WARNING -- Variable "find-option-plus-values" used in module "_meroon" is undefined *** WARNING -- Variable "find-option-present?" used in module "_meroon" is undefined *** WARNING -- Variable "find-option-single-value" used in module "_meroon" is undefined *** WARNING -- Variable "general-make" used in module "_meroon" is undefined *** WARNING -- Variable "generate-class-name" used in module "_meroon" is undefined *** WARNING -- Variable "generate-lengther-name" used in module "_meroon" is undefined *** WARNING -- Variable "generate-reader-name" used in module "_meroon" is undefined *** WARNING -- Variable "generate-writer-name" used in module "_meroon" is undefined *** WARNING -- Variable "get-new-class-number" used in module "_meroon" is undefined *** WARNING -- Variable "get-new-generic-number" used in module "_meroon" is undefined *** WARNING -- Variable "globalize-dispatcher" used in module "_meroon" is undefined *** WARNING -- Variable "goto-margin" used in module "_meroon" is undefined *** WARNING -- Variable "identity" used in module "_meroon" is undefined *** WARNING -- Variable "implements?" used in module "_meroon" is undefined *** WARNING -- Variable "instance-clone" used in module "_meroon" is undefined *** WARNING -- Variable "internal-meroon-error" used in module "_meroon" is undefined *** WARNING -- Variable "iota" used in module "_meroon" is undefined *** WARNING -- Variable "last-pair" used in module "_meroon" is undefined *** WARNING -- Variable "look-generic" used in module "_meroon" is undefined *** WARNING -- Variable "look4keyword" used in module "_meroon" is undefined *** WARNING -- Variable "make-maker" used in module "_meroon" is undefined *** WARNING -- Variable "meroon-keyword-eq?" used in module "_meroon" is undefined *** WARNING -- Variable "meroon-reduce" used in module "_meroon" is undefined *** WARNING -- Variable "oo-error" used in module "_meroon" is undefined *** WARNING -- Variable "option-not-there" used in module "_meroon" is undefined *** WARNING -- Variable "propagate-super-methods!" used in module "_meroon" is undefined *** WARNING -- Variable "really-indexize-dispatcher" used in module "_meroon" is undefined *** WARNING -- Variable "register-Generic-1" used in module "_meroon" is undefined *** WARNING -- Variable "register-method" used in module "_meroon" is undefined *** WARNING -- Variable "remove" used in module "_meroon" is undefined *** WARNING -- Variable "remove-option" used in module "_meroon" is undefined *** WARNING -- Variable "report-already-initialized" used in module "_meroon" is undefined *** WARNING -- Variable "report-bad-coercion-to-field" used in module "_meroon" is undefined *** WARNING -- Variable "report-bad-index" used in module "_meroon" is undefined *** WARNING -- Variable "report-immutable-field" used in module "_meroon" is undefined *** WARNING -- Variable "report-meroon-error" used in module "_meroon" is undefined *** WARNING -- Variable "report-missing-index" used in module "_meroon" is undefined *** WARNING -- Variable "report-superfluous-allocation" used in module "_meroon" is undefined *** WARNING -- Variable "report-uninitialized-field" used in module "_meroon" is undefined *** WARNING -- Variable "resolve-virtual-field" used in module "_meroon" is undefined *** WARNING -- Variable "retrieve-named-field" used in module "_meroon" is undefined *** WARNING -- Variable "reverse!" used in module "_meroon" is undefined *** WARNING -- Variable "sequence-find" used in module "_meroon" is undefined *** WARNING -- Variable "sequence-map" used in module "_meroon" is undefined *** WARNING -- Variable "show-already-unveiled-object" used in module "_meroon" is undefined *** WARNING -- Variable "show-field" used in module "_meroon" is undefined *** WARNING -- Variable "show-index" used in module "_meroon" is undefined *** WARNING -- Variable "show-list" used in module "_meroon" is undefined *** WARNING -- Variable "show-unveiled" used in module "_meroon" is undefined *** WARNING -- Variable "show-unveiled-list-content" used in module "_meroon" is undefined *** WARNING -- Variable "show-unveiled-vector-content" used in module "_meroon" is undefined *** WARNING -- Variable "show-vector" used in module "_meroon" is undefined *** WARNING -- Variable "simple-append-fields" used in module "_meroon" is undefined *** WARNING -- Variable "skip2next-keyword" used in module "_meroon" is undefined *** WARNING -- Variable "symbol->class" used in module "_meroon" is undefined *** WARNING -- Variable "symbol->generic" used in module "_meroon" is undefined *** WARNING -- Variable "symbol-concatenate" used in module "_meroon" is undefined *** WARNING -- Variable "vector-extend" used in module "_meroon" is undefined [ Meroon V3 Paques2001+1 $Revision: 1.2 $ ] "/home/lucier/programs/MeroonV3-2015Mar04/_meroon.o1"
(define-class Point (Object) (x y))
*** ERROR -- Unbound variable: check-and-process-class-definition
Meroon is written in Meroon (with a bootstrap step, initial classes and objects constructed by hand, etc.)
So it appears that the compiler included in the library onl those routines actively used to build Meroon.
If Gambit had a proper module system, perhaps the compiler could include all routines needed by the exported procedures and macros.
Now *that* would be cool.
Brad
Can you describe what you mean here, with a before - and - after code example?
2015-03-29 10:03 GMT+05:30 Bradley Lucier lucier@math.purdue.edu: ..
If Gambit had a proper module system, perhaps the compiler could include all routines needed by the exported procedures and macros.
Now *that* would be cool.
Brad