diff options
Diffstat (limited to 'lisp/emacs-lisp/comp-common.el')
| -rw-r--r-- | lisp/emacs-lisp/comp-common.el | 362 |
1 files changed, 362 insertions, 0 deletions
diff --git a/lisp/emacs-lisp/comp-common.el b/lisp/emacs-lisp/comp-common.el index 23de3ddcbdf..11c14f413ff 100644 --- a/lisp/emacs-lisp/comp-common.el +++ b/lisp/emacs-lisp/comp-common.el | |||
| @@ -62,6 +62,345 @@ Used to modify the compiler environment." | |||
| 62 | :risky t | 62 | :risky t |
| 63 | :version "28.1") | 63 | :version "28.1") |
| 64 | 64 | ||
| 65 | (defconst comp-known-type-specifiers | ||
| 66 | `( | ||
| 67 | ;; Functions we can trust not to be redefined, or, if redefined, | ||
| 68 | ;; to expose the same type. The vast majority of these are | ||
| 69 | ;; either pure or primitive; the original list is the union of | ||
| 70 | ;; pure + side-effect-free-fns + side-effect-and-error-free-fns: | ||
| 71 | (% (function ((or number marker) (or number marker)) number)) | ||
| 72 | (* (function (&rest (or number marker)) number)) | ||
| 73 | (+ (function (&rest (or number marker)) number)) | ||
| 74 | (- (function (&rest (or number marker)) number)) | ||
| 75 | (/ (function ((or number marker) &rest (or number marker)) number)) | ||
| 76 | (/= (function ((or number marker) (or number marker)) boolean)) | ||
| 77 | (1+ (function ((or number marker)) number)) | ||
| 78 | (1- (function ((or number marker)) number)) | ||
| 79 | (< (function ((or number marker) &rest (or number marker)) boolean)) | ||
| 80 | (<= (function ((or number marker) &rest (or number marker)) boolean)) | ||
| 81 | (= (function ((or number marker) &rest (or number marker)) boolean)) | ||
| 82 | (> (function ((or number marker) &rest (or number marker)) boolean)) | ||
| 83 | (>= (function ((or number marker) &rest (or number marker)) boolean)) | ||
| 84 | (abs (function (number) number)) | ||
| 85 | (acos (function (number) float)) | ||
| 86 | (append (function (&rest t) t)) | ||
| 87 | (aref (function (t fixnum) t)) | ||
| 88 | (arrayp (function (t) boolean)) | ||
| 89 | (ash (function (integer integer) integer)) | ||
| 90 | (asin (function (number) float)) | ||
| 91 | (assq (function (t list) list)) | ||
| 92 | (atan (function (number &optional number) float)) | ||
| 93 | (atom (function (t) boolean)) | ||
| 94 | (bignump (function (t) boolean)) | ||
| 95 | (bobp (function () boolean)) | ||
| 96 | (bolp (function () boolean)) | ||
| 97 | (bool-vector-count-consecutive | ||
| 98 | (function (bool-vector boolean integer) fixnum)) | ||
| 99 | (bool-vector-count-population (function (bool-vector) fixnum)) | ||
| 100 | (bool-vector-not (function (bool-vector &optional bool-vector) bool-vector)) | ||
| 101 | (bool-vector-p (function (t) boolean)) | ||
| 102 | (bool-vector-subsetp (function (bool-vector bool-vector) boolean)) | ||
| 103 | (boundp (function (symbol) boolean)) | ||
| 104 | (buffer-end (function ((or number marker)) integer)) | ||
| 105 | (buffer-file-name (function (&optional buffer) (or string null))) | ||
| 106 | (buffer-list (function (&optional frame) list)) | ||
| 107 | (buffer-local-variables (function (&optional buffer) list)) | ||
| 108 | (buffer-modified-p | ||
| 109 | (function (&optional buffer) (or boolean (member autosaved)))) | ||
| 110 | (buffer-size (function (&optional buffer) integer)) | ||
| 111 | (buffer-string (function () string)) | ||
| 112 | (buffer-substring | ||
| 113 | (function ((or integer marker) (or integer marker)) string)) | ||
| 114 | (bufferp (function (t) boolean)) | ||
| 115 | (byte-code-function-p (function (t) boolean)) | ||
| 116 | (capitalize (function (or integer string) (or integer string))) | ||
| 117 | (car (function (list) t)) | ||
| 118 | (car-less-than-car (function (list list) boolean)) | ||
| 119 | (car-safe (function (t) t)) | ||
| 120 | (case-table-p (function (t) boolean)) | ||
| 121 | (cdr (function (list) t)) | ||
| 122 | (cdr-safe (function (t) t)) | ||
| 123 | (ceiling (function (number &optional number) integer)) | ||
| 124 | (char-after (function (&optional (or marker integer)) (or fixnum null))) | ||
| 125 | (char-before (function (&optional (or marker integer)) (or fixnum null))) | ||
| 126 | (char-equal (function (integer integer) boolean)) | ||
| 127 | (char-or-string-p (function (t) boolean)) | ||
| 128 | (char-to-string (function (fixnum) string)) | ||
| 129 | (char-width (function (fixnum) fixnum)) | ||
| 130 | (characterp (function (t &optional t) boolean)) | ||
| 131 | (charsetp (function (t) boolean)) | ||
| 132 | (commandp (function (t &optional t) boolean)) | ||
| 133 | (compare-strings | ||
| 134 | (function (string (or integer marker null) (or integer marker null) string | ||
| 135 | (or integer marker null) (or integer marker null) | ||
| 136 | &optional t) | ||
| 137 | (or (member t) fixnum))) | ||
| 138 | (concat (function (&rest sequence) string)) | ||
| 139 | (cons (function (t t) cons)) | ||
| 140 | (consp (function (t) boolean)) | ||
| 141 | (coordinates-in-window-p | ||
| 142 | (function (cons window) | ||
| 143 | (or cons null | ||
| 144 | (member bottom-divider right-divider mode-line header-line | ||
| 145 | tab-line left-fringe right-fringe vertical-line | ||
| 146 | left-margin right-margin)))) | ||
| 147 | (copy-alist (function (list) list)) | ||
| 148 | (copy-marker (function (&optional (or integer marker) boolean) marker)) | ||
| 149 | (copy-sequence (function (sequence) sequence)) | ||
| 150 | (copysign (function (float float) float)) | ||
| 151 | (cos (function (number) float)) | ||
| 152 | (count-lines | ||
| 153 | (function ((or integer marker) (or integer marker) &optional t) integer)) | ||
| 154 | (current-buffer (function () buffer)) | ||
| 155 | (current-global-map (function () cons)) | ||
| 156 | (current-indentation (function () integer)) | ||
| 157 | (current-local-map (function () (or cons null))) | ||
| 158 | (current-minor-mode-maps (function () (or cons null))) | ||
| 159 | (current-time (function () cons)) | ||
| 160 | (current-time-string (function (&optional (or number list) | ||
| 161 | (or symbol string cons integer)) | ||
| 162 | string)) | ||
| 163 | (current-time-zone (function (&optional (or number list) | ||
| 164 | (or symbol string cons integer)) | ||
| 165 | cons)) | ||
| 166 | (custom-variable-p (function (symbol) t)) | ||
| 167 | (decode-char (function (cons t) (or fixnum null))) | ||
| 168 | (decode-time (function (&optional (or number list) | ||
| 169 | (or symbol string cons integer) | ||
| 170 | symbol) | ||
| 171 | cons)) | ||
| 172 | (default-boundp (function (symbol) boolean)) | ||
| 173 | (default-value (function (symbol) t)) | ||
| 174 | (degrees-to-radians (function (number) float)) | ||
| 175 | (documentation | ||
| 176 | (function ((or function symbol subr) &optional t) (or null string))) | ||
| 177 | (downcase (function ((or fixnum string)) (or fixnum string))) | ||
| 178 | (elt (function (sequence integer) t)) | ||
| 179 | (encode-char (function (fixnum symbol) (or fixnum null))) | ||
| 180 | (encode-time (function (cons &rest t) cons)) | ||
| 181 | (eobp (function () boolean)) | ||
| 182 | (eolp (function () boolean)) | ||
| 183 | (eq (function (t t) boolean)) | ||
| 184 | (eql (function (t t) boolean)) | ||
| 185 | (equal (function (t t) boolean)) | ||
| 186 | (error-message-string (function (list) string)) | ||
| 187 | (eventp (function (t) boolean)) | ||
| 188 | (exp (function (number) float)) | ||
| 189 | (expt (function (number number) number)) | ||
| 190 | (fboundp (function (symbol) boolean)) | ||
| 191 | (fceiling (function (float) float)) | ||
| 192 | (featurep (function (symbol &optional symbol) boolean)) | ||
| 193 | (ffloor (function (float) float)) | ||
| 194 | (file-directory-p (function (string) boolean)) | ||
| 195 | (file-exists-p (function (string) boolean)) | ||
| 196 | (file-locked-p (function (string) (or boolean string))) | ||
| 197 | (file-name-absolute-p (function (string) boolean)) | ||
| 198 | (file-newer-than-file-p (function (string string) boolean)) | ||
| 199 | (file-readable-p (function (string) boolean)) | ||
| 200 | (file-symlink-p (function (string) (or boolean string))) | ||
| 201 | (file-writable-p (function (string) boolean)) | ||
| 202 | (fixnump (function (t) boolean)) | ||
| 203 | (float (function (number) float)) | ||
| 204 | (float-time (function (&optional (or number list)) float)) | ||
| 205 | (floatp (function (t) boolean)) | ||
| 206 | (floor (function (number &optional number) integer)) | ||
| 207 | (following-char (function () fixnum)) | ||
| 208 | (format (function (string &rest t) string)) | ||
| 209 | (format-time-string (function (string &optional (or number list) | ||
| 210 | (or symbol string cons integer)) | ||
| 211 | string)) | ||
| 212 | (frame-first-window (function ((or frame window)) window)) | ||
| 213 | (frame-root-window (function (&optional (or frame window)) window)) | ||
| 214 | (frame-selected-window (function (&optional (or frame window)) window)) | ||
| 215 | (frame-visible-p (function (frame) (or boolean (member icon)))) | ||
| 216 | (framep (function (t) symbol)) | ||
| 217 | (fround (function (float) float)) | ||
| 218 | (ftruncate (function (float) float)) | ||
| 219 | (get (function (symbol symbol) t)) | ||
| 220 | (get-buffer (function ((or buffer string)) (or buffer null))) | ||
| 221 | (get-buffer-window | ||
| 222 | (function (&optional (or buffer string) (or symbol (integer 0 0))) | ||
| 223 | (or null window))) | ||
| 224 | (get-file-buffer (function (string) (or null buffer))) | ||
| 225 | (get-largest-window (function (&optional t t t) (or window null))) | ||
| 226 | (get-lru-window (function (&optional t t t) (or window null))) | ||
| 227 | (getenv (function (string &optional frame) (or null string))) | ||
| 228 | (gethash (function (t hash-table &optional t) t)) | ||
| 229 | (hash-table-count (function (hash-table) integer)) | ||
| 230 | (hash-table-p (function (t) boolean)) | ||
| 231 | (identity (function (t) t)) | ||
| 232 | (ignore (function (&rest t) null)) | ||
| 233 | (int-to-string (function (number) string)) | ||
| 234 | (integer-or-marker-p (function (t) boolean)) | ||
| 235 | (integerp (function (t) boolean)) | ||
| 236 | (interactive-p (function () boolean)) | ||
| 237 | (intern-soft (function ((or string symbol) &optional vector) symbol)) | ||
| 238 | (invocation-directory (function () string)) | ||
| 239 | (invocation-name (function () string)) | ||
| 240 | (isnan (function (float) boolean)) | ||
| 241 | (keymap-parent (function (cons) (or cons null))) | ||
| 242 | (keymapp (function (t) boolean)) | ||
| 243 | (keywordp (function (t) boolean)) | ||
| 244 | (last (function (list &optional integer) list)) | ||
| 245 | (lax-plist-get (function (list t) t)) | ||
| 246 | (ldexp (function (number integer) float)) | ||
| 247 | (length (function (t) (integer 0 *))) | ||
| 248 | (length< (function (sequence fixnum) boolean)) | ||
| 249 | (length= (function (sequence fixnum) boolean)) | ||
| 250 | (length> (function (sequence fixnum) boolean)) | ||
| 251 | (line-beginning-position (function (&optional integer) integer)) | ||
| 252 | (line-end-position (function (&optional integer) integer)) | ||
| 253 | (list (function (&rest t) list)) | ||
| 254 | (listp (function (t) boolean)) | ||
| 255 | (local-variable-if-set-p (function (symbol &optional buffer) boolean)) | ||
| 256 | (local-variable-p (function (symbol &optional buffer) boolean)) | ||
| 257 | (locale-info (function ((member codeset days months paper)) (or null string))) | ||
| 258 | (log (function (number number) float)) | ||
| 259 | (log10 (function (number) float)) | ||
| 260 | (logand (function (&rest (or integer marker)) integer)) | ||
| 261 | (logb (function (number) integer)) | ||
| 262 | (logcount (function (integer) integer)) | ||
| 263 | (logior (function (&rest (or integer marker)) integer)) | ||
| 264 | (lognot (function (integer) integer)) | ||
| 265 | (logxor (function (&rest (or integer marker)) integer)) | ||
| 266 | ;; (lsh (function ((integer ,most-negative-fixnum *) integer) integer)) ? | ||
| 267 | (lsh (function (integer integer) integer)) | ||
| 268 | (make-byte-code | ||
| 269 | (function ((or fixnum list) string vector integer &optional string t | ||
| 270 | &rest t) | ||
| 271 | vector)) | ||
| 272 | (make-list (function (integer t) list)) | ||
| 273 | (make-marker (function () marker)) | ||
| 274 | (make-string (function (integer fixnum &optional t) string)) | ||
| 275 | (make-symbol (function (string) symbol)) | ||
| 276 | (mark (function (&optional t) (or integer null))) | ||
| 277 | (mark-marker (function () marker)) | ||
| 278 | (marker-buffer (function (marker) (or buffer null))) | ||
| 279 | (markerp (function (t) boolean)) | ||
| 280 | (max (function ((or number marker) &rest (or number marker)) number)) | ||
| 281 | (max-char (function (&optional t) fixnum)) | ||
| 282 | (member (function (t list) list)) | ||
| 283 | (memory-limit (function () integer)) | ||
| 284 | (memq (function (t list) list)) | ||
| 285 | (memql (function (t list) list)) | ||
| 286 | (min (function ((or number marker) &rest (or number marker)) number)) | ||
| 287 | (minibuffer-selected-window (function () (or window null))) | ||
| 288 | (minibuffer-window (function (&optional frame) window)) | ||
| 289 | (mod | ||
| 290 | (function ((or number marker) (or number marker)) | ||
| 291 | (or (integer 0 *) (float 0 *)))) | ||
| 292 | (mouse-movement-p (function (t) boolean)) | ||
| 293 | (multibyte-char-to-unibyte (function (fixnum) fixnum)) | ||
| 294 | (natnump (function (t) boolean)) | ||
| 295 | (next-window (function (&optional window t t) window)) | ||
| 296 | (nlistp (function (t) boolean)) | ||
| 297 | (not (function (t) boolean)) | ||
| 298 | (nth (function (integer list) t)) | ||
| 299 | (nthcdr (function (integer t) t)) | ||
| 300 | (null (function (t) boolean)) | ||
| 301 | (number-or-marker-p (function (t) boolean)) | ||
| 302 | (number-to-string (function (number) string)) | ||
| 303 | (numberp (function (t) boolean)) | ||
| 304 | (one-window-p (function (&optional t t) boolean)) | ||
| 305 | (overlayp (function (t) boolean)) | ||
| 306 | (parse-colon-path (function (string) cons)) | ||
| 307 | (plist-get (function (list t &optional t) t)) | ||
| 308 | (plist-member (function (list t &optional t) list)) | ||
| 309 | (point (function () integer)) | ||
| 310 | (point-marker (function () marker)) | ||
| 311 | (point-max (function () integer)) | ||
| 312 | (point-min (function () integer)) | ||
| 313 | (preceding-char (function () fixnum)) | ||
| 314 | (previous-window (function (&optional window t t) window)) | ||
| 315 | (prin1-to-string (function (t &optional t t) string)) | ||
| 316 | (processp (function (t) boolean)) | ||
| 317 | (proper-list-p (function (t) (or fixnum null))) | ||
| 318 | (propertize (function (string &rest t) string)) | ||
| 319 | (radians-to-degrees (function (number) float)) | ||
| 320 | (rassoc (function (t list) list)) | ||
| 321 | (rassq (function (t list) list)) | ||
| 322 | (read-from-string (function (string &optional integer integer) cons)) | ||
| 323 | (recent-keys (function (&optional (or cons null)) vector)) | ||
| 324 | (recursion-depth (function () integer)) | ||
| 325 | (regexp-opt (function (list) string)) | ||
| 326 | (regexp-quote (function (string) string)) | ||
| 327 | (region-beginning (function () integer)) | ||
| 328 | (region-end (function () integer)) | ||
| 329 | (reverse (function (sequence) sequence)) | ||
| 330 | (round (function (number &optional number) integer)) | ||
| 331 | (safe-length (function (t) integer)) | ||
| 332 | (selected-frame (function () frame)) | ||
| 333 | (selected-window (function () window)) | ||
| 334 | (sequencep (function (t) boolean)) | ||
| 335 | (sin (function (number) float)) | ||
| 336 | (sqrt (function (number) float)) | ||
| 337 | (standard-case-table (function () char-table)) | ||
| 338 | (standard-syntax-table (function () char-table)) | ||
| 339 | (string (function (&rest fixnum) string)) | ||
| 340 | (string-as-multibyte (function (string) string)) | ||
| 341 | (string-as-unibyte (function (string) string)) | ||
| 342 | (string-equal (function ((or string symbol) (or string symbol)) boolean)) | ||
| 343 | (string-lessp (function ((or string symbol) (or string symbol)) boolean)) | ||
| 344 | (string-make-multibyte (function (string) string)) | ||
| 345 | (string-make-unibyte (function (string) string)) | ||
| 346 | (string-search (function (string string &optional integer) (or integer null))) | ||
| 347 | (string-to-char (function (string) fixnum)) | ||
| 348 | (string-to-multibyte (function (string) string)) | ||
| 349 | (string-to-number (function (string &optional integer) number)) | ||
| 350 | (string-to-syntax (function (string) (or cons null))) | ||
| 351 | (string< (function ((or string symbol) (or string symbol)) boolean)) | ||
| 352 | (string= (function ((or string symbol) (or string symbol)) boolean)) | ||
| 353 | (stringp (function (t) boolean)) | ||
| 354 | (subrp (function (t) boolean)) | ||
| 355 | (substring | ||
| 356 | (function ((or string vector) &optional integer integer) (or string vector))) | ||
| 357 | (sxhash (function (t) integer)) | ||
| 358 | (sxhash-eq (function (t) integer)) | ||
| 359 | (sxhash-eql (function (t) integer)) | ||
| 360 | (sxhash-equal (function (t) integer)) | ||
| 361 | (symbol-function (function (symbol) t)) | ||
| 362 | (symbol-name (function (symbol) string)) | ||
| 363 | (symbol-plist (function (symbol) list)) | ||
| 364 | (symbol-value (function (symbol) t)) | ||
| 365 | (symbolp (function (t) boolean)) | ||
| 366 | (syntax-table (function () char-table)) | ||
| 367 | (syntax-table-p (function (t) boolean)) | ||
| 368 | (tan (function (number) float)) | ||
| 369 | (this-command-keys (function () string)) | ||
| 370 | (this-command-keys-vector (function () vector)) | ||
| 371 | (this-single-command-keys (function () vector)) | ||
| 372 | (this-single-command-raw-keys (function () vector)) | ||
| 373 | (time-convert (function ((or number list) &optional (or symbol integer)) | ||
| 374 | (or cons number))) | ||
| 375 | (truncate (function (number &optional number) integer)) | ||
| 376 | (type-of (function (t) symbol)) | ||
| 377 | (unibyte-char-to-multibyte (function (fixnum) fixnum)) ;; byte is fixnum | ||
| 378 | (upcase (function ((or fixnum string)) (or fixnum string))) | ||
| 379 | (user-full-name (function (&optional integer) (or string null))) | ||
| 380 | (user-login-name (function (&optional integer) (or string null))) | ||
| 381 | (user-original-login-name (function (&optional integer) (or string null))) | ||
| 382 | (user-real-login-name (function () string)) | ||
| 383 | (user-real-uid (function () integer)) | ||
| 384 | (user-uid (function () integer)) | ||
| 385 | (vconcat (function (&rest sequence) vector)) | ||
| 386 | (vector (function (&rest t) vector)) | ||
| 387 | (vectorp (function (t) boolean)) | ||
| 388 | (visible-frame-list (function () list)) | ||
| 389 | (wholenump (function (t) boolean)) | ||
| 390 | (window-configuration-p (function (t) boolean)) | ||
| 391 | (window-live-p (function (t) boolean)) | ||
| 392 | (window-valid-p (function (t) boolean)) | ||
| 393 | (windowp (function (t) boolean)) | ||
| 394 | (zerop (function (number) boolean)) | ||
| 395 | ;; Type hints | ||
| 396 | (comp-hint-fixnum (function (t) fixnum)) | ||
| 397 | (comp-hint-cons (function (t) cons)) | ||
| 398 | ;; Non returning functions | ||
| 399 | (throw (function (t t) nil)) | ||
| 400 | (error (function (string &rest t) nil)) | ||
| 401 | (signal (function (symbol t) nil))) | ||
| 402 | "Alist used for type propagation.") | ||
| 403 | |||
| 65 | (defconst comp-limple-calls '(call | 404 | (defconst comp-limple-calls '(call |
| 66 | callref | 405 | callref |
| 67 | direct-call | 406 | direct-call |
| @@ -180,6 +519,29 @@ Account for `native-comp-eln-load-path' and `comp-native-version-dir'." | |||
| 180 | (expand-file-name dir invocation-directory)))) | 519 | (expand-file-name dir invocation-directory)))) |
| 181 | native-comp-eln-load-path)) | 520 | native-comp-eln-load-path)) |
| 182 | 521 | ||
| 522 | ;;;###autoload | ||
| 523 | (defun comp-function-type-spec (function) | ||
| 524 | "Return the type specifier of FUNCTION. | ||
| 525 | |||
| 526 | This function returns a cons cell whose car is the function | ||
| 527 | specifier, and cdr is a symbol, either `inferred' or `know'. | ||
| 528 | If the symbol is `inferred', the type specifier is automatically | ||
| 529 | inferred from the code itself by the native compiler; if it is | ||
| 530 | `know', the type specifier comes from `comp-known-type-specifiers'." | ||
| 531 | (let ((kind 'know) | ||
| 532 | type-spec ) | ||
| 533 | (when-let ((res (assoc function comp-known-type-specifiers))) | ||
| 534 | (setf type-spec (cadr res))) | ||
| 535 | (let ((f (and (symbolp function) | ||
| 536 | (symbol-function function)))) | ||
| 537 | (when (and f | ||
| 538 | (null type-spec) | ||
| 539 | (subr-native-elisp-p f)) | ||
| 540 | (setf kind 'inferred | ||
| 541 | type-spec (subr-type f)))) | ||
| 542 | (when type-spec | ||
| 543 | (cons type-spec kind)))) | ||
| 544 | |||
| 183 | (provide 'comp-common) | 545 | (provide 'comp-common) |
| 184 | 546 | ||
| 185 | ;;; comp-common.el ends here | 547 | ;;; comp-common.el ends here |