unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#59390] [PATCH 0/5] Doing 'match-record' work at expansion time
@ 2022-11-19 22:23 Ludovic Courtès
  2022-11-19 22:24 ` [bug#59390] [PATCH 1/5] records: 'match-record' checks fields at macro-expansion time Ludovic Courtès
  2022-12-01 23:07 ` bug#59390: [PATCH 0/5] Doing 'match-record' work at expansion time Ludovic Courtès
  0 siblings, 2 replies; 7+ messages in thread
From: Ludovic Courtès @ 2022-11-19 22:23 UTC (permalink / raw)
  To: 59390; +Cc: Ludovic Courtès

Hello Guix!

This addresses a longstanding issue: making ‘match-record’ efficient,
and allowing it to error out on unknown field names are macro-expansion
time.

It does so by changing the record type identifier passed to
‘define-record-type*’ to a macro that can either expand to the actual
record type descriptor (RTD) or provide the list of fields of
this type:

--8<---------------cut here---------------start------------->8---
scheme@(guix records)> (define-record-type* <foo> foo make-foo foo? (one foo-one) (two foo-two))
scheme@(guix records)> <foo>
$89 = #<record-type <foo>>
scheme@(guix records)> ,expand <foo>
$90 = #{% <foo> rtd}#
scheme@(guix records)> ,expand (<foo> map-fields f)
$91 = (f (one two))
scheme@(guix records)> ,optimize (match-record x <foo>
				   (two one)
				   (list one two))
$92 = (if (eq? (struct-vtable x) #{% <foo> rtd}#)
  (let* ((two (struct-ref x 1)) (one (struct-ref x 0)))
    (list one two))
  (throw 'wrong-type-arg x))
scheme@(guix records)> ,expand (match-record x <foo>
				 (xyz)
				 #f)
While executing meta-command:
Syntax error:
unknown file:12066:34: lookup-field: unknown record type field in subform xyz of (lookup-field xyz (+ 1 (+ 1 0)) ())
--8<---------------cut here---------------end--------------->8---

I changed a few services that were using ‘match’ to use either
‘match-record’ or accessors (the latter when accessing just one
or two fields).

This change breaks the ABI: we’ll have to run:

  make clean-go && make

Thoughts?

Ludo’.

Ludovic Courtès (5):
  records: 'match-record' checks fields at macro-expansion time.
  doc: Recommend 'match-record'.
  home: services: Use 'match-record' instead of 'match'.
  services: base: Use 'match-record' instead of 'match'.
  services: networking: Avoid 'match' on records.

 doc/contributing.texi        |   7 +-
 gnu/home/services/mcron.scm  |  58 +--
 gnu/home/services/shells.scm |  50 +-
 gnu/home/services/xdg.scm    |  36 +-
 gnu/services/base.scm        | 882 +++++++++++++++++------------------
 gnu/services/cuirass.scm     |   4 +-
 gnu/services/getmail.scm     |  22 +-
 gnu/services/networking.scm  | 661 +++++++++++++-------------
 guix/records.scm             |  87 +++-
 tests/records.scm            |  33 ++
 10 files changed, 967 insertions(+), 873 deletions(-)


base-commit: bb04b5e0ceb606c8d33d53bf06f7fc8855a2c56b
-- 
2.38.1





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-12-01 23:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-19 22:23 [bug#59390] [PATCH 0/5] Doing 'match-record' work at expansion time Ludovic Courtès
2022-11-19 22:24 ` [bug#59390] [PATCH 1/5] records: 'match-record' checks fields at macro-expansion time Ludovic Courtès
2022-11-19 22:24   ` [bug#59390] [PATCH 2/5] doc: Recommend 'match-record' Ludovic Courtès
2022-11-19 22:24   ` [bug#59390] [PATCH 3/5] home: services: Use 'match-record' instead of 'match' Ludovic Courtès
2022-11-19 22:24   ` [bug#59390] [PATCH 4/5] services: base: " Ludovic Courtès
2022-11-19 22:24   ` [bug#59390] [PATCH 5/5] services: networking: Avoid 'match' on records Ludovic Courtès
2022-12-01 23:07 ` bug#59390: [PATCH 0/5] Doing 'match-record' work at expansion time Ludovic Courtès

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).