From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: byte-opt.el addition - optimize list of compile-time constants Date: Wed, 08 Dec 2004 11:56:49 -0500 Message-ID: References: <87u0qxgn65.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 1102526453 30560 80.91.229.6 (8 Dec 2004 17:20:53 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 8 Dec 2004 17:20:53 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Dec 08 18:20:45 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 1Cc5Ua-0004vw-00 for ; Wed, 08 Dec 2004 18:20:44 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1Cc5eR-0000jF-Md for ged-emacs-devel@m.gmane.org; Wed, 08 Dec 2004 12:30:55 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1Cc5TA-00061i-HX for emacs-devel@gnu.org; Wed, 08 Dec 2004 12:19:16 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1Cc5Sq-0005uY-4d for emacs-devel@gnu.org; Wed, 08 Dec 2004 12:18:57 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1Cc5Sp-0005oz-Vv for emacs-devel@gnu.org; Wed, 08 Dec 2004 12:18:56 -0500 Original-Received: from [132.204.24.67] (helo=mercure.iro.umontreal.ca) by monty-python.gnu.org with esmtp (Exim 4.34) id 1Cc57m-0001wm-Tp for emacs-devel@gnu.org; Wed, 08 Dec 2004 11:57:11 -0500 Original-Received: from hidalgo.iro.umontreal.ca (hidalgo.iro.umontreal.ca [132.204.27.50]) by mercure.iro.umontreal.ca (Postfix) with ESMTP id 7FC8C8282E8; Wed, 8 Dec 2004 11:57:10 -0500 (EST) Original-Received: from asado.iro.umontreal.ca (asado.iro.umontreal.ca [132.204.24.84]) by hidalgo.iro.umontreal.ca (Postfix) with ESMTP id 453434AC660; Wed, 8 Dec 2004 11:56:50 -0500 (EST) Original-Received: by asado.iro.umontreal.ca (Postfix, from userid 20848) id 109F08CA69; Wed, 8 Dec 2004 11:56:49 -0500 (EST) Original-To: Zack Weinberg In-Reply-To: <87u0qxgn65.fsf@codesourcery.com> (Zack Weinberg's message of "Wed, 08 Dec 2004 01:21:54 -0800") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/21.3.50 (gnu/linux) X-DIRO-MailScanner-Information: Please contact the ISP for more information X-DIRO-MailScanner: Found to be clean X-DIRO-MailScanner-SpamCheck: n'est pas un polluriel, SpamAssassin (score=-4.304, requis 5, autolearn=not spam, AWL 0.60, BAYES_00 -4.90) X-MailScanner-From: monnier@iro.umontreal.ca 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:30868 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:30868 > I dug through the byte-compiler a bit and determined that it makes no > attempt whatsoever to optimize (list ...) expressions. So I wrote a The reason for this is that (eq (list 1) (list 1)) returns nil. So the optimization which replaces (list 1) with '(1) can change the behavior of the code. Example: (defun foo () (list 1)) ... (message "%s" (if (eq (foo) (foo)) "Optimized" "No optimization")) Admittedly, such situations are relatively uncommon, but they do arise and it is very difficult [read: impossible] to detect them, Stefan PS: Note that `concat' has the same problem, and yet (concat "foo" "bar") is byte-optimized to "foobar". The reason for the difference is that it so happens that such differences matter much less often for strings, and also that the optimzation has been used for such a long time that it can be considered as part of the semantics of `concat'.