From 8dcec9142667d0b29cf71ca55cf48c0c4f5d4400 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 15 Oct 2014 09:22:23 +0200 Subject: packages: Improve the package-to-derivation cache. * guix/packages.scm (cache): Preserve the former values associated with PACKAGE. (cached): Bind SYSTEM in 'let', to prevent double evaluation. --- guix/packages.scm | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/guix/packages.scm b/guix/packages.scm index b397a24678..070eb4e9d5 100644 --- a/guix/packages.scm +++ b/guix/packages.scm @@ -573,22 +573,26 @@ (define (cache package system thunk) ;; Use `hashq-set!' instead of `hash-set!' because `hash' returns the ;; same value for all structs (as of Guile 2.0.6), and because pointer ;; equality is sufficient in practice. - (hashq-set! %derivation-cache package `((,system ,@vals))) + (hashq-set! %derivation-cache package + `((,system ,@vals) + ,@(or (hashq-ref %derivation-cache package) + '()))) (apply values vals))) (define-syntax-rule (cached package system body ...) "Memoize the result of BODY for the arguments PACKAGE and SYSTEM. Return the cached result when available." - (let ((thunk (lambda () body ...))) + (let ((thunk (lambda () body ...)) + (key system)) (match (hashq-ref %derivation-cache package) ((alist (... ...)) - (match (assoc-ref alist system) + (match (assoc-ref alist key) ((vals (... ...)) (apply values vals)) (#f - (cache package system thunk)))) + (cache package key thunk)))) (#f - (cache package system thunk))))) + (cache package key thunk))))) (define* (expand-input store package input system #:optional cross-system) "Expand INPUT, an input tuple, such that it contains only references to -- cgit v1.2.3