]> git.eshelyaron.com Git - emacs.git/commit
Constprop of lexical variables
authorMattias Engdegård <mattiase@acm.org>
Sat, 6 Feb 2021 17:34:45 +0000 (18:34 +0100)
committerMattias Engdegård <mattiase@acm.org>
Sat, 6 Feb 2021 19:22:24 +0000 (20:22 +0100)
commit83983b6b7a115474572973b62eb5e42251713e63
tree16df61103e1412655a7e9c4910c9c403af2fe816
parentf95266ee68ab85f7a237b473f98b36413b542553
Constprop of lexical variables

Lexical variables bound to a constant value (symbol, number or string)
are substituted at their point of use and the variable then eliminated
if possible.  Example:

  (let ((x (+ 2 3))) (f x))  =>  (f 5)

This reduces code size, eliminates stack operations, and enables
further optimisations.  The implementation is conservative, and is
strongly curtailed by the presence of variable mutation, conditions
and loops.

* lisp/emacs-lisp/byte-opt.el
(byte-optimize-enable-variable-constprop)
(byte-optimize-warn-eliminated-variable): New constants.
(byte-optimize--lexvars, byte-optimize--vars-outside-condition)
(byte-optimize--vars-outside-loop, byte-optimize--dynamic-vars):
New dynamic variables.
(byte-optimize--substitutable-p, byte-optimize-let-form):
New functions.
(byte-optimize-form-code-walker): Adapt clauses for variable
constprop, and add clauses for 'setq' and 'defvar'.
* test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-test-var)
(bytecomp-test-get-var, bytecomp-test-identity)
(byte-opt-testsuite-arith-data): Add test cases.
lisp/emacs-lisp/byte-opt.el
test/lisp/emacs-lisp/bytecomp-tests.el