From cf4dee6e0fd14de3ff83aa55e495622ddf8c8eb0 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Thu, 13 Mar 2008 03:46:25 -0500 Subject: [PATCH] Tree-shaker now computes which globals it needs to strip, not which ones it needs to keep --- extra/tools/deploy/backend/backend.factor | 48 +++--- extra/tools/deploy/config/config.factor | 2 +- extra/tools/deploy/deploy-tests.factor | 24 ++- extra/tools/deploy/shaker/shaker.factor | 190 ++++++++++++++-------- extra/tools/deploy/test/1/1.factor | 6 + extra/tools/deploy/test/1/deploy.factor | 14 ++ extra/tools/deploy/test/2/2.factor | 6 + extra/tools/deploy/test/2/deploy.factor | 14 ++ extra/tools/deploy/test/3/3.factor | 8 + extra/tools/deploy/test/3/deploy.factor | 14 ++ 10 files changed, 237 insertions(+), 89 deletions(-) create mode 100755 extra/tools/deploy/test/1/1.factor create mode 100755 extra/tools/deploy/test/1/deploy.factor create mode 100755 extra/tools/deploy/test/2/2.factor create mode 100755 extra/tools/deploy/test/2/deploy.factor create mode 100755 extra/tools/deploy/test/3/3.factor create mode 100755 extra/tools/deploy/test/3/deploy.factor diff --git a/extra/tools/deploy/backend/backend.factor b/extra/tools/deploy/backend/backend.factor index 301ffa3378..15dc32115e 100755 --- a/extra/tools/deploy/backend/backend.factor +++ b/extra/tools/deploy/backend/backend.factor @@ -34,31 +34,33 @@ IN: tools.deploy.backend : ?, [ , ] [ drop ] if ; -: bootstrap-profile ( config -- profile ) +: bootstrap-profile ( -- profile ) [ - [ - "math" deploy-math? get ?, - "compiler" deploy-compiler? get ?, - "ui" deploy-ui? get ?, - "io" native-io? ?, - ] { } make - ] bind ; + "math" deploy-math? get ?, + "compiler" deploy-compiler? get ?, + "ui" deploy-ui? get ?, + "io" native-io? ?, + ] { } make ; -: staging-image-name ( profile -- name ) - "staging." swap bootstrap-profile "-" join ".image" 3append ; +: staging-image-name ( -- name ) + "staging." + bootstrap-profile strip-word-names? [ "strip" add ] when + "-" join ".image" 3append ; : staging-command-line ( config -- flags ) [ - "-i=" my-boot-image-name append , + [ + "-i=" my-boot-image-name append , - "-output-image=" over staging-image-name append , + "-output-image=" staging-image-name append , - "-include=" swap bootstrap-profile " " join append , + "-include=" bootstrap-profile " " join append , - "-no-stack-traces" , + strip-word-names? [ "-no-stack-traces" , ] when - "-no-user-init" , - ] { } make ; + "-no-user-init" , + ] { } make + ] bind ; : run-factor ( vm flags -- ) swap add* dup . run-with-output ; inline @@ -68,16 +70,18 @@ IN: tools.deploy.backend : deploy-command-line ( image vocab config -- flags ) [ - "-i=" swap staging-image-name append , + [ + "-i=" staging-image-name append , - "-run=tools.deploy.shaker" , + "-run=tools.deploy.shaker" , - "-deploy-vocab=" swap append , + "-deploy-vocab=" swap append , - "-output-image=" swap append , + "-output-image=" swap append , - "-no-stack-traces" , - ] { } make ; + strip-word-names? [ "-no-stack-traces" , ] when + ] { } make + ] bind ; : make-deploy-image ( vm image vocab config -- ) make-boot-image diff --git a/extra/tools/deploy/config/config.factor b/extra/tools/deploy/config/config.factor index 64f863b730..78f1d487de 100755 --- a/extra/tools/deploy/config/config.factor +++ b/extra/tools/deploy/config/config.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: vocabs.loader io.files io kernel sequences assocs splitting parser prettyprint namespaces math vocabs -hashtables tools.browser ; +hashtables tools.vocabs ; IN: tools.deploy.config SYMBOL: deploy-name diff --git a/extra/tools/deploy/deploy-tests.factor b/extra/tools/deploy/deploy-tests.factor index d473d8f640..0f770f7b60 100755 --- a/extra/tools/deploy/deploy-tests.factor +++ b/extra/tools/deploy/deploy-tests.factor @@ -5,7 +5,7 @@ tools.deploy.backend math ; : shake-and-bake "." resource-path [ vm - "hello.image" temp-file + "test.image" temp-file rot dup deploy-config make-deploy-image ] with-directory ; @@ -15,8 +15,30 @@ tools.deploy.backend math ; "hello.image" temp-file file-length 500000 <= ] unit-test +[ ] [ "sudoku" shake-and-bake ] unit-test + +[ t ] [ + "hello.image" temp-file file-length 1500000 <= +] unit-test + [ ] [ "hello-ui" shake-and-bake ] unit-test [ t ] [ "hello.image" temp-file file-length 2000000 <= ] unit-test + +[ ] [ "bunny" shake-and-bake ] unit-test + +[ t ] [ + "hello.image" temp-file file-length 3000000 <= +] unit-test + +[ ] [ + "tools.deploy.test.1" shake-and-bake + vm "-i=" "test.image" temp-file append try-process +] unit-test + +[ ] [ + "tools.deploy.test.2" shake-and-bake + vm "-i=" "test.image" temp-file append try-process +] unit-test diff --git a/extra/tools/deploy/shaker/shaker.factor b/extra/tools/deploy/shaker/shaker.factor index 0ddc2d5707..bddf3d76c9 100755 --- a/extra/tools/deploy/shaker/shaker.factor +++ b/extra/tools/deploy/shaker/shaker.factor @@ -1,11 +1,29 @@ -! Copyright (C) 2007 Slava Pestov. +! Copyright (C) 2007, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: namespaces continuations.private kernel.private init -assocs kernel vocabs words sequences memory io system arrays -continuations math definitions mirrors splitting parser classes -inspector layouts vocabs.loader prettyprint.config prettyprint -debugger io.streams.c io.streams.duplex io.files io.backend -quotations words.private tools.deploy.config compiler.units ; +USING: qualified io.streams.c init fry namespaces assocs kernel +parser tools.deploy.config vocabs sequences words words.private +memory kernel.private continuations io prettyprint +vocabs.loader debugger system strings ; +QUALIFIED: bootstrap.stage2 +QUALIFIED: classes +QUALIFIED: compiler.errors.private +QUALIFIED: compiler.units +QUALIFIED: continuations +QUALIFIED: definitions +QUALIFIED: init +QUALIFIED: inspector +QUALIFIED: io.backend +QUALIFIED: io.nonblocking +QUALIFIED: io.thread +QUALIFIED: layouts +QUALIFIED: libc.private +QUALIFIED: libc.private +QUALIFIED: listener +QUALIFIED: prettyprint.config +QUALIFIED: random.private +QUALIFIED: source-files +QUALIFIED: threads +QUALIFIED: vocabs IN: tools.deploy.shaker : strip-init-hooks ( -- ) @@ -43,9 +61,6 @@ IN: tools.deploy.shaker run-file ] when ; -: strip-assoc ( retained-keys assoc -- newassoc ) - swap [ nip member? ] curry assoc-subset ; - : strip-word-names ( words -- ) "Stripping word names" show [ f over set-word-name f swap set-word-vocabulary ] each ; @@ -57,8 +72,11 @@ IN: tools.deploy.shaker : strip-word-props ( retain-props words -- ) "Stripping word properties" show [ - [ word-props strip-assoc f assoc-like ] keep - set-word-props + [ + word-props swap + '[ , nip member? ] assoc-subset + f assoc-like + ] keep set-word-props ] with each ; : retained-props ( -- seq ) @@ -81,10 +99,101 @@ IN: tools.deploy.shaker strip-word-names? [ dup strip-word-names ] when 2drop ; -: strip-environment ( retain-globals -- ) +: strip-recompile-hook ( -- ) + [ [ f ] { } map>assoc ] + compiler.units:recompile-hook + set-global ; + +: strip-vocab-globals ( except names -- words ) + [ child-vocabs [ words ] map concat ] map concat seq-diff ; + +: stripped-globals ( -- seq ) + [ + random.private:mt , + + { + bootstrap.stage2:bootstrap-time + continuations:error + continuations:error-continuation + continuations:error-thread + continuations:restarts + error-hook + init:init-hooks + inspector:inspector-hook + io.thread:io-thread + libc.private:mallocs + source-files:source-files + stderr + stdio + } % + + deploy-threads? [ + threads:initial-thread , + ] unless + + strip-io? [ io.backend:io-backend , ] when + + { io.backend:io-backend io.nonblocking:default-buffer-size } + { "alarms" "io" "tools" } strip-vocab-globals % + + strip-dictionary? [ + { } { "cpu" } strip-vocab-globals % + + { + vocabs:dictionary + lexer-factory + vocabs:load-vocab-hook + layouts:num-tags + layouts:num-types + layouts:tag-mask + layouts:tag-numbers + layouts:type-numbers + classes:typemap + vocab-roots + definitions:crossref + compiled-crossref + interactive-vocabs + word + compiler.units:recompile-hook + listener:listener-hook + lexer-factory + classes:update-map + classes:classr word-vocabulary r> member? ] curry - subset % - ] when - ] { } make dup . ; - -: strip-recompile-hook ( -- ) - [ [ f ] { } map>assoc ] recompile-hook set-global ; - : strip ( -- ) strip-libc strip-cocoa @@ -165,7 +225,7 @@ SYMBOL: deploy-vocab strip-init-hooks deploy-vocab get vocab-main set-boot-quot* retained-props >r - retained-globals strip-environment + stripped-globals strip-globals r> strip-words ; : (deploy) ( final-image vocab config -- ) diff --git a/extra/tools/deploy/test/1/1.factor b/extra/tools/deploy/test/1/1.factor new file mode 100755 index 0000000000..0bf8b10d0c --- /dev/null +++ b/extra/tools/deploy/test/1/1.factor @@ -0,0 +1,6 @@ +IN: tools.deploy.test.1 +USING: threads ; + +: deploy-test-1 1000 sleep ; + +MAIN: deploy-test-1 diff --git a/extra/tools/deploy/test/1/deploy.factor b/extra/tools/deploy/test/1/deploy.factor new file mode 100755 index 0000000000..f06bcbc0f0 --- /dev/null +++ b/extra/tools/deploy/test/1/deploy.factor @@ -0,0 +1,14 @@ +USING: tools.deploy.config ; +H{ + { deploy-c-types? f } + { deploy-io 2 } + { deploy-reflection 1 } + { deploy-threads? t } + { deploy-word-props? f } + { deploy-word-defs? f } + { deploy-name "tools.deploy.test.1" } + { deploy-math? t } + { deploy-compiler? t } + { "stop-after-last-window?" t } + { deploy-ui? f } +} diff --git a/extra/tools/deploy/test/2/2.factor b/extra/tools/deploy/test/2/2.factor new file mode 100755 index 0000000000..e029e3050a --- /dev/null +++ b/extra/tools/deploy/test/2/2.factor @@ -0,0 +1,6 @@ +IN: tools.deploy.test.2 +USING: calendar calendar.format ; + +: deploy-test-2 now (timestamp>string) ; + +MAIN: deploy-test-2 diff --git a/extra/tools/deploy/test/2/deploy.factor b/extra/tools/deploy/test/2/deploy.factor new file mode 100755 index 0000000000..bd087d65bf --- /dev/null +++ b/extra/tools/deploy/test/2/deploy.factor @@ -0,0 +1,14 @@ +USING: tools.deploy.config ; +H{ + { deploy-c-types? f } + { deploy-io 2 } + { deploy-reflection 1 } + { deploy-threads? t } + { deploy-word-props? f } + { deploy-word-defs? f } + { deploy-name "tools.deploy.test.2" } + { deploy-math? t } + { deploy-compiler? t } + { "stop-after-last-window?" t } + { deploy-ui? f } +} diff --git a/extra/tools/deploy/test/3/3.factor b/extra/tools/deploy/test/3/3.factor new file mode 100755 index 0000000000..443e82f7d9 --- /dev/null +++ b/extra/tools/deploy/test/3/3.factor @@ -0,0 +1,8 @@ +IN: tools.deploy.test.3 +USING: io.encodings.ascii io.files kernel ; + +: deploy-test-3 + "resource:extra/tools/deploy/test/3/3.factor" + ?resource-path ascii file-contents drop ; + +MAIN: deploy-test-3 diff --git a/extra/tools/deploy/test/3/deploy.factor b/extra/tools/deploy/test/3/deploy.factor new file mode 100755 index 0000000000..b8b8bf4aa2 --- /dev/null +++ b/extra/tools/deploy/test/3/deploy.factor @@ -0,0 +1,14 @@ +USING: tools.deploy.config ; +H{ + { deploy-math? t } + { deploy-reflection 1 } + { deploy-name "tools.deploy.test.3" } + { deploy-threads? t } + { deploy-word-props? f } + { "stop-after-last-window?" t } + { deploy-ui? f } + { deploy-io 3 } + { deploy-compiler? t } + { deploy-word-defs? f } + { deploy-c-types? f } +}