summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2024-04-13 17:58:39 +0200
committerLudovic Courtès <ludo@gnu.org>2024-05-04 19:14:24 +0200
commit76127069e0221a603f880a950ba0fb42a499be3d (patch)
treec27da0e3971a96425f64be154beaa056bdd125f7
parentc14b8636fbac9826115f4524d500536d54c15625 (diff)
downloadguix-patches-76127069e0221a603f880a950ba0fb42a499be3d.tar
guix-patches-76127069e0221a603f880a950ba0fb42a499be3d.tar.gz
packages: ‘define-public’ replacement calls ‘module-export!’ directly.
This reduces code bloat and loading overhead for package modules, which use ‘define-public’ extensively. * guix/packages.scm (define-public*): Use ‘define’ followed by ‘module-export!’ directly instead of ‘define-public’. Change-Id: I7f56d46b391c1e3eeeb0b9a08a9d34b5de341245
-rw-r--r--guix/packages.scm22
1 files changed, 17 insertions, 5 deletions
diff --git a/guix/packages.scm b/guix/packages.scm
index 6f276160f2..cd5df9130b 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -481,7 +481,8 @@ one-indexed line numbers."
(define-syntax define-public*
(lambda (s)
"Like 'define-public' but set 'current-definition-location' for the
-lexical scope of its body."
+lexical scope of its body. (This also disables notification of \"module
+observers\", but this is unlikely to affect anyone.)"
(define location
(match (syntax-source s)
(#f #f)
@@ -498,10 +499,21 @@ lexical scope of its body."
(syntax-case s ()
((_ prototype body ...)
- #`(define-public prototype
- (syntax-parameterize ((current-definition-location
- (lambda (s) #,location)))
- body ...))))))
+ (with-syntax ((name (syntax-case #'prototype ()
+ ((id _ ...) #'id)
+ (id #'id))))
+ #`(begin
+ (define prototype
+ (syntax-parameterize ((current-definition-location
+ (lambda (s) #,location)))
+ body ...))
+
+ ;; Note: Use 'module-export!' directly to avoid emitting a
+ ;; 'call-with-deferred-observers' call for each 'define-public*'
+ ;; instance, which is not only pointless but also contributes to
+ ;; code bloat and to load-time overhead in package modules.
+ (eval-when (expand load eval)
+ (module-export! (current-module) '(name)))))))))
(define-syntax validate-texinfo
(let ((validate? (getenv "GUIX_UNINSTALLED")))