diff --git a/LOG b/LOG index 4a10702c24..a7065a26c7 100644 --- a/LOG +++ b/LOG @@ -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 diff --git a/csug/system.stex b/csug/system.stex index 1e18a9c907..a19d6287b5 100644 --- a/csug/system.stex +++ b/csug/system.stex @@ -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}} %---------------------------------------------------------------------------- diff --git a/mats/misc.ms b/mats/misc.ms index 587db49166..326d73f858 100644 --- a/mats/misc.ms +++ b/mats/misc.ms @@ -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))) + ) diff --git a/s/primdata.ss b/s/primdata.ss index 3ba4d628c2..c8383a90d6 100644 --- a/s/primdata.ss +++ b/s/primdata.ss @@ -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]) diff --git a/s/syntax.ss b/s/syntax.ss index c5bd0b8bae..c39699e831 100644 --- a/s/syntax.ss +++ b/s/syntax.ss @@ -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)