Inheritance vs. ‘this-package’

  • Open
  • quality assurance status badge
Details
3 participants
  • Ludovic Courtès
  • Ludovic Courtès
  • Ulf Herrman
Owner
unassigned
Submitted by
Ludovic Courtès
Severity
normal
Merged with
L
L
Ludovic Courtès wrote on 2 Sep 2021 15:48
(address . bug-guix@gnu.org)
87r1e73x78.fsf@inria.fr
Hi!

We stumbled upon an idiom for package arguments that, combined with
package inheritance, would not work as expected. It goes like this

Toggle snippet (23 lines)
(define-public starpu
(package
;; …
(arguments
(substitute-keyword-arguments (package-arguments starpu-1.2)
((#:configure-flags flags '())
(match (assoc "mpi" (package-propagated-inputs this-package))
(("mpi" mpi)
(if (string=? (package-name mpi) "nmad")
`(cons "--enable-nmad" ,flags)
flags))))))
(propagated-inputs `(("mpi" ,openmpi)))))

(define-public starpu+fxt
(package
(inherit starpu)
;; …
(arguments
(substitute-keyword-arguments (package-arguments starpu)
((#:configure-flags flags '())
`(cons "--with-fxt" ,flags))))))

The first package, ‘starpu’, has its arguments depend on:

(package-propagated-inputs this-package)

This is smart because if you inherit from it without changing the
‘arguments’ field (for instance by doing ‘--with-input=openmpi=nmad’),
it’ll adjust its configure flags based on the MPI package it actually
depends on.

However, this trick doesn’t work with the second package, ‘starpu-fxt’:
if you do:

guix build starpu-fxt --with-input=openmpi=nmad

the ‘--enable-nmad’ configure flag will not be passed. This is because
‘starpu-fxt’ calls:

(package-arguments starpu)

which returns the original arguments of ‘starpu’.


Still here? :-)

This is admittedly a pretty far-fetched example and there are ways to
work around it¹. Still, I wonder if we could up with a linguistic
device (ah ha!) to address that.

We don’t want to (package-arguments this-package) here: that would
naturally lead to an infinite loop. But we want something close to it,
in spirit: (package-arguments parent), where ‘parent’ is the package we
inherit from.

(package-arguments parent) could call the ‘arguments’ thunk of the
parent, but it would pass it the child as its argument.

Or something like that.

Thoughts?

Ludo’.

L
L
Ludovic Courtès wrote on 4 Mar 2023 16:15
Re: bug#50335: Inheritance vs. ‘this-package ’
(address . 50335@debbugs.gnu.org)(address . philippe.swartvagher@inria.fr)
87a60stumx.fsf@gnu.org
Ludovic Courtès <ludovic.courtes@inria.fr> skribis:

Toggle quote (3 lines)
> We stumbled upon an idiom for package arguments that, combined with
> package inheritance, would not work as expected.

[...]

Toggle quote (8 lines)
> We don’t want to (package-arguments this-package) here: that would
> naturally lead to an infinite loop. But we want something close to it,
> in spirit: (package-arguments parent), where ‘parent’ is the package we
> inherit from.
>
> (package-arguments parent) could call the ‘arguments’ thunk of the
> parent, but it would pass it the child as its argument.

Here’s an example where I ended up manually defining ‘parent’:


Ludo’.
U
U
Ulf Herrman wrote on 22 Oct 2023 00:33
Merge new duplicate
(address . control@debbugs.gnu.org)
87y1fvppvp.fsf@tilde.club
forcemerge 50335 66510
?
Your comment

Commenting via the web interface is currently disabled.

To comment on this conversation send an email to 50335@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 50335
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch