>From d7ef79a885d7fc02b2a893e3e000a30db1cac899 Mon Sep 17 00:00:00 2001 From: Evan Hanson Date: Mon, 18 Oct 2021 17:00:20 +1300 Subject: [PATCH 1/3] Simplify library requirement processing This is a "clarity" patch that simplifies the handling of `##core#require` forms and tries to improve the naming of a couple of related identifiers to keep things internally consistent. First, rename the `core-unit?` procedure to `core-library?`, since it's used to check all library IDs encountered during compilation and not just units. Then, use that procedure to check whether a library should be added to the list of `required-libraries` directly within core.scm, rather than returning multiple values from `##sys#process-require`. This separates the logic for determining whether something is built-in from the compiler's handling of `##core#require` forms a little more cleanly. If something is a `core-library?` it should _not_ be added to the list, else it should, the result being that `required-libraries` contains only things that needs to be treated as an extension (and thus linked from the eggs repository), and the interpreter doesn't have to care about any of these decisions at all. Then, because what we're building is really a list of _extensions_ that need to be linked, rename `required-libraries` to `required-extensions`. And finally, drop the list of `builtin-features`, which do not actually need any special treatment from a library-loading point of view. --- batch-driver.scm | 4 ++-- core.scm | 23 ++++++++++------------- eval.scm | 45 +++++++++++++++++---------------------------- 3 files changed, 29 insertions(+), 43 deletions(-) diff --git a/batch-driver.scm b/batch-driver.scm index 6f1d5f56..5ca2eedc 100644 --- a/batch-driver.scm +++ b/batch-driver.scm @@ -676,7 +676,7 @@ (initialize-analysis-database) ;; collect requirements and load inline files - (let ((extensions required-libraries)) + (let ((extensions required-extensions)) (when enable-inline-files (for-each (lambda (id) @@ -851,7 +851,7 @@ ;; generate link file (when emit-link-file - (let ((exts required-libraries)) + (let ((exts required-extensions)) (dribble "generating link file `~a' ..." emit-link-file) (with-output-to-file emit-link-file (cut pp exts)))) diff --git a/core.scm b/core.scm index 0b980913..e35e40ca 100644 --- a/core.scm +++ b/core.scm @@ -315,7 +315,7 @@ extended-bindings standard-bindings ;; Non-booleans set and read by the (batch) driver - required-libraries linked-libraries used-libraries + required-extensions linked-libraries used-libraries ;; non-booleans set by the (batch) driver, and read by the (c) backend target-heap-size target-stack-size unit-name used-units @@ -450,7 +450,7 @@ (define callback-names '()) (define toplevel-scope #t) (define toplevel-lambda-id #f) -(define required-libraries '()) +(define required-extensions '()) (define linked-libraries '()) (define used-libraries '()) @@ -738,17 +738,14 @@ ((##core#require) (let ((lib (cadr x)) (mod (and (pair? (cddr x)) (caddr x)))) - (let-values (((reqform builtin) - (##sys#process-require - lib mod - (if (or (memq lib linked-libraries) - static-extensions) - 'static - 'dynamic)))) - (unless builtin - (set! required-libraries - (lset-adjoin/eq? required-libraries lib))) - (walk reqform e dest ldest h ln #f)))) + (unless (chicken.load#core-library? lib) + (set! required-extensions (lset-adjoin/eq? required-extensions lib))) + (walk (##sys#process-require + lib mod + (if (or (memq lib linked-libraries) static-extensions) + 'static + 'dynamic)) + e dest ldest h ln #f))) ((##core#let) (let* ((bindings (cadr x)) diff --git a/eval.scm b/eval.scm index 30c651cd..0e756394 100644 --- a/eval.scm +++ b/eval.scm @@ -596,9 +596,8 @@ [(##core#require) (let ((lib (cadr x)) - (mod (and (pair? (cddr x)) (caddr x)))) - (let-values (((reqform _) (##sys#process-require lib mod #f))) - (compile reqform e #f tf cntr #f)))] + (mod (and (pair? (cddr x)) (caddr x)))) + (compile (##sys#process-require lib mod #f) e #f tf cntr #f))] [(##core#elaborationtimeonly ##core#elaborationtimetoo) ; <- Note this! (##sys#eval/meta (cadr x)) @@ -904,6 +903,7 @@ ;;; Core unit information +;; this maps built-in library names to require forms when the mapping isn't 1:1 (define-constant core-unit-requirements '((chicken.foreign . (##core#require-for-syntax chicken-ffi-syntax)) @@ -912,6 +912,9 @@ (##core#require-for-syntax chicken-syntax) (##core#require library))))) +;; this list contains built-in units that are provided by libchicken +;; and should not be treated as separate extension libraries during +;; linking (they are omitted from types/inline/link files etc.) (define-constant core-units '(chicken-syntax chicken-ffi-syntax continuation data-structures debugger-client eval eval-modules expand extras file internal @@ -934,17 +937,10 @@ (define ##sys#load-dynamic-extension default-load-library-extension) -(define (chicken.load#core-unit? id) ; used by batch-driver.scm +(define (chicken.load#core-library? id) ; used by core.scm (or (memq id core-units) (assq id core-unit-requirements))) -; these are actually in unit extras, but that is used by default - -(define-constant builtin-features - '(srfi-30 srfi-46 srfi-61 srfi-62 ; runtime - srfi-0 srfi-2 srfi-8 srfi-9 srfi-11 srfi-15 srfi-16 ; syntax - srfi-17 srfi-26 srfi-31 srfi-55 srfi-87 srfi-88)) ; syntax cont - (define default-dynamic-load-libraries (case (software-version) ((cygwin) cygwin-default-dynamic-load-libraries) @@ -1251,26 +1247,19 @@ (define (##sys#process-require lib mod compile-mode) (let ((mod (or (eq? lib mod) mod))) (cond - ((assq lib core-unit-requirements) => - (lambda (a) (values (cdr a) #t))) - ((memq lib builtin-features) - (values '(##core#undefined) #t)) + ((assq lib core-unit-requirements) => cdr) ((memq lib core-units) - (values - (if compile-mode - `(##core#callunit ,lib) - `(chicken.load#load-unit (##core#quote ,lib) - (##core#quote #f) - (##core#quote #f))) - #t)) + (if compile-mode + `(##core#callunit ,lib) + `(chicken.load#load-unit (##core#quote ,lib) + (##core#quote #f) + (##core#quote #f)))) ((eq? compile-mode 'static) - (values `(##core#callunit ,lib) #f)) + `(##core#callunit ,lib)) (else - (values - `(chicken.load#load-extension (##core#quote ,lib) - (##core#quote ,mod) - (##core#quote #f)) - #f))))) + `(chicken.load#load-extension (##core#quote ,lib) + (##core#quote ,mod) + (##core#quote #f)))))) ;;; Find included file: -- 2.31.1