]> git.eshelyaron.com Git - emacs.git/commit
Propagate aliased lexical variables in byte compiler
authorMattias Engdegård <mattiase@acm.org>
Fri, 30 Jul 2021 11:44:07 +0000 (13:44 +0200)
committerMattias Engdegård <mattiase@acm.org>
Sat, 11 Sep 2021 15:17:33 +0000 (17:17 +0200)
commit020a408edabcbaa3722af6fc5bb8b5fe6add6af0
tree9175f95b1379875b9dd418b0941e79731fb33d8a
parent376a31b0cdf64f4264904e2a9d49216959a35bd2
Propagate aliased lexical variables in byte compiler

Replace uses of a variable aliasing another variable with that aliased
variable, to allow for variable removal when possible.  This also
enables opportunities for other optimisations.  Example:

 (let ((y x)) (f y)) => (f x)

The optimisation is only performed if both aliased and aliasing
variables are lexically bound.  Shadowing bindings are α-renamed when
necessary for correctness.  Example:

   (let* ((b a) (a EXPR)) (f a b))
=> (let* ((a{new} EXPR)) (f a{new} a))

* lisp/emacs-lisp/byte-opt.el (byte-optimize--aliased-vars): New.
(byte-optimize-form-code-walker): Cancel aliasing upon mutation.
(byte-optimize--rename-var-body, byte-optimize--rename-var): New.
(byte-optimize-let-form): Add the optimisation.
* test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-tests--test-cases):
Add relevant test cases.
lisp/emacs-lisp/byte-opt.el
test/lisp/emacs-lisp/bytecomp-tests.el