From patchwork Thu Apr 27 22:06:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\\(" X-Patchwork-Id: 49605 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 352C627BBEA; Thu, 27 Apr 2023 23:08:34 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 8490527BBE2 for ; Thu, 27 Apr 2023 23:08:33 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ps9mX-0005Lc-VM; Thu, 27 Apr 2023 18:08:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ps9mV-0005Kc-IM for guix-patches@gnu.org; Thu, 27 Apr 2023 18:08:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ps9mU-0007Hl-MF for guix-patches@gnu.org; Thu, 27 Apr 2023 18:08:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ps9mU-0000kh-FY for guix-patches@gnu.org; Thu, 27 Apr 2023 18:08:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#63135] [PATCH 2/3] records: match-record: Display more helpful field-not-found error. Resent-From: "(" Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 27 Apr 2023 22:08:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63135 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 63135@debbugs.gnu.org Cc: "\(" , Josselin Poiret Received: via spool by 63135-submit@debbugs.gnu.org id=B63135.16826332272807 (code B ref 63135); Thu, 27 Apr 2023 22:08:02 +0000 Received: (at 63135) by debbugs.gnu.org; 27 Apr 2023 22:07:07 +0000 Received: from localhost ([127.0.0.1]:59974 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ps9la-0000jB-GR for submit@debbugs.gnu.org; Thu, 27 Apr 2023 18:07:06 -0400 Received: from knopi.disroot.org ([178.21.23.139]:53992) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ps9lW-0000ib-7p for 63135@debbugs.gnu.org; Thu, 27 Apr 2023 18:07:02 -0400 Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id BAD2140306; Fri, 28 Apr 2023 00:07:01 +0200 (CEST) X-Virus-Scanned: SPAM Filter at disroot.org Received: from knopi.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QQQQQgHpRCy5; Fri, 28 Apr 2023 00:07:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1682633220; bh=aa/TNg6F4FuftaCqmdSb5c/md+/36DE3Ku+qtLN2znA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Lgv8AUJVz1WSThRrGfojcVQksNqw5AryDHhFDoewSIrgqEto5KDn2oZRbUwrWGvrG t81jgkcyMsitt/2LxC1eT2n+FTXUDKb9OqvUkd19HA21jmdEi2FIei12/PdAwC9C30 cRqLs/BfbOGrK6dXuVUbCf8OItdQvCth8+80P1WpTGdBqdAQ4gYAS79/hrW4EOjxKS nSVfNrG/uC95wDZIBSA1QRBKgJ84Wg+XAaRRN1QARaGjn6kyQjyV7n8DUhPjh6A1ss GZhUaKxrxRGnkriAlyMd+H35BXlT5UncxsmsNRAD1WAwdBiROD5Q5/1Czp8Cdnnpft yKuN5JFxEY5Tg== Date: Thu, 27 Apr 2023 23:06:52 +0100 Message-Id: <20230427220653.5228-2-paren@disroot.org> In-Reply-To: <20230427220653.5228-1-paren@disroot.org> References: <20230427220653.5228-1-paren@disroot.org> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: "\(" X-ACL-Warn: , "\( via Guix-patches" X-Patchwork-Original-From: "\( via Guix-patches" via From: "\\(" Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * guix/records.scm (match-record): Display MATCH-RECORD as the origin of "unknown record type field" errors. Show the original MATCH-RECORD form, rather than an intermediate LOOKUP-FIELD form, within said errors. --- guix/records.scm | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/guix/records.scm b/guix/records.scm index d8966998c1..4bee9d0aac 100644 --- a/guix/records.scm +++ b/guix/records.scm @@ -582,44 +582,46 @@ (define-syntax lookup-field (lambda (s) "Look up FIELD in the given list and return an expression that represents its offset in the record. Raise a syntax violation when the field is not -found." +found, displaying it as originating in form S*." (syntax-case s () - ((_ field offset ()) - (syntax-violation 'lookup-field "unknown record type field" - s #'field)) - ((_ field offset (head tail ...)) + ((_ s* field offset ()) + (syntax-violation 'match-record + "unknown record type field" + #'s* #'field)) + ((_ s* field offset (head tail ...)) (free-identifier=? #'field #'head) #'offset) - ((_ field offset (_ tail ...)) - #'(lookup-field field (+ 1 offset) (tail ...)))))) + ((_ s* field offset (_ tail ...)) + #'(lookup-field s* field (+ 1 offset) (tail ...)))))) (define-syntax match-record-inner (lambda (s) (syntax-case s () - ((_ record type ((field variable) rest ...) body ...) + ((_ s* record type ((field variable) rest ...) body ...) #'(let-syntax ((field-offset (syntax-rules () ((_ f) - (lookup-field field 0 f))))) + (lookup-field s* field 0 f))))) (let* ((offset (type (map-fields type match-record) field-offset)) (variable (struct-ref record offset))) - (match-record-inner record type (rest ...) body ...)))) - ((_ record type (field rest ...) body ...) + (match-record-inner s* record type (rest ...) body ...)))) + ((_ s* record type (field rest ...) body ...) ;; Redirect to the canonical form above. - #'(match-record-inner record type ((field field) rest ...) body ...)) - ((_ record type () body ...) + #'(match-record-inner s* record type ((field field) rest ...) body ...)) + ((_ s* record type () body ...) #'(begin body ...))))) (define-syntax match-record - (syntax-rules () + (lambda (s) "Bind each FIELD of a RECORD of the given TYPE to it's FIELD name. The order in which fields appear does not matter. A syntax error is raised if an unknown field is queried. The current implementation does not support thunked and delayed fields." ;; TODO support thunked and delayed fields - ((_ record type (fields ...) body ...) - (if (eq? (struct-vtable record) type) - (match-record-inner record type (fields ...) body ...) - (throw 'wrong-type-arg record))))) + (syntax-case s () + ((_ record type (fields ...) body ...) + #`(if (eq? (struct-vtable record) type) + (match-record-inner #,s record type (fields ...) body ...) + (throw 'wrong-type-arg record)))))) ;;; records.scm ends here