diff options
| author | Po Lu | 2023-06-05 08:46:58 +0800 |
|---|---|---|
| committer | Po Lu | 2023-06-05 08:46:58 +0800 |
| commit | 6f0ebe11aaf9b2e54df14147cd2f62b048ffec9a (patch) | |
| tree | c5f87c4ab9f4f264c361856a013b90604e3c5ce8 | |
| parent | 835ac18a76a30e2a5142e6e643e858bb05e83642 (diff) | |
| parent | 6058b4559d4b7d42bbcb6da787a95334aa8994ca (diff) | |
| download | emacs-6f0ebe11aaf9b2e54df14147cd2f62b048ffec9a.tar.gz emacs-6f0ebe11aaf9b2e54df14147cd2f62b048ffec9a.zip | |
Merge remote-tracking branch 'origin/master' into feature/android
| -rw-r--r-- | lisp/emacs-lisp/byte-opt.el | 14 | ||||
| -rw-r--r-- | lisp/emacs-lisp/comp-cstr.el | 19 | ||||
| -rw-r--r-- | lisp/emacs-lisp/comp.el | 75 | ||||
| -rw-r--r-- | lisp/help-fns.el | 12 |
4 files changed, 88 insertions, 32 deletions
diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el index 562f21aa751..f64674d5a6c 100644 --- a/lisp/emacs-lisp/byte-opt.el +++ b/lisp/emacs-lisp/byte-opt.el | |||
| @@ -447,16 +447,10 @@ for speeding up processing.") | |||
| 447 | . ,(byte-optimize-body exps for-effect))) | 447 | . ,(byte-optimize-body exps for-effect))) |
| 448 | 448 | ||
| 449 | ;; Needed as long as we run byte-optimize-form after cconv. | 449 | ;; Needed as long as we run byte-optimize-form after cconv. |
| 450 | (`(internal-make-closure . ,_) | 450 | (`(internal-make-closure ,vars ,env . ,rest) |
| 451 | (and (not for-effect) | 451 | (if for-effect |
| 452 | (progn | 452 | `(progn ,@(byte-optimize-body env t)) |
| 453 | ;; Look up free vars and mark them to be kept, so that they | 453 | `(,fn ,vars ,(mapcar #'byte-optimize-form env) . ,rest))) |
| 454 | ;; won't be optimized away. | ||
| 455 | (dolist (var (caddr form)) | ||
| 456 | (let ((lexvar (assq var byte-optimize--lexvars))) | ||
| 457 | (when lexvar | ||
| 458 | (setcar (cdr lexvar) t)))) | ||
| 459 | form))) | ||
| 460 | 454 | ||
| 461 | (`((lambda . ,_) . ,_) | 455 | (`((lambda . ,_) . ,_) |
| 462 | (let ((newform (macroexp--unfold-lambda form))) | 456 | (let ((newform (macroexp--unfold-lambda form))) |
diff --git a/lisp/emacs-lisp/comp-cstr.el b/lisp/emacs-lisp/comp-cstr.el index 416ca7f11b0..e0db82604f2 100644 --- a/lisp/emacs-lisp/comp-cstr.el +++ b/lisp/emacs-lisp/comp-cstr.el | |||
| @@ -36,6 +36,7 @@ | |||
| 36 | ;;; Code: | 36 | ;;; Code: |
| 37 | 37 | ||
| 38 | (require 'cl-lib) | 38 | (require 'cl-lib) |
| 39 | (require 'cl-macs) | ||
| 39 | 40 | ||
| 40 | (defconst comp--typeof-builtin-types (mapcar (lambda (x) | 41 | (defconst comp--typeof-builtin-types (mapcar (lambda (x) |
| 41 | (append x '(t))) | 42 | (append x '(t))) |
| @@ -1181,8 +1182,8 @@ FN non-nil indicates we are parsing a function lambda list." | |||
| 1181 | :ret (comp-type-spec-to-cstr ret))) | 1182 | :ret (comp-type-spec-to-cstr ret))) |
| 1182 | (_ (error "Invalid type specifier")))) | 1183 | (_ (error "Invalid type specifier")))) |
| 1183 | 1184 | ||
| 1184 | (defun comp-cstr-to-type-spec (cstr) | 1185 | (defun comp--simple-cstr-to-type-spec (cstr) |
| 1185 | "Given CSTR return its type specifier." | 1186 | "Given a non comp-cstr-f CSTR return its type specifier." |
| 1186 | (let ((valset (comp-cstr-valset cstr)) | 1187 | (let ((valset (comp-cstr-valset cstr)) |
| 1187 | (typeset (comp-cstr-typeset cstr)) | 1188 | (typeset (comp-cstr-typeset cstr)) |
| 1188 | (range (comp-cstr-range cstr)) | 1189 | (range (comp-cstr-range cstr)) |
| @@ -1236,6 +1237,20 @@ FN non-nil indicates we are parsing a function lambda list." | |||
| 1236 | `(not ,final) | 1237 | `(not ,final) |
| 1237 | final)))) | 1238 | final)))) |
| 1238 | 1239 | ||
| 1240 | (defun comp-cstr-to-type-spec (cstr) | ||
| 1241 | "Given CSTR return its type specifier." | ||
| 1242 | (cl-etypecase cstr | ||
| 1243 | (comp-cstr-f | ||
| 1244 | `(function | ||
| 1245 | ,(mapcar (lambda (x) | ||
| 1246 | (cl-etypecase x | ||
| 1247 | (comp-cstr (comp-cstr-to-type-spec x)) | ||
| 1248 | (symbol x))) | ||
| 1249 | (comp-cstr-f-args cstr)) | ||
| 1250 | ,(comp--simple-cstr-to-type-spec (comp-cstr-f-ret cstr)))) | ||
| 1251 | (comp-cstr | ||
| 1252 | (comp--simple-cstr-to-type-spec cstr)))) | ||
| 1253 | |||
| 1239 | (provide 'comp-cstr) | 1254 | (provide 'comp-cstr) |
| 1240 | 1255 | ||
| 1241 | ;;; comp-cstr.el ends here | 1256 | ;;; comp-cstr.el ends here |
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index 2ea405728a3..b65da148787 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el | |||
| @@ -277,10 +277,10 @@ Useful to hook into pass checkers.") | |||
| 277 | ;; FIXME this probably should not be here but... good for now. | 277 | ;; FIXME this probably should not be here but... good for now. |
| 278 | (defconst comp-known-type-specifiers | 278 | (defconst comp-known-type-specifiers |
| 279 | `( | 279 | `( |
| 280 | ;; Functions we can trust not to be or if redefined should expose | 280 | ;; Functions we can trust not to be redefined, or, if redefined, |
| 281 | ;; the same type. Vast majority of these is either pure or | 281 | ;; to expose the same type. The vast majority of these are |
| 282 | ;; primitive, the original list is the union of pure + | 282 | ;; either pure or primitive; the original list is the union of |
| 283 | ;; side-effect-free-fns + side-effect-and-error-free-fns: | 283 | ;; pure + side-effect-free-fns + side-effect-and-error-free-fns: |
| 284 | (% (function ((or number marker) (or number marker)) number)) | 284 | (% (function ((or number marker) (or number marker)) number)) |
| 285 | (* (function (&rest (or number marker)) number)) | 285 | (* (function (&rest (or number marker)) number)) |
| 286 | (+ (function (&rest (or number marker)) number)) | 286 | (+ (function (&rest (or number marker)) number)) |
| @@ -307,7 +307,8 @@ Useful to hook into pass checkers.") | |||
| 307 | (bignump (function (t) boolean)) | 307 | (bignump (function (t) boolean)) |
| 308 | (bobp (function () boolean)) | 308 | (bobp (function () boolean)) |
| 309 | (bolp (function () boolean)) | 309 | (bolp (function () boolean)) |
| 310 | (bool-vector-count-consecutive (function (bool-vector boolean integer) fixnum)) | 310 | (bool-vector-count-consecutive |
| 311 | (function (bool-vector boolean integer) fixnum)) | ||
| 311 | (bool-vector-count-population (function (bool-vector) fixnum)) | 312 | (bool-vector-count-population (function (bool-vector) fixnum)) |
| 312 | (bool-vector-not (function (bool-vector &optional bool-vector) bool-vector)) | 313 | (bool-vector-not (function (bool-vector &optional bool-vector) bool-vector)) |
| 313 | (bool-vector-p (function (t) boolean)) | 314 | (bool-vector-p (function (t) boolean)) |
| @@ -317,10 +318,12 @@ Useful to hook into pass checkers.") | |||
| 317 | (buffer-file-name (function (&optional buffer) (or string null))) | 318 | (buffer-file-name (function (&optional buffer) (or string null))) |
| 318 | (buffer-list (function (&optional frame) list)) | 319 | (buffer-list (function (&optional frame) list)) |
| 319 | (buffer-local-variables (function (&optional buffer) list)) | 320 | (buffer-local-variables (function (&optional buffer) list)) |
| 320 | (buffer-modified-p (function (&optional buffer) (or boolean (member autosaved)))) | 321 | (buffer-modified-p |
| 322 | (function (&optional buffer) (or boolean (member autosaved)))) | ||
| 321 | (buffer-size (function (&optional buffer) integer)) | 323 | (buffer-size (function (&optional buffer) integer)) |
| 322 | (buffer-string (function () string)) | 324 | (buffer-string (function () string)) |
| 323 | (buffer-substring (function ((or integer marker) (or integer marker)) string)) | 325 | (buffer-substring |
| 326 | (function ((or integer marker) (or integer marker)) string)) | ||
| 324 | (bufferp (function (t) boolean)) | 327 | (bufferp (function (t) boolean)) |
| 325 | (byte-code-function-p (function (t) boolean)) | 328 | (byte-code-function-p (function (t) boolean)) |
| 326 | (capitalize (function (or integer string) (or integer string))) | 329 | (capitalize (function (or integer string) (or integer string))) |
| @@ -340,17 +343,27 @@ Useful to hook into pass checkers.") | |||
| 340 | (characterp (function (t &optional t) boolean)) | 343 | (characterp (function (t &optional t) boolean)) |
| 341 | (charsetp (function (t) boolean)) | 344 | (charsetp (function (t) boolean)) |
| 342 | (commandp (function (t &optional t) boolean)) | 345 | (commandp (function (t &optional t) boolean)) |
| 343 | (compare-strings (function (string (or integer marker null) (or integer marker null) string (or integer marker null) (or integer marker null) &optional t) (or (member t) fixnum))) | 346 | (compare-strings |
| 347 | (function (string (or integer marker null) (or integer marker null) string | ||
| 348 | (or integer marker null) (or integer marker null) | ||
| 349 | &optional t) | ||
| 350 | (or (member t) fixnum))) | ||
| 344 | (concat (function (&rest sequence) string)) | 351 | (concat (function (&rest sequence) string)) |
| 345 | (cons (function (t t) cons)) | 352 | (cons (function (t t) cons)) |
| 346 | (consp (function (t) boolean)) | 353 | (consp (function (t) boolean)) |
| 347 | (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)))) | 354 | (coordinates-in-window-p |
| 355 | (function (cons window) | ||
| 356 | (or cons null | ||
| 357 | (member bottom-divider right-divider mode-line header-line | ||
| 358 | tab-line left-fringe right-fringe vertical-line | ||
| 359 | left-margin right-margin)))) | ||
| 348 | (copy-alist (function (list) list)) | 360 | (copy-alist (function (list) list)) |
| 349 | (copy-marker (function (&optional (or integer marker) boolean) marker)) | 361 | (copy-marker (function (&optional (or integer marker) boolean) marker)) |
| 350 | (copy-sequence (function (sequence) sequence)) | 362 | (copy-sequence (function (sequence) sequence)) |
| 351 | (copysign (function (float float) float)) | 363 | (copysign (function (float float) float)) |
| 352 | (cos (function (number) float)) | 364 | (cos (function (number) float)) |
| 353 | (count-lines (function ((or integer marker) (or integer marker) &optional t) integer)) | 365 | (count-lines |
| 366 | (function ((or integer marker) (or integer marker) &optional t) integer)) | ||
| 354 | (current-buffer (function () buffer)) | 367 | (current-buffer (function () buffer)) |
| 355 | (current-global-map (function () cons)) | 368 | (current-global-map (function () cons)) |
| 356 | (current-indentation (function () integer)) | 369 | (current-indentation (function () integer)) |
| @@ -372,7 +385,8 @@ Useful to hook into pass checkers.") | |||
| 372 | (default-boundp (function (symbol) boolean)) | 385 | (default-boundp (function (symbol) boolean)) |
| 373 | (default-value (function (symbol) t)) | 386 | (default-value (function (symbol) t)) |
| 374 | (degrees-to-radians (function (number) float)) | 387 | (degrees-to-radians (function (number) float)) |
| 375 | (documentation (function ((or function symbol subr) &optional t) (or null string))) | 388 | (documentation |
| 389 | (function ((or function symbol subr) &optional t) (or null string))) | ||
| 376 | (downcase (function ((or fixnum string)) (or fixnum string))) | 390 | (downcase (function ((or fixnum string)) (or fixnum string))) |
| 377 | (elt (function (sequence integer) t)) | 391 | (elt (function (sequence integer) t)) |
| 378 | (encode-char (function (fixnum symbol) (or fixnum null))) | 392 | (encode-char (function (fixnum symbol) (or fixnum null))) |
| @@ -412,12 +426,14 @@ Useful to hook into pass checkers.") | |||
| 412 | (frame-root-window (function (&optional (or frame window)) window)) | 426 | (frame-root-window (function (&optional (or frame window)) window)) |
| 413 | (frame-selected-window (function (&optional (or frame window)) window)) | 427 | (frame-selected-window (function (&optional (or frame window)) window)) |
| 414 | (frame-visible-p (function (frame) (or boolean (member icon)))) | 428 | (frame-visible-p (function (frame) (or boolean (member icon)))) |
| 415 | (framep (function (t) (or boolean (member x w32 ns pc pgtk haiku)))) | 429 | (framep (function (t) symbol)) |
| 416 | (fround (function (float) float)) | 430 | (fround (function (float) float)) |
| 417 | (ftruncate (function (float) float)) | 431 | (ftruncate (function (float) float)) |
| 418 | (get (function (symbol symbol) t)) | 432 | (get (function (symbol symbol) t)) |
| 419 | (get-buffer (function ((or buffer string)) (or buffer null))) | 433 | (get-buffer (function ((or buffer string)) (or buffer null))) |
| 420 | (get-buffer-window (function (&optional (or buffer string) (or symbol (integer 0 0))) (or null window))) | 434 | (get-buffer-window |
| 435 | (function (&optional (or buffer string) (or symbol (integer 0 0))) | ||
| 436 | (or null window))) | ||
| 421 | (get-file-buffer (function (string) (or null buffer))) | 437 | (get-file-buffer (function (string) (or null buffer))) |
| 422 | (get-largest-window (function (&optional t t t) (or window null))) | 438 | (get-largest-window (function (&optional t t t) (or window null))) |
| 423 | (get-lru-window (function (&optional t t t) (or window null))) | 439 | (get-lru-window (function (&optional t t t) (or window null))) |
| @@ -462,7 +478,10 @@ Useful to hook into pass checkers.") | |||
| 462 | (logxor (function (&rest (or integer marker)) integer)) | 478 | (logxor (function (&rest (or integer marker)) integer)) |
| 463 | ;; (lsh (function ((integer ,most-negative-fixnum *) integer) integer)) ? | 479 | ;; (lsh (function ((integer ,most-negative-fixnum *) integer) integer)) ? |
| 464 | (lsh (function (integer integer) integer)) | 480 | (lsh (function (integer integer) integer)) |
| 465 | (make-byte-code (function ((or fixnum list) string vector integer &optional string t &rest t) vector)) | 481 | (make-byte-code |
| 482 | (function ((or fixnum list) string vector integer &optional string t | ||
| 483 | &rest t) | ||
| 484 | vector)) | ||
| 466 | (make-list (function (integer t) list)) | 485 | (make-list (function (integer t) list)) |
| 467 | (make-marker (function () marker)) | 486 | (make-marker (function () marker)) |
| 468 | (make-string (function (integer fixnum &optional t) string)) | 487 | (make-string (function (integer fixnum &optional t) string)) |
| @@ -480,7 +499,9 @@ Useful to hook into pass checkers.") | |||
| 480 | (min (function ((or number marker) &rest (or number marker)) number)) | 499 | (min (function ((or number marker) &rest (or number marker)) number)) |
| 481 | (minibuffer-selected-window (function () (or window null))) | 500 | (minibuffer-selected-window (function () (or window null))) |
| 482 | (minibuffer-window (function (&optional frame) window)) | 501 | (minibuffer-window (function (&optional frame) window)) |
| 483 | (mod (function ((or number marker) (or number marker)) (or (integer 0 *) (float 0 *)))) | 502 | (mod |
| 503 | (function ((or number marker) (or number marker)) | ||
| 504 | (or (integer 0 *) (float 0 *)))) | ||
| 484 | (mouse-movement-p (function (t) boolean)) | 505 | (mouse-movement-p (function (t) boolean)) |
| 485 | (multibyte-char-to-unibyte (function (fixnum) fixnum)) | 506 | (multibyte-char-to-unibyte (function (fixnum) fixnum)) |
| 486 | (natnump (function (t) boolean)) | 507 | (natnump (function (t) boolean)) |
| @@ -544,7 +565,8 @@ Useful to hook into pass checkers.") | |||
| 544 | (string= (function ((or string symbol) (or string symbol)) boolean)) | 565 | (string= (function ((or string symbol) (or string symbol)) boolean)) |
| 545 | (stringp (function (t) boolean)) | 566 | (stringp (function (t) boolean)) |
| 546 | (subrp (function (t) boolean)) | 567 | (subrp (function (t) boolean)) |
| 547 | (substring (function ((or string vector) &optional integer integer) (or string vector))) | 568 | (substring |
| 569 | (function ((or string vector) &optional integer integer) (or string vector))) | ||
| 548 | (sxhash (function (t) integer)) | 570 | (sxhash (function (t) integer)) |
| 549 | (sxhash-eq (function (t) integer)) | 571 | (sxhash-eq (function (t) integer)) |
| 550 | (sxhash-eql (function (t) integer)) | 572 | (sxhash-eql (function (t) integer)) |
| @@ -4425,6 +4447,27 @@ of (commands) to run simultaneously." | |||
| 4425 | (delete-directory subdir)))))) | 4447 | (delete-directory subdir)))))) |
| 4426 | (message "Cache cleared")) | 4448 | (message "Cache cleared")) |
| 4427 | 4449 | ||
| 4450 | ;;;###autoload | ||
| 4451 | (defun comp-function-type-spec (function) | ||
| 4452 | "Return the type specifier of FUNCTION. | ||
| 4453 | |||
| 4454 | This function returns a cons cell whose car is the function | ||
| 4455 | specifier, and cdr is a symbol, either `inferred' or `know'. | ||
| 4456 | If the symbol is `inferred', the type specifier is automatically | ||
| 4457 | inferred from the code itself by the native compiler; if it is | ||
| 4458 | `know', the type specifier comes from `comp-known-type-specifiers'." | ||
| 4459 | (let ((kind 'know) | ||
| 4460 | type-spec ) | ||
| 4461 | (when-let ((res (gethash function comp-known-func-cstr-h))) | ||
| 4462 | (setf type-spec (comp-cstr-to-type-spec res))) | ||
| 4463 | (let ((f (symbol-function function))) | ||
| 4464 | (when (and (null type-spec) | ||
| 4465 | (subr-native-elisp-p f)) | ||
| 4466 | (setf kind 'inferred | ||
| 4467 | type-spec (subr-type f)))) | ||
| 4468 | (when type-spec | ||
| 4469 | (cons type-spec kind)))) | ||
| 4470 | |||
| 4428 | (provide 'comp) | 4471 | (provide 'comp) |
| 4429 | 4472 | ||
| 4430 | ;; LocalWords: limplified limplification limplify Limple LIMPLE libgccjit elc eln | 4473 | ;; LocalWords: limplified limplification limplify Limple LIMPLE libgccjit elc eln |
diff --git a/lisp/help-fns.el b/lisp/help-fns.el index c4e09e48bea..b9388b45397 100644 --- a/lisp/help-fns.el +++ b/lisp/help-fns.el | |||
| @@ -711,10 +711,14 @@ the C sources, too." | |||
| 711 | (unless (and (symbolp function) | 711 | (unless (and (symbolp function) |
| 712 | (get function 'reader-construct)) | 712 | (get function 'reader-construct)) |
| 713 | (insert high-usage "\n") | 713 | (insert high-usage "\n") |
| 714 | (when (and (featurep 'native-compile) | 714 | (when-let* ((res (comp-function-type-spec function)) |
| 715 | (subr-native-elisp-p (symbol-function function)) | 715 | (type-spec (car res)) |
| 716 | (subr-type (symbol-function function))) | 716 | (kind (cdr res))) |
| 717 | (insert (format "\nInferred type: %s\n" (subr-type (symbol-function function)))))) | 717 | (insert (format |
| 718 | (if (eq kind 'inferred) | ||
| 719 | "\nInferred type: %s\n" | ||
| 720 | "\nType: %s\n") | ||
| 721 | type-spec)))) | ||
| 718 | (fill-region fill-begin (point)) | 722 | (fill-region fill-begin (point)) |
| 719 | high-doc))))) | 723 | high-doc))))) |
| 720 | 724 | ||