summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/comp.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/emacs-lisp/comp.el')
-rw-r--r--lisp/emacs-lisp/comp.el55
1 files changed, 34 insertions, 21 deletions
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index 9f4118dfc86..025d21631bb 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -186,8 +186,9 @@ and above."
:type '(repeat string)
:version "28.1")
-(defcustom native-comp-driver-options (when (eq system-type 'darwin)
- '("-Wl,-w"))
+(defcustom native-comp-driver-options
+ (cond ((eq system-type 'darwin) '("-Wl,-w"))
+ ((eq system-type 'cygwin) '("-Wl,-dynamicbase")))
"Options passed verbatim to the native compiler's back-end driver.
Note that not all options are meaningful; typically only the options
affecting the assembler and linker are likely to be useful.
@@ -1711,6 +1712,10 @@ Return value is the fall-through block name."
(defun comp-jump-table-optimizable (jmp-table)
"Return t if JMP-TABLE can be optimized out."
+ ;; Identify LAP sequences like:
+ ;; (byte-constant #s(hash-table size 3 test eq rehash-size 1.5 rehash-threshold 0.8125 purecopy t data (created 126 deleted 126 changed 126)) . 24)
+ ;; (byte-switch)
+ ;; (TAG 126 . 10)
(cl-loop
with labels = (cl-loop for target-label being each hash-value of jmp-table
collect target-label)
@@ -1718,7 +1723,10 @@ Return value is the fall-through block name."
for l in (cdr-safe labels)
unless (= l x)
return nil
- finally return t))
+ finally return (pcase (nth (1+ (comp-limplify-pc comp-pass))
+ (comp-func-lap comp-func))
+ (`(TAG ,label . ,_label-sp)
+ (= label l)))))
(defun comp-emit-switch (var last-insn)
"Emit a Limple for a lap jump table given VAR and LAST-INSN."
@@ -1763,27 +1771,32 @@ Return value is the fall-through block name."
(_ (signal 'native-ice
'("missing previous setimm while creating a switch")))))
+(defun comp--func-arity (subr-name)
+ "Like `func-arity' but invariant against primitive redefinitions.
+SUBR-NAME is the name of function."
+ (or (gethash subr-name comp-subr-arities-h)
+ (func-arity subr-name)))
+
(defun comp-emit-set-call-subr (subr-name sp-delta)
"Emit a call for SUBR-NAME.
SP-DELTA is the stack adjustment."
- (let ((subr (symbol-function subr-name))
- (nargs (1+ (- sp-delta))))
- (let* ((arity (func-arity subr))
- (minarg (car arity))
- (maxarg (cdr arity)))
- (when (eq maxarg 'unevalled)
- (signal 'native-ice (list "subr contains unevalled args" subr-name)))
- (if (eq maxarg 'many)
- ;; callref case.
- (comp-emit-set-call (comp-callref subr-name nargs (comp-sp)))
- ;; Normal call.
- (unless (and (>= maxarg nargs) (<= minarg nargs))
- (signal 'native-ice
- (list "incoherent stack adjustment" nargs maxarg minarg)))
- (let* ((subr-name subr-name)
- (slots (cl-loop for i from 0 below maxarg
- collect (comp-slot-n (+ i (comp-sp))))))
- (comp-emit-set-call (apply #'comp-call (cons subr-name slots))))))))
+ (let* ((nargs (1+ (- sp-delta)))
+ (arity (comp--func-arity subr-name))
+ (minarg (car arity))
+ (maxarg (cdr arity)))
+ (when (eq maxarg 'unevalled)
+ (signal 'native-ice (list "subr contains unevalled args" subr-name)))
+ (if (eq maxarg 'many)
+ ;; callref case.
+ (comp-emit-set-call (comp-callref subr-name nargs (comp-sp)))
+ ;; Normal call.
+ (unless (and (>= maxarg nargs) (<= minarg nargs))
+ (signal 'native-ice
+ (list "incoherent stack adjustment" nargs maxarg minarg)))
+ (let* ((subr-name subr-name)
+ (slots (cl-loop for i from 0 below maxarg
+ collect (comp-slot-n (+ i (comp-sp))))))
+ (comp-emit-set-call (apply #'comp-call (cons subr-name slots)))))))
(eval-when-compile
(defun comp-op-to-fun (x)