Commit graph

9846 commits

Author SHA1 Message Date
Andrea Corallo
509e7f877b * Rework 'comp-normalize-valset' (bug#71116)
* lisp/emacs-lisp/comp-cstr.el (comp-normalize-valset): Rework to
improve consistency.
2024-05-27 20:41:06 +02:00
Michael Heerdegen
804f36d5ab Don't let pp fall back to prin1 for conses
* lisp/emacs-lisp/pp.el (pp--insert-lisp): Don't `prin1' non-list
conses; use our pp function for cons and list printing
`pp--format-list' instead.
2024-05-27 19:51:39 +02:00
Michael Heerdegen
3580dc155c Don't try to pretty-print non-lists as binding list
* lisp/emacs-lisp/pp.el (pp--format-definition): Ensure that what we try
to print as a list of bindings has an appropriate format.  This avoids
raising an error for SEXPs like (let X Y) inside `pcase' forms where our
heuristic expects a binding list in the X position.
2024-05-27 18:44:48 +02:00
Michael Heerdegen
34fc71c004 Further tweak pp code printing
This fixes an aspect of Bug#70868.

* lisp/emacs-lisp/pp.el (pp--insert-lisp): Print characters with
`prin1-char'.  In all other cases consistently print with `prin1'.
2024-05-26 14:17:21 +02:00
Po Lu
74ceb6922c Address compilation errors and warnings on x86 Solaris 10 systems
* doc/misc/ede.texi (Extending EDE):

* doc/misc/flymake.texi (Top, Using Flymake): Insert punctuation
after xrefs.

* lisp/emacs-lisp/loaddefs-gen.el (loaddefs-generate): Print
number of files being scraped.

* src/dired.c (directory_files_internal):

* src/eval.c (Fmake_interpreted_closure, Fdefvaralias):

* src/fns.c (Fassoc): Work around optimizer failures.
2024-05-26 11:50:45 +08:00
Dmitry Gutov
2a12f39ffe Improve navigation to cl-defgeneric uses
* lisp/emacs-lisp/cl-generic.el
(cl--generic-find-defgeneric-regexp):
Use "symbol end" boundary (bug#71068).
2024-05-26 05:56:14 +03:00
Stefan Monnier
d8af7c99bb * lisp/emacs-lisp/pcase.el (pcase--subtype-bitsets): Fix bootstrap failure
`rm lisp/emacs-lisp/cl-preloaded.elc src/bootstrap-emacs`
followed by `make` ended up loading right after defining
`built-in-class-p` but before actually defining the
built-in-classes so the computation of bitsets failed.
2024-05-22 13:27:50 -04:00
Andrea Corallo
931663f123 Silence 3 warnings for non sqlite builds
* lisp/emacs-lisp/multisession.el (sqlite-commit)
(sqlite-transaction, sqlite-rollback): Declare.
2024-05-19 14:54:10 +02:00
Joost Kremers
4f27d763bb Make 'vtable-insert-object' more versatile
* lisp/emacs-lisp/vtable.el (vtable-insert-object): Rename
argument AFTER-OBJECT to LOCATION; allow use of index to
refer to the insertion position; add argument BEFORE.
(Bug#70664).

* etc/NEWS:
* doc/misc/vtable.texi (Interface Functions): Document the
change.

* test/lisp/emacs-lisp/vtable-tests.el
(test-vtable-insert-object): New test.
2024-05-18 11:52:33 +03:00
Stefan Monnier
acfb2c6163 (describe-package-1): Handle (nil . "string") in :maintainer
* lisp/emacs-lisp/package.el (describe-package-1): Refine the
check to distinguish the old single-maintainer format from the
new multi-maintainer format.  (bug#69712)
2024-05-16 11:04:50 -04:00
Andrea Corallo
1b622ff66e * Fix bootstrap with checking enabled
* lisp/emacs-lisp/comp.el (comp--limplify-top-level): Set function
safety.
2024-05-16 07:53:48 +02:00
Andrea Corallo
b87670b564 * Allow for optional function name parameter in 'ftype' declaration
* lisp/emacs-lisp/byte-run.el (defun-declarations-alist): Allow for
optional function name parameter in 'ftype' declaration.
2024-05-14 11:17:25 +02:00
Andrea Corallo
6e1bb713f6 Change 'type' declaration to 'ftype'
* lisp/window.el (get-lru-window, get-largest-window)
(one-window-p): Update function type declaration.
* lisp/subr.el (ignore, error, zerop, fixnump, bignump, lsh)
(last, eventp, mouse-movement-p, log10, memory-limit)
(internal-pop-keymap): Likewise.
* lisp/simple.el (count-lines, mark, string-empty-p): Likewise.
* lisp/files.el (parse-colon-path): Likewise.
* lisp/env.el (getenv): Likewise.
* lisp/emacs-lisp/regexp-opt.el (regexp-opt): Likewise.
* lisp/emacs-lisp/lisp.el (buffer-end): Likewise.
* lisp/emacs-lisp/comp.el (comp--final): Likewise.
* lisp/custom.el (custom-variable-p): Likewise.
* lisp/emacs-lisp/byte-run.el (defun-declarations-alist): Rename 'type'
-> 'ftype'.
2024-05-14 11:17:25 +02:00
Eli Zaretskii
f6d060b39a ; Fix documentation of recently-installed changes
* lisp/emacs-lisp/bytecomp.el (compilation-safety): Doc fix.

* etc/NEWS: Fix wording of the 'compilation-safety' entry.

* doc/lispref/functions.texi (Declare Form): Fix cross-reference
and wording.
* doc/lispref/compile.texi (Native-Compilation Variables): Add the
missing @anchor.  Fix wording.
2024-05-14 08:51:13 +03:00
Andrea Corallo
04e7078d5e Add some 'compilation-safety' documentation
* lisp/emacs-lisp/bytecomp.el (compilation-safety): Better doc.
* doc/lispref/functions.texi (Declare Form): Add 'safety'.
* doc/lispref/compile.texi (Native-Compilation Variables): Add
'compilation-safety'.
2024-05-13 23:09:09 +02:00
Andrea Corallo
9e4e6d0fc9 Add 'safety' function declaration
* lisp/emacs-lisp/comp.el (comp-known-predicates): Use
'comp-func-safety'.
(comp-ctxt, comp-mvar-type-hint-match-p): New 'safety' slot.
(comp-c-func-name): New function.
(comp--spill-lap-function, comp--intern-func-in-ctxt): Update.
* lisp/emacs-lisp/bytecomp.el (byte-compile-from-buffer): Spill safety.
* lisp/emacs-lisp/byte-run.el (byte-run--set-completion): New alias.
(defun-declarations-alist): Update.
2024-05-13 23:01:08 +02:00
Andrea Corallo
13ddfc2011 Introduce 'compilation-safety' variable
* lisp/emacs-lisp/bytecomp.el (compilation-safety): New customize.
* src/comp.c (comp_t): Add func_safety.
(emit_call_with_type_hint, emit_call2_with_type_hint): Make use of.
(compile_function): Set 'comp.func_safety'.
2024-05-13 23:01:08 +02:00
Andrea Corallo
595799edd3 * lisp/emacs-lisp/comp.el (comp--get-function-cstr): Fix it. 2024-05-13 16:49:29 +02:00
Mattias Engdegård
38091e43be Safer and faster string sorting
* lisp/emacs-lisp/cl-seq.el (cl-sort):
Don't use string mutation when sorting the characters in a string.
This avoids O(n^2) run time and makes it future-safe.
2024-05-12 14:58:38 +02:00
Mattias Engdegård
de5a89254c Don't mutate strings in cl-substitute
This fixes cl-substitute, cl-substitute-if, cl-substitute-if-not,
cl-nsubstitute, cl-nsubstitute-if and cl-nsubstitute-if-not,
when called with a string sequence argument.

* lisp/emacs-lisp/cl-seq.el (cl-nsubstitute):
Avoid running in O(n^2) time and make future-safe.
2024-05-08 16:38:40 +02:00
Po Lu
32b8c07817 Correct earlier change to map-ynp
* lisp/emacs-lisp/map-ynp.el (map-y-or-n-p): Don't call
set-text-conversion-style if not bound.
2024-05-08 20:26:08 +08:00
Eli Zaretskii
4b31074f5f ; * lisp/emacs-lisp/map-ynp.el (map-y-or-n-p): Add commentary. 2024-05-07 15:00:31 +03:00
Po Lu
d4d9db8dc6 Disable text-conversion in map-ynp
* lisp/emacs-lisp/map-ynp.el (map-y-or-n-p): Bind
overriding-text-conversion-style to nil around read-event and
arrange that the input method be reset.
2024-05-07 09:02:00 +08:00
Stefan Monnier
f63615208a edebug.el: Fix edebug-remove-instrumentation (bug#70791)
* lisp/emacs-lisp/edebug.el (edebug-unwrap*): Traverse interpreted
functions.
2024-05-06 14:33:43 -04:00
Juri Linkov
4460317225 * lisp/emacs-lisp/warnings.el (display-warning): Add guardrails for window.
Check for non-nil 'window' returned from 'display-buffer' for the case when
users decide to use 'allow-no-window' in 'display-buffer-alist' (#70795).
2024-05-06 20:00:23 +03:00
Eli Zaretskii
e091967ce2 Revert "Disable text conversion in map-ynp"
This reverts commit f50a58123a.
Please don't make such changes without discussing them.
2024-05-06 15:02:37 +03:00
Eli Zaretskii
74ebd729c7 ; Avoid byte-compiler warning in comp.el
* lisp/emacs-lisp/comp.el (comp--symbol-func-to-fun): Move to
before its first use.
2024-05-06 13:54:19 +03:00
Po Lu
f50a58123a Disable text conversion in map-ynp
* lisp/emacs-lisp/map-ynp.el (map-y-or-n-p): Read response with
read-key, not read-char.
2024-05-06 15:59:48 +08:00
Andrea Corallo
f920959ac9 Remove unnecessary cons in function-type property
* lisp/emacs-lisp/comp-common.el (comp-function-type-spec): Remove
unnecessary car.
* lisp/emacs-lisp/comp.el (comp--intern-func-in-ctxt): Likewise.
* lisp/emacs-lisp/byte-run.el (byte-run--set-function-type): Update
lambda list.
2024-05-05 23:58:31 +02:00
Andrea Corallo
77f87d4b48 Fix intra compilation unit function type declaration
* lisp/emacs-lisp/comp.el (comp-func): Add 'slot'.
(comp--intern-func-in-ctxt): Update.
(comp--get-function-cstr): Update.
2024-05-05 23:58:31 +02:00
Stefan Monnier
44036b32ba eglot.el: Require track-changes unconditionally
* lisp/emacs-lisp/track-changes.el: Bump version.

* lisp/progmodes/eglot.el: Require `track-changes` unconditionally.
(Package-Requires:): Add `track-changes`.
(eglot--track-changes-signal, eglot--signal-textDocument/didChange)
(eglot--managed-mode): Remove non-track-changes alternative code.
(eglot--before-change, eglot--after-change): Delete functions.
2024-05-05 17:23:29 -04:00
Stefan Monnier
c9b0e2bd8e * lisp/emacs-lisp/track-changes.el (track-changes-inconsistent-state-p): Typo 2024-05-03 16:39:29 -04:00
Stefan Monnier
b6d4e81a48 track-changes.el: Add a workaround for bug#70541
* lisp/emacs-lisp/track-changes.el (track-changes-inconsistent-state-p):
 New function.
* lisp/progmodes/eglot.el (eglot--track-changes-signal): Use it.
2024-05-03 13:23:00 -04:00
Andrea Corallo
da8b06bd61 Merge branch 'lisp-func-type-decls' into 'master' 2024-05-02 17:06:07 +02:00
Juri Linkov
592873a52d * lisp/emacs-lisp/warnings.el: Fix 'warning-display-at-bottom'.
(display-warning): Move point to the beginning of the last line
instead of its end for 'warning-display-at-bottom' (bug#69983).
2024-05-02 09:54:22 +03:00
Andrea Corallo
468f3f1cb4 (disassemble): Fix case of (byte-code ...) argument
* lisp/emacs-lisp/disass.el (disassemble): Handle (byte-code ...) here..
(disassemble-internal): ...instead of here.
(disassemble-1): Adjust text to reflect the existence of other
compiled functions.
2024-05-01 14:14:01 -04:00
Basil L. Contovounesios
65fa47e3fa Assume match before calling help-xref-button
help-xref-button fails if not preceded by a valid match, so a
preceding unconditional search should not be allowed to fail
silently.

* lisp/emacs-lisp/ert.el (ert-describe-test):
* lisp/help-fns.el (help-fns--compiler-macro)
(help-fns-function-description-header, describe-variable)
(help-fns--customize-variable, describe-face)
(help-fns--face-attributes, describe-keymap): Let unconditional
re-search-backward before help-xref-button fail early, as that would
indicate a logic bug, and the backtrace would more accurately point
to the actual source of the mistake.
2024-05-01 12:38:51 +02:00
Mattias Engdegård
c15d67ecfc * lisp/emacs-lisp/bytecomp.el (byte-compile-make-closure): Simplify. 2024-04-30 16:22:48 +02:00
Mattias Engdegård
c3c2e3b4d3 * lisp/emacs-lisp/bytecomp.el (byte-compile-lambda): Simplify.
Remove the add-lambda argument.  All callers adapted.
2024-04-30 16:20:45 +02:00
Andrea Corallo
1087d55d27 * lisp/emacs-lisp/regexp-opt.el (regexp-opt): Fix type declaration. 2024-04-30 09:19:31 +02:00
Mattias Engdegård
3000edc617 Use the nthcdr byte-op for drop, and raise open-code limit
* lisp/emacs-lisp/byte-opt.el (byte-optimize-nthcdr):
Open-code for any integral N<5.  Always use the byte-op otherwise.
2024-04-29 22:16:08 +02:00
Andrea Corallo
0757ea9865 Rename property 'declared-type' to 'function-type'
* lisp/emacs-lisp/byte-run.el (byte-run--set-function-type): Rename.
(defun-declarations-alist): Update.
* lisp/emacs-lisp/comp.el (comp--get-function-cstr): Likewise.
2024-04-29 20:41:11 +02:00
Stefan Monnier
ccb49acd2a (disassemble-internal): Handle new function values
* lisp/emacs-lisp/disass.el (disassemble-internal): Fix the
`interpreted-function` case.
2024-04-29 13:47:15 -04:00
Andrea Corallo
fa0bf96837 Move lisp function arg type declarations to the functions itself
* lisp/emacs-lisp/comp-common.el (comp-primitive-type-specifiers):
Remove type declaration of lisp functions.
* lisp/window.el (get-lru-window, get-largest-window)
(one-window-p): Declare type.
* lisp/subr.el (ignore, error, zerop, fixnump, bignump, lsh)
(last, eventp, mouse-movement-p, log10, memory-limit)
(interactive-p): Likewise.
* lisp/simple.el (count-lines, mark, lax-plist-get): Likewise.
* lisp/files.el (parse-colon-path): Likewise.
* lisp/env.el (getenv): Likewise.
* lisp/emacs-lisp/regexp-opt.el (regexp-opt): Likewise.
* lisp/emacs-lisp/lisp.el (buffer-end): Likewise.
* lisp/emacs-lisp/comp.el (comp-hint-fixnum, comp-hint-cons): Likewise.
* lisp/custom.el (custom-variable-p): Likewise.
2024-04-29 19:27:28 +02:00
Andrea Corallo
d8c941df7d Make use of Lisp function declarations
* lisp/emacs-lisp/comp.el (comp-primitive-func-cstr-h): Rename.
(comp--get-function-cstr): Define new function.
(comp--add-call-cstr, comp--fwprop-call): Update.
* lisp/emacs-lisp/comp-common.el (comp-function-type-spec): Update.
* lisp/help-fns.el (help-fns--signature): Mention when a type is
declared.
* lisp/emacs-lisp/comp.el (comp-primitive-func-cstr-h): Rename.
2024-04-29 19:27:23 +02:00
Stefan Monnier
7cf767ef54 (byte-compile): Fix interaction with old advice.el
* lisp/emacs-lisp/bytecomp.el (byte-compile): Handle symbols whose
function "value" is a bare lambda expression (bug#70368).
2024-04-29 13:14:31 -04:00
Andrea Corallo
1c7b809983 * Add function type declarations for Lisp functions
* lisp/emacs-lisp/byte-run.el (byte-run--set-declared-type): Add alias.
(defun-declarations-alist): Use it for 'type' declaration.
2024-04-29 18:40:36 +02:00
Mattias Engdegård
3be382311f Declare the variable rx-constituents obsolete.
It has been effectively obsolete since Emacs 27, when the modern
extension mechanism was introduced.

* lisp/emacs-lisp/rx.el (rx-constituents): Make obsolete.
* test/lisp/emacs-lisp/rx-tests.el (rx-constituents): Suppress warning.
* etc/NEWS: Announce.
2024-04-29 14:29:53 +02:00
Stefan Monnier
f2bccae22b Use a dedicated type to represent interpreted-function values
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.
2024-04-28 11:58:12 -04:00
Eshel Yaron
f5439a9291
Refine the Custom type of generated '*-modes' options
* lisp/emacs-lisp/easy-mmode.el (define-globalized-minor-mode):
Refine the Custom type of the '*-modes' option, generated when
this macro is given a ':predicate' argument.  (Bug#70589)
2024-04-27 17:18:31 +02:00