From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: (if (and (featurep 'xemacs) blah) not optimized anymore Date: Tue, 13 Nov 2007 09:46:25 -0500 Message-ID: References: <200710201609.l9KG9PFJ006092@oogie-boogie.ics.uci.edu> <200710220545.l9M5jmvI010460@oogie-boogie.ics.uci.edu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1194965219 10077 80.91.229.12 (13 Nov 2007 14:46:59 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 13 Nov 2007 14:46:59 +0000 (UTC) Cc: emacs-devel@gnu.org To: Dan Nicolaescu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Nov 13 15:47:03 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Irx2O-0006kk-6m for ged-emacs-devel@m.gmane.org; Tue, 13 Nov 2007 15:46:48 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Irx2B-0002ge-IV for ged-emacs-devel@m.gmane.org; Tue, 13 Nov 2007 09:46:35 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Irx27-0002eL-Nh for emacs-devel@gnu.org; Tue, 13 Nov 2007 09:46:31 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Irx27-0002dG-12 for emacs-devel@gnu.org; Tue, 13 Nov 2007 09:46:31 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Irx26-0002d1-Th for emacs-devel@gnu.org; Tue, 13 Nov 2007 09:46:30 -0500 Original-Received: from mercure.iro.umontreal.ca ([132.204.24.67]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Irx26-0001AR-Cj for emacs-devel@gnu.org; Tue, 13 Nov 2007 09:46:30 -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 92E272CF336; Tue, 13 Nov 2007 09:46:29 -0500 (EST) Original-Received: from faina.iro.umontreal.ca (faina.iro.umontreal.ca [132.204.26.177]) by hidalgo.iro.umontreal.ca (Postfix) with ESMTP id 5546B3FE0; Tue, 13 Nov 2007 09:46:25 -0500 (EST) Original-Received: by faina.iro.umontreal.ca (Postfix, from userid 20848) id 3B1A06CAA5; Tue, 13 Nov 2007 09:46:25 -0500 (EST) In-Reply-To: <200710220545.l9M5jmvI010460@oogie-boogie.ics.uci.edu> (Dan Nicolaescu's message of "Sun, 21 Oct 2007 22:45:48 -0700") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.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=-2.82, requis 5, autolearn=not spam, ALL_TRUSTED -2.82) X-DIRO-MailScanner-From: monnier@iro.umontreal.ca X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) 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: news.gmane.org gmane.emacs.devel:83124 Archived-At: > I still see one issue: > After applying this patch: > --- viper-cmd.el 19 Aug 2007 13:47:07 -0000 1.63 > +++ viper-cmd.el 22 Oct 2007 05:37:24 -0000 > @@ -861,7 +861,7 @@ > (1- (length quail-current-str))))) > )) > ((and viper-special-input-method > - viper-xemacs-p > + nil > (fboundp 'quail-start-translation)) > ;; same as above but for XEmacs, which doesn't have > ;; quail-input-method > the byte compiler will still warn about about quail-start-translation > not being defined. I won't warn if the expression is > (and nil viper-special-input-method ...) The patch below seems to fix it, but it does a bit more and I'm not sure if it behaves well in practice (e.g. performancewise), so please try it out on a large scale. If you find it to work well, feel free to install it. Stefan --- orig/lisp/emacs-lisp/byte-opt.el +++ mod/lisp/emacs-lisp/byte-opt.el @@ -185,6 +185,7 @@ ;;; Code: (require 'bytecomp) +(eval-when-compile (require 'cl)) (defun byte-compile-log-lap-1 (format &rest args) (if (aref byte-code-vector 0) @@ -626,12 +628,24 @@ ;; It is now safe to optimize code such that it introduces new bindings. ;; I'd like this to be a defsubst, but let's not be self-referential... -(defmacro byte-compile-trueconstp (form) - ;; Returns non-nil if FORM is a non-nil constant. - `(cond ((consp ,form) (eq (car ,form) 'quote)) - ((not (symbolp ,form))) - ((eq ,form t)) - ((keywordp ,form)))) +(defsubst byte-compile-trueconstp (form) + "Return non-nil if FORM always evaluates to a non-nil value." + (cond ((consp form) + (case (car form) + (quote (cadr form)) + (progn (byte-compile-trueconstp (car (last (cdr form))))))) + ((not (symbolp form))) + ((eq form t)) + ((keywordp form)))) + +(defsubst byte-compile-nilconstp (form) + "Return non-nil if FORM always evaluates to a nil value." + (cond ((consp form) + (case (car form) + (quote (null (cadr form))) + (progn (byte-compile-nilconstp (car (last (cdr form))))))) + ((not (symbolp form)) nil) + ((null form)))) ;; If the function is being called with constant numeric args, ;; evaluate as much as possible at compile-time. This optimizer @@ -990,17 +1004,17 @@ (setq rest form) (while (setq rest (cdr rest)) (cond ((byte-compile-trueconstp (car-safe (car rest))) - (cond ((eq rest (cdr form)) - (setq form - (if (cdr (car rest)) - (if (cdr (cdr (car rest))) - (cons 'progn (cdr (car rest))) - (nth 1 (car rest))) - (car (car rest))))) + ;; This branch will always be taken: kill the subsequent ones. + (cond ((eq rest (cdr form)) ;First branch of `cond'. + (setq form `(progn ,@(car rest)))) ((cdr rest) (setq form (copy-sequence form)) (setcdr (memq (car rest) form) nil))) - (setq rest nil))))) + (setq rest nil)) + ((and (consp (car rest)) + (byte-compile-nilconstp (caar rest))) + ;; This branch will never be taken: kill its body. + (setcdr (car rest) nil))))) ;; ;; Turn (cond (( )) ... ) into (or (cond ... )) (if (eq 'cond (car-safe form)) @@ -1031,11 +1045,9 @@ (byte-optimize-if `(if ,(car (last clause)) ,@(nthcdr 2 form))))))) ((byte-compile-trueconstp clause) - (nth 2 form)) - ((null clause) - (if (nthcdr 4 form) - (cons 'progn (nthcdr 3 form)) - (nth 3 form))) + `(progn ,clause ,(nth 2 form))) + ((byte-compile-nilconstp clause) + `(progn ,clause ,@(nthcdr 3 form))) ((nth 2 form) (if (equal '(nil) (nthcdr 3 form)) (list 'if clause (nth 2 form))