summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/byte-opt.el
diff options
context:
space:
mode:
authorMattias EngdegÄrd <mattiase@acm.org>2023-05-04 17:37:17 +0200
committerMattias EngdegÄrd <mattiase@acm.org>2023-05-05 22:00:28 +0200
commit044392c5c563a0bb2c24b65e5222b8f9b3cbe0d8 (patch)
tree2d6421dec3cc10aca7addee045e9836ce1cb13f8 /lisp/emacs-lisp/byte-opt.el
parent3b038d46e24532bc4bca56f37d30afd70fae388d (diff)
downloademacs-044392c5c563a0bb2c24b65e5222b8f9b3cbe0d8.tar.gz
emacs-044392c5c563a0bb2c24b65e5222b8f9b3cbe0d8.tar.bz2
emacs-044392c5c563a0bb2c24b65e5222b8f9b3cbe0d8.zip
Constant-propagate cons and vector literals
* lisp/emacs-lisp/byte-opt.el (byte-optimize--substitutable-p): Allow quoted lists and conses, and vector literals, to be substituted from lexical variables. This can eliminate variable bindings and create new constant folding opportunities.
Diffstat (limited to 'lisp/emacs-lisp/byte-opt.el')
-rw-r--r--lisp/emacs-lisp/byte-opt.el22
1 files changed, 9 insertions, 13 deletions
diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el
index d046c4d401c..8fe5066c49e 100644
--- a/lisp/emacs-lisp/byte-opt.el
+++ b/lisp/emacs-lisp/byte-opt.el
@@ -221,21 +221,17 @@ for speeding up processing.")
(defun byte-optimize--substitutable-p (expr)
"Whether EXPR is a constant that can be propagated."
- ;; Only consider numbers, symbols and strings to be values for substitution
- ;; purposes. Numbers and symbols are immutable, and mutating string
- ;; literals (or results from constant-evaluated string-returning functions)
- ;; can be considered undefined.
- ;; (What about other quoted values, like conses?)
(or (booleanp expr)
(numberp expr)
- (stringp expr)
- (and (consp expr)
- (or (and (memq (car expr) '(quote function))
- (symbolp (cadr expr)))
- ;; (internal-get-closed-var N) can be considered constant for
- ;; const-prop purposes.
- (and (eq (car expr) 'internal-get-closed-var)
- (integerp (cadr expr)))))
+ (arrayp expr)
+ (let ((head (car-safe expr)))
+ (cond ((eq head 'quote) t)
+ ;; Don't substitute #'(lambda ...) since that would enable
+ ;; uncontrolled inlining.
+ ((eq head 'function) (symbolp (cadr expr)))
+ ;; (internal-get-closed-var N) can be considered constant for
+ ;; const-prop purposes.
+ ((eq head 'internal-get-closed-var) (integerp (cadr expr)))))
(keywordp expr)))
(defmacro byte-optimize--pcase (exp &rest cases)