>From c671683ede94443a631e6b1f86e444aa0156c7e9 Mon Sep 17 00:00:00 2001 From: Evan Hanson Date: Mon, 18 Oct 2021 17:25:54 +1300 Subject: [PATCH 2/3] Make "primitive modules" avoid triggering any code loading This changes the way code loading is done, or rather _not_ done, for so-called "primitive modules". Previously, these modules would be given a library name that matches their module name, which would be passed to the compiler, which would process a `##core#require` form only to decide decide there's nothing to do (usually resulting in a `##core#undefined` node). Really, this is useless work, since there is no library code to load for any of these modules, and we know that up front. Instead, we should just set the `library` field for these modules to false, to indicate that they provide only syntax and don't need to load any code. This is what's done by the change to `##sys#register-primitive-module`. The two modules that are currently registered as "primitive modules" but _do_ need to load code are chicken.foreign and chicken.condition, which are handled as special cases in eval.scm. To keep the current behaviour, we change these to use `##sys#register-core-module`, and explicitly set their `library` field to the current value, i.e. the module name. Note the changes in the patch do not only affect the modules defined within modules.scm but also the chicken.csi module, for which the `##sys#register-primitive-module` procedure is used in its import file. As such, this fixes the problem of chicken.csi appearing in link files because, as a primitive module, it will not create a `##core#require` node and so will not end up in the list of `required-extensions`. Also, drop the module alias for the srfi-88 library, which is already defined (and more correctly) at modules.scm:1180. --- chicken.condition.import.scm | 2 +- chicken.foreign.import.scm | 3 ++- modules.scm | 18 +++++++++--------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/chicken.condition.import.scm b/chicken.condition.import.scm index 200d0141..0d72a84b 100644 --- a/chicken.condition.import.scm +++ b/chicken.condition.import.scm @@ -25,7 +25,7 @@ (##sys#register-core-module 'chicken.condition - 'library + 'chicken.condition ; mapped to distinct run/compile-time requirements in eval unit '((abort . chicken.condition#abort) (signal . chicken.condition#signal) (current-exception-handler . chicken.condition#current-exception-handler) diff --git a/chicken.foreign.import.scm b/chicken.foreign.import.scm index 03c7c535..d7ede987 100644 --- a/chicken.foreign.import.scm +++ b/chicken.foreign.import.scm @@ -24,7 +24,8 @@ ; POSSIBILITY OF SUCH DAMAGE. -(##sys#register-primitive-module +(##sys#register-core-module 'chicken.foreign + 'chicken.foreign ; mapped to distinct run/compile-time requirements in eval unit '() ##sys#chicken-ffi-macro-environment) diff --git a/modules.scm b/modules.scm index cbe48fe7..c89b0af6 100644 --- a/modules.scm +++ b/modules.scm @@ -442,9 +442,10 @@ (set! ##sys#module-table (cons (cons name mod) ##sys#module-table)) mod)) -;; same as register-core-module, but uses module's name as its library +;; same as register-core-module (above) but does not load any code, +;; used to register modules that provide only syntax (define (##sys#register-primitive-module name vexports #!optional (sexports '())) - (##sys#register-core-module name name vexports sexports)) + (##sys#register-core-module name #f vexports sexports)) (define (find-export sym mod indirect) (let ((exports (module-export-list mod))) @@ -1095,19 +1096,18 @@ (##sys#register-core-module 'r5rs-null #f '() r4rs-syntax)) (##sys#register-module-alias 'r5rs 'scheme) -(##sys#register-module-alias 'srfi-88 'chicken.keyword) (define-inline (se-subset names env) (map (cut assq <> env) names)) ;; Hack for library.scm to use macros from modules it defines itself. -(##sys#register-core-module - 'chicken.internal.syntax #f '() (##sys#macro-environment)) +(##sys#register-primitive-module + 'chicken.internal.syntax '() (##sys#macro-environment)) -(##sys#register-core-module - 'chicken.module #f '() ##sys#chicken.module-macro-environment) +(##sys#register-primitive-module + 'chicken.module '() ##sys#chicken.module-macro-environment) -(##sys#register-core-module - 'chicken.type #f '() ##sys#chicken.type-macro-environment) +(##sys#register-primitive-module + 'chicken.type '() ##sys#chicken.type-macro-environment) (##sys#register-primitive-module 'srfi-0 '() (se-subset '(cond-expand) ##sys#default-macro-environment)) -- 2.31.1