GNU bug report logs -
#59390
[PATCH 0/5] Doing 'match-record' work at expansion time
Previous Next
Reported by: Ludovic Courtès <ludo <at> gnu.org>
Date: Sat, 19 Nov 2022 22:24:02 UTC
Severity: normal
Tags: patch
Done: Ludovic Courtès <ludo <at> gnu.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Your message dated Fri, 02 Dec 2022 00:07:42 +0100
with message-id <87wn7awwn5.fsf <at> gnu.org>
and subject line Re: bug#59390: [PATCH 0/5] Doing 'match-record' work at expansion time
has caused the debbugs.gnu.org bug report #59390,
regarding [PATCH 0/5] Doing 'match-record' work at expansion time
to be marked as done.
(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)
--
59390: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=59390
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
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
[Message part 3 (message/rfc822, inline)]
Ludovic Courtès <ludo <at> gnu.org> skribis:
> This addresses a longstanding issue: making ‘match-record’ efficient,
> and allowing it to error out on unknown field names at macro-expansion
> time.
I went ahead, rebased, and pushed these:
00ddf185e6 services: networking: Avoid 'match' on records.
adfe1064c8 services: base: Use 'match-record' instead of 'match'.
4c8eea027a home: services: Use 'match-record' instead of 'match'.
cc9ee514e3 doc: Recommend 'match-record'.
7c1161dba4 records: 'match-record' checks fields at macro-expansion time.
This change breaks the ABI: we’ll have to run:
make clean-go && make
Inquiries welcome!
Ludo’.
This bug report was last modified 2 years and 171 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.