From patchwork Thu Mar 31 12:46:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Attila Lendvai X-Patchwork-Id: 38249 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 7614E27BBEA; Thu, 31 Mar 2022 13:50:49 +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=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS autolearn=unavailable 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 0B80527BBE9 for ; Thu, 31 Mar 2022 13:50:49 +0100 (BST) Received: from localhost ([::1]:45486 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZuGG-0005Yp-0w for patchwork@mira.cbaines.net; Thu, 31 Mar 2022 08:50:48 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33734) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZuEY-0003T2-4b for guix-patches@gnu.org; Thu, 31 Mar 2022 08:49:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:44335) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nZuEX-00059c-RZ for guix-patches@gnu.org; Thu, 31 Mar 2022 08:49:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nZuEX-00053n-MW for guix-patches@gnu.org; Thu, 31 Mar 2022 08:49:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#54652] [PATCH 1/2] guix: Only check the object type once in the MATCH-RECORD expansion. Resent-From: Attila Lendvai Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 31 Mar 2022 12:49:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 54652 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 54652@debbugs.gnu.org Cc: Attila Lendvai X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.164873092119422 (code B ref -1); Thu, 31 Mar 2022 12:49:01 +0000 Received: (at submit) by debbugs.gnu.org; 31 Mar 2022 12:48:41 +0000 Received: from localhost ([127.0.0.1]:38232 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nZuED-00053C-AF for submit@debbugs.gnu.org; Thu, 31 Mar 2022 08:48:41 -0400 Received: from lists.gnu.org ([209.51.188.17]:39350) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nZuEB-000533-PA for submit@debbugs.gnu.org; Thu, 31 Mar 2022 08:48:40 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33616) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZuEB-0002XM-Fz for guix-patches@gnu.org; Thu, 31 Mar 2022 08:48:39 -0400 Received: from [2a00:1450:4864:20::62d] (port=46684 helo=mail-ej1-x62d.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nZuE9-0004uX-NP for guix-patches@gnu.org; Thu, 31 Mar 2022 08:48:39 -0400 Received: by mail-ej1-x62d.google.com with SMTP id c10so29472369ejs.13 for ; Thu, 31 Mar 2022 05:48:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xjbLRrxys9+mq7HbWwjU0J9dJiSyGgcAJyi+rfWxN20=; b=DwrAQHigqZhYk4wUarxiTaoo41EFKiXga7kBBnrxzGc3IAfQW4gPuVKliQ2IsXkULU FValKlkgaFwGJargNC9bDEtrtQBjFyb9wGiZ8cLIZKmUAtmxMzk7tM2+3eFgvpxFQXu1 m7494oG2AxEJE98nzrMiNCp+u88MrqvzVGT5iOthMB/qGKP1OfktWi40yCcMLZsSYiia PJdtXhC+kAe3jl8emVM4CFcIRcrt4hzFWarUJRiyraXgfxHG63qFTGMSejhHYlxv24Ul KGvWrweKqQtyyyQfYxJTBmzJr4AkqJ5c9kBA6Q8B8h8WzQScHAjImnGy5mY5vDtvnMf8 ZBMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=xjbLRrxys9+mq7HbWwjU0J9dJiSyGgcAJyi+rfWxN20=; b=HbwrgwMyUuvN1kvbgGz4qEuOGaZpXtqcC1pNKU16CquXVC5YSOGGepsQpUdH6U0qy6 ZDuLf7YRSnBWjq43VIunFq94xpr7sJO5y6cbncQaSHZzut8OXLUyxg80zbhEU4PiLxfv YAwzLoTMJi8jSnu1FarO7foRy8JeFKiFViZskVMFGuaPQZuBec7KSyM7/Rq7ghCf94WL tCMsbebgtJ36kjIi5YAZxUha9hOO4molKTtNzsFoxTmzOG/v8RZMWKQOeag40ipZuAfy bFYswQ3ygmLxjiAjgoJcnEQrTWRhszeVCrYywylOBKvsWCgx8IdPuPbGt41FMT2UmeOB zT8g== X-Gm-Message-State: AOAM532gnKceY8pxigCdn6fmT88pZmpolfT42IlR+E8mBI+YN/vs5N+T LVN2KPrC2zPx+38ETxobtuTvCL5jInE= X-Google-Smtp-Source: ABdhPJzoY3ubVdGZ0BYp5RtnRhxuQuVF+iWaZXA/wOISBxLxi4SWcD4U9xCnpYCfRH6zScq1aCAiVw== X-Received: by 2002:a17:907:96a9:b0:6e0:db4a:ba8d with SMTP id hd41-20020a17090796a900b006e0db4aba8dmr4898698ejc.87.1648730915558; Thu, 31 Mar 2022 05:48:35 -0700 (PDT) Received: from lelap.local (catv-89-132-245-188.catv.fixed.vodafone.hu. [89.132.245.188]) by smtp.gmail.com with ESMTPSA id l20-20020a1709062a9400b006ce71a88bf5sm9262915eje.183.2022.03.31.05.48.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Mar 2022 05:48:35 -0700 (PDT) From: Attila Lendvai Date: Thu, 31 Mar 2022 14:46:57 +0200 Message-Id: <20220331124657.2985-1-attila@lendvai.name> X-Mailer: git-send-email 2.34.0 MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::62d (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::62d; envelope-from=attila.lendvai@gmail.com; helo=mail-ej1-x62d.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action 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: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * guix/records.scm (match-record/fields): New macro. (match-record): Only check the object type once in the expansion. --- guix/records.scm | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/guix/records.scm b/guix/records.scm index ed94c83dac..e311086d73 100644 --- a/guix/records.scm +++ b/guix/records.scm @@ -535,17 +535,25 @@ (define (recutils->alist port) (else (error "unmatched line" line)))))))) +(define-syntax match-record/fields + (syntax-rules () + ((_ record type (field fields ...) body ...) + (let ((field ((record-accessor type 'field) record))) + ;; TODO compute indices and report wrong-field-name errors at + ;; expansion time + ;; TODO support thunked and delayed fields + (match-record/fields record type (fields ...) body ...))) + ((_ record type () body ...) + (begin body ...)))) + (define-syntax match-record (syntax-rules () "Bind each FIELD of a RECORD of the given TYPE to it's FIELD name. The current implementation does not support thunked and delayed fields." ((_ record type (field fields ...) body ...) (if (eq? (struct-vtable record) type) - ;; TODO compute indices and report wrong-field-name errors at - ;; expansion time - ;; TODO support thunked and delayed fields - (let ((field ((record-accessor type 'field) record))) - (match-record record type (fields ...) body ...)) + ;; So that we only test the type once. + (match-record/fields record type (field fields ...) body ...) (throw 'wrong-type-arg record))) ((_ record type () body ...) (begin body ...))))