Commit graph

1075 commits

Author SHA1 Message Date
Mattias Engdegård
a3db503351 Move lexical-binding warning from checkdoc to byte-compiler
This warning is much more appropriate for the compiler, since lexical
binding affects what it can reason and warn about, than for checkdoc
as the warning has no bearing to documentation at all.
The move also improves the reach of the warning.

* etc/NEWS: Update.
* lisp/emacs-lisp/checkdoc.el (checkdoc-lexical-binding-flag)
(checkdoc-file-comments-engine): Move warning from here....
* lisp/emacs-lisp/bytecomp.el (byte-compile-file): ...to here.
* test/lisp/emacs-lisp/bytecomp-resources/no-byte-compile.el:
* test/lisp/emacs-lisp/bytecomp-tests.el
(bytecomp-tests--unescaped-char-literals)
(bytecomp-tests-function-put, bytecomp-tests--not-writable-directory)
(bytecomp-tests--target-file-no-directory):
Update tests.
(bytecomp-tests--log-from-compilation)
(bytecomp-tests--lexical-binding-cookie): New test.
2023-10-21 15:12:55 +02:00
Mattias Engdegård
1f95f91d85 Simplify and describe docstrings-wide check
* lisp/emacs-lisp/bytecomp.el
(byte-compile--wide-docstring-substitution-len): Remove.
* lisp/emacs-lisp/bytecomp.el (bytecomp--docstring-line-width):
Add back explanatory comments lost in a previous change.
2023-10-14 13:26:20 +02:00
Mattias Engdegård
fbbe40cf50 Make the docstrings-wide check 70x faster
Instead of performing a number of expensive transformations on the
original doc string and then use a dynamically-created regexp to find
wide lines, step through the lines in the unmodified string and only
perform the transformations on lines that exceed the limit.
This is sound because the transformations are contractive.

The new check will usually not cons nor perform any regexp matching.

* lisp/emacs-lisp/bytecomp.el (bytecomp--docstring-line-width): New.
(byte-compile--wide-docstring-p): Cheaper implementation.
2023-10-14 12:15:33 +02:00
Mattias Engdegård
548bc3e3d1 Sort byte compiler warnings in alphabetic order
* lisp/emacs-lisp/bytecomp.el (byte-compile-warning-types):
Rearrange.  Add a few missing ones.
2023-10-14 10:34:10 +02:00
Mattias Engdegård
a52d627b37 Separate docstrings-wide warning identifier
This allows the docstring line width warning to be disabled without
also disabling the one checking for curly quotes etc.

* lisp/emacs-lisp/bytecomp.el (byte-compile-warning-types)
(byte-compile-warnings, byte-compile-docstring-style-warn):
Add `docstrings-wide`.
* etc/NEWS: Annonuce.
2023-10-13 14:31:18 +02:00
Mattias Engdegård
6e4432673c Small clean-up of byte-compile-docstring-style-warn
* lisp/emacs-lisp/bytecomp.el (byte-compile-docstring-style-warn):
Make the code slightly cheaper.  It's still dominated by the
huge cost of `byte-compile--wide-docstring-p`, though.
2023-09-29 17:59:50 +02:00
Mattias Engdegård
5959a28cce Include all in byte-compile-warnings defcustom type
* lisp/emacs-lisp/bytecomp.el (byte-compile-warnings):
Let "All" mean `all`, not `t`.
2023-09-29 17:59:50 +02:00
Mattias Engdegård
b03338c70d Warn about duplicated :tag strings in defcustom choices
It is bad user experience when two menu items have identical labels.

* lisp/emacs-lisp/bytecomp.el (bytecomp--check-cus-type): Add check.
* test/lisp/emacs-lisp/bytecomp-tests.el
(bytecomp-test-defcustom-type): Add test case.
2023-09-19 15:21:03 +02:00
Mattias Engdegård
f8ea47ebf4 Expanded defcustom type byte-compilation warnings (bug#65852)
Warn about more kinds of mistakes in :type arguments of `defcustom`
and `define-widget`.  These include:

- misplaced keyword args, as in (const red :tag "A reddish hue")
- missing subordinate types, as in (repeat :tag "List of names")
  or (choice list string)
- duplicated values, as in (choice (const yes) (const yes))
- misplaced `other` member, as in
  (choice (const red) (other nil) (const blue))
- various type name mistakes, as in (vector bool functionp)

* lisp/emacs-lisp/bytecomp.el (byte-compile--defcustom-type-quoted)
(byte-compile-nogroup-warn): Remove.
(byte-compile-normal-call): Remove call to the above.
(bytecomp--cus-warn, bytecomp--check-cus-type)
(bytecomp--custom-declare): New.
2023-09-17 17:16:35 +02:00
Stefan Kangas
1c0fb3de47 ; Delete code commented out since 1992 2023-08-25 17:43:59 +02:00
Alan Mackenzie
18a84922c5 Remove harmful and redundant bindings from the byte compiler.
This fixes bug#65017.  Binding symbols-with-pos-enabled in two
macro handling functions was harmful; one of these caused
cl--labels-convert to fail.  Binding print-symbols-bare in many
places in the byte compiler was redundant.

* lisp/emacs-lisp/bytecomp.el (byte-compile-recurse-toplevel)
(byte-compile-initial-macro-environment)
(byte-compile-output-file-form, byte-compile-output-docform)
(byte-compile-preprocess): Remove bindings of
print-symbols-bare.

* lisp/emacs-lisp/macroexp.el (macroexp--compiler-macro)
(internal-macroexpand-for-load): Remove bindings of
symbols-with-pos-enabled.
(internal-macroexpand-for-load): Remove binding of
print-symbols-bare.
2023-08-09 11:29:22 +00:00
Mattias Engdegård
41e766b449 Check keyword args of make-pipe-process (bug#65030)
* lisp/emacs-lisp/bytecomp.el (make-pipe-process): Add check.
2023-08-08 18:35:19 +02:00
Helmut Eller
3e79fd3d4e Check keyword args of make-process
The functions make-process and make-network-process have many
keyword args and it's easy to misspell some of them.

Use a compiler macro to warn about some possible mistakes.

* lisp/emacs-lisp/bytecomp.el (bytecomp--check-keyword-args): New
  helper.
  (make-process, make-network-process): Define a compiler macro that
  performs some checks but doesn't anything else.

* test/lisp/emacs-lisp/bytecomp-tests.el: Add some tests.

* test/lisp/emacs-lisp/bytecomp-resources/:
  (warn-make-process-missing-keyword-arg.el,
   warn-make-process-missing-keyword-value.el,
   warn-make-process-repeated-keyword-arg.el,
   warn-make-process-unknown-keyword-arg.el): New test files
2023-08-08 18:23:00 +02:00
Jim Porter
0a6a25320e Merge from origin/emacs-29
1e8322bb26 Fix handling of 'byte-compile-ignore-files' when nil
2023-08-05 21:26:14 -07:00
Jim Porter
1e8322bb26 Fix handling of 'byte-compile-ignore-files' when nil
Before this fix, when 'byte-compile-ignore-files' was nil,
'byte-recompile-directory' would ignore every file (bug#64985).

* lisp/emacs-lisp/bytecomp.el (byte-recompile-directory): Handle case
when 'byte-compile-ignore-files' is nil.
2023-08-05 10:14:15 -07:00
Eli Zaretskii
54d7426428 Merge from origin/emacs-29
6eddbfe33f Clarify the meaning of the argument of ':align-to' space ...
5c6a51668b ; * doc/misc/eshell.texi (Argument Modifiers): Fix typo i...
da5e05a50e Fix handling of ".elpaignore" file when compiling packages
2023-08-04 03:17:50 -04:00
Jim Porter
da5e05a50e Fix handling of ".elpaignore" file when compiling packages
* lisp/emacs-lisp/bytecomp.el (byte-recompile-directory): Treat
'byte-compile-ignore-files' as a list of regexps per its docstring
(bug#64985).
2023-08-01 18:14:35 -07:00
Mattias Engdegård
93eccb5e04 Better compilation of char-before, backward-char and backward-word
Implement char-before, backward-char and backward-word as compiler
macros instead of byte-compile handlers so that the source-level
optimiser gets to simplify the result.  In particular, this removes
some branches.

* lisp/emacs-lisp/bytecomp.el (byte-compile-char-before)
(byte-compile-backward-char, byte-compile-backward-word): Remove.
(bytecomp--char-before, bytecomp--backward-char)
(bytecomp--backward-word): New.
2023-07-27 17:09:30 +02:00
Stefan Monnier
3710178024 * lisp/emacs-lisp/bytecomp.el (byte-compile-eval): Fix bug#64232 2023-07-07 12:09:50 -04:00
Mattias Engdegård
59a350cb91 Warn about misplaced :success in condition-case (bug#64404)
* lisp/emacs-lisp/bytecomp.el (byte-compile-condition-case):
Warn if :success is part of a list of conditions (it must come alone).
2023-07-02 11:53:36 +02:00
Stefan Monnier
82875b1575 cl-macs-tests.el (cl-&key-arguments): Fix regression
* lisp/emacs-lisp/bytecomp.el (byte-compile-form): Turn "cannot use
lexical var" errors into warnings.
Make the obey `with-suppressed-warnings`.

* test/lisp/emacs-lisp/cl-macs-tests.el (cl-&key-arguments):
Suppress warnings.
2023-06-27 16:14:32 -04:00
Stefan Monnier
0228421e34 Allow suppressing the "lexical arg shadows dynbound var" warning
In most cases the right way to fix this warning is by renaming
the offending argument, but in some cases this is inconvenient, as is
the case in `cl-defstruct` where arg names are imposed by slot names.

This patch also happens to fix a few bugs along the way:
- miscompilation of (lambda (gcs-done) (lambda (x) (+ x gcs-done)))
- errors about void function `byte-compile-warn-x` if the warning was
  emitted via `cconv-fv` when bytecomp was not loaded.
Oh, and it improves the warning by making the location info slightly
more precise.

* lisp/emacs-lisp/cconv.el (cconv--analyze-function): Remove this warning.
* lisp/emacs-lisp/bytecomp.el (byte-compile-check-lambda-list):
Warn about it here instead.  Let `with-suppressed-warnings` control it
under `lexical`.
2023-06-25 11:14:03 -04:00
Stefan Monnier
e85ebb3d82 (macroexp--unfold-lambda): Obey the lexbind semantics
While at it, rework the code so as not to rely on an
intermediate rewriting of (funcall (lambda ..) ...)
to ((lambda ..) ...) since that forms is deprecated.

* lisp/emacs-lisp/byte-opt.el (byte-optimize-funcall): Unfold lambdas
instead of turning them into the deprecated ((lambda ..) ..).
(byte-optimize-form-code-walker): Don't unfold ((lambda ..) ..) any more.
(byte-compile-inline-expand): Revert to non-optimized call if the unfolding
can't be optimized.

* lisp/emacs-lisp/bytecomp.el (byte-compile-form): Don't unfold
((lambda ..) ..) any more.

* lisp/emacs-lisp/cl-macs.el (cl--slet): Remove workaround.

* lisp/emacs-lisp/disass.el (disassemble): Make sure the code is
compiled with its own `lexical-binding` value.

* lisp/emacs-lisp/macroexp.el (macroexp--unfold-lambda): Make it work
both for ((lambda ..) ..) and for (funcall #'(lambda ..) ..).
Be careful not to move dynbound vars from `lambda` to `let`.
(macroexp--expand-all): Unfold (funcall #'(lambda ..) ..) instead of
turning it into ((lambda ..) ..).  Don't unfold ((lambda ..) ..) any more.
2023-06-24 17:53:41 -04:00
Mattias Engdegård
ef1394fca0 Move quoted lambda funarg check and expand coverage
* lisp/emacs-lisp/macroexp.el (macroexp--expand-all):
Move check for incorrectly quoted lambda arguments from here...
* lisp/emacs-lisp/bytecomp.el (byte-compile-form):
... to here, which should provide more detection opportunities.
Expand the set of functions for which this check is performed, now
also for some keyword arguments.
2023-06-13 14:27:48 +02:00
Mattias Engdegård
c9c0d1cf7f ; fix important-return-value-fns mistake
* lisp/emacs-lisp/bytecomp.el (important-return-value-fns):
Remove assoc-string; it's already side-effect-free.
2023-06-08 19:25:16 +02:00
Mattias Engdegård
0d411a0a6d Remove special fset byte-compilation warning
* lisp/emacs-lisp/bytecomp.el (fset, byte-compile-fset):
Remove special warning for fset, subsumed by the more general quoted
lambda funarg warning.
2023-06-08 19:25:16 +02:00
Mattias Engdegård
ddf8587bb5 Disable unused-return-value warning for delq and delete, again
* lisp/emacs-lisp/bytecomp.el (important-return-value-fns):
Remove `delq` and `delete` since they resulted in false
positives that nobody was interested in silencing (bug#61730).
2023-05-31 17:09:12 +02:00
Mattias Engdegård
49c56f3335 Add function declarations
* lisp/emacs-lisp/byte-opt.el (side-effect-free-fns):
Add get-byte, string-width, unibyte-string, special-variable-p, frexp,
buffer-hash, buffer-line-statistics, load-average, md5, secure-hash,
string-collate-equalp, string-collate-lessp, string-to-unibyte,
string-version-lessp, current-cpu-time.
(side-effect-and-error-free-fns): Add equal-including-properties.
(pure-fns): Add equal-including-properties, string-version-lessp.
* lisp/emacs-lisp/bytecomp.el (important-return-value-fns):
Add match-data.
* lisp/subr.el (buffer-local-boundp, subr-primitive-p, gensym)
(frame-configuration-p, apply-partially, make-composed-keymap)
(keymap-canonicalize, listify-key-sequence, event-modifiers)
(event-basic-type, mouse-event-p, event-start, event-end)
(event-click-count, event-line-count, posnp, posn-window, posn-area)
(posn-point, posn-x-y, posn-col-row, posn-actual-col-row)
(posn-timestamp, posn-string, posn-image, posn-object)
(posn-object-x-y, posn-object-width-height, provided-mode-derived-p)
(derived-mode-p, autoloadp, locate-eln-file, symbol-file)
(process-lines-handling-status, process-lines)
(process-lines-ignore-status, process-get)
(copy-overlay, shell-quote-argument, field-at-pos):
Add appropriate function declarations.
2023-05-30 17:46:06 +02:00
Mattias Engdegård
08291e6f17 Clean up defcustom type quote check
* lisp/emacs-lisp/bytecomp.el
(byte-compile--suspicious-defcustom-choice): Rename to...
(byte-compile--defcustom-type-quoted): ...this and rewrite to make
more sense.  All callers updated.
(byte-compile-nogroup-warn): Better warning message.
* test/lisp/emacs-lisp/bytecomp-tests.el
(test-bytecomp-defgroup-choice): This never failed because it wasn't
actually a test.  Turn it into...
(bytecomp-test-defcustom-type-quoted): ...this, which is.
2023-05-30 09:51:10 +02:00
Mattias Engdegård
f8cdb9e050 Declare more mutating functions
* lisp/emacs-lisp/bytecomp.el (mutating-fns):
Add assoc-delete-all, assq-delete-all and rassq-delete-all.
* lisp/emacs-lisp/shortdoc.el (alist, list):
Don't mutate constants in examples illustrating use of
assoc-delete-all, assq-delete-all and rassq-delete-all.
2023-05-20 20:34:55 +02:00
Mattias Engdegård
88d1e9b436 Declare more functions as having important-return-value
* lisp/subr.el (assoc-delete-all, assq-delete-all, rassq-delete-all)
(alist-get): Declare as important-return-value.
* lisp/emacs-lisp/bytecomp.el (important-return-value-fns):
Add `assoc-string`.
2023-05-20 18:38:33 +02:00
Mattias Engdegård
8c9377b6c4 Try declaring delq and delete important-return-value (bug#61730)
* lisp/emacs-lisp/bytecomp.el (important-return-value-fns):
Add (uncomment) `delq` and `delete`.
2023-05-18 17:22:41 +02:00
Mattias Engdegård
9f856e4cd0 Use mutate-constant as warning identifier
* etc/NEWS:
* lisp/emacs-lisp/byte-run.el (with-suppressed-warnings):
* lisp/emacs-lisp/bytecomp.el (byte-compile-warnings)
(byte-compile-form):
* test/lisp/emacs-lisp/bytecomp-tests.el
(bytecomp-test--with-suppressed-warnings):
Use the new warning name `mutate-constant` instead of using the
somewhat overloaded `suspicious`.
2023-05-13 14:30:59 +02:00
Mattias Engdegård
bfc07100d2 Byte-compiler warning about mutation of constant values
When we can easily detect mutation of constants (quoted lists, strings
and vectors), warn.  For example,

  (setcdr '(1 . 2) 3)
  (nreverse [1 2 3])
  (put-text-property 0 3 'face 'highlight "moo")

Such code can result in surprising behaviour and problems that
are difficult to debug.

* lisp/emacs-lisp/bytecomp.el (byte-compile-form, mutating-fns):
Add the warning and a list of functions to warn about.
* etc/NEWS: Announce.
* test/lisp/emacs-lisp/bytecomp-tests.el
(bytecomp-test--with-suppressed-warnings): Add test cases.
2023-05-13 11:53:25 +02:00
Mattias Engdegård
7acb3f1c06 Add the function declaration and property important-return-value
Now the declaration

 (declare (important-return-value t))

can be used to have the byte-compiler warn when the return value from
a call is discarded (bug#61730).

* lisp/emacs-lisp/bytecomp.el (byte-compile-form)
(important-return-value-fns): Use the function property
`important-return-value` instead of looking through a static list.
* lisp/emacs-lisp/byte-run.el (byte-run--set-important-return-value)
(defun-declarations-alist): New function declaration, setting the
property of the same name.
* lisp/emacs-lisp/cl-macs.el:
* lisp/subr.el (assoc-default): Set the property.
* doc/lispref/functions.texi (Declare Form):
* doc/lispref/symbols.texi (Standard Properties): Document.
* etc/NEWS: Announce.
2023-05-01 17:11:50 +02:00
Mattias Engdegård
ea9831bb3c Better compilation of arguments to ignore
* lisp/emacs-lisp/bytecomp.el (byte-compile-form)
(byte-compile-ignore):
Instead of compiling each `ignore` argument for value which is then
immediately discarded, compile it for effect but suppress
ignore-return-value warnings by passing the special value
`for-effect-no-warn` as for-effect parameter.
Proposed by Stefan Monnier.
2023-04-12 10:47:42 +02:00
Mattias Engdegård
6157e3e4bc Extend ignored-return-value warning to more functions (bug#61730)
Warn when the return value of certain functions is unused.  Previously
this was only done for side-effect-free functions, and for `mapcar`.

These are functions where the return value is important for correct
usage or where ignoring it is likely to indicate a mistake.  The exact
set of functions is tentative and will be modified as we gain a better
understanding of which ones to include.

The current set comprises higher order functions such as `mapcar`
which are not primarily called for the effects of their function
arguments, and list-mutating functions like `nreverse` whose return
value is essential.

* lisp/emacs-lisp/bytecomp.el (byte-compile-form): Add list of
functions to warn about when their value is ignored.
* etc/NEWS: Announce.
2023-04-09 18:23:05 +02:00
Mattias Engdegård
aef996cd34 Consolidate existing warnings about unused return values
Move the warning about unused return values from calls to
side-effect-free functions from the source-level optimiser to the code
generator, where it can be unified with the special-purpose warning
about unused values from `mapcar`.  This change also cures spurious
duplicate warnings about the same code, makes the warnings amenable to
suppression through `with-suppressed-warnings`, and now warns about
some unused values that weren't caught before.

* lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker):
Move warning away from here.
* lisp/emacs-lisp/byte-run.el (with-suppressed-warnings):
* lisp/emacs-lisp/bytecomp.el (byte-compile-warnings):
Doc string updates.
(byte-compile-form): Put the new warnings here.
(byte-compile-normal-call): Move mapcar warning away from here.
* lisp/emacs-lisp/bytecomp.el (byte-compile-ignore):
Compile args to `ignore` for value to avoid unused-value warnings, and
then discard the generated values immediately thereafter.  Mostly this
does not affect the generated code but in rare cases it might result
in slightly worse code.
* test/lisp/emacs-lisp/bytecomp-tests.el
(bytecomp-test--with-suppressed-warnings): Adapt test.
2023-04-08 19:34:30 +02:00
Mattias Engdegård
75f04848a6 Repair and speed up safe-copy-tree and make it internal (bug#61962)
There is no particular requirement for safe-copy-tree so let's make it
internal for now.  The new implementation is faster and more correct.

* doc/lispref/lists.texi (Building Lists):
* etc/NEWS:  Remove doc and announcement.
* lisp/subr.el (safe-copy-tree--seen, safe-copy-tree--1)
(safe-copy-tree): Remove old version.
* lisp/emacs-lisp/bytecomp.el (bytecomp--copy-tree-seen)
(bytecomp--copy-tree-1, bytecomp--copy-tree): Add new version.
(byte-compile-initial-macro-environment): Use it.
* test/lisp/subr-tests.el (subr--safe-copy-tree):
* test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp--copy-tree):
Move and improve tests.
2023-03-12 18:12:18 +01:00
Alan Mackenzie
29f65920fb safe-copy-tree. Correct mistakes from earlier patch.
* lisp/emacs-lisp/bytecomp.el (compile-defun): Remove unintended change.

* lisp/subr.el (safe-copy-tree--seen): Correct grammatical error in doc
string.
(safe-copy-tree): Delete hash table at end of function.

* doc/lispref/lists.texi (Building Lists): Add an "@end defun" line.
2023-03-07 15:26:20 +00:00
Alan Mackenzie
fa83b23611 eval-and-compile: Strip symbol positions for eval but not for compile.
This fixes bug #61962.

* lisp/subr.el (safe-copy-tree): New function.

* lisp/emacs-lisp/bytecomp.el (byte-compile-initial-macro-environment): Amend
the entry for eval-and-compile to use safe-copy-tree and
byte-run-strip-symbol-positions for the eval part.

* doc/lispref/lists.texi (Building Lists): Document safe-copy-tree.

* etc/NEWS: Note the new function safe-copy-tree.
2023-03-07 08:00:25 +00:00
Mattias Engdegård
828c49ae29 Fix cond miscompilation bug
This fixes a bug that miscompiled

  (cond ... C S1...Sn)

where S1...Sn are switch clauses (that can be compiled into a switch
op) and C a non-switch clause, by tucking on an extra copy of C at the
end.  This was a serious wrong-code bug when the condition of C had
side-effects; otherwise it was only a waste of time and space.

* lisp/emacs-lisp/bytecomp.el (byte-compile-cond): Fix.
* test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-tests--test-cases):
Add test case.
2023-03-02 15:47:26 +01:00
Mattias Engdegård
5f38dcd43d More accurate suppression of ignored return value warning
* lisp/emacs-lisp/bytecomp.el (byte-compile-file-form-defalias):
Be careful to propagate the for-effect mode through a
`with-suppressed-warnings` form when compiling, so that a form
inside isn't erroneously considered to have its value 'used'
by the surrounding warning suppression form itself.
2023-02-24 16:53:32 +01:00
Mattias Engdegård
450be633bb Remove stray quotes
* lisp/emacs-lisp/bytecomp.el (byte-compile-form):
* lisp/help-fns.el (help-fns--interactive-only): Fix obvious mistake.
Since `interactive-only` is not supposed to be anything other than
a symbol at these points it was not a very consequential bug.
2023-02-21 18:32:51 +01:00
Mattias Engdegård
7a59f20a4e Follow aliases for interactive-only declarations
Make `interactive-only` declarations apply to aliases of the same
function as well since this quality isn't in the name but in what
the function does.

* lisp/emacs-lisp/bytecomp.el (byte-compile-form):
* lisp/help-fns.el (help-fns--interactive-only):
Follow aliases when retrieving the `interactive-only` property.
2023-02-21 12:32:48 +01:00
Alan Mackenzie
fcf2f7aead Make the byte compiler give correct warning positions in eval-and-compile
This fixes bug #61579.

* lisp/emacs-lisp/bytecomp.el (byte-compile-initial-environment): Remove a
spurious `byte-run-strip-symbol-position' from the core form of the
eval-and-compile element.
2023-02-17 17:31:17 +00:00
Mattias Engdegård
254c75fc29 Better commutative binary numerical op codegen
* lisp/emacs-lisp/bytecomp.el (byte-compile-variadic-numeric):
Put a constant argument last for better LAP code opportunities.
This applies to commutative binary operations (+ and *).
`min` and `max` are not included being not quite commutative.
2023-01-29 13:48:23 +01:00
Mattias Engdegård
e55855c5a1 Better compilation of n-ary comparisons
Transform n-ary comparisons to a chain of binary comparisons in the
Lisp optimiser instead of in codegen, to allow for subsequent
optimisations.  This generalises the transform, so that

   (< 1 X 10)  ->  (let ((x X)) (and (< 1 x) (< x 10)))

where (< 1 x) is then flipped to (> x 1) in codegen since it's
slightly more efficient to have the constant argument last.  Arguments
that are neither constants nor variables are given temporary bindings.

This results in about 2× speedup for 3-ary comparisons of fixnums with
nontrivial arguments, and also improves the code slightly for binary
comparisons with a constant first argument.

* lisp/emacs-lisp/byte-opt.el (byte-opt--nary-comparison): New,
set as the `byte-optimizer` property for =, <, <=, >, and >=.
* lisp/emacs-lisp/bytecomp.el (byte-compile-and-folded):
Rename to...
(byte-compile-cmp): ...and rewrite.
2023-01-29 12:02:57 +01:00
Mattias Engdegård
efb9ec11bb Improved docstring single quote warning
* lisp/emacs-lisp/bytecomp.el (byte-compile-docstring-style-warn):
More robust regexp.  More explicit warning message.
2023-01-18 18:50:23 +01:00
Mattias Engdegård
bcaa63ac50 * lisp/emacs-lisp/bytecomp.el (format-message): Warn on bad arity. 2023-01-16 19:42:31 +01:00