diff options
| author | Alan Mackenzie | 2023-11-08 20:49:48 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2023-11-08 20:49:48 +0000 |
| commit | 06e4ebc81a44c709b08ce72c746629c6c77e6f6e (patch) | |
| tree | 446db534f18b702256c39d2ce2001294d326ca34 /test/src/comp-tests.el | |
| parent | bf9cbc2354124a1e9eb3327007468ba384ba2945 (diff) | |
| download | emacs-06e4ebc81a44c709b08ce72c746629c6c77e6f6e.tar.gz emacs-06e4ebc81a44c709b08ce72c746629c6c77e6f6e.zip | |
With `native-compile', compile lambdas in a defun or lambda too
This fixes bug#64646. Also refactor two functions to reduce
code duplication.
* lisp/emacs-lisp/comp.el (comp-spill-lap-function/symbol)
(comp-spill-lap-function/list): Add all functions found by the
byte compiler (including lambdas) to the native compiler's
context, thus making them be native compiled. Refactor to use
comp-intern-func-in-ctxt. Make comp-spill-lap-function/list
also compile closures.
* test/src/comp-resources/comp-test-funcs.el
(comp-tests-lambda-return-f2): New function
* test/src/comp-tests.el (comp-test-lambda-return2)
(comp-tests-free-fun-f2): New functions to test that internal
lambdas get native compiled.
Diffstat (limited to 'test/src/comp-tests.el')
| -rw-r--r-- | test/src/comp-tests.el | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/test/src/comp-tests.el b/test/src/comp-tests.el index 2b3c3dd4c75..c2f0af51570 100644 --- a/test/src/comp-tests.el +++ b/test/src/comp-tests.el | |||
| @@ -327,6 +327,14 @@ Check that the resulting binaries do not differ." | |||
| 327 | (should (subr-native-elisp-p f)) | 327 | (should (subr-native-elisp-p f)) |
| 328 | (should (= (funcall f 3) 4)))) | 328 | (should (= (funcall f 3) 4)))) |
| 329 | 329 | ||
| 330 | (comp-deftest lambda-return2 () | ||
| 331 | "Check a nested lambda function gets native compiled." | ||
| 332 | (let ((f (comp-tests-lambda-return-f2))) | ||
| 333 | (should (subr-native-elisp-p f)) | ||
| 334 | (let ((f2 (funcall f))) | ||
| 335 | (should (subr-native-elisp-p f2)) | ||
| 336 | (should (= (funcall f2 3) 4))))) | ||
| 337 | |||
| 330 | (comp-deftest recursive () | 338 | (comp-deftest recursive () |
| 331 | (should (= (comp-tests-fib-f 10) 55))) | 339 | (should (= (comp-tests-fib-f 10) 55))) |
| 332 | 340 | ||
| @@ -388,7 +396,27 @@ Check that the resulting binaries do not differ." | |||
| 388 | "Some doc.")) | 396 | "Some doc.")) |
| 389 | (should (commandp #'comp-tests-free-fun-f)) | 397 | (should (commandp #'comp-tests-free-fun-f)) |
| 390 | (should (equal (interactive-form #'comp-tests-free-fun-f) | 398 | (should (equal (interactive-form #'comp-tests-free-fun-f) |
| 391 | '(interactive)))) | 399 | '(interactive nil)))) |
| 400 | |||
| 401 | (declare-function comp-tests-free-fun-f2 nil) | ||
| 402 | |||
| 403 | (comp-deftest free-fun2 () | ||
| 404 | "Check compiling a symbol's function compiles contained lambdas." | ||
| 405 | (eval '(defun comp-tests-free-fun-f2 () | ||
| 406 | (lambda (x) | ||
| 407 | "Some doc." | ||
| 408 | (interactive) | ||
| 409 | x))) | ||
| 410 | (native-compile #'comp-tests-free-fun-f2) | ||
| 411 | |||
| 412 | (let* ((f (symbol-function 'comp-tests-free-fun-f2)) | ||
| 413 | (f2 (funcall f))) | ||
| 414 | (should (subr-native-elisp-p f)) | ||
| 415 | (should (subr-native-elisp-p f2)) | ||
| 416 | (should (string= (documentation f2) "Some doc.")) | ||
| 417 | (should (commandp f2)) | ||
| 418 | (should (equal (interactive-form f2) '(interactive nil))) | ||
| 419 | (should (= (funcall f2 3) 3)))) | ||
| 392 | 420 | ||
| 393 | (declare-function comp-tests/free\fun-f nil) | 421 | (declare-function comp-tests/free\fun-f nil) |
| 394 | 422 | ||