From 43e67019dfc4fb7d3474e0fbedcfec60f2300521 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Fri, 11 Feb 2011 14:48:54 -0500 Subject: Make cconv-analyse understand the need for closures. * lisp/emacs-lisp/byte-lexbind.el (byte-compile-lforminfo-analyze): Understand the :fun-body case for catch, save-window-excursion, and condition-case. (byte-compile-maybe-push-heap-environment): No need when nclosures is zero and byte-compile-current-num-closures is -1. * lisp/emacs-lisp/bytecomp.el (byte-compile-lambda): Fix `fun' that was not renamed to `bytecomp-fun'. * lisp/emacs-lisp/cconv.el (cconv-not-lexical-var-p): New function. (cconv-freevars): Use it. (cconv-closure-convert-rec): Avoid `position'. (cconv-analyse-function): New function. (cconv-analyse-form): Use it. `inclosure' can't be nil any more. Check lexical vars at let-binding time rather than when referenced. For defuns to be in an empty environment and lambdas to take lexical args. Pay attention to the need to build closures in catch, unwind-protect, save-window-excursion, condition-case, and track-mouse. Fix defconst/defvar handling. --- lisp/emacs-lisp/byte-lexbind.el | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'lisp/emacs-lisp/byte-lexbind.el') diff --git a/lisp/emacs-lisp/byte-lexbind.el b/lisp/emacs-lisp/byte-lexbind.el index df463c17549..313c4b6ad0f 100644 --- a/lisp/emacs-lisp/byte-lexbind.el +++ b/lisp/emacs-lisp/byte-lexbind.el @@ -1,6 +1,6 @@ ;;; byte-lexbind.el --- Lexical binding support for byte-compiler ;; -;; Copyright (C) 2001, 2002, 2010 Free Software Foundation, Inc. +;; Copyright (C) 2001, 2002, 2010, 2011 Free Software Foundation, Inc. ;; ;; Author: Miles Bader ;; Keywords: lisp, compiler, lexical binding @@ -202,24 +202,25 @@ LFORMINFO." (byte-compile-lvarinfo-note-set vinfo) (byte-compile-lforminfo-note-closure lforminfo vinfo closure-flag))))))) - ((eq fun 'catch) + ((and (eq fun 'catch) (not (eq :fun-body (nth 2 form)))) ;; tag (byte-compile-lforminfo-analyze lforminfo (cadr form) - ignore closure-flag) + ignore closure-flag) ;; `catch' uses a closure for the body (byte-compile-lforminfo-analyze-forms lforminfo form 2 ignore (or closure-flag - (and (not byte-compile-use-downward-closures) - (byte-compile-lforminfo-make-closure-flag))))) + (and (not byte-compile-use-downward-closures) + (byte-compile-lforminfo-make-closure-flag))))) ((eq fun 'cond) (byte-compile-lforminfo-analyze-clauses lforminfo (cdr form) 0 ignore closure-flag)) ((eq fun 'condition-case) ;; `condition-case' separates its body/handlers into ;; separate closures. - (unless (or closure-flag byte-compile-use-downward-closures) + (unless (or (eq (nth 1 form) :fun-body) + closure-flag byte-compile-use-downward-closures) ;; condition case is implemented by calling a function (setq closure-flag (byte-compile-lforminfo-make-closure-flag))) ;; value form @@ -281,7 +282,8 @@ LFORMINFO." ((eq fun 'quote) ;; do nothing ) - ((eq fun 'save-window-excursion) + ((and (eq fun 'save-window-excursion) + (not (eq :fun-body (nth 1 form)))) ;; `save-window-excursion' currently uses a funny implementation ;; that requires its body forms be put into a closure (it should ;; be fixed to work more like `save-excursion' etc., do). @@ -579,6 +581,7 @@ proper scope)." (let ((nclosures (and lforminfo (byte-compile-lforminfo-num-closures lforminfo)))) (if (or (null lforminfo) + (zerop nclosures) (= nclosures byte-compile-current-num-closures)) ;; No need to push a heap environment. nil @@ -692,5 +695,4 @@ binding slots have been popped." (provide 'byte-lexbind) -;;; arch-tag: b8f1dff6-9edb-4430-a96f-323d42a681a9 ;;; byte-lexbind.el ends here -- cgit v1.2.3