add expand-omit-library-invocations

original commit: 35dbfdaa9ea3832f2ded108b7edcaead61922007
This commit is contained in:
Matthew Flatt 2018-01-04 17:53:27 -07:00
parent cf87f8c4f6
commit 3526ab71fa
5 changed files with 55 additions and 3 deletions

4
LOG
View File

@ -774,6 +774,6 @@
5_3.ss, 5_3.ms, fl.ms, root-experr*, patch*
- fix bug in date->time-utc caused by incorrect use of difftime in Windows
stats.c, date.ms, release_notes.stex
- add current-generate-id, which can be useful for avoiding library
recompilation
- add current-generate-id and expand-omit-library-invocations, which can be
useful for avoiding library recompilation and redundant invocation checks
syntax.ss, record.ss, primdata.ss, misc.ms, system.stex

View File

@ -2228,6 +2228,27 @@ Configure \scheme{make-x-generator} this way only in situations where
the potential for unspecified failure is more tolerable than
recompilation.
%----------------------------------------------------------------------------
\entryheader
\formdef{expand-omit-library-invocations}{\categorythreadparameter}{expand-omit-library-invocations}
\listlibraries
\endentryheader
\noindent
This boolean-valued parameter determines whether library uses are
recorded in macro expansion. Normally, when an expression expands to a
reference to a library-defined identifier, the expansion is prefixed
with a check to ensure that the exporting library is defined and
invoked. If \scheme{expand-omit-library-invocations} is set to true,
the prefix is omitted.
Setting \scheme{expand-omit-library-invocations} to true makes sense
only when evaluating many small expressions in a context where all
referenced libraries are known to be present and already invoked, and
only when it's worth saving the small overhead of representing and
running the check.
\section{Source Directories and Files\label{SECTSYSTEMSOURCE}}
%----------------------------------------------------------------------------

View File

@ -5041,3 +5041,24 @@
(def))))
(equal? 3 (return-x)))
)
(mat expand-omit-library-invocations
(not (expand-omit-library-invocations))
(begin
(library (define-m-as-one) (export m) (import (chezscheme)) (define m 1))
(define (find-define-m-as-one s)
(or (eq? s 'define-m-as-one)
(and (pair? s)
(or (find-define-m-as-one (car s))
(find-define-m-as-one (cdr s))))))
#t)
(find-define-m-as-one (expand '(let () (import (define-m-as-one)) m)))
(begin
(expand-omit-library-invocations 'yes)
(eq? #t (expand-omit-library-invocations)))
(not (find-define-m-as-one (expand '(let () (import (define-m-as-one)) m))))
(begin
(expand-omit-library-invocations #f)
(not (expand-omit-library-invocations)))
(find-define-m-as-one (expand '(let () (import (define-m-as-one)) m)))
)

View File

@ -947,6 +947,7 @@
(enable-cross-library-optimization [sig [() -> (boolean)] [(ptr) -> (void)]] [flags unrestricted])
(enable-object-counts [sig [() -> (boolean)] [(ptr) -> (void)]] [flags])
(eval-syntax-expanders-when [sig [() -> (list)] [(sub-list) -> (void)]] [flags])
(expand-omit-library-invocations [sig [() -> (boolean)] [(ptr) -> (void)]] [flags])
(expand-output [sig [() -> (maybe-textual-output-port)] [(maybe-textual-output-port) -> (void)]] [flags])
(expand/optimize-output [sig [() -> (maybe-textual-output-port)] [(maybe-textual-output-port) -> (void)]] [flags])
(exit-handler [sig [() -> (procedure)] [(procedure) -> (void)]] [flags])

View File

@ -3420,7 +3420,12 @@
(define residualize-invoke-requirements
(case-lambda
[(code) (residualize-invoke-requirements '() (require-visit) (require-invoke) code)]
[(code) (residualize-invoke-requirements '()
(require-visit)
(if (expand-omit-library-invocations)
'()
(require-invoke))
code)]
[(import* visit* invoke* code)
(build-sequence no-source
`(,@(map (build-requirement '$import-library) import*)
@ -4961,6 +4966,10 @@
(lambda ()
(list-loaded-libraries)))
(set! expand-omit-library-invocations
($make-thread-parameter #f
(lambda (v) (and v #t))))
(let ()
(define maybe-get-lib
(lambda (who libref)