Function: comp-function-call-maybe-fold
comp-function-call-maybe-fold is a byte-compiled function defined in
comp.el.gz.
Signature
(comp-function-call-maybe-fold INSN F ARGS)
Documentation
Given INSN, when F is pure if all ARGS are known, remove the function call.
Return non-nil if the function is folded successfully.
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/comp.el.gz
(defun comp-function-call-maybe-fold (insn f args)
"Given INSN, when F is pure if all ARGS are known, remove the function call.
Return non-nil if the function is folded successfully."
(cl-flet ((rewrite-insn-as-setimm (insn value)
;; See `comp-emit-setimm'.
(comp-add-const-to-relocs value)
(setf (car insn) 'setimm
(cddr insn) `(,value))))
(cond
((eq f 'symbol-value)
(when-let* ((arg0 (car args))
(const (comp-cstr-imm-vld-p arg0))
(ok-to-optim (member (comp-cstr-imm arg0)
comp-symbol-values-optimizable)))
(rewrite-insn-as-setimm insn (symbol-value (comp-cstr-imm
(car args))))))
((comp-function-foldable-p f args)
(ignore-errors
;; No point to complain here in case of error because we
;; should do basic block pruning in order to be sure that this
;; is not dead-code. This is now left to gcc, to be
;; implemented only if we want a reliable diagnostic here.
(let* ((f (if-let (f-in-ctxt (comp-symbol-func-to-fun f))
;; If the function is IN the compilation ctxt
;; and know to be pure.
(comp-func-byte-func f-in-ctxt)
f))
(value (comp-apply-in-env f (mapcar #'comp-cstr-imm args))))
(rewrite-insn-as-setimm insn value)))))))