Commit graph

9832 commits

Author SHA1 Message Date
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
Eli Zaretskii
a7d51085cf Improve documentation of 'package-enable-at-startup'
* doc/emacs/package.texi (Package Installation): Clarify how to
customize 'package-enable-at-startup'.

* lisp/emacs-lisp/package.el (package-enable-at-startup): Add note
about customization.  (Bug#70402)
2024-04-27 11:52:30 +03:00
Philip Kaludercic
758fe9b670 Always update VC packages from a vc-dir buffer
* lisp/emacs-lisp/package-vc.el (vc-dir-prepare-status-buffer):
Add a declaration.
(package-vc-upgrade): Prepare a dummy vc-dir buffer to ensure
that 'vc-pull' (or rather 'vc-deduce-fileset') can correctly
infer the VC backend to use.  (bug#70526)
2024-04-26 08:21:37 +02:00
Mattias Engdegård
e442161f11 Better format string compilation warning
* lisp/emacs-lisp/bytecomp.el (byte-compile-format-warn):
Speed up by eliminating the temporary buffer.
Detect invalid format sequences.  Use plurals properly.
* test/lisp/emacs-lisp/bytecomp-tests.el: Update test.
2024-04-22 19:27:24 +02:00
Juri Linkov
086608876a * lisp/emacs-lisp/warnings.el (warning-display-at-bottom): New defcustom.
(display-warning): Use 'warning-display-at-bottom' to display
the warning buffer at the bottom of the screen and to scroll
to the last warning message (bug#69983).
2024-04-22 09:50:45 +03:00
Stefan Monnier
0536b96011 (backtrace--print-func-and-args): Fix (part of) bug#70436
The source of bug#70436 is that we print a value into the buffer
and then we generate its print representation a second time to
get its length to find the bounds of the thing we just printed.
Not only it's wasteful, but it risks bugs because the two
"prints" can be inconsistent with each other.

This is not a complete fix because in the non EVALD case we
still use that same broken way.

* lisp/emacs-lisp/backtrace.el (backtrace--print-func-and-args):
Don't re-print things just to get their length.
(backtrace--print-to-string): Skip a temp-buffer indirection.
2024-04-20 11:23:58 -04:00
Stefan Monnier
24ea3024ae (cl-print-object): Fix indirect cause of bug#70436
* lisp/emacs-lisp/cl-print.el (cl-print-object): Fix specializer
for the byte-code case.
2024-04-20 11:17:39 -04:00
Stefan Monnier
71d2ec7aba (track-changes--call-signal): Silence late signals
* lisp/emacs-lisp/track-changes.el (track-changes--call-signal):
Skip the call if the tracker was unregistered.
2024-04-19 22:19:00 -04:00
Augusto Stoffel
3cdd86b8af Propagate 'lexical-binding' value to pp buffers
See bug#70137.

* lisp/emacs-lisp/pp.el (pp-display-expression): Set lexical-binding to
match the value in the calling buffer.
2024-04-17 17:02:11 -04:00
Juri Linkov
4dd3288569 * lisp/emacs-lisp/icons.el (define-icon): Add 'doc-string' to 'declare'. 2024-04-17 21:01:14 +03:00
Stefan Monnier
523aca13a4 * lisp/emacs-lisp/track-changes.el: Fix trailer 2024-04-17 10:57:11 -04:00
Stefan Monnier
3660c51736 track-changes.el: Fix last change for early use
* lisp/emacs-lisp/track-changes.el (track-changes--recover-from-error):
Don't burp if there have been fewer than 20 keystrokes since Emacs start.
2024-04-17 09:04:12 -04:00
Juri Linkov
ada429c375 * lisp/emacs-lisp/lisp.el (forward-sexp-function): Set back to nil.
(forward-sexp): Revert back to checking 'forward-sexp-function'
for nil (bug#70426).
2024-04-17 09:53:02 +03:00
Stefan Monnier
a33ab7565e track-changes.el: Minor changes for version 1.0
Arrange for the library to be usable on older Emacsen, which
includes reducing the noise when `before/after-change-functions`
are badly paired or missing.
Also, since the signal function receives the distance (for `:disjoint`),
we don't need `track-changes--disjoint-threshold`: the signal
function can simply do nothing when the distance is smaller than
the threshold it wants to use.

* lisp/emacs-lisp/track-changes.el: Prepare header for ELPA.
(track-changes--tracker, track-changes--state): Don't use `:noinline`,
so as to be compatible with Emacs<27.
(track-changes-record-errors): New variable.
(track-changes--recover-from-error): Use it.  Record only the last 20
keys and the last 50 stack frames in the error log.
(track-changes--disjoint-threshold): Delete variable.
(track-changes--before): Don't use it any more.

* lisp/progmodes/eglot.el (eglot--track-changes-signal):
Coalesce disjoint changes nearer than what used to be coalesced because of
`track-changes--disjoint-threshold`.
2024-04-16 21:57:05 -04:00
Stefan Monnier
484b097909 (cl-defstruct): Improve handling of unknown options
Until now `cl-defstruct` signaled an error when encountering an
unknown option.  It's easy to code and it does the job, but it
doesn't give good location info in the compiler's output,
and it makes it more painful to use not-yet-supported options.
So just signal a warning instead.

* lisp/emacs-lisp/cl-macs.el (cl-defstruct): Warn about unknown
options, instead of signaling an error.
2024-04-16 21:17:47 -04:00