The changes I made in version-control.scm and gnucash.scm in commite6301fb76d0a8d931ece2e18d197e3c2cc53fc6c revealed an abstraction leakageI wasn’t aware of: there’s a pattern where users “see” that thunkedfields are thunked: (package ;; … (inputs …) (arguments `(foo bar ,(inputs) …))) ;<- here ‘inputs’ is seen as a thunk Fortunately I could only find two occurrences of this and this use caseis more elegantly replaced by: (package-inputs this-record) … which also has better semantics. It’s remains a bug, though. Ludo’.
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:
Toggle quote (11 lines)> 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 fieldnames to their values before calling the constructor. In these let*-bindings the fields are already wrapped, e.g. inputs will be bound tothe 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 fearthat exposing raw values through let-binding probably eliminates thedelayed/thunked nature of said fields in some ways. WDYT?
From 1f38ff4c8b93cde533cf3d3f67358aafe9cf3dfa Mon Sep 17 00:00:00 2001From: Leo Prikler <firstname.lastname@example.org>Date: Tue, 24 Aug 2021 17:32:33 +0200Subject: [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 rawvalue.[field-value]: Always wrap the value.[record-inheritance]: Wrap "inherited" values.--- guix/records.scm | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
Toggle diff (44 lines)diff --git a/guix/records.scm b/guix/records.scmindex 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