aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorStefan Monnier2024-03-11 16:12:26 -0400
committerStefan Monnier2024-04-18 15:28:36 -0400
commit126be02077520a943252d0d219bb7677466d0168 (patch)
treef762237714f11b303c708f93f09a8dc72426bb2a /test
parent7842af6095db4384898725fb4a14ebaa11379a34 (diff)
downloademacs-scratch/interpreted-function.tar.gz
emacs-scratch/interpreted-function.zip
Use a dedicated type to represent interpreted-function valuesscratch/interpreted-function
Change `function` so that when evaluating #'(lambda ...) we return an object of type `interpreted-function` rather than a list starting with one of `lambda` or `closure`. The new type reuses the existing PVEC_CLOSURE (nee PVEC_COMPILED) tag and tries to align the corresponding elements: - the arglist, the docstring, and the interactive-form go in the same slots as for byte-code functions. - the body of the function goes in the slot used for the bytecode string. - the lexical context goes in the slot used for the constants of bytecoded functions. The first point above means that `help-function-arglist`, `documentation`, and `interactive-form`s don't need to distinguish interpreted and bytecode functions any more. Main benefits of the change: - We can now reliably distinguish a list from a function value. - `cl-defmethod` can dispatch on `interactive-function` and `closure`. Dispatch on `function` also works now for interpreted functions but still won't work for functions represented as lists or as symbols, of course. - Function values are now self-evaluating. That was alrready the case when byte-compiled, but not when interpreted since (eval '(closure ...)) signals a void-function error. That also avoids false-positive warnings about "don't quote your lambdas" when doing things like `(mapcar ',func ...)`. * src/eval.c (Fmake_interpreted_closure): New function. (Ffunction): Use it and change calling convention of `Vinternal_make_interpreted_closure_function`. (FUNCTIONP, Fcommandp, eval_sub, funcall_general, funcall_lambda) (Ffunc_arity, lambda_arity): Simplify. (funcall_lambda): Adjust to new representation. (syms_of_eval): `defsubr` the new function. Remove definition of `Qclosure`. * lisp/emacs-lisp/cconv.el (cconv-make-interpreted-closure): Change calling convention and use `make-interpreted-closure`. * src/data.c (Fcl_type_of): Distinguish `byte-code-function`s from `interpreted-function`s. (Fclosurep, finterpreted_function_p): New functions. (Fbyte_code_function_p): Don't be confused by `interpreted-function`s. (Finteractive_form, Fcommand_modes): Simplify. (syms_of_data): Define new type symbols and `defsubr` the two new functions. * lisp/emacs-lisp/cl-print.el (cl-print-object) <interpreted-function>: New method. * lisp/emacs-lisp/oclosure.el (oclosure): Refine the parent to be `closure`. (oclosure--fix-type, oclosure-type): Simplify. (oclosure--copy, oclosure--get, oclosure--set): Adjust to new representation. * src/callint.c (Fcall_interactively): Adjust to new representation. * src/lread.c (bytecode_from_rev_list): * lisp/simple.el (function-documentation): * lisp/help.el (help-function-arglist): Remove the old `closure` case and adjust the byte-code case so it handles `interpreted-function`s. * lisp/emacs-lisp/cl-preloaded.el (closure): New type. (byte-code-function): Add it as a parent. (interpreted-function): Adjust parent (the type itself was already added earlier by accident). * lisp/emacs-lisp/bytecomp.el (byte-compile--reify-function): Adjust to new representation. (byte-compile): Use `interpreted-function-p`. * lisp/emacs-lisp/byte-opt.el (byte-compile-inline-expand): Adjust to new representation. (side-effect-free-fns): Add `interpreted-function-p` and `closurep`. * src/profiler.c (trace_hash, ffunction_equal): Simplify. * lisp/profiler.el (profiler-function-equal): Simplify. * lisp/emacs-lisp/nadvice.el (advice--interactive-form-1): Use `interpreted-function-p`; adjust to new representation; and take advantage of the fact that function values are now self-evaluating. * lisp/emacs-lisp/lisp-mode.el (closure): Remove `lisp-indent-function` property. * lisp/emacs-lisp/disass.el (disassemble-internal): Adjust to new representation. * lisp/emacs-lisp/edebug.el (edebug--strip-instrumentation): Use `interpreted-function-p`. * lisp/emacs-lisp/comp-common.el (comp-known-type-specifiers): Add `closurep` and `interpreted-function-p`. * test/lisp/help-fns-tests.el (help-fns-test-lisp-defun): Adjust to more precise type info in `describe-function`. * test/lisp/erc/resources/erc-d/erc-d-tests.el (erc-d--render-entries): Use `interpreted-function-p`. * test/lisp/emacs-lisp/macroexp-resources/vk.el (vk-f4, vk-f5): Don't hardcode function values. * doc/lispref/functions.texi (Anonymous Functions): Don't suggest that function values are lists. Reword "self-quoting" to reflect the fact that #' doesn't return the exact same object. Update examples with the new shape of the return value. * doc/lispref/variables.texi (Lexical Binding): * doc/lispref/lists.texi (Rearrangement): * doc/lispref/control.texi (Handling Errors): Update examples to reflect new representation of function values.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/emacs-lisp/macroexp-resources/vk.el48
-rw-r--r--test/lisp/erc/resources/erc-d/erc-d-tests.el5
-rw-r--r--test/lisp/help-fns-tests.el10
3 files changed, 33 insertions, 30 deletions
diff --git a/test/lisp/emacs-lisp/macroexp-resources/vk.el b/test/lisp/emacs-lisp/macroexp-resources/vk.el
index 5358bcaeb5c..c59a6b9f8f1 100644
--- a/test/lisp/emacs-lisp/macroexp-resources/vk.el
+++ b/test/lisp/emacs-lisp/macroexp-resources/vk.el
@@ -78,29 +78,31 @@
78 78
79(defconst vk-val3 (eval-when-compile (vk-f3 0))) 79(defconst vk-val3 (eval-when-compile (vk-f3 0)))
80 80
81(defconst vk-f4 '(lambda (x) 81(defconst vk-f4 (eval '(lambda (x)
82 (defvar vk-v4) 82 (defvar vk-v4)
83 (let ((vk-v4 31) 83 (let ((vk-v4 31)
84 (y 32)) 84 (y 32))
85 (ignore vk-v4 x y) 85 (ignore vk-v4 x y)
86 (list 86 (list
87 (vk-variable-kind vk-a) ; dyn 87 (vk-variable-kind vk-a) ; dyn
88 (vk-variable-kind vk-b) ; dyn 88 (vk-variable-kind vk-b) ; dyn
89 (vk-variable-kind vk-v4) ; dyn 89 (vk-variable-kind vk-v4) ; dyn
90 (vk-variable-kind x) ; dyn 90 (vk-variable-kind x) ; dyn
91 (vk-variable-kind y))))) ; dyn 91 (vk-variable-kind y)))) ; dyn
92 92 nil))
93(defconst vk-f5 '(closure (t) (x) 93
94 (defvar vk-v5) 94(defconst vk-f5 (eval '(lambda (x)
95 (let ((vk-v5 41) 95 (defvar vk-v5)
96 (y 42)) 96 (let ((vk-v5 41)
97 (ignore vk-v5 x y) 97 (y 42))
98 (list 98 (ignore vk-v5 x y)
99 (vk-variable-kind vk-a) ; dyn 99 (list
100 (vk-variable-kind vk-b) ; dyn 100 (vk-variable-kind vk-a) ; dyn
101 (vk-variable-kind vk-v5) ; dyn 101 (vk-variable-kind vk-b) ; dyn
102 (vk-variable-kind x) ; lex 102 (vk-variable-kind vk-v5) ; dyn
103 (vk-variable-kind y))))) ; lex 103 (vk-variable-kind x) ; lex
104 (vk-variable-kind y)))) ; lex
105 t))
104 106
105(defun vk-f6 () 107(defun vk-f6 ()
106 (eval '(progn 108 (eval '(progn
diff --git a/test/lisp/erc/resources/erc-d/erc-d-tests.el b/test/lisp/erc/resources/erc-d/erc-d-tests.el
index 78f87399afb..dda1b1ced84 100644
--- a/test/lisp/erc/resources/erc-d/erc-d-tests.el
+++ b/test/lisp/erc/resources/erc-d/erc-d-tests.el
@@ -367,8 +367,9 @@
367 (should (equal (funcall it) "foo3foo"))) 367 (should (equal (funcall it) "foo3foo")))
368 368
369 (ert-info ("Exits clean") 369 (ert-info ("Exits clean")
370 (when (listp (alist-get 'f (erc-d-dialog-vars dialog))) ; may be compiled 370 (when (interpreted-function-p
371 (should (eq 'closure (car (alist-get 'f (erc-d-dialog-vars dialog)))))) 371 (alist-get 'f (erc-d-dialog-vars dialog))) ; may be compiled
372 (should (aref (alist-get 'f (erc-d-dialog-vars dialog)) 2)))
372 (should-not (funcall it)) 373 (should-not (funcall it))
373 (should (equal (erc-d-dialog-vars dialog) 374 (should (equal (erc-d-dialog-vars dialog)
374 `((:a . 1) 375 `((:a . 1)
diff --git a/test/lisp/help-fns-tests.el b/test/lisp/help-fns-tests.el
index 1beeb77640c..82350a4bc71 100644
--- a/test/lisp/help-fns-tests.el
+++ b/test/lisp/help-fns-tests.el
@@ -63,14 +63,14 @@ Return first line of the output of (describe-function-1 FUNC)."
63 (should (string-match regexp result)))) 63 (should (string-match regexp result))))
64 64
65(ert-deftest help-fns-test-lisp-defun () 65(ert-deftest help-fns-test-lisp-defun ()
66 (let ((regexp (if (featurep 'native-compile) 66 (let ((regexp "a \\([^ ]+\\) in .+subr\\.el")
67 "a subr-native-elisp in .+subr\\.el"
68 "a compiled-function in .+subr\\.el"))
69 (result (help-fns-tests--describe-function 'last))) 67 (result (help-fns-tests--describe-function 'last)))
70 (should (string-match regexp result)))) 68 (should (string-match regexp result))
69 (should (member (match-string 1 result)
70 '("subr-native-elisp" "byte-code-function")))))
71 71
72(ert-deftest help-fns-test-lisp-defsubst () 72(ert-deftest help-fns-test-lisp-defsubst ()
73 (let ((regexp "a compiled-function in .+subr\\.el") 73 (let ((regexp "a byte-code-function in .+subr\\.el")
74 (result (help-fns-tests--describe-function 'posn-window))) 74 (result (help-fns-tests--describe-function 'posn-window)))
75 (should (string-match regexp result)))) 75 (should (string-match regexp result))))
76 76