From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Robert Cochran Newsgroups: gmane.emacs.bugs Subject: bug#31718: 26.1; Strange behavior of `cond' Date: Wed, 06 Jun 2018 00:41:50 -0700 Message-ID: <87wovc8ipt.fsf@cochranmail.com> References: <37954.1528179962@localhost> <46058.1528263715@localhost> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1528270875 15221 195.159.176.226 (6 Jun 2018 07:41:15 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 6 Jun 2018 07:41:15 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: Andreas Schwab , 31718@debbugs.gnu.org, Vibhav Pant To: Ikumi Keita Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jun 06 09:41:10 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fQT45-0003gj-1l for geb-bug-gnu-emacs@m.gmane.org; Wed, 06 Jun 2018 09:41:05 +0200 Original-Received: from localhost ([::1]:50725 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQT6A-0005mI-CE for geb-bug-gnu-emacs@m.gmane.org; Wed, 06 Jun 2018 03:43:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44626) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQT61-0005lE-Jt for bug-gnu-emacs@gnu.org; Wed, 06 Jun 2018 03:43:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fQT5y-0001ZA-Fv for bug-gnu-emacs@gnu.org; Wed, 06 Jun 2018 03:43:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:56159) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fQT5y-0001Yd-8g for bug-gnu-emacs@gnu.org; Wed, 06 Jun 2018 03:43:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fQT5y-0002Zg-1s for bug-gnu-emacs@gnu.org; Wed, 06 Jun 2018 03:43:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Robert Cochran Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 06 Jun 2018 07:43:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 31718 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 31718-submit@debbugs.gnu.org id=B31718.15282709239816 (code B ref 31718); Wed, 06 Jun 2018 07:43:02 +0000 Original-Received: (at 31718) by debbugs.gnu.org; 6 Jun 2018 07:42:03 +0000 Original-Received: from localhost ([127.0.0.1]:35823 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fQT51-0002YG-5h for submit@debbugs.gnu.org; Wed, 06 Jun 2018 03:42:03 -0400 Original-Received: from vps28183.inmotionhosting.com ([23.235.221.66]:29587) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fQT4z-0002Xj-7s for 31718@debbugs.gnu.org; Wed, 06 Jun 2018 03:42:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=cochranmail.com; s=default; h=Content-Type:MIME-Version:Message-ID: In-Reply-To:Date:References:Subject:Cc:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=5GU5l+iEYj1NbvCo/nGOrTJO8SHQe/M/e/Uy+mJTXiQ=; b=3HJaTJej7LxwRonVySKHIrg4I jITcnv/I6l7nsqOu9ofKPUTMvnIe3cB5HrLWOAWKeA70XNRBx+bQvbPQxp9o1NLAxYw1571uJV/VU PNFkrNvUTP5fOqo7LhdMX1J1JGgT4gQ6yGVBcmE1rIaNBn4xUBonFVxOG4T/LZfWZ+x/DOhkM+uUX IYOVNoKjI9vt/5x2yDxdr/jh5njBkpqao4ZX3PFl8Nb7n82cZ7qT6YPbOlcGZdKOCi1zyGA8X86Np /PK2Ab4Gvtftf+J58/JL6Qf1j3CjFWkg+MgSOl3Ap+JNeWjQnBWcDgvvcTLF/Kis7Gk1drKHfHqDU tGJOyLiqw==; Original-Received: from 131-191-86-130.as.clicknet.org ([131.191.86.130]:42516 helo=SoraLaptop) by vps28183.inmotionhosting.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fQT4s-0002WJ-2h; Wed, 06 Jun 2018 00:41:54 -0700 In-Reply-To: <46058.1528263715@localhost> (Ikumi Keita's message of "Wed, 06 Jun 2018 14:41:55 +0900") X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - vps28183.inmotionhosting.com X-AntiAbuse: Original Domain - debbugs.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - cochranmail.com X-Get-Message-Sender-Via: vps28183.inmotionhosting.com: authenticated_id: robert@cochranmail.com X-Authenticated-Sender: vps28183.inmotionhosting.com: robert@cochranmail.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:147078 Archived-At: --=-=-= Content-Type: text/plain Ikumi Keita writes: > Hi Andreas, thanks for your reply. > >>>>>> Andreas Schwab writes: >> On Jun 05 2018, Ikumi Keita wrote: >>> (defun xyz (arg) >>> "dummy" >>> ; (cond ((eq arg nil) ; OK >>> ; (cond ((eq arg 'abc) ; OK >>> ; (cond ((eq arg 'def) ; OK >>> (cond ((eq arg 'default) ; NG > >> The byte-compiler uses 'default as a magic symbol, which breaks this >> case. > > Does this mean that this behavior is a (new) designed feature of elisp > and not a bug? > If so, is it the respoisibility of the authors of the codes to rewrite > not to use `default' or else to make sure to set > `byte-compile-cond-use-jump-table' to nil at byte compile? I for one consider this a bug, for 2 reasons: 1) It's not reasonable to expect a Lisp programmer to just know that using the symbol default is problematic. 2) It creates diverging behavior between compiled and non-compiled Lisp. To that end, I've made a small patch to rectify the behavior. Instead of hardcoding a symbol, it uses gensym to create a unique one. I did a full build of Emacs, as well as ran 'make check' and had identical results pre- and post-change, so I'm reasonably sure it's correct. Comments and corrections are of course welcomed. HTH, -- ~Robert Cochran GPG Fingerprint - BD0C 5F8B 381C 64F0 F3CE E7B9 EC9A 872C 41B2 77C2 ----- --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Use-a-gensym-for-the-default-case-in-byte-compile-co.patch Content-Description: Use a gensym for byte compiler cond switch >From 4a025170b2b293810cf03c964b402963495fe7d7 Mon Sep 17 00:00:00 2001 From: Robert Cochran Date: Wed, 6 Jun 2018 00:31:25 -0700 Subject: [PATCH] Use a gensym for the default case in byte-compile-cond-jump-table * lisp/bytecomp.el (byte-compile-cond-jump-table): Create gensym to use as default case symbol (byte-compile-cond-jump-table-info): new argument `default-sym'; use it when generating default case clause --- lisp/emacs-lisp/bytecomp.el | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index ad6b5b7ce2..0fedfd0868 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -4092,7 +4092,7 @@ byte-compile-cond-vars (and (symbolp obj1) (macroexp-const-p obj2) (cons obj1 obj2)) (and (symbolp obj2) (macroexp-const-p obj1) (cons obj2 obj1)))) -(defun byte-compile-cond-jump-table-info (clauses) +(defun byte-compile-cond-jump-table-info (clauses default-sym) "If CLAUSES is a `cond' form where: The condition for each clause is of the form (TEST VAR VALUE). VAR is a variable. @@ -4124,14 +4124,15 @@ byte-compile-cond-jump-table-info (not (assq obj2 cases))) (push (list (if (consp obj2) (eval obj2) obj2) body) cases) (if (and (macroexp-const-p condition) condition) - (progn (push (list 'default (or body `(,condition))) cases) + (progn (push (list default-sym (or body `(,condition))) cases) (throw 'break t)) (setq ok nil) (throw 'break nil)))))) (list (cons prev-test prev-var) (nreverse cases))))) (defun byte-compile-cond-jump-table (clauses) - (let* ((table-info (byte-compile-cond-jump-table-info clauses)) + (let* ((default-sym (gensym "byte-compile--cond-default-sym")) + (table-info (byte-compile-cond-jump-table-info clauses default-sym)) (test (caar table-info)) (var (cdar table-info)) (cases (cadr table-info)) @@ -4141,7 +4142,7 @@ byte-compile-cond-jump-table ;; set it to `t' for cond forms with a small number of cases. (setq jump-table (make-hash-table :test test :purecopy t - :size (if (assq 'default cases) + :size (if (assq default-sym cases) (1- (length cases)) (length cases))) default-tag (byte-compile-make-tag) @@ -4175,8 +4176,8 @@ byte-compile-cond-jump-table (let ((byte-compile-depth byte-compile-depth)) (byte-compile-goto 'byte-goto default-tag)) - (when (assq 'default cases) - (setq default-case (cadr (assq 'default cases)) + (when (assq default-sym cases) + (setq default-case (cadr (assq default-sym cases)) cases (butlast cases 1))) (dolist (case cases) -- 2.17.1 --=-=-=--