From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tom Breton Newsgroups: gmane.emacs.bugs Subject: bug#5728: Byte compile doesn't work right on macro Date: Mon, 15 Mar 2010 22:25:51 -0400 Message-ID: NNTP-Posting-Host: lo.gmane.org X-Trace: dough.gmane.org 1268833080 11785 80.91.229.12 (17 Mar 2010 13:38:00 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 17 Mar 2010 13:38:00 +0000 (UTC) To: 5728@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Mar 17 14:37:55 2010 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1NrtRa-0007cw-Tg for geb-bug-gnu-emacs@m.gmane.org; Wed, 17 Mar 2010 14:37:55 +0100 Original-Received: from localhost ([127.0.0.1]:52608 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NrtRa-0006cT-4j for geb-bug-gnu-emacs@m.gmane.org; Wed, 17 Mar 2010 09:37:54 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NrMw1-0003gj-7X for bug-gnu-emacs@gnu.org; Mon, 15 Mar 2010 22:55:09 -0400 Original-Received: from [140.186.70.92] (port=53510 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NrMvo-0003fY-Ey for bug-gnu-emacs@gnu.org; Mon, 15 Mar 2010 22:55:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NrMvg-0005Mm-61 for bug-gnu-emacs@gnu.org; Mon, 15 Mar 2010 22:54:49 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:45354) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NrMvg-0005Mc-2X for bug-gnu-emacs@gnu.org; Mon, 15 Mar 2010 22:54:48 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1NrMeT-0001K0-Ut; Mon, 15 Mar 2010 22:37:01 -0400 X-Loop: bug-gnu-emacs@gnu.org Resent-From: Tom Breton Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 16 Mar 2010 02:37:01 +0000 Resent-Message-ID: Resent-Sender: bug-gnu-emacs@gnu.org X-GNU-PR-Message: report 5728 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.12687069975037 (code B ref -1); Tue, 16 Mar 2010 02:37:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 16 Mar 2010 02:36:37 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NrMe2-0001JC-M8 for submit@debbugs.gnu.org; Mon, 15 Mar 2010 22:36:36 -0400 Original-Received: from mail.gnu.org ([199.232.76.166] helo=mx10.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NrMTp-0001F8-ON for submit@debbugs.gnu.org; Mon, 15 Mar 2010 22:26:04 -0400 Original-Received: from lists.gnu.org ([199.232.76.165]:47635) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NrMTm-00067k-1W for submit@debbugs.gnu.org; Mon, 15 Mar 2010 22:25:58 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NrMTl-0006gI-Ck for bug-gnu-emacs@gnu.org; Mon, 15 Mar 2010 22:25:57 -0400 Original-Received: from [140.186.70.92] (port=52411 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NrMTj-0006eL-SM for bug-gnu-emacs@gnu.org; Mon, 15 Mar 2010 22:25:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NrMTi-0003UF-AS for bug-gnu-emacs@gnu.org; Mon, 15 Mar 2010 22:25:55 -0400 Original-Received: from mail2.panix.com ([166.84.1.73]:61149) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NrMTi-0003UB-7X for bug-gnu-emacs@gnu.org; Mon, 15 Mar 2010 22:25:54 -0400 Original-Received: from mailbackend.panix.com (mailbackend.panix.com [166.84.1.89]) by mail2.panix.com (Postfix) with ESMTP id 75DA638E4D for ; Mon, 15 Mar 2010 22:25:53 -0400 (EDT) Original-Received: from localhost (pool-96-252-49-112.bstnma.fios.verizon.net [96.252.49.112]) by mailbackend.panix.com (Postfix) with ESMTP id 56E932FD44 for ; Mon, 15 Mar 2010 22:25:53 -0400 (EDT) Original-Received: from tehom by localhost with local (Exim 4.69) (envelope-from ) id 1NrMTf-0000f5-TZ for bug-gnu-emacs@gnu.org; Mon, 15 Mar 2010 22:25:51 -0400 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Mailman-Approved-At: Mon, 15 Mar 2010 22:36:33 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Mon, 15 Mar 2010 22:37:01 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Mailman-Approved-At: Wed, 17 Mar 2010 09:37:49 -0400 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: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:35608 Archived-At: When I byte-compile certain code, the results are different than when it's not byte-compiled. It seems to wrongly merge lists. The one unusual thing I was doing with the code is using a macro to generate a call to a ctor (as generated by defstruct) I have attached two elisp files which demonstrate the buggy behavior. The first, "byte-compile-bug.el", is meant to be alternately loaded plain or loaded byte-compiled. The second, "demo-byte-compile-bug.el" is partly a script which demonstartes that the behavior is indeed different when byte-compiled, and partly a collection of (quote-protected) calls to slightly different examples of the bug and examples of similar code which does not exhibit the bug, all defined in the first file. In GNU Emacs 22.2.1 (i486-pc-linux-gnu, X toolkit, Xaw3d scroll bars) of 2008-11-09 on raven, modified by Debian Windowing system distributor `The X.Org Foundation', version 11.0.10402000 configured using `configure '--build=i486-linux-gnu' '--host=i486-linux-gnu' '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib' '--localstatedir=/var/lib' '--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-pop=yes' '--enable-locallisppath=/etc/emacs22:/etc/emacs:/usr/local/share/emacs/22.2/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/22.2/site-lisp:/usr/share/emacs/site-lisp:/usr/share/emacs/22.2/leim' '--with-x=yes' '--with-x-toolkit=athena' '--with-toolkit-scroll-bars' 'build_alias=i486-linux-gnu' 'host_alias=i486-linux-gnu' 'CFLAGS=-DDEBIAN -g -O2' 'LDFLAGS=-g' 'CPPFLAGS='' Important settings: value of $LC_ALL: nil value of $LC_COLLATE: nil value of $LC_CTYPE: nil value of $LC_MESSAGES: nil value of $LC_MONETARY: nil value of $LC_NUMERIC: nil value of $LC_TIME: nil value of $LANG: nil locale-coding-system: nil default-enable-multibyte-characters: t Major mode: Lisp Interaction Minor modes in effect: tooltip-mode: t tool-bar-mode: t mouse-wheel-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t unify-8859-on-encoding-mode: t utf-translate-cjk-mode: t auto-compression-mode: t line-number-mode: t Recent input: M-x r e p o r t Recent messages: ("emacs" "-Q") For information about GNU Emacs and the GNU system, type C-h C-a. Making completion list... Loading help-mode...done Loading emacsbug... Loading regexp-opt...done Loading emacsbug...done next-history-element: Beginning of history; no preceding item ===File ~/projects/elisp/bugs/byte-compile-bug.el============ ;;;_ byte-compile-bug.el --- File to reproduce byte-compile bug ;;;_. Headers ;;;_ , Commentary: ;;Bug report by Tom Breton (Tehom) ;; The bug seems to involve: ;; defstruct ;; macro that builds a ctor. ;; a while loop ;; The byte compiler ;;Observe that it occurs only in compiled code. ;;The macro is made by defmacro* but the same occurs with defmacro ;;feeding defun* ;;;_ , Requires (eval-when-compile (require 'cl)) ;;;_. Body ;;;_ , Type (defstruct (BUG:structure (:conc-name BUG:structure->) (:constructor BUG:make-structure)) "An ADT make by defstruct" edits a) ;;;_ , BUG:helper (defun BUG:helper (accessor oobj form) "" (subst (list accessor oobj) '-old- (copy-tree form))) (defmacro* BUG:make-form (oobj &key edits a) "Construct an BUG:structure object adapted from CAND. Syntax is almost that of a ctor, but in each form, the symbol `-old-' is replaced by the value of the respective field of OOBJ." `(BUG:make-structure :edits ,(BUG:helper 'BUG:structure->edits oobj edits) :a ,(BUG:helper 'BUG:structure->a oobj a))) ;;;_ , BUG (defun BUG (a) "Contains a bug involving the byte-compiler" (let ( (cand (BUG:make-structure :edits '() :a a))) (catch 'BUG:answer (while t (let ( (a (BUG:structure->a cand))) (unless a (throw 'BUG:answer (reverse (BUG:structure->edits cand)))) (setq cand (BUG:make-form cand :edits (cons (car a) -old-) :a (cdr -old-)))))))) (defun BUG-2 (a) "Equivalent to BUG except no catch/throw. Still a bug." (let ( (done nil) (cand (BUG:make-structure :edits '() :a a))) (while (not done) (let ( (a (BUG:structure->a cand))) (if a (setq cand (BUG:make-form cand :edits (cons (car a) -old-) :a (cdr -old-))) (setq done t)))) (reverse (BUG:structure->edits cand)))) (defun BUG-3 (a) "Equivalent to BUG. Also buggy, slightly different manifestation. Slightly different form not involving the second field `a' of BUG:structure." (let ( (cand (BUG:make-structure :edits '()))) (catch 'BUG:answer (while t (unless a (throw 'BUG:answer (reverse (BUG:structure->edits cand)))) (setq cand (BUG:make-form cand :edits (cons (car a) -old-))) (pop a))))) (defun BUG-4 (a) "Equivalent to BUG. Also buggy, slightly different manifestation. Slightly different form not directly using a while loop." (let ( (cand (BUG:make-structure :edits '()))) (dotimes (i (length a)) (setq cand (BUG:make-form cand :edits (cons (car a) -old-))) (pop a)) (reverse (BUG:structure->edits cand)))) (defun NOBUG (a) "Equivalent to BUG. This form extracts elements from list `a' before using them. No buggy behavior." (let ( (cand (BUG:make-structure :edits '() :a a))) (catch 'BUG:answer (progn (dolist (x a) (setq cand (BUG:make-form cand :edits (cons x -old-) :a (cdr -old-)))) (throw 'BUG:answer (reverse (BUG:structure->edits cand))))))) (defun NOBUG-2 (a) "Equivalent to BUG except doesn't use the second field `a' of BUG:structure and extracts elements from list `a' before using them. No buggy behavior." (let ( (cand (BUG:make-structure :edits '()))) (catch 'BUG:answer (while t (let ((x (pop a))) (unless x (throw 'BUG:answer (reverse (BUG:structure->edits cand)))) (setq cand (BUG:make-form cand :edits (cons x -old-)))))))) ;;;_. Footers ;;;_ , Provides (provide 'byte-compile-bug) ;;;_ * Local emacs vars. ;;;_ + Local variables: ;;;_ + mode: allout ;;;_ + End: ;;;_ , End ;;; byte-compile-bug.el ends here ============================================================ ===File ~/projects/elisp/bugs/demo-byte-compile-bug.el====== ;;File to demonstrate this bug. eval-buffer to see it. Also various ;;examples of it are included for easy C-x C-e exploration. (defun BUG:assert-works-ok (str) "" (message str) (assert (equal (BUG '(a b c d)) '(a b c d)) t)) (progn (load-file "byte-compile+cl.el") (BUG:assert-works-ok "Uncompiled version works OK") (byte-compile-file "byte-compile+cl.el") (load-file "byte-compile+cl.elc") (BUG:assert-works-ok "Compiled version doesn't")) ;;For comparison: ;;Buggy equivalents ' (assert (equal (BUG-2 '(a b c d)) '(a b c d)) t) ' (assert (equal (BUG-3 '(a b c d)) '(a b c d)) t) ' (assert (equal (BUG-4 '(a b c d)) '(a b c d)) t) ;;Non-buggy equivalents ' (assert (equal (NOBUG '(a b c d)) '(a b c d)) t) ' (assert (equal (NOBUG-2 '(a b c d)) '(a b c d)) t)============================================================