diff options
author | Mattias EngdegÄrd <mattiase@acm.org> | 2021-07-28 21:12:27 +0200 |
---|---|---|
committer | Mattias EngdegÄrd <mattiase@acm.org> | 2021-07-30 09:54:29 +0200 |
commit | 566e29f78ccee4fcf0421576c0306860c8afae0f (patch) | |
tree | aaedb56c599f5d80cb102b34e0fbc6522d74ba08 /lisp/emacs-lisp | |
parent | 5fb8b20fa35a931660d9d59afc9ca863dd33a123 (diff) | |
download | emacs-566e29f78ccee4fcf0421576c0306860c8afae0f.tar.gz emacs-566e29f78ccee4fcf0421576c0306860c8afae0f.tar.bz2 emacs-566e29f78ccee4fcf0421576c0306860c8afae0f.zip |
Single source optimiser entry point
Make the optimiser aware of lexical arguments. Otherwise we cannot
know for sure whether a variable is lexical or dynamic during
traversal.
* lisp/emacs-lisp/byte-opt.el (byte-optimize-one-form): New optimiser
entry point, replacing the recursive byte-optimize-form.
* lisp/emacs-lisp/bytecomp.el (byte-optimize-one-form): Autoload.
(byte-compile-keep-pending, byte-compile-top-level):
Use byte-optimize-one-form.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r-- | lisp/emacs-lisp/byte-opt.el | 9 | ||||
-rw-r--r-- | lisp/emacs-lisp/bytecomp.el | 6 |
2 files changed, 11 insertions, 4 deletions
diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el index ad9f827171a..4117533cda5 100644 --- a/lisp/emacs-lisp/byte-opt.el +++ b/lisp/emacs-lisp/byte-opt.el @@ -652,8 +652,15 @@ Same format as `byte-optimize--lexvars', with shared structure and contents.") (byte-optimize-constant-args form) form)))))) -(defun byte-optimize-form (form &optional for-effect) +(defun byte-optimize-one-form (form &optional for-effect) "The source-level pass of the optimizer." + ;; Make optimiser aware of lexical arguments. + (let ((byte-optimize--lexvars + (mapcar (lambda (v) (list (car v) t)) + byte-compile--lexical-environment))) + (byte-optimize-form form for-effect))) + +(defun byte-optimize-form (form &optional for-effect) (while (progn ;; First, optimize all sub-forms of this one. diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index a6e7e03cb0a..7bd642d2b23 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -192,7 +192,7 @@ otherwise adds \".elc\"." (autoload 'byte-compile-inline-expand "byte-opt") ;; This is the entry point to the lapcode optimizer pass1. -(autoload 'byte-optimize-form "byte-opt") +(autoload 'byte-optimize-one-form "byte-opt") ;; This is the entry point to the lapcode optimizer pass2. (autoload 'byte-optimize-lapcode "byte-opt") @@ -2455,7 +2455,7 @@ list that represents a doc string reference. (defun byte-compile-keep-pending (form &optional handler) (if (memq byte-optimize '(t source)) - (setq form (byte-optimize-form form t))) + (setq form (byte-optimize-one-form form t))) (if handler (let ((byte-compile--for-effect t)) ;; To avoid consing up monstrously large forms at load time, we split @@ -3155,7 +3155,7 @@ for symbols generated by the byte compiler itself." (byte-compile-output nil) (byte-compile-jump-tables nil)) (if (memq byte-optimize '(t source)) - (setq form (byte-optimize-form form byte-compile--for-effect))) + (setq form (byte-optimize-one-form form byte-compile--for-effect))) (while (and (eq (car-safe form) 'progn) (null (cdr (cdr form)))) (setq form (nth 1 form))) ;; Set up things for a lexically-bound function. |