From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Zack Weinberg Newsgroups: gmane.emacs.devel Subject: Re: byte-opt.el addition - optimize list of compile-time constants Date: Wed, 08 Dec 2004 14:47:36 -0800 Message-ID: <87llc8tnjr.fsf@codesourcery.com> References: <87u0qxgn65.fsf@codesourcery.com> <878y88hazn.fsf@codesourcery.com> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1102546115 24834 80.91.229.6 (8 Dec 2004 22:48:35 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 8 Dec 2004 22:48:35 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Dec 08 23:48:29 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1CcAbl-0002iE-00 for ; Wed, 08 Dec 2004 23:48:29 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CcAlc-0005MW-Sz for ged-emacs-devel@m.gmane.org; Wed, 08 Dec 2004 17:58:40 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1CcAlH-0005KF-5G for emacs-devel@gnu.org; Wed, 08 Dec 2004 17:58:19 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1CcAlF-0005J8-Mw for emacs-devel@gnu.org; Wed, 08 Dec 2004 17:58:18 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CcAlF-0005Iy-Iu for emacs-devel@gnu.org; Wed, 08 Dec 2004 17:58:17 -0500 Original-Received: from [65.74.133.9] (helo=mail.codesourcery.com) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.34) id 1CcAaw-0005Sd-1B for emacs-devel@gnu.org; Wed, 08 Dec 2004 17:47:38 -0500 Original-Received: (qmail 16307 invoked from network); 8 Dec 2004 22:47:36 -0000 Original-Received: from localhost (HELO taltos.codesourcery.com) (zack@127.0.0.1) by mail.codesourcery.com with SMTP; 8 Dec 2004 22:47:36 -0000 Original-Received: by taltos.codesourcery.com (sSMTP sendmail emulation); Wed, 8 Dec 2004 14:47:36 -0800 Original-To: Stefan Monnier In-Reply-To: (Stefan Monnier's message of "Wed, 08 Dec 2004 14:27:04 -0500") User-Agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3 (gnu/linux) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:30898 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:30898 Stefan Monnier writes: >> I seriously wonder how much would break if this optimization were >> implemented for 'list'. My suspicion is that people don't commonly >> apply 'eq' to lists in the first place. > > Well, try it: > > (put 'list 'byte-optimizer 'byte-optimize-pure-func) > (put 'list* 'byte-optimizer 'byte-optimize-pure-func) > (put 'cons 'byte-optimizer 'byte-optimize-pure-func) > (put 'append 'byte-optimizer 'byte-optimize-pure-func) I checked out CVS Emacs and tried this, and it fails catastrophically during bootstrap; so I guess my intuition was wrong. Optimizing list or append with byte-optimize-pure-func causes errors like the following: In byte-optimize-lapcode: byte-opt.el:1748:45:Warning: `t' called as a function byte-opt.el:1970:52:Warning: `nil' called as a function In end of data: byte-opt.el:2044:1:Warning: the following functions are not known to be defined: t, nil and optimizing cons causes In toplevel form: ../../emacs/lisp/emacs-lisp/byte-opt.el:1508:45:Error: Wrong type argument: sequencep, 0 -- both of these are from compiling byte-opt.el from 'make bootstrap'. I'm interested in debugging this, but I don't know how to proceed. I'll also point out that this does not solve the problem I am interested in solving; with list optimized via byte-optimize-pure-func, debug-on-entry byte-optimize-pure-func and then execute (disassemble (lambda nil `(:a 1 :b 2 :c #'(lambda nil (when (eq (following-char) ?\n) (forward-char 1)))))) and (disassemble (lambda nil `(:a 1 :b 2 :c ,#'(lambda nil (when (eq (following-char) ?\n) (forward-char 1)))))) In the first case, byte-optimize-pure-func is never called and the inner function is not compiled (I assume this is because ` is being optimized to ' when there is no , or ,@ anywhere in its form). In the second place, byte-optimize-pure-func is called, but the optimization fails because a (function ...) form appears inside the arguments to list, which does not count as byte-compile-constp. This is the other problem I mentioned earlier - at the point at which the 'byte-optimizer function for list is called, the inner function has not yet been compiled, contrary to the general principle that the byte optimizer operates depth-first. zw