From: Leo Prikler <leo.prikler@student.tugraz.at>
To: "Ludovic Courtès" <ludo@gnu.org>, 34999@debbugs.gnu.org
Subject: bug#34999: Record special field abstraction leakage
Date: Tue, 24 Aug 2021 17:47:30 +0200 [thread overview]
Message-ID: <bd16e5d6ff2c424945f883ac6892c5e7b0385c28.camel@student.tugraz.at> (raw)
In-Reply-To: <87zhpiht6k.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 1084 bytes --]
Hi Ludo,
I think I have found out why users see the thunked fields as below.
Am Dienstag, den 26.03.2019, 10:38 +0100 schrieb Ludovic Courtès:
> The changes I made in version-control.scm and gnucash.scm in commit
> e6301fb76d0a8d931ece2e18d197e3c2cc53fc6c revealed an abstraction
> leakage
> I wasn’t aware of: there’s a pattern where users “see” that thunked
> fields are thunked:
>
> (package
> ;; …
> (inputs …)
> (arguments `(foo bar ,(inputs) …))) ;<- here ‘inputs’ is seen as
> a thunk
The issue is that for constructing the records, we let*-bind the field
names to their values before calling the constructor. In these let*-
bindings the fields are already wrapped, e.g. inputs will be bound to
the value that the record field inputs will have, not to the raw value.
I've attached a patch to fix this issue as well as a MWE to try it out.
I'm not sure about the broader semantics of this patch, though. I fear
that exposing raw values through let-binding probably eliminates the
delayed/thunked nature of said fields in some ways. WDYT?
[-- Attachment #2: 0001-guix-records-let-bind-raw-values-wrap-them-in-constr.patch --]
[-- Type: text/x-patch, Size: 2684 bytes --]
From 1f38ff4c8b93cde533cf3d3f67358aafe9cf3dfa Mon Sep 17 00:00:00 2001
From: Leo Prikler <leo.prikler@student.tugraz.at>
Date: Tue, 24 Aug 2021 17:32:33 +0200
Subject: [PATCH] guix: records: let*-bind raw values, wrap them in
constructor.
This fixes the abstraction leakage mentioned in <https://bugs.gnu.org/34999>.
* guix/records.scm (make-syntactic-constructor)[field-bindings]: Bind to raw
value.
[field-value]: Always wrap the value.
[record-inheritance]: Wrap "inherited" values.
---
guix/records.scm | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/guix/records.scm b/guix/records.scm
index ed94c83dac..074f1650c8 100644
--- a/guix/records.scm
+++ b/guix/records.scm
@@ -153,7 +153,10 @@ of TYPE matches the expansion-time ABI."
#`(make-struct/no-tail type
#,@(map (lambda (field index)
- (or (field-inherited-value field)
+ (or (and=>
+ (field-inherited-value field)
+ (lambda (value)
+ (wrap-field-value field value)))
(if (innate-field? field)
(wrap-field-value
field (field-default-value field))
@@ -211,8 +214,7 @@ of TYPE matches the expansion-time ABI."
(map (lambda (field+value)
(syntax-case field+value ()
((field value)
- #`(field
- #,(wrap-field-value #'field #'value)))))
+ #`(field value))))
field+value))
(syntax-case s (inherit expected ...)
@@ -224,10 +226,11 @@ of TYPE matches the expansion-time ABI."
((_ (field value) (... ...))
(let ((fields (map syntax->datum #'(field (... ...)))))
(define (field-value f)
- (or (find (lambda (x)
- (eq? f (syntax->datum x)))
- #'(field (... ...)))
- (wrap-field-value f (field-default-value f))))
+ (wrap-field-value f
+ (or (find (lambda (x)
+ (eq? f (syntax->datum x)))
+ #'(field (... ...)))
+ (field-default-value f))))
;; Pass S to make sure source location info is preserved.
(report-duplicate-field-specifier 'name s)
--
2.33.0
[-- Attachment #3: 34999-mwe.scm --]
[-- Type: text/x-scheme, Size: 537 bytes --]
(use-modules (guix records))
(define-record-type* <thing> thing make-thing
thing?
this-thing
(name thing-name (thunked))
(name2 thing-name2))
(let* ((%thing
(thing
(name "foo")
(name2 name)))
(%thing2
(thing
(inherit %thing)
(name "bar"))))
(format #t "thing1:~% name: ~a~% name2: ~a~%~%"
(thing-name %thing)
(thing-name2 %thing))
(format #t "thing2:~% name: ~a~% name2: ~a~%"
(thing-name %thing2)
(thing-name2 %thing2)))
prev parent reply other threads:[~2021-08-24 15:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-26 9:38 bug#34999: Record special field abstraction leakage Ludovic Courtès
2021-08-24 15:47 ` Leo Prikler [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bd16e5d6ff2c424945f883ac6892c5e7b0385c28.camel@student.tugraz.at \
--to=leo.prikler@student.tugraz.at \
--cc=34999@debbugs.gnu.org \
--cc=ludo@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).