diff options
| author | Mattias EngdegÄrd | 2021-12-11 22:11:08 +0100 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2021-12-11 22:16:55 +0100 |
| commit | 8716f21d94bfda0072843e087833fedb38dcf13e (patch) | |
| tree | 668849f67d7fa4b50d59b19ebaa6e52c546a9544 | |
| parent | 36cd4f5d81c3c19e5719e25daa1a8e08c88cc1a7 (diff) | |
| download | emacs-8716f21d94bfda0072843e087833fedb38dcf13e.tar.gz emacs-8716f21d94bfda0072843e087833fedb38dcf13e.zip | |
Constant-propagate access to captured variables
* lisp/emacs-lisp/byte-opt.el (byte-optimize--substitutable-p):
Treat (internal-get-closed-var N) as constants for propagation
purposes, because that is effectively what such forms will be compiled
to. This allows for the elimination of some lexical variables.
* test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-tests--test-cases):
Add test case.
| -rw-r--r-- | lisp/emacs-lisp/byte-opt.el | 8 | ||||
| -rw-r--r-- | test/lisp/emacs-lisp/bytecomp-tests.el | 6 |
2 files changed, 12 insertions, 2 deletions
diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el index f6db803b78e..2bdf1f55111 100644 --- a/lisp/emacs-lisp/byte-opt.el +++ b/lisp/emacs-lisp/byte-opt.el | |||
| @@ -342,8 +342,12 @@ for speeding up processing.") | |||
| 342 | (numberp expr) | 342 | (numberp expr) |
| 343 | (stringp expr) | 343 | (stringp expr) |
| 344 | (and (consp expr) | 344 | (and (consp expr) |
| 345 | (memq (car expr) '(quote function)) | 345 | (or (and (memq (car expr) '(quote function)) |
| 346 | (symbolp (cadr expr))) | 346 | (symbolp (cadr expr))) |
| 347 | ;; (internal-get-closed-var N) can be considered constant for | ||
| 348 | ;; const-prop purposes. | ||
| 349 | (and (eq (car expr) 'internal-get-closed-var) | ||
| 350 | (integerp (cadr expr))))) | ||
| 347 | (keywordp expr))) | 351 | (keywordp expr))) |
| 348 | 352 | ||
| 349 | (defmacro byte-optimize--pcase (exp &rest cases) | 353 | (defmacro byte-optimize--pcase (exp &rest cases) |
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el index 7e51f820b70..a442eb473be 100644 --- a/test/lisp/emacs-lisp/bytecomp-tests.el +++ b/test/lisp/emacs-lisp/bytecomp-tests.el | |||
| @@ -686,6 +686,12 @@ inner loops respectively." | |||
| 686 | (let* ((x 'a)) | 686 | (let* ((x 'a)) |
| 687 | (list x (funcall g) (funcall h))))))) | 687 | (list x (funcall g) (funcall h))))))) |
| 688 | (funcall (funcall f 'b))) | 688 | (funcall (funcall f 'b))) |
| 689 | |||
| 690 | ;; Test constant-propagation of access to captured variables. | ||
| 691 | (let* ((x 2) | ||
| 692 | (f (lambda () | ||
| 693 | (let ((y x)) (list y 3 y))))) | ||
| 694 | (funcall f)) | ||
| 689 | ) | 695 | ) |
| 690 | "List of expressions for cross-testing interpreted and compiled code.") | 696 | "List of expressions for cross-testing interpreted and compiled code.") |
| 691 | 697 | ||