Subject: [bug#46101] [PATCH 3/4] inferior: Memoize inferior package search path access.

From: Ricardo Wurmus <[email-masked]>
Date: Mon, 25 Jan 2021 14:37:37 +0100

* guix/inferior.scm (%inferior-package-search-paths): Return memoized
procedure accepting a package.
(inferior-package-native-search-paths, inferior-package-search-paths,
inferior-package-transitive-native-search-paths): Adapt.
---
 guix/inferior.scm | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/guix/inferior.scm b/guix/inferior.scm
index 7bfce5d810..0c85a9ea08 100644
--- a/guix/inferior.scm
+++ b/guix/inferior.scm
@@ -45,6 +45,7 @@
   #:use-module (guix store)
   #:use-module (guix derivations)
   #:use-module (guix base32)
+  #:use-module ((guix memoization) #:select (mlambdaq))
   #:use-module (gcrypt hash)
   #:autoload   (guix cache) (maybe-remove-expired-cache-entries
                              file-expiration-time)
@@ -430,27 +431,28 @@ inferior package."
 (define inferior-package-transitive-propagated-inputs
   (cut inferior-package-input-field <> 'package-transitive-propagated-inputs))
 
-(define (%inferior-package-search-paths package field)
+(define (%inferior-package-search-paths field)
   "Return the list of search path specifications of PACKAGE, an inferior
 package."
-  (define paths
-    (inferior-package-field package
-                            `(compose (lambda (paths)
-                                        (map (@ (guix search-paths)
-                                                search-path-specification->sexp)
-                                             paths))
-                                      ,field)))
+  (mlambdaq (package)
+    (define paths
+      (inferior-package-field package
+                              `(compose (lambda (paths)
+                                          (map (@ (guix search-paths)
+                                                  search-path-specification->sexp)
+                                               paths))
+                                        ,field)))
 
-  (map sexp->search-path-specification paths))
+    (map sexp->search-path-specification paths)))
 
 (define inferior-package-native-search-paths
-  (cut %inferior-package-search-paths <> 'package-native-search-paths))
+  (%inferior-package-search-paths 'package-native-search-paths))
 
 (define inferior-package-search-paths
-  (cut %inferior-package-search-paths <> 'package-search-paths))
+  (%inferior-package-search-paths 'package-search-paths))
 
 (define inferior-package-transitive-native-search-paths
-  (cut %inferior-package-search-paths <> 'package-transitive-native-search-paths))
+  (%inferior-package-search-paths 'package-transitive-native-search-paths))
 
 (define (inferior-package-provenance package)
   "Return a \"provenance sexp\" for PACKAGE, an inferior package.  The result
-- 
2.29.2