mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-28 08:11:05 -08:00
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.
This commit is contained in:
parent
3b038d46e2
commit
044392c5c5
1 changed files with 9 additions and 13 deletions
|
|
@ -221,21 +221,17 @@ for speeding up processing.")
|
||||||
|
|
||||||
(defun byte-optimize--substitutable-p (expr)
|
(defun byte-optimize--substitutable-p (expr)
|
||||||
"Whether EXPR is a constant that can be propagated."
|
"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)
|
(or (booleanp expr)
|
||||||
(numberp expr)
|
(numberp expr)
|
||||||
(stringp expr)
|
(arrayp expr)
|
||||||
(and (consp expr)
|
(let ((head (car-safe expr)))
|
||||||
(or (and (memq (car expr) '(quote function))
|
(cond ((eq head 'quote) t)
|
||||||
(symbolp (cadr expr)))
|
;; Don't substitute #'(lambda ...) since that would enable
|
||||||
;; (internal-get-closed-var N) can be considered constant for
|
;; uncontrolled inlining.
|
||||||
;; const-prop purposes.
|
((eq head 'function) (symbolp (cadr expr)))
|
||||||
(and (eq (car expr) 'internal-get-closed-var)
|
;; (internal-get-closed-var N) can be considered constant for
|
||||||
(integerp (cadr expr)))))
|
;; const-prop purposes.
|
||||||
|
((eq head 'internal-get-closed-var) (integerp (cadr expr)))))
|
||||||
(keywordp expr)))
|
(keywordp expr)))
|
||||||
|
|
||||||
(defmacro byte-optimize--pcase (exp &rest cases)
|
(defmacro byte-optimize--pcase (exp &rest cases)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue