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.el101
1 files changed, 64 insertions, 37 deletions
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index 8f40f2f40a0..2ea405728a3 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.
@@ -316,7 +317,7 @@ Useful to hook into pass checkers.")
(buffer-file-name (function (&optional buffer) (or string null)))
(buffer-list (function (&optional frame) list))
(buffer-local-variables (function (&optional buffer) list))
- (buffer-modified-p (function (&optional buffer) boolean))
+ (buffer-modified-p (function (&optional buffer) (or boolean (member autosaved))))
(buffer-size (function (&optional buffer) integer))
(buffer-string (function () string))
(buffer-substring (function ((or integer marker) (or integer marker)) string))
@@ -343,7 +344,7 @@ Useful to hook into pass checkers.")
(concat (function (&rest sequence) string))
(cons (function (t t) cons))
(consp (function (t) boolean))
- (coordinates-in-window-p (function (cons window) boolean))
+ (coordinates-in-window-p (function (cons window) (or cons null (member bottom-divider right-divider mode-line header-line tab-line left-fringe right-fringe vertical-line left-margin right-margin))))
(copy-alist (function (list) list))
(copy-marker (function (&optional (or integer marker) boolean) marker))
(copy-sequence (function (sequence) sequence))
@@ -362,7 +363,7 @@ Useful to hook into pass checkers.")
(current-time-zone (function (&optional (or number list)
(or symbol string cons integer))
cons))
- (custom-variable-p (function (symbol) boolean))
+ (custom-variable-p (function (symbol) t))
(decode-char (function (cons t) (or fixnum null)))
(decode-time (function (&optional (or number list)
(or symbol string cons integer)
@@ -384,18 +385,18 @@ Useful to hook into pass checkers.")
(error-message-string (function (list) string))
(eventp (function (t) boolean))
(exp (function (number) float))
- (expt (function (number number) float))
+ (expt (function (number number) number))
(fboundp (function (symbol) boolean))
(fceiling (function (float) float))
(featurep (function (symbol &optional symbol) boolean))
(ffloor (function (float) float))
(file-directory-p (function (string) boolean))
(file-exists-p (function (string) boolean))
- (file-locked-p (function (string) boolean))
+ (file-locked-p (function (string) (or boolean string)))
(file-name-absolute-p (function (string) boolean))
(file-newer-than-file-p (function (string string) boolean))
(file-readable-p (function (string) boolean))
- (file-symlink-p (function (string) boolean))
+ (file-symlink-p (function (string) (or boolean string)))
(file-writable-p (function (string) boolean))
(fixnump (function (t) boolean))
(float (function (number) float))
@@ -410,8 +411,8 @@ Useful to hook into pass checkers.")
(frame-first-window (function ((or frame window)) window))
(frame-root-window (function (&optional (or frame window)) window))
(frame-selected-window (function (&optional (or frame window)) window))
- (frame-visible-p (function (frame) boolean))
- (framep (function (t) boolean))
+ (frame-visible-p (function (frame) (or boolean (member icon))))
+ (framep (function (t) (or boolean (member x w32 ns pc pgtk haiku))))
(fround (function (float) float))
(ftruncate (function (float) float))
(get (function (symbol symbol) t))
@@ -505,7 +506,7 @@ Useful to hook into pass checkers.")
(previous-window (function (&optional window t t) window))
(prin1-to-string (function (t &optional t t) string))
(processp (function (t) boolean))
- (proper-list-p (function (t) boolean))
+ (proper-list-p (function (t) (or fixnum null)))
(propertize (function (string &rest t) string))
(radians-to-degrees (function (number) float))
(rassoc (function (t list) list))
@@ -640,11 +641,14 @@ Useful to hook into pass checkers.")
(defun comp-known-predicate-p (predicate)
"Return t if PREDICATE is known."
- (when (gethash predicate comp-known-predicates-h) t))
+ (when (or (gethash predicate comp-known-predicates-h)
+ (gethash predicate (comp-cstr-ctxt-pred-type-h comp-ctxt)))
+ t))
(defun comp-pred-to-cstr (predicate)
"Given PREDICATE, return the corresponding constraint."
- (gethash predicate comp-known-predicates-h))
+ (or (gethash predicate comp-known-predicates-h)
+ (gethash predicate (comp-cstr-ctxt-pred-type-h comp-ctxt))))
(defconst comp-symbol-values-optimizable '(most-positive-fixnum
most-negative-fixnum)
@@ -1241,7 +1245,7 @@ clashes."
(defun comp-decrypt-arg-list (x function-name)
"Decrypt argument list X for FUNCTION-NAME."
(unless (fixnump x)
- (signal 'native-compiler-error-dyn-func function-name))
+ (signal 'native-compiler-error-dyn-func (list function-name)))
(let ((rest (not (= (logand x 128) 0)))
(mandatory (logand x 127))
(nonrest (ash x -8)))
@@ -1285,7 +1289,7 @@ clashes."
'pure))))
(when (byte-code-function-p f)
(signal 'native-compiler-error
- "can't native compile an already byte-compiled function"))
+ '("can't native compile an already byte-compiled function")))
(setf (comp-func-byte-func func)
(byte-compile (comp-func-name func)))
(let ((lap (byte-to-native-lambda-lap
@@ -1309,7 +1313,7 @@ clashes."
"Byte-compile FORM, spilling data from the byte compiler."
(unless (eq (car-safe form) 'lambda)
(signal 'native-compiler-error
- "Cannot native-compile, form is not a lambda"))
+ '("Cannot native-compile, form is not a lambda")))
(unless (comp-ctxt-output comp-ctxt)
(setf (comp-ctxt-output comp-ctxt)
(make-temp-file "comp-lambda-" nil ".eln")))
@@ -1390,7 +1394,7 @@ clashes."
(alist-get 'no-native-compile byte-native-qualities))
(throw 'no-native-compile nil))
(unless byte-to-native-top-level-forms
- (signal 'native-compiler-error-empty-byte filename))
+ (signal 'native-compiler-error-empty-byte (list filename)))
(unless (comp-ctxt-output comp-ctxt)
(setf (comp-ctxt-output comp-ctxt) (comp-el-to-eln-filename
filename
@@ -1427,11 +1431,13 @@ clashes."
"Byte-compile and spill the LAP representation for INPUT.
If INPUT is a symbol, it is the function-name to be compiled.
If INPUT is a string, it is the filename to be compiled."
- (let ((byte-native-compiling t)
- (byte-to-native-lambdas-h (make-hash-table :test #'eq))
- (byte-to-native-top-level-forms ())
- (byte-to-native-plist-environment ()))
- (comp-spill-lap-function input)))
+ (let* ((byte-native-compiling t)
+ (byte-to-native-lambdas-h (make-hash-table :test #'eq))
+ (byte-to-native-top-level-forms ())
+ (byte-to-native-plist-environment ())
+ (res (comp-spill-lap-function input)))
+ (comp-cstr-ctxt-update-type-slots comp-ctxt)
+ res))
;;; Limplification pass specific code.
@@ -1539,7 +1545,7 @@ STACK-OFF is the index of the first slot frame involved."
for sp from stack-off
collect (comp-slot-n sp))))
-(cl-defun make-comp-mvar (&key slot (constant nil const-vld) type)
+(cl-defun make-comp-mvar (&key slot (constant nil const-vld) type neg)
"`comp-mvar' initializer."
(let ((mvar (make--comp-mvar :slot slot)))
(when const-vld
@@ -1547,6 +1553,8 @@ STACK-OFF is the index of the first slot frame involved."
(setf (comp-cstr-imm mvar) constant))
(when type
(setf (comp-mvar-typeset mvar) (list type)))
+ (when neg
+ (setf (comp-mvar-neg mvar) t))
mvar))
(defun comp-new-frame (size vsize &optional ssa)
@@ -1711,14 +1719,15 @@ Return value is the fall-through block name."
(defun comp-jump-table-optimizable (jmp-table)
"Return t if JMP-TABLE can be optimized out."
- (cl-loop
- with labels = (cl-loop for target-label being each hash-value of jmp-table
- collect target-label)
- with x = (car labels)
- for l in (cdr-safe labels)
- unless (= l x)
- return nil
- finally return t))
+ ;; 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)
+ (let ((targets (hash-table-values jmp-table)))
+ (when (apply #'= targets)
+ (pcase (nth (1+ (comp-limplify-pc comp-pass)) (comp-func-lap comp-func))
+ (`(TAG ,target . ,_label-sp)
+ (= target (car targets)))))))
(defun comp-emit-switch (var last-insn)
"Emit a Limple for a lap jump table given VAR and LAST-INSN."
@@ -1761,7 +1770,7 @@ Return value is the fall-through block name."
do (puthash ff-bb-name ff-bb (comp-func-blocks comp-func))
(setf (comp-limplify-curr-block comp-pass) ff-bb))))
(_ (signal 'native-ice
- "missing previous setimm while creating a switch"))))
+ '("missing previous setimm while creating a switch")))))
(defun comp--func-arity (subr-name)
"Like `func-arity' but invariant against primitive redefinitions.
@@ -2535,6 +2544,19 @@ TARGET-BB-SYM is the symbol name of the target block."
for insns-seq on (comp-block-insns b)
do
(pcase insns-seq
+ (`((set ,(and (pred comp-mvar-p) mvar-tested-copy)
+ ,(and (pred comp-mvar-p) mvar-tested))
+ (set ,(and (pred comp-mvar-p) mvar-1)
+ (call type-of ,(and (pred comp-mvar-p) mvar-tested-copy)))
+ (set ,(and (pred comp-mvar-p) mvar-2)
+ (call symbol-value ,(and (pred comp-cstr-cl-tag-p) mvar-tag)))
+ (set ,(and (pred comp-mvar-p) mvar-3)
+ (call memq ,(and (pred comp-mvar-p) mvar-1) ,(and (pred comp-mvar-p) mvar-2)))
+ (cond-jump ,(and (pred comp-mvar-p) mvar-3) ,(pred comp-mvar-p) ,bb1 ,bb2))
+ (push `(assume ,mvar-tested ,(make-comp-mvar :type (comp-cstr-cl-tag mvar-tag)))
+ (comp-block-insns (comp-add-cond-cstrs-target-block b bb2)))
+ (push `(assume ,mvar-tested ,(make-comp-mvar :type (comp-cstr-cl-tag mvar-tag) :neg t))
+ (comp-block-insns (comp-add-cond-cstrs-target-block b bb1))))
(`((set ,(and (pred comp-mvar-p) cmp-res)
(,(pred comp-call-op-p)
,(and (or (pred comp-equality-fun-p)
@@ -2849,7 +2871,7 @@ blocks."
(first-processed (l)
(if-let ((p (cl-find-if (lambda (p) (comp-block-idom p)) l)))
p
- (signal 'native-ice "can't find first preprocessed"))))
+ (signal 'native-ice '("can't find first preprocessed")))))
(when-let ((blocks (comp-func-blocks comp-func))
(entry (gethash 'entry blocks))
@@ -3190,7 +3212,11 @@ Fold the call in case."
(+ (comp-cstr-add lval args))
(- (comp-cstr-sub lval args))
(1+ (comp-cstr-add lval `(,(car args) ,comp-cstr-one)))
- (1- (comp-cstr-sub lval `(,(car args) ,comp-cstr-one))))))
+ (1- (comp-cstr-sub lval `(,(car args) ,comp-cstr-one)))
+ (record (when (comp-cstr-imm-vld-p (car args))
+ (comp-cstr-shallow-copy lval
+ (comp-type-spec-to-cstr
+ (comp-cstr-imm (car args)))))))))
(defun comp-fwprop-insn (insn)
"Propagate within INSN."
@@ -3749,7 +3775,7 @@ Prepare every function for final compilation and drive the C back-end."
(progn
(delete-file temp-file)
output)
- (signal 'native-compiler-error (buffer-string)))
+ (signal 'native-compiler-error (list (buffer-string))))
(comp-log-to-buffer (buffer-string))))))))
@@ -4231,8 +4257,9 @@ bytecode definition was not changed in the meantime)."
;; compilation, so update `comp-files-queue' to reflect that.
(unless (or (null load)
(eq load (cdr entry)))
- (cl-substitute (cons file load) (car entry) comp-files-queue
- :key #'car :test #'string=))
+ (setf comp-files-queue
+ (cl-substitute (cons file load) (car entry) comp-files-queue
+ :key #'car :test #'string=)))
(unless (native-compile-async-skip-p file load selector)
(let* ((out-filename (comp-el-to-eln-filename file))