From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id MOKLDKqjRWL0RgEAgWs5BA (envelope-from ) for ; Thu, 31 Mar 2022 14:50:50 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id 0HM1CaqjRWKbfgAAauVa8A (envelope-from ) for ; Thu, 31 Mar 2022 14:50:50 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id C87A531C89 for ; Thu, 31 Mar 2022 14:50:49 +0200 (CEST) Received: from localhost ([::1]:45486 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZuGG-0005Yp-Uu for larch@yhetil.org; 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 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1648731050; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=xjbLRrxys9+mq7HbWwjU0J9dJiSyGgcAJyi+rfWxN20=; b=H8XpYTHGL7dLyd9vmYBLsnmRxLdP8PrjmXrptcyMPKF2KfWInjTFaHgy7GPdEtHnoeAvIu 4rAt46/zomKLyQwp2HZ1CeSVg/EjcvnL9Y0EN2XUMjTAeZsAMU/mOGDLd/w1y9AAEcj5CG kL3/U8UE7cZgJBkilFDdKMghU2g3QZHxAjHE4Jw0p9oj9sPlzJZKa+d+9SjwW0emT8n5Qd bo/oYO5+XUu9chcYmGtmdkA2yFI/6fOKBPoHcNjnDtiZNEBLJSsvJabU72ck0ysy5CZIRR W6Y2/0caoGeK9DUCWvzRbD+FMzu3/7uS5O5Q4xLzyrfJo8RxAEMxMzmvI5YETQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1648731050; a=rsa-sha256; cv=none; b=M0lK3hyfmvEBje7OAZiaTzN+Y6tMmULwjLv4e+Od/ATb6KjNudwwUks15bHLNaBGQWXXgU sLxcMLEkagGFL8I+f5PzWH6QohtPaP09Vx8ERUTooDPeMY2nlCGcRpZIazyFLJlYMwmWXn VopNwTVPNFk0XqrMaI98RxwETO1hSJJTT+75usP1Q+gAr9VsmXj7ZyAN+T7oh3scY3uyxC zc2nM+IAjChe6NkodU1UB/Nj6+yYnmgI2YCdTmRKcpHhFFUHzJ6LFd9Xc6qR0TZTId8QVF jgB5ZWpNAjnoCvFdvtdgDOJihtjyRur7n5GFJlS2shTVPDBXCGaomV0+dAYDpg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=DwrAQHig; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 2.23 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=DwrAQHig; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: C87A531C89 X-Spam-Score: 2.23 X-Migadu-Scanner: scn1.migadu.com X-TUID: 5uNNjvDcO90B * 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 ...)))) -- 2.34.0