From unknown Sat Jun 21 10:23:16 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#78792 <78792@debbugs.gnu.org> To: bug#78792 <78792@debbugs.gnu.org> Subject: Status: [PATCH] Fix compilation of defalias with a constant macro cons pair Reply-To: bug#78792 <78792@debbugs.gnu.org> Date: Sat, 21 Jun 2025 17:23:16 +0000 retitle 78792 [PATCH] Fix compilation of defalias with a constant macro con= s pair reassign 78792 emacs submitter 78792 zach shaftel severity 78792 normal tag 78792 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 14 21:40:31 2025 Received: (at submit) by debbugs.gnu.org; 15 Jun 2025 01:40:31 +0000 Received: from localhost ([127.0.0.1]:49326 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uQcMI-0000Ti-Lf for submit@debbugs.gnu.org; Sat, 14 Jun 2025 21:40:31 -0400 Received: from lists.gnu.org ([2001:470:142::17]:54030) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uQcMF-0000Qg-Dd for submit@debbugs.gnu.org; Sat, 14 Jun 2025 21:40:27 -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 1uQcM7-0001CW-Tb for bug-gnu-emacs@gnu.org; Sat, 14 Jun 2025 21:40:19 -0400 Received: from smtp.forwardemail.net ([149.28.215.223]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uQcM6-0005sP-53 for bug-gnu-emacs@gnu.org; Sat, 14 Jun 2025 21:40:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shaf.tel; h=Content-Type: MIME-Version: Message-ID: Date: Subject: To: From; q=dns/txt; s=fe-acc5b42812; t=1749951614; bh=wh7KsuQez+XH4zOBqapjK5IWYERc1w/tZeeoUTBKHJ4=; b=V7fF7WYG3OBxNd0MR7mtDaxSCzGWMncq06Sd/5fK35awIdIQMI0g9aInEsqGqSbiqfInJkVlq Ppx6GVWQ1Bnmjg4ewNRTeUm9KXin/zqfPPVwBrlgVxvwteSD9oOYjZ38J1AF4KXuFljf//bjRV8 b2LV3fuOOvMAu0BtPn07vGQ= X-Forward-Email-ID: 684e247b02e1f8d44a6ab5d4 X-Forward-Email-Sender: rfc822; zach@shaf.tel, smtp.forwardemail.net, 149.28.215.223 X-Forward-Email-Version: 1.0.3 X-Forward-Email-Website: https://forwardemail.net X-Complaints-To: abuse@forwardemail.net X-Report-Abuse: abuse@forwardemail.net X-Report-Abuse-To: abuse@forwardemail.net From: zach shaftel To: bug-gnu-emacs@gnu.org Subject: [PATCH] Fix compilation of defalias with a constant macro cons pair User-Agent: mu4e 1.12.10; emacs 31.0.50 X-Debbugs-Cc: Shigeru Fukaya Date: Sat, 14 Jun 2025 21:40:08 -0400 Message-ID: <87qzzlpytj.fsf@shaf.tel> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=149.28.215.223; envelope-from=SRS0=c56e=Y6=shaf.tel=zach@fe-bounces.shaf.tel; helo=smtp.forwardemail.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.9 (/) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.1 (/) --=-=-= Content-Type: text/plain Tags: patch byte-compile-file-form-defalias destructures (cons 'macro 'fn) and '(macro . fn) the same way, so in the latter case fn would be unquoted, and then eval would later signal (void-variable fn). this patch just re-quotes fn, and adds a test for this scenario. In GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.49, cairo version 1.18.4) of 2025-06-11 built on bigbox Repository revision: f90cee6f761b0c2bffcfa64556284884c0f7348f Repository branch: feature/igc System Description: Arch Linux Configured using: 'configure --with-modules --with-native-compilation --with-tree-sitter --without-gsettings --without-gconf --without-gpm --with-pgtk --without-compress-install --with-mps 'CFLAGS=-mtune=native -march=native -O3 -fuse-ld=mold'' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Fix-compilation-of-defalias-with-a-constant-macro-co.patch >From f0b9f227c5711c1cbf7a38c20fd05b184536c12a Mon Sep 17 00:00:00 2001 From: Zach Shaftel Date: Sat, 14 Jun 2025 20:57:21 -0400 Subject: [PATCH] Fix compilation of defalias with a constant macro cons pair * lisp/emacs-lisp/bytecomp.el (byte-compile-file-form-defalias): Quote the function name in '(macro . function-name), since we eval it later. * test/lisp/emacs-lisp/bytecomp-tests.el (test-eager-load-macro-expand-defalias): New test. --- lisp/emacs-lisp/bytecomp.el | 3 ++- test/lisp/emacs-lisp/bytecomp-tests.el | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 0ec8db214bc..973792c4daa 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -5159,7 +5159,8 @@ byte-compile-file-form-defalias (pcase-let* ;; `macro' is non-nil if it defines a macro. ;; `fun' is the function part of `arg' (defaults to `arg'). - (((or (and (or `(cons 'macro ,fun) `'(macro . ,fun)) (let macro t)) + (((or (and (or `(cons 'macro ,fun) `'(macro . ,(app (list 'quote) fun))) + (let macro t)) (and (let fun arg) (let macro nil))) arg) ;; `lam' is the lambda expression in `fun' (or nil if not diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el index 8b0c1dad4c0..b14f10d6eb7 100644 --- a/test/lisp/emacs-lisp/bytecomp-tests.el +++ b/test/lisp/emacs-lisp/bytecomp-tests.el @@ -1322,6 +1322,24 @@ test-eager-load-macro-expand-lexical-override (defun def () (m)))) (should (equal (funcall 'def) 4))) +(ert-deftest test-eager-load-macro-expand-defalias () + (ert-with-temp-file elfile + :suffix ".el" + (write-region + (concat ";;; -*- lexical-binding: t -*-\n" + (mapconcat #'prin1-to-string + '((defalias 'nothing '(macro . ignore)) + (defalias 'something (cons 'macro #'identity)) + (defalias 'five (cons 'macro (lambda (&rest _) 5))) + (eval-when-compile + (defun def () (or (nothing t) (something (five nil)))))) + "\n")) + nil elfile) + (let* ((byte-compile-debug t) + (byte-compile-dest-file-function #'ignore)) + (byte-compile-file elfile) + (should (equal (funcall 'def) 5))))) + (defmacro bytecomp-tests--with-temp-file (file-name-var &rest body) (declare (indent 1)) (cl-check-type file-name-var symbol) -- 2.49.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sun Jun 15 01:25:27 2025 Received: (at 78792) by debbugs.gnu.org; 15 Jun 2025 05:25:27 +0000 Received: from localhost ([127.0.0.1]:52010 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uQfry-0003xJ-PR for submit@debbugs.gnu.org; Sun, 15 Jun 2025 01:25:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52696) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uQfrw-0003vx-8o for 78792@debbugs.gnu.org; Sun, 15 Jun 2025 01:25:25 -0400 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 1uQfrn-00021T-M2; Sun, 15 Jun 2025 01:25:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=E72ix+vR9l3iaRD3T7u21qtiYvKy55lLVIp/YSlsJEs=; b=CUrKYXvd2TiaDuk/vN+g bVOYCNOocffs/XAxe8uasVaIkXDBMtDTRvZ5xURjCDva8c+wEnklqJuQkTaIK1BbK1OKRMHIVLtv+ WlYPz3O8JdEA8lYrBTj9zxt2SDDaS8QTjKzhv/1YJAZ54ejtfdoMAt3IXIb+4euEGWor6rNXnHSxf OFJlEN1dj/torp8zFoIxRp5TuYvpS5D6LkK4iM7e/5cwqueUJ18qr/zV6uL5goZGNB+6o48/Z+9CR GpH5cvBok+sjLUhAAHDVWIr9HE0GF8Y0I5oTV5JqsyrBD2keIeLjFxiMI7OPxhTvG+ENyDroyZmOs 9TSWrKUjag3t1Q==; Date: Sun, 15 Jun 2025 08:25:11 +0300 Message-Id: <86cyb5r2yw.fsf@gnu.org> From: Eli Zaretskii To: zach shaftel , Stefan Monnier , Mattias =?iso-8859-1?Q?Engdeg=E5rd?= , Andrea Corallo In-Reply-To: <87qzzlpytj.fsf@shaf.tel> (bug-gnu-emacs@gnu.org) Subject: Re: bug#78792: [PATCH] Fix compilation of defalias with a constant macro cons pair References: <87qzzlpytj.fsf@shaf.tel> MIME-version: 1.0 Content-type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 78792 Cc: 78792@debbugs.gnu.org, shigeru.fukaya@gmail.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Cc: Shigeru Fukaya > Date: Sat, 14 Jun 2025 21:40:08 -0400 > From: zach shaftel via "Bug reports for GNU Emacs, > the Swiss army knife of text editors" > > byte-compile-file-form-defalias destructures (cons 'macro 'fn) and > '(macro . fn) the same way, so in the latter case fn would be unquoted, > and then eval would later signal (void-variable fn). this patch just > re-quotes fn, and adds a test for this scenario. Thanks, I've added the relevant people to this discussion, > In GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version > 3.24.49, cairo version 1.18.4) of 2025-06-11 built on bigbox > Repository revision: f90cee6f761b0c2bffcfa64556284884c0f7348f > Repository branch: feature/igc > System Description: Arch Linux > > Configured using: > 'configure --with-modules --with-native-compilation --with-tree-sitter > --without-gsettings --without-gconf --without-gpm --with-pgtk > --without-compress-install --with-mps 'CFLAGS=-mtune=native > -march=native -O3 -fuse-ld=mold'' > > >From f0b9f227c5711c1cbf7a38c20fd05b184536c12a Mon Sep 17 00:00:00 2001 > From: Zach Shaftel > Date: Sat, 14 Jun 2025 20:57:21 -0400 > > * lisp/emacs-lisp/bytecomp.el (byte-compile-file-form-defalias): Quote > the function name in '(macro . function-name), since we eval it later. > * test/lisp/emacs-lisp/bytecomp-tests.el > (test-eager-load-macro-expand-defalias): New test. > --- > lisp/emacs-lisp/bytecomp.el | 3 ++- > test/lisp/emacs-lisp/bytecomp-tests.el | 18 ++++++++++++++++++ > 2 files changed, 20 insertions(+), 1 deletion(-) > > diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el > index 0ec8db214bc..973792c4daa 100644 > --- a/lisp/emacs-lisp/bytecomp.el > +++ b/lisp/emacs-lisp/bytecomp.el > @@ -5159,7 +5159,8 @@ byte-compile-file-form-defalias > (pcase-let* > ;; `macro' is non-nil if it defines a macro. > ;; `fun' is the function part of `arg' (defaults to `arg'). > - (((or (and (or `(cons 'macro ,fun) `'(macro . ,fun)) (let macro t)) > + (((or (and (or `(cons 'macro ,fun) `'(macro . ,(app (list 'quote) fun))) > + (let macro t)) > (and (let fun arg) (let macro nil))) > arg) > ;; `lam' is the lambda expression in `fun' (or nil if not > diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el > index 8b0c1dad4c0..b14f10d6eb7 100644 > --- a/test/lisp/emacs-lisp/bytecomp-tests.el > +++ b/test/lisp/emacs-lisp/bytecomp-tests.el > @@ -1322,6 +1322,24 @@ test-eager-load-macro-expand-lexical-override > (defun def () (m)))) > (should (equal (funcall 'def) 4))) > > +(ert-deftest test-eager-load-macro-expand-defalias () > + (ert-with-temp-file elfile > + :suffix ".el" > + (write-region > + (concat ";;; -*- lexical-binding: t -*-\n" > + (mapconcat #'prin1-to-string > + '((defalias 'nothing '(macro . ignore)) > + (defalias 'something (cons 'macro #'identity)) > + (defalias 'five (cons 'macro (lambda (&rest _) 5))) > + (eval-when-compile > + (defun def () (or (nothing t) (something (five nil)))))) > + "\n")) > + nil elfile) > + (let* ((byte-compile-debug t) > + (byte-compile-dest-file-function #'ignore)) > + (byte-compile-file elfile) > + (should (equal (funcall 'def) 5))))) > + > (defmacro bytecomp-tests--with-temp-file (file-name-var &rest body) > (declare (indent 1)) > (cl-check-type file-name-var symbol) > -- > 2.49.0 > From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 18 04:11:23 2025 Received: (at 78792) by debbugs.gnu.org; 18 Jun 2025 08:11:23 +0000 Received: from localhost ([127.0.0.1]:44986 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uRntC-0003pg-Er for submit@debbugs.gnu.org; Wed, 18 Jun 2025 04:11:23 -0400 Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]:43254) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1uRnt8-0003od-Ix for 78792@debbugs.gnu.org; Wed, 18 Jun 2025 04:11:20 -0400 Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-553b9eb2299so487927e87.0 for <78792@debbugs.gnu.org>; Wed, 18 Jun 2025 01:11:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750234272; x=1750839072; darn=debbugs.gnu.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:sender:from:to:cc:subject :date:message-id:reply-to; bh=8EqRWsGtjdxarxPV5HoQv7VMIeX1LhYR6USEIBK9BNw=; b=lr+tSQKbrjafvD5U4PKK65hCCWoshPzh4efu/v6FOcEs+N6mHO/X2AusqZegm6cRxI 5/IkZKXHbYKJ9tyM0I1EoUkjD7WIBAmyigJjNYPdxvS7ASt2Y8WYqNrQxzgzKlm9469R vd488jh4TDSfRk8l351qdJwuQyL3eEw4A3XSXRzfM4Zkj6KIEDtfMxxnnUfGWu3McMXa l4fcVDRmId8Qe3RI4Xeyp7OyVhe7td6DMJhXeFBtM3XTx78lz8hG8vC0/UApu9C3/7tg ql5vsZYccPKgKkr0tAEXAu+KtQ9ABTDoadKTzvb6KjcFxzzsrhDt2pLU764PhDY+8Snt Cnyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750234272; x=1750839072; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:sender:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=8EqRWsGtjdxarxPV5HoQv7VMIeX1LhYR6USEIBK9BNw=; b=kP1/jfz4lzVwWYiNATKpJvFS+tzVKmkHBDuoqu7UxTw2Gpn4fj4/G0nq0MIuQY7c2R 3s00l7Wh/Q4cUNoneHAauNZKsDiz+HeZisZPw4x1UKg71l7IEfrfGhHUk5UDZ8qoY/m8 L62UUZ6QInnVrcQR1hlBB/6lJ1lN/OfiNlEMGJ0+gzFfqeBYbU32xdzynIbhZjLKXcSl osbCF/Kz9heuMTWgNMy0GAVVq1XggUcaqJdpIYcOipLeHdWMJHhCRxiXtxcHIq4x6Uy/ sTqohnbNJejmbthiqXLYii42DAUq+sjX4qc6ci8d+BoLhbMV9Na+SVrYsUpzw3y8P5KE B/1Q== X-Forwarded-Encrypted: i=1; AJvYcCVF3OLJ6mgc5J4aRG62kdQF1TMBVm/WJQUx84CJYBQePeBbTCMGqQMBx1Sf+vC4q00tQhKimA==@debbugs.gnu.org X-Gm-Message-State: AOJu0Yz9RvdnAC4o6rFSVv//cK7HM9bBgAHSsiKq60aDaGfsV64vrs2F r4/7l9b/UZ6A8RJC5I5t6Ov1VrnI+WtgpBvZiyPtJj1JKjcxtC8x9jWV X-Gm-Gg: ASbGnctacr1rA2CfoJELt2Uw2ScYwo1OLgiHM0+jo8+XhhxVyjueka3pgF4nTnwD0tD lul7dMQV5KRZJ2xY2uDhn3AuAl0E0bv/+ejbs0ii5E5/yXKir6urEkObc1zVURpzo0/Jfliq6qY Gyttvcw2PHWax2YpgJwAyaTQGhZ01SRnDqcHId0s3O0x9h15DyiHkhHOCfEkxrW8BXEXpKjRRBo 16OXVxbKrLGO4R13yQDTvKpPFy3KPmrYVq5KdgFP2XFBk/8ywqiewbBxAjCsPiqgCbDsNVwXnYn 7+4XJ6WTL+sO0/PJEmai3AIPTPh/jURwNA097d2ytvAXuOZE4kZUb+Lsb9AzMZE3XaeeViLyJbi VoQO6snD+2GM9mT5e4y9wAOmx+zPfmFFw/G4tKUrdzSN2trfxV6qU X-Google-Smtp-Source: AGHT+IHr0XJ2KY/ynXjji35KQ9hNoQDFWK//ytytfF7+k58KCZMuk3lIvr5v0lAszscNAHTrciNDRA== X-Received: by 2002:a05:6512:3b09:b0:54a:c4af:15 with SMTP id 2adb3069b0e04-553d393e2fdmr590041e87.19.1750234271667; Wed, 18 Jun 2025 01:11:11 -0700 (PDT) Received: from smtpclient.apple (c188-150-186-155.bredband.tele2.se. [188.150.186.155]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-553ac1aad39sm2194762e87.116.2025.06.18.01.11.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jun 2025 01:11:11 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\)) Subject: Re: bug#78792: [PATCH] Fix compilation of defalias with a constant macro cons pair From: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= In-Reply-To: <86cyb5r2yw.fsf@gnu.org> Date: Wed, 18 Jun 2025 10:11:09 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: <957BA8B2-DB12-406B-884F-FE1736751683@gmail.com> References: <87qzzlpytj.fsf@shaf.tel> <86cyb5r2yw.fsf@gnu.org> To: Eli Zaretskii X-Mailer: Apple Mail (2.3654.120.0.1.15) X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 78792 Cc: shigeru.fukaya@gmail.com, Andrea Corallo , Stefan Monnier , zach shaftel , 78792@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) >> byte-compile-file-form-defalias destructures (cons 'macro 'fn) and >> '(macro . fn) the same way, so in the latter case fn would be = unquoted, >> and then eval would later signal (void-variable fn). this patch just >> re-quotes fn, and adds a test for this scenario. This seems to be a genuine bug indeed, thank you for reporting. >> @@ -5159,7 +5159,8 @@ byte-compile-file-form-defalias >> (pcase-let* >> ;; `macro' is non-nil if it defines a macro. >> ;; `fun' is the function part of `arg' (defaults to = `arg'). >> - (((or (and (or `(cons 'macro ,fun) `'(macro . ,fun)) (let = macro t)) >> + (((or (and (or `(cons 'macro ,fun) `'(macro . ,(app (list = 'quote) fun))) >> + (let macro t)) >> (and (let fun arg) (let macro nil))) Patch looks fine as far as I can tell. There is a test (naturally!) as = well. From debbugs-submit-bounces@debbugs.gnu.org Thu Jun 19 09:41:59 2025 Received: (at 78792) by debbugs.gnu.org; 19 Jun 2025 13:42:00 +0000 Received: from localhost ([127.0.0.1]:33675 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uSFWg-0006eQ-6m for submit@debbugs.gnu.org; Thu, 19 Jun 2025 09:41:59 -0400 Received: from mail-4316.protonmail.ch ([185.70.43.16]:21771) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uSFWc-0006co-6Q for 78792@debbugs.gnu.org; Thu, 19 Jun 2025 09:41:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1750340507; x=1750599707; bh=S2o9g0T4SuLhcbbSC2OxqkU9eAJHY/Yh2OvWkYGOMew=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=zgao1LP8yUXYBBBUS+3IKUwwGP/0awBfHt3rsxw1GOius6I+UgWtb5QmnDZpDejR4 tWNVubXvitKtM2H+4lqTXlv9bTANk5NxUMt8wt+/tYm73gic/n0WjJtuLXH/D6aafy pftu06+zPWia7UHRFo+H96csPHviArBK+OxMWPU3EuUQEIrZ+xIgGLToreDWoncxqd jDvB2AyBdamiVjSN1q+T6+xvDB15Lj666r1+/g+oXqcuWLMUf1eYr1GntngCBx0IEk acj3wHgmqvUU1albzSNqtRSDsxJiLS2+GPPsnZu5k1hKIPPTanLsoHhkhLf8BEZ8fo O8Ea9uXN63a+g== Date: Thu, 19 Jun 2025 13:41:41 +0000 To: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= From: Pip Cet Subject: Re: bug#78792: [PATCH] Fix compilation of defalias with a constant macro cons pair Message-ID: <87plezrgq9.fsf@protonmail.com> In-Reply-To: <957BA8B2-DB12-406B-884F-FE1736751683@gmail.com> References: <87qzzlpytj.fsf@shaf.tel> <86cyb5r2yw.fsf@gnu.org> <957BA8B2-DB12-406B-884F-FE1736751683@gmail.com> Feedback-ID: 112775352:user:proton X-Pm-Message-ID: b49d70a3816134213be24a954c1f7985346ebd9d MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 78792 Cc: 78792@debbugs.gnu.org, shigeru.fukaya@gmail.com, zach shaftel , Stefan Monnier , Eli Zaretskii , Andrea Corallo X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Mattias Engdeg=C3=A5rd writes: >>> byte-compile-file-form-defalias destructures (cons 'macro 'fn) and >>> '(macro . fn) the same way, so in the latter case fn would be unquoted, >>> and then eval would later signal (void-variable fn). this patch just >>> re-quotes fn, and adds a test for this scenario. > > This seems to be a genuine bug indeed, thank you for reporting. Did this occur in the wild or do you have to trigger it deliberately? I don't think defmacro ever produces a problematic defalias, but maybe some other macro does? That's just curiosity, of course. Both the analysis and the patch seem correct to me. >>> @@ -5159,7 +5159,8 @@ byte-compile-file-form-defalias >>> (pcase-let* >>> ;; `macro' is non-nil if it defines a macro. >>> ;; `fun' is the function part of `arg' (defaults to `arg'). >>> - (((or (and (or `(cons 'macro ,fun) `'(macro . ,fun)) (let m= acro t)) >>> + (((or (and (or `(cons 'macro ,fun) `'(macro . ,(app (list '= quote) fun))) >>> + (let macro t)) >>> (and (let fun arg) (let macro nil))) > > Patch looks fine as far as I can tell. There is a test (naturally!) as we= ll. TBH, I had to look up the (app F X) pcase pattern. I think that means we should use it more, not less, so people will become used to it and stop emulating it badly, which is what I've done so far... The rest of this email is relevant only because we should maybe just delete this code instead of fixing it: We should have a hard look at whether this function makes sense in its current form: if we can't parse/compile a defalias form, and it defined a function, that's okay. But if we can't compile it and it defined a macro, shouldn't that be a fatal error? And since we can't tell whether a Lisp expression evaluates to a macro definition or a function definition, maybe it's time to handle the remaining common cases only and make the rest errors (which is okay, not every conceivable Elisp program can be byte-compiled)? Here's an example which we miscompile (make sure NOT to evaluate this in the session which then compiles it): ;; -*- lexical-binding: t; -*- (defalias 'mybq3 (symbol-function '\`)) (message "%S" (mybq3 (,3))) Pip From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 21 04:41:57 2025 Received: (at 78792-done) by debbugs.gnu.org; 21 Jun 2025 08:41:57 +0000 Received: from localhost ([127.0.0.1]:33650 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uStnP-00075i-MR for submit@debbugs.gnu.org; Sat, 21 Jun 2025 04:41:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50160) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uStnM-00074U-LK for 78792-done@debbugs.gnu.org; Sat, 21 Jun 2025 04:41:53 -0400 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 1uStnG-0007KE-Ka; Sat, 21 Jun 2025 04:41:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=Dl023BEg+35fquFi0XkASOqneKOudgt2WhJ5Rv5taT0=; b=H5Zof5LgJqjotV9FXfNL GvxxeYFmEbhoXB6Ej6k0TJbJVUfREsz24q1xHq4CTbVt88N862xL5juM69468leeEIY8n60JvsYhy 12k/moasMyGKB2tD/15+8DkWEQSvFnWiVG52c5vpYwh1VAwqY7qg293scM8ouwMoDV0S6KzzjrzjD RdTKMtdadVV9q5FzoWPdZzUDpb9L1pa/6zXSSyOkVC57MQV+e1pRqevpnTgNE2C7uBhcBKnOPXBFN Iqz8kWSqJovLFutVxDhr9o4tgOH6UgIymuxuqhHDsqch1Yeg1xusC0mw+9emH7hnWTcKSelsfrgoJ e6GdKpRvrnb19g==; Date: Sat, 21 Jun 2025 11:41:42 +0300 Message-Id: <868qlljxkp.fsf@gnu.org> From: Eli Zaretskii To: Mattias =?utf-8?Q?Engdeg=C3=A5rd?= In-Reply-To: <957BA8B2-DB12-406B-884F-FE1736751683@gmail.com> (message from Mattias =?utf-8?Q?Engdeg=C3=A5rd?= on Wed, 18 Jun 2025 10:11:09 +0200) Subject: Re: bug#78792: [PATCH] Fix compilation of defalias with a constant macro cons pair References: <87qzzlpytj.fsf@shaf.tel> <86cyb5r2yw.fsf@gnu.org> <957BA8B2-DB12-406B-884F-FE1736751683@gmail.com> MIME-version: 1.0 Content-type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 78792-done Cc: shigeru.fukaya@gmail.com, acorallo@gnu.org, monnier@iro.umontreal.ca, zach@shaf.tel, 78792-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Mattias EngdegÄrd > Date: Wed, 18 Jun 2025 10:11:09 +0200 > Cc: zach shaftel , > Stefan Monnier , > Andrea Corallo , > 78792@debbugs.gnu.org, > shigeru.fukaya@gmail.com > > >> byte-compile-file-form-defalias destructures (cons 'macro 'fn) and > >> '(macro . fn) the same way, so in the latter case fn would be unquoted, > >> and then eval would later signal (void-variable fn). this patch just > >> re-quotes fn, and adds a test for this scenario. > > This seems to be a genuine bug indeed, thank you for reporting. > > >> @@ -5159,7 +5159,8 @@ byte-compile-file-form-defalias > >> (pcase-let* > >> ;; `macro' is non-nil if it defines a macro. > >> ;; `fun' is the function part of `arg' (defaults to `arg'). > >> - (((or (and (or `(cons 'macro ,fun) `'(macro . ,fun)) (let macro t)) > >> + (((or (and (or `(cons 'macro ,fun) `'(macro . ,(app (list 'quote) fun))) > >> + (let macro t)) > >> (and (let fun arg) (let macro nil))) > > Patch looks fine as far as I can tell. There is a test (naturally!) as well. Thanks for the review; now installed on the master branch, and closing the bug.