Subject: bug#71941: Broken `map-derivation' procedure

From: Ludovic Courtès <[email-masked]>
Date: Tue, 25 Feb 2025 18:27:53 +0100

Sergio Pastor Pérez <[email-masked]> skribis:

> Implement caching to speed up computation.
>
> Change-Id: I186e2a62f6655e3b0738dd6e0f628faccd8b855e

Nice!

> +      (let ((cached-drv (hash-ref computed-drvs drv)))
> +        (if cached-drv
> +            cached-drv
> +            (let* ((inputs       (map (cut rewritten-input <> loop)

Two things:

  1. Preferably use ‘hashq-set!’ and ‘hashq-ref’ for the cache, to
     compare derivations according to ‘eq?’;

  2. Instead of rolling your own, perhaps you can use ‘mlambdaq’, which
     also has the advantage of maintaining statistics; you can see them
     by setting GUIX_PROFILING=memoization.

For #2, essentially you would write:

  (define loop
    (mlambdaq (drv)
      contents of the loop…))

  (loop drv)

I *think* that would do the job.

We you able to test this on meaningful cases?

Thanks for your work, and apologies for the delay!

Ludo’.