From patchwork Sat Feb 22 14:59:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 38978 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 C0D2127BBEB; Sat, 22 Feb 2025 15:01:31 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED 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 3C3D527BBE2 for ; Sat, 22 Feb 2025 15:01:31 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlr0C-0001Ap-DG; Sat, 22 Feb 2025 10:01:12 -0500 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 1tlr0A-0001AR-Q3 for guix-patches@gnu.org; Sat, 22 Feb 2025 10:01:10 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tlr09-0007Qv-W9; Sat, 22 Feb 2025 10:01:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:From:To:Subject; bh=4MSsxYPaMgrM4+6gjxOmnvFcZ1QVQka/05Yj9YSAEB4=; b=mmL+qyKXJjfVuUj0vYeI7qyyQZE9mwQHxsKkFHr/S2zLi7ZKLlLVxwg8mJR5u3nFXuEmxwbceBc9X3//rpkEyzTxv13tCEchbgYRZRmExgFOn5cWQd8s4KDI9GP0CA6GJ6weEL3bbhqCsDlPYRdahiVUwwol86wL+TJ/C5aKkPUuX5vDPiUKYvHTkU8k4LexPf3fTEYH+WPKmPBExFffUOwFr/Bk1YTHtLdEjsJSNvqrJFOp3h1QJV8HHV70he8LFCJVYQ+BB6FtQywWjo58sXdHV8Ubjw9zUraeLrInv9HgJ0sxu1oOD4tZgweU8IHQqH8lTgHpwgSfkJEdmBR8hw==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tlr09-0002SR-Cj; Sat, 22 Feb 2025 10:01:09 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#76485] [PATCH] gexp: =?utf-8?b?4oCYd2l0aC1wYXJhbWV0ZXJz4oCZ?= properly handles =?utf-8?b?4oCYJWdyYWZ0P+KAmS4=?= Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Sat, 22 Feb 2025 15:01:07 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 76485 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 76485@debbugs.gnu.org Cc: David Elsing , Ludovic =?utf-8?q?Court=C3=A8s?= , Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-To: guix-patches@gnu.org X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by submit@debbugs.gnu.org id=B.17402364599345 (code B ref -1); Sat, 22 Feb 2025 15:01:07 +0000 Received: (at submit) by debbugs.gnu.org; 22 Feb 2025 15:00:59 +0000 Received: from localhost ([127.0.0.1]:52663 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tlqzs-0002PV-Gi for submit@debbugs.gnu.org; Sat, 22 Feb 2025 10:00:59 -0500 Received: from lists.gnu.org ([2001:470:142::17]:50054) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tlqyy-0002CB-PY for submit@debbugs.gnu.org; Sat, 22 Feb 2025 10:00:01 -0500 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 1tlqys-0000z6-IA for guix-patches@gnu.org; Sat, 22 Feb 2025 09:59:50 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tlqys-00079u-90; Sat, 22 Feb 2025 09:59:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=4MSsxYPaMgrM4+6gjxOmnvFcZ1QVQka/05Yj9YSAEB4=; b=K5Q5n1RsPmwPJF Rd4FxRGRk8mOcJmOgIFl+CaSZCPxihn91jEHgycT70yPTBCg75PM2if3hHRweWTBIIG5/or/o1mwN AcWCCtw2Xim2MjseW4nQKT9eI7aj9kveDiT4a86vg5Kf4L/HxEBKmepMX6QeN5ZLyroZVre+Y1vUN CsEl/pFvspX4D/qb9KqYuHLHd35gG8bv+bMPn7O9usAuvcx4fxD7eFhJVAs4hM63BucG3aMLCk5TJ 7uNpZG8Zqy2dKFJrxhQiixO57/reUQGt5hfd6xWuDPrAeCDR8FTNmgRpwU7E9OtmuDk0U3qFvDewU pZwyXLxOslqTCc+eb9dQ==; From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Sat, 22 Feb 2025 15:59:37 +0100 Message-ID: <256e623843a70b001801dcddd7acb4138e6216b4.1740236293.git.ludo@gnu.org> X-Mailer: git-send-email 2.48.1 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: , 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 Fixes . * guix/gexp.scm (mcall-with-parameters): New procedure. (compile-parameterized): Use it instead of ‘with-fluids’. * tests/gexp.scm ("with-parameters for %graft?"): New test. Reported-by: David Elsing Change-Id: Iddda7ead2aeef24dd989ac37a53fc99b726731b3 --- guix/gexp.scm | 31 ++++++++++++++++++++++++------- tests/gexp.scm | 20 ++++++++++++++++++++ 2 files changed, 44 insertions(+), 7 deletions(-) base-commit: 90aa90eb05429553402e0b5225d23f84742a9286 diff --git a/guix/gexp.scm b/guix/gexp.scm index ad51bc55b78..012a6b2573a 100644 --- a/guix/gexp.scm +++ b/guix/gexp.scm @@ -728,19 +728,34 @@ (define-syntax-rule (with-parameters ((param value) ...) body ...) (lambda () body ...))) +(define (mcall-with-parameters parameters values thunk) + "Set PARAMETERS to VALUES for the dynamic extent of THUNK, a monadic +procedure." + ;; This is the procedural variant of 'mparameterize'. + (define (set-value parameter value) + (parameter value)) + + ;; XXX: Non-local exits can leave PARAMETERS set to VALUES. + (mlet* %store-monad ((old-values + (return (map set-value parameters values))) + (result (thunk))) + (mbegin %store-monad + (return (map set-value parameters old-values)) ;restore old values + (return result)))) + (define-gexp-compiler compile-parameterized compiler => (lambda (parameterized system target) (match (parameterized-bindings parameterized) (((parameters values) ...) - (let ((fluids (map parameter-fluid parameters)) - (thunk (parameterized-thunk parameterized))) + (let ((thunk (parameterized-thunk parameterized))) ;; Install the PARAMETERS for the dynamic extent of THUNK. - (with-fluids* fluids - (map (lambda (thunk) (thunk)) values) + ;; Special-case '%current-system' and '%current-target-system' to + ;; make sure we get the desired effect. + (mcall-with-parameters + parameters + (map (lambda (thunk) (thunk)) values) (lambda () - ;; Special-case '%current-system' and '%current-target-system' to - ;; make sure we get the desired effect. (let ((system (if (memq %current-system parameters) (%current-system) system)) @@ -2350,4 +2365,6 @@ (define* (references-file item #:optional (name "references") (read-hash-extend #\$ read-ungexp) (read-hash-extend #\+ (cut read-ungexp <> <> #t))) -;;; gexp.scm ends here +;;; Local Variables: +;;; eval: (put 'mcall-with-parameters 'scheme-indent-function 2) +;;; End: diff --git a/tests/gexp.scm b/tests/gexp.scm index e870f6cb1b9..2376c70d1ba 100644 --- a/tests/gexp.scm +++ b/tests/gexp.scm @@ -451,6 +451,26 @@ (define %extension-package (return (string=? (derivation-file-name drv) (derivation-file-name result))))) +(test-assertm "with-parameters for %graft?" + (mlet* %store-monad ((replacement -> (package + (inherit %bootstrap-guile) + (name (string-upcase + (package-name + %bootstrap-guile))))) + (guile -> (package + (inherit %bootstrap-guile) + (replacement replacement))) + (drv0 (package->derivation %bootstrap-guile)) + (drv1 (package->derivation replacement)) + (obj0 -> (with-parameters ((%graft? #f)) + guile)) + (obj1 -> (with-parameters ((%graft? #t)) + guile)) + (result0 (lower-object obj0)) + (result1 (lower-object obj1))) + (return (and (eq? drv0 result0) + (eq? drv1 result1))))) + (test-assert "with-parameters + file-append" (let* ((system (match (%current-system) ("aarch64-linux" "x86_64-linux")