guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/04: grafts: Simplify access to store item references.


From: guix-commits
Subject: 01/04: grafts: Simplify access to store item references.
Date: Wed, 1 Apr 2020 18:06:35 -0400 (EDT)

civodul pushed a commit to branch master
in repository guix.

commit 4b75a7060058bc2e959dcb4145067f6bba3e34e5
Author: Ludovic Courtès <address@hidden>
AuthorDate: Wed Apr 1 22:51:46 2020 +0200

    grafts: Simplify access to store item references.
    
    This is a followup to 710854304b1ab29332edcb76f3de532e0724c197.
    
    This also slightly reduces the number of 'query-references' RPCs, for
    instance from 176 to 166 from "guix build emacs -d".
    
    * guix/grafts.scm (references-oracle): Remove.
    (non-self-references): Remove 'references' parameter and add 'store'.
    Add 'references*' procedure and use it instead of 'references'.  Adjust
    caller accordingly.
    (cumulative-grafts): Remove 'references' parameter and adjust caller
    accordingly.
---
 guix/grafts.scm | 60 +++++++++++++++------------------------------------------
 1 file changed, 15 insertions(+), 45 deletions(-)

diff --git a/guix/grafts.scm b/guix/grafts.scm
index 5173a77..69d6fe4 100644
--- a/guix/grafts.scm
+++ b/guix/grafts.scm
@@ -152,43 +152,23 @@ are not recursively applied to dependencies of DRV."
 
                                      #:properties properties)))))
 
-(define (non-self-references references drv outputs)
+(define (non-self-references store drv outputs)
   "Return the list of references of the OUTPUTS of DRV, excluding self
-references.  Call REFERENCES to get the list of references."
-  (let ((refs (append-map (compose references
-                                   (cut derivation->output-path drv <>))
-                          outputs))
-        (self (match (derivation->output-paths drv)
-                (((names . items) ...)
-                 items))))
-    (remove (cut member <> self) refs)))
-
-(define (references-oracle store input)
-  "Return a one-argument procedure that, when passed the output file names of
-INPUT, a derivation input, or their dependencies, returns the list of
-references of that item.  Build INPUT if it's not available."
+references."
   (define (references* items)
     ;; Return the references of ITEMS.
     (guard (c ((store-protocol-error? c)
                ;; ITEMS are not in store so build INPUT first.
-               (and (build-derivations store (list input))
-                    (map (cut references/cached store <>) items))))
-      (map (cut references/cached store <>) items)))
+               (and (build-derivations store (list drv))
+                    (append-map (cut references/cached store <>) items))))
+      (append-map (cut references/cached store <>) items)))
 
-  (let loop ((items (derivation-input-output-paths input))
-             (result vlist-null))
-    (match items
-      (()
-       (lambda (item)
-         (match (vhash-assoc item result)
-           ((_ . refs) refs)
-           (#f         #f))))
-      (_
-       (let* ((refs   (references* items))
-              (result (fold vhash-cons result items refs)))
-         (loop (remove (cut vhash-assoc <> result)
-                       (delete-duplicates (concatenate refs) string=?))
-               result))))))
+  (let ((refs (references* (map (cut derivation->output-path drv <>)
+                                outputs)))
+        (self (match (derivation->output-paths drv)
+                (((names . items) ...)
+                 items))))
+    (remove (cut member <> self) refs)))
 
 (define-syntax-rule (with-cache key exp ...)
   "Cache the value of monadic expression EXP under KEY."
@@ -231,15 +211,12 @@ of DRV."
                        (set-insert drv visited)))))))))
 
 (define* (cumulative-grafts store drv grafts
-                            references
                             #:key
                             (outputs (derivation-output-names drv))
                             (guile (%guile-for-build))
                             (system (%current-system)))
   "Augment GRAFTS with additional grafts resulting from the application of
-GRAFTS to the dependencies of DRV; REFERENCES must be a one-argument procedure
-that returns the list of references of the store item it is given.  Return the
-resulting list of grafts.
+GRAFTS to the dependencies of DRV.  Return the resulting list of grafts.
 
 This is a monadic procedure in %STATE-MONAD where the state is a vhash mapping
 derivations to the corresponding set of grafts."
@@ -262,7 +239,7 @@ derivations to the corresponding set of grafts."
        ;; If GRAFTS already contains a graft from DRV, do not override it.
        (if (find (cut graft-origin? drv <>) grafts)
            (state-return grafts)
-           (cumulative-grafts store drv grafts references
+           (cumulative-grafts store drv grafts
                               #:outputs (list output)
                               #:guile guile
                               #:system system)))
@@ -270,7 +247,7 @@ derivations to the corresponding set of grafts."
        (state-return grafts))))
 
   (with-cache (cons (derivation-file-name drv) outputs)
-    (match (non-self-references references drv outputs)
+    (match (non-self-references store drv outputs)
       (()                                         ;no dependencies
        (return grafts))
       (deps                                       ;one or more dependencies
@@ -307,15 +284,8 @@ derivations to the corresponding set of grafts."
   "Apply GRAFTS to the OUTPUTS of DRV and all their dependencies, recursively.
 That is, if GRAFTS apply only indirectly to DRV, graft the dependencies of
 DRV, and graft DRV itself to refer to those grafted dependencies."
-
-  ;; First, pre-compute the dependency tree of the outputs of DRV.  Do this
-  ;; upfront to have as much parallelism as possible when querying substitute
-  ;; info or when building DRV.
-  (define references
-    (references-oracle store (derivation-input drv outputs)))
-
   (match (run-with-state
-             (cumulative-grafts store drv grafts references
+             (cumulative-grafts store drv grafts
                                 #:outputs outputs
                                 #:guile guile #:system system)
            vlist-null)                            ;the initial cache



reply via email to

[Prev in Thread] Current Thread [Next in Thread]