Exposing more values to GC by not making them toplevels
This commit is contained in:
parent
255489e0af
commit
26c7625c79
|
@ -40,6 +40,7 @@ Here's the idea:
|
||||||
|
|
||||||
(require racket/pretty
|
(require racket/pretty
|
||||||
racket/system
|
racket/system
|
||||||
|
"mpi.rkt"
|
||||||
"util.rkt"
|
"util.rkt"
|
||||||
"nodep.rkt"
|
"nodep.rkt"
|
||||||
"merge.rkt"
|
"merge.rkt"
|
||||||
|
@ -51,61 +52,62 @@ Here's the idea:
|
||||||
compiler/zo-marshal
|
compiler/zo-marshal
|
||||||
racket/set)
|
racket/set)
|
||||||
|
|
||||||
(define excluded-modules (make-parameter (set)))
|
(define (main file-to-batch)
|
||||||
(define file-to-batch
|
(define-values (base name dir?) (split-path file-to-batch))
|
||||||
(command-line #:program "batch"
|
(when (or (eq? base #f) dir?)
|
||||||
#:multi
|
(error 'batch "Cannot run on directory"))
|
||||||
[("-e" "--exclude-modules") mod
|
|
||||||
"Exclude a module from being batched"
|
|
||||||
(excluded-modules (set-add (excluded-modules) mod))]
|
|
||||||
#:args (filename) filename))
|
|
||||||
|
|
||||||
(define-values (base name dir?) (split-path file-to-batch))
|
;; Compile
|
||||||
(when (or (eq? base #f) dir?)
|
|
||||||
(error 'batch "Cannot run on directory"))
|
|
||||||
|
|
||||||
|
(log-info "Compiling module")
|
||||||
|
(void (system* (find-executable-path "raco") "make" file-to-batch))
|
||||||
|
|
||||||
;; Compile
|
(define merged-zo-path (path-add-suffix file-to-batch #"_merged.zo"))
|
||||||
|
|
||||||
(log-info "Compiling module")
|
;; Transformations
|
||||||
(void (system* (find-executable-path "raco") "make" file-to-batch))
|
(define path-cache (make-hash))
|
||||||
|
|
||||||
|
(log-info "Removing dependencies")
|
||||||
|
(define-values (batch-nodep top-lang-info top-self-modidx get-modvar-rewrite)
|
||||||
|
(parameterize ([MODULE-PATHS path-cache])
|
||||||
|
(nodep-file file-to-batch)))
|
||||||
|
|
||||||
(define merged-zo-path (path-add-suffix file-to-batch #"_merged.zo"))
|
(log-info "Merging modules")
|
||||||
|
(define batch-merge
|
||||||
|
(parameterize ([MODULE-PATHS path-cache])
|
||||||
|
(merge-compilation-top get-modvar-rewrite batch-nodep)))
|
||||||
|
|
||||||
;; Transformations
|
; Not doing this for now
|
||||||
(log-info "Removing dependencies")
|
;(log-info "GC-ing top-levels")
|
||||||
(define-values (batch-nodep top-lang-info top-self-modidx get-modvar-rewrite)
|
(define batch-gcd
|
||||||
(nodep-file file-to-batch (excluded-modules)))
|
batch-merge
|
||||||
|
#;(gc-toplevels batch-merge))
|
||||||
|
|
||||||
(log-info "Merging modules")
|
(log-info "Alpha-varying top-levels")
|
||||||
(define batch-merge
|
(define batch-alpha
|
||||||
(merge-compilation-top get-modvar-rewrite batch-nodep))
|
(alpha-vary-ctop batch-gcd))
|
||||||
|
|
||||||
; Not doing this for now
|
(log-info "Replacing self-modidx")
|
||||||
;(log-info "GC-ing top-levels")
|
(define batch-replace-modidx
|
||||||
(define batch-gcd
|
(replace-modidx batch-alpha top-self-modidx))
|
||||||
batch-merge
|
|
||||||
#;(gc-toplevels batch-merge))
|
|
||||||
|
|
||||||
(log-info "Alpha-varying top-levels")
|
(define batch-modname
|
||||||
(define batch-alpha
|
(string->symbol (regexp-replace #rx"\\.zo$" (path->string merged-zo-path) "")))
|
||||||
(alpha-vary-ctop batch-gcd))
|
(log-info (format "Modularizing into ~a" batch-modname))
|
||||||
|
(define batch-mod
|
||||||
|
(wrap-in-kernel-module batch-modname batch-modname top-lang-info top-self-modidx batch-replace-modidx))
|
||||||
|
|
||||||
(log-info "Replacing self-modidx")
|
(log-info "Writing merged zo")
|
||||||
(define batch-replace-modidx
|
(void
|
||||||
(replace-modidx batch-alpha top-self-modidx))
|
(with-output-to-file
|
||||||
|
merged-zo-path
|
||||||
|
(lambda ()
|
||||||
|
(zo-marshal-to batch-mod (current-output-port)))
|
||||||
|
#:exists 'replace)))
|
||||||
|
|
||||||
(define batch-modname
|
(command-line #:program "batch"
|
||||||
(string->symbol (regexp-replace #rx"\\.zo$" (path->string merged-zo-path) "")))
|
#:multi
|
||||||
(log-info (format "Modularizing into ~a" batch-modname))
|
[("-e" "--exclude-modules") mod
|
||||||
(define batch-mod
|
"Exclude a module from being batched"
|
||||||
(wrap-in-kernel-module batch-modname batch-modname top-lang-info top-self-modidx batch-replace-modidx))
|
(current-excluded-modules (set-add (current-excluded-modules) mod))]
|
||||||
|
#:args (filename) (main filename))
|
||||||
(log-info "Writing merged zo")
|
|
||||||
(void
|
|
||||||
(with-output-to-file
|
|
||||||
merged-zo-path
|
|
||||||
(lambda ()
|
|
||||||
(zo-marshal-to batch-mod (current-output-port)))
|
|
||||||
#:exists 'replace))
|
|
|
@ -7,7 +7,6 @@
|
||||||
s
|
s
|
||||||
(module-path-index-join `(quote ,s) #f)))
|
(module-path-index-join `(quote ,s) #f)))
|
||||||
|
|
||||||
|
|
||||||
(define (wrap-in-kernel-module name srcname lang-info self-modidx top)
|
(define (wrap-in-kernel-module name srcname lang-info self-modidx top)
|
||||||
(match top
|
(match top
|
||||||
[(struct compilation-top (max-let-depth prefix form))
|
[(struct compilation-top (max-let-depth prefix form))
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#lang scheme
|
#lang racket
|
||||||
(require syntax/modresolve)
|
(require syntax/modresolve)
|
||||||
|
|
||||||
(define current-module-path (make-parameter #f))
|
(define current-module-path (make-parameter #f))
|
||||||
|
@ -9,10 +9,10 @@
|
||||||
[else
|
[else
|
||||||
(mpi->path! modidx)]))
|
(mpi->path! modidx)]))
|
||||||
|
|
||||||
(define MODULE-PATHS (make-hash))
|
(define MODULE-PATHS (make-parameter #f))
|
||||||
(define (mpi->path! mpi)
|
(define (mpi->path! mpi)
|
||||||
(hash-ref!
|
(hash-ref!
|
||||||
MODULE-PATHS mpi
|
(MODULE-PATHS) mpi
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(define _pth
|
(define _pth
|
||||||
(resolve-module-path-index mpi (current-module-path)))
|
(resolve-module-path-index mpi (current-module-path)))
|
||||||
|
@ -20,11 +20,12 @@
|
||||||
(simplify-path _pth #t)
|
(simplify-path _pth #t)
|
||||||
_pth))))
|
_pth))))
|
||||||
(define (mpi->path* mpi)
|
(define (mpi->path* mpi)
|
||||||
(hash-ref MODULE-PATHS mpi
|
(hash-ref (MODULE-PATHS) mpi
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(error 'mpi->path* "Cannot locate cache of path for ~S" mpi))))
|
(error 'mpi->path* "Cannot locate cache of path for ~S" mpi))))
|
||||||
|
|
||||||
(provide/contract
|
(provide/contract
|
||||||
|
[MODULE-PATHS (parameter/c (or/c false/c hash?))]
|
||||||
[current-module-path (parameter/c path-string?)]
|
[current-module-path (parameter/c path-string?)]
|
||||||
[mpi->path! (module-path-index? . -> . (or/c symbol? path?))]
|
[mpi->path! (module-path-index? . -> . (or/c symbol? path?))]
|
||||||
[mpi->path* (module-path-index? . -> . (or/c symbol? path?))])
|
[mpi->path* (module-path-index? . -> . (or/c symbol? path?))])
|
|
@ -4,13 +4,13 @@
|
||||||
"mpi.rkt"
|
"mpi.rkt"
|
||||||
racket/set)
|
racket/set)
|
||||||
|
|
||||||
(define excluded-modules (make-parameter null))
|
(define current-excluded-modules (make-parameter (set)))
|
||||||
|
|
||||||
(define ZOS (make-parameter #f))
|
(define ZOS (make-parameter #f))
|
||||||
(define MODULE-IDX-MAP (make-parameter #f))
|
(define MODULE-IDX-MAP (make-parameter #f))
|
||||||
(define PHASE*MODULE-CACHE (make-parameter #f))
|
(define PHASE*MODULE-CACHE (make-parameter #f))
|
||||||
|
|
||||||
(define (nodep-file file-to-batch excluded)
|
(define (nodep-file file-to-batch)
|
||||||
(define idx-map (make-hash))
|
(define idx-map (make-hash))
|
||||||
(parameterize ([ZOS (make-hash)]
|
(parameterize ([ZOS (make-hash)]
|
||||||
[MODULE-IDX-MAP idx-map]
|
[MODULE-IDX-MAP idx-map]
|
||||||
|
@ -20,7 +20,6 @@
|
||||||
(hash-ref idx-map pth
|
(hash-ref idx-map pth
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(error 'get-modvar-rewrite "Cannot locate modvar rewrite for ~S" pth))))
|
(error 'get-modvar-rewrite "Cannot locate modvar rewrite for ~S" pth))))
|
||||||
(excluded-modules excluded)
|
|
||||||
(match (get-nodep-module-code/path file-to-batch 0)
|
(match (get-nodep-module-code/path file-to-batch 0)
|
||||||
[(struct @phase (_ (struct module-code (modvar-rewrite lang-info ctop))))
|
[(struct @phase (_ (struct module-code (modvar-rewrite lang-info ctop))))
|
||||||
(values ctop lang-info (modvar-rewrite-modidx modvar-rewrite) get-modvar-rewrite)])))
|
(values ctop lang-info (modvar-rewrite-modidx modvar-rewrite) get-modvar-rewrite)])))
|
||||||
|
@ -31,7 +30,7 @@
|
||||||
(call-with-input-file pth zo-parse))))
|
(call-with-input-file pth zo-parse))))
|
||||||
|
|
||||||
(define (excluded? pth)
|
(define (excluded? pth)
|
||||||
(set-member? (excluded-modules) (path->string pth)))
|
(set-member? (current-excluded-modules) (path->string pth)))
|
||||||
|
|
||||||
(define (get-nodep-module-code/index mpi phase)
|
(define (get-nodep-module-code/index mpi phase)
|
||||||
(define pth (mpi->path! mpi))
|
(define pth (mpi->path! mpi))
|
||||||
|
@ -185,5 +184,6 @@
|
||||||
([modidx module-path-index?]
|
([modidx module-path-index?]
|
||||||
[provide->toplevel (symbol? exact-nonnegative-integer? . -> . exact-nonnegative-integer?)])]
|
[provide->toplevel (symbol? exact-nonnegative-integer? . -> . exact-nonnegative-integer?)])]
|
||||||
[get-modvar-rewrite/c contract?]
|
[get-modvar-rewrite/c contract?]
|
||||||
[nodep-file (-> path-string? set?
|
[current-excluded-modules (parameter/c set?)]
|
||||||
|
[nodep-file (-> path-string?
|
||||||
(values compilation-top? lang-info/c module-path-index? get-modvar-rewrite/c))])
|
(values compilation-top? lang-info/c module-path-index? get-modvar-rewrite/c))])
|
Loading…
Reference in New Issue
Block a user