summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/comp.el
diff options
context:
space:
mode:
authorAndrea Corallo <akrl@sdf.org>2020-06-06 14:49:01 +0200
committerAndrea Corallo <akrl@sdf.org>2020-06-06 22:03:11 +0100
commitdcfcbb14f5037d2661280c4bb93e7db618819106 (patch)
tree19b101eef5567f5ad9af5a64e9bae8710f791224 /lisp/emacs-lisp/comp.el
parent6449a058b150edd2a5997d761a284ad6b9b5aa97 (diff)
downloademacs-dcfcbb14f5037d2661280c4bb93e7db618819106.tar.gz
emacs-dcfcbb14f5037d2661280c4bb93e7db618819106.tar.bz2
emacs-dcfcbb14f5037d2661280c4bb93e7db618819106.zip
* Allow for optimizing anonymous lambdas in call-optim
* lisp/emacs-lisp/comp.el (comp-func-in-unit): New function. (comp-call-optim-form-call): Update logic for optimizing anonymous lambdas.
Diffstat (limited to 'lisp/emacs-lisp/comp.el')
-rw-r--r--lisp/emacs-lisp/comp.el30
1 files changed, 23 insertions, 7 deletions
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index e776b664812..f30409ae5cd 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -1976,19 +1976,31 @@ Backward propagate array placement properties."
;; the full compilation unit.
;; For this reason this is triggered only at comp-speed == 3.
+(defun comp-func-in-unit (func)
+ "Given FUNC return the `comp-fun' definition in the current context.
+FUNCTION can be a function-name or byte compiled function."
+ (if (symbolp func)
+ (gethash (gethash func
+ (comp-ctxt-sym-to-c-name-h comp-ctxt))
+ (comp-ctxt-funcs-h comp-ctxt))
+ (cl-assert (byte-code-function-p func))
+ (gethash func (comp-ctxt-byte-func-to-func-h comp-ctxt))))
+
(defun comp-call-optim-form-call (callee args)
""
(cl-flet ((fill-args (args total)
;; Fill missing args to reach TOTAL
(append args (cl-loop repeat (- total (length args))
collect (make-comp-mvar :constant nil)))))
- (when (and (symbolp callee) ; Do nothing if callee is a byte compiled func.
+ (when (and (or (symbolp callee)
+ (gethash callee (comp-ctxt-byte-func-to-func-h comp-ctxt)))
(not (memq callee comp-never-optimize-functions)))
- (let* ((f (symbol-function callee))
+ (let* ((f (if (symbolp callee)
+ (symbol-function callee)
+ (cl-assert (byte-code-function-p callee))
+ callee))
(subrp (subrp f))
- (comp-func-callee (gethash (gethash callee
- (comp-ctxt-sym-to-c-name-h comp-ctxt))
- (comp-ctxt-funcs-h comp-ctxt))))
+ (comp-func-callee (comp-func-in-unit callee)))
(cond
((and subrp (not (subr-native-elisp-p f)))
;; Trampoline removal.
@@ -2005,8 +2017,12 @@ Backward propagate array placement properties."
`(,call-type ,callee ,@args)))
;; Intra compilation unit procedure call optimization.
;; Attention speed 3 triggers this for non self calls too!!
- ((and (>= comp-speed 3)
- comp-func-callee)
+ ((and comp-func-callee
+ (or (>= comp-speed 3)
+ (and (>= comp-speed 2)
+ ;; Anonymous lambdas can't be redefined so are
+ ;; always safe to optimize.
+ (byte-code-function-p callee))))
(let* ((func-args (comp-func-args comp-func-callee))
(nargs (comp-nargs-p func-args))
(call-type (if nargs 'direct-callref 'direct-call))