Commit graph

431 commits

Author SHA1 Message Date
Mattias Engdegård
c51d1bce1e equal is not error-free
* lisp/emacs-lisp/byte-opt.el (side-effect-free-fns)
(side-effect-and-error-free-fns)
(byte-compile-side-effect-and-error-free-ops)
(byte-compile-side-effect-free-ops):
Demote `equal` and `equal-including-properties` from error-free to
merely side-effect-free since they may in fact signal error on
circularity.
2023-08-13 11:51:03 +02:00
Mattias Engdegård
89bd651976 Teach byte-compiler about Aristotelian identity
* lisp/emacs-lisp/byte-opt.el (byte-optimize-equal, byte-optimize-eq):
Optimise (eq X X) -> t where X is a variable; idem for eql and equal.
* test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-tests--test-cases):
Add test case.
2023-08-08 11:46:18 +02:00
Mattias Engdegård
44d7fd3805 Don't allow the eq and unbind byte-ops to commute (bug#65017)
* lisp/emacs-lisp/byte-opt.el (byte-after-unwind-ops):
Cease sinking `eq` past `unwind`, because that optimised away the
let-binding in

  (let ((symbols-with-pos-enabled nil))
    (eq x y))

and `eq` is currently sensitive to `symbols-with-pos-enabled`.
* test/lisp/emacs-lisp/bytecomp-tests.el
(bytecomp--eq-symbols-with-pos-enabled): New test.
2023-08-04 11:08:57 +02:00
Mattias Engdegård
4336d7e44a * lisp/emacs-lisp/byte-opt.el (byte-compile-trueconstp): Extend
Add skip-chars-forward, skip-chars-backward, skip-syntax-forward,
skip-syntax-backward, current-column, current-indentation,
char-syntax, syntax-class-to-char, parse-partial-sexp, goto-char,
forward-line, next-window, previous-window, minibuffer-window,
selected-frame, selected-window, standard-case-table,
standard-syntax-table, syntax-table, frame-first-window,
frame-root-window and frame-selected-window as always-true functions.
2023-07-27 17:09:30 +02:00
Mattias Engdegård
27944247d1 Fix broken byte-compilation of unary comparisons
* lisp/emacs-lisp/byte-opt.el (byte-opt--nary-comparison):
Fix a typo causing miscompilation of code such as (OP X),
where OP is <, >, <=, >= or =.
* test/lisp/emacs-lisp/bytecomp-tests.el
(bytecomp-tests--test-cases): Add test case.

Reported by Richard Copley.
2023-07-26 18:49:51 +02:00
Mattias Engdegård
b4063c399b * lisp/emacs-lisp/byte-opt.el (pure-fns): Add max-char 2023-07-26 17:34:03 +02: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
195ca6b9a3 Don't compile (+ X 0) as (* X 1)
Previously (+ X 0) was reduced to (+ X) which became (* X 1) in
codegen, but this is wrong for X = -0.0 and also slightly slower.

* lisp/emacs-lisp/byte-opt.el (byte-optimize-plus): Don't reduce an
addition to (+ X) by eliminating zeros; retain one 0 argument.
* test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-tests--test-cases):
Add test case.
2023-06-21 18:00:26 +02:00
Mattias Engdegård
6058b4559d Better internal-make-closure optimisation
* lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker):
Optimise closed-over values in closure creation like any other, which
can lead to stack variables being eliminated.
2023-06-04 19:17:15 +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
044392c5c5 Constant-propagate cons and vector literals
* lisp/emacs-lisp/byte-opt.el (byte-optimize--substitutable-p):
Allow quoted lists and conses, and vector literals, to be substituted
from lexical variables.  This can eliminate variable bindings and
create new constant folding opportunities.
2023-05-05 22:00:28 +02:00
Mattias Engdegård
3b038d46e2 Remove useless handling of erroneous code in Lisp optimiser
* lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker):
((closure ...) ...) is a malformed function call; treat it as such.
Better malformed function warning location.
2023-05-05 22:00:27 +02:00
Mattias Engdegård
1438574dd7 Don't inline funcall to literal lambda form
* lisp/emacs-lisp/byte-opt.el (byte-optimize-funcall): Don't convert

  (funcall '(lambda ...) ...) -> ((lambda ...) ...)

because that would inline what is essentially an `eval` of a
function using dynamic binding rules into lexbound code.
2023-05-05 22:00:27 +02:00
Mattias Engdegård
1dcb737405 Don't rewrite (nconc X nil) -> X for any X (bug#63103)
Since the last cdr of a non-terminal argument to `nconc` is
overwritten no matter its value:

  (nconc (cons 1 2) nil) => (1)

a terminating nil arg cannot just be eliminated unconditionally.

* lisp/emacs-lisp/byte-opt.el (byte-optimize-nconc):
Only eliminate a terminal nil arg to `nconc` if preceded by
a nonempty proper list.  Right now we only bother to prove this
for `(list ...)`, so that

  (nconc (list 1 2 3) nil) -> (list 1 2 3)

* test/lisp/emacs-lisp/bytecomp-tests.el
(bytecomp-tests--test-cases): Add test cases.
2023-04-27 14:20:45 +02:00
Mattias Engdegård
e6ca5834a6 Improved nconc and append compiler optimisations
Add the transforms:

  (nconc) -> nil
  (nconc X) -> X

and for arguments to `nconc`:

  nil -> <elided>
  (list X...) (list Y...) -> (list X... Y...)
  (list X) Y -> (cons X Y)

* lisp/emacs-lisp/byte-opt.el (byte-optimize-nconc): New.
(byte-optimize-append): Fix minor flaws and generalise.
2023-04-22 09:47:23 +02:00
Mattias Engdegård
df4a6342fa ; reorder function effect-declaration lists
* lisp/emacs-lisp/byte-opt.el (side-effect-free-fns)
(side-effect-and-error-free-fns, pure-fns): Group by file.
2023-04-13 14:26:31 +02:00
Mattias Engdegård
feef1a0592 Update effect declarations for many built-in functions
* lisp/emacs-lisp/byte-opt.el (side-effect-free-fns)
(side-effect-and-error-free-fns, pure-fns): Add many functions.
* lisp/subr.el (copy-tree): Declare error-free.
2023-04-13 14:26:16 +02:00
Mattias Engdegård
9d025eab24 byte-code-function-p is error-free
* lisp/emacs-lisp/byte-opt.el
(side-effect-free-fns, side-effect-and-error-free-fns):
Upgrade `byte-code-function-p` to error-free status.
2023-04-12 10:47:43 +02:00
Mattias Engdegård
48ff93ba18 Adjust side-effect-free declarations
* lisp/emacs-lisp/byte-opt.el (side-effect-and-error-free-fns):
Add `eql` here.
* lisp/emacs-lisp/cl-macs.el (eql, cl-subst, cl-sublis):
Don't set the `side-effect-free` property here.
`cl-subst` and `cl-sublis` are not side-effect-free.
* lisp/emacs-lisp/cl-extra.el (cl-revappend):
Declare side-effect-free.
* lisp/emacs-lisp/cl-lib.el (cl-copy-list):
Declare side-effect-free and error-free.
2023-04-09 16:45:40 +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
52b67740d1 Generalise a LAP optimisation rule
* lisp/emacs-lisp/byte-opt.el (byte-optimize-lapcode):
Accept (stack-set 1) as equivalent to (discardN-preserve-tos 1) in a
rule previously overlooked.  This is usually beneficial in code size
and almost always shortens dynamic paths.
2023-03-25 16:21:09 +01:00
Mattias Engdegård
a1d90e48bb Small unwind-protect optimisation improvement
* lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker):
Use the current for-effect mode when optimising the body form,
instead of always optimising it for value.
2023-03-02 15:47:26 +01:00
Mattias Engdegård
42f4691388 Simplify effect-free code elimination
* lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker):
Simplify overly defensive code.  This does not affect code generation.
2023-03-01 13:37:06 +01:00
Mattias Engdegård
1767d18c91 Adjust some pure and side-effect-free function declarations
* lisp/emacs-lisp/byte-opt.el (side-effect-free-fns):
Add `format-message` and `substring-no-properties`.
* lisp/subr.el (number-sequence, copy-tree, looking-at-p)
(string-match-p, string-trim-right, string-lines):
Declare side-effect-free.
(syntax-class, version-list-<, version-list-=, version-list-<=)
(version-list-not-zero): Declare pure and side-effect-free.
(ensure-list): Declare side-effect-free and error-free.
(string-equal-ignore-case): Remove `pure` declaration.
We may want it to be pure but right now it's not.
2023-02-27 14:34:22 +01:00
Mattias Engdegård
1defa5000b Follow function aliases for side-effect-free and pure properties
This way we don't need to set these properties on aliases at all;
it was always easy to forget doing so.

* lisp/emacs-lisp/byte-opt.el (byte-opt--fget): New function.
(byte-optimize-form-code-walker, byte-optimize-form): Use it.
(side-effect-free-fns, side-effect-and-error-free-fns, pure-fns):
Remove aliases from lists, leaving only built-in functions.
2023-02-24 16:53:32 +01:00
Mattias Engdegård
170b419df0 Declare indirect-function to be side-effect-free and error-free
* lisp/emacs-lisp/byte-opt.el (side-effect-and-error-free-fns):
Add `indirect-function` which is now error-free.
2023-02-22 17:46:03 +01:00
Mattias Engdegård
d5bf26f488 Move side-effect-free and pure declarations to function definitions
Some Lisp functions still had their `side-effect-free` and `pure`
properties declared in byte-opt.el; do it at their definition instead.
The lists in byte-opt.el now only contain functions implemented in C
and function aliases.

* lisp/emacs-lisp/byte-opt.el (side-effect-free-fns)
(side-effect-and-error-free-fns, pure-fns):
Remove functions whose properties are now declared elsewhere
and some obsolete entries.
* lisp/custom.el (custom-variable-p):
* lisp/emacs-lisp/lisp.el (buffer-end):
* lisp/emacs-lisp/regexp-opt.el (regexp-opt):
* lisp/env.el (getenv):
* lisp/simple.el (count-lines, mark, string-empty-p, lax-plist-get):
* lisp/subr.el (ignore, always, zerop, fixnump, bignump, lsh, last)
(eventp, mouse-movement-p, log10, memory-limit, string-greaterp)
(interactive-p):
* lisp/window.el (get-lru-window, get-largest-window, (window-edges)
(window-body-edges, window-pixel-edges, window-body-pixel-edges)
(window-absolute-pixel-edges, window-absolute-body-pixel-edges)
(one-window-p):
Declare functions `side-effect-free` and/or `pure` as appropriate.
2023-02-17 14:52:54 +01:00
Mattias Engdegård
864bf5dda4 Fix recent LAP optimiser error
* lisp/emacs-lisp/byte-opt.el (byte-optimize-lapcode):
Fix a flaw in the

  dup (varset|varbind|stack-set) discard -> (varset|varbind|stack-set)

rule: don't match stack-set(1) which is dealt with elsewhere, and
generalise to discard(N).
2023-02-14 17:14:07 +01:00
Mattias Engdegård
8aef401b4f LAP optimiser: more stack reduction hoisting
Hoisting stack reduction ops allows them to coalesce and/or cancel out
pushing ops, and for useful operations to sink and combine, such as
not + goto-if-[not-]nil.

* lisp/emacs-lisp/byte-opt.el (byte-optimize-lapcode):
Add the rule

  UNARY discardN-preserve-tos --> discardN-preserve-tos UNARY

where UNARY pops and pushes one value.

Generalise the rule

  const discardN-preserve-tos --> discardN const

to any 0-ary op, not just const: varref, point, etc.
2023-02-13 16:57:49 +01:00
Mattias Engdegård
85a2eb2c78 LAP peephole optimiser improvementsa
* lisp/emacs-lisp/byte-opt.el (byte-optimize-lapcode):
Make the improvements:

- Add the rule

    stack-ref(X) discardN-preserve-tos(Y)
    --> discard(Y) stack-ref(X-Y),                X≥Y
        discard(X) discardN-preserve-tos(Y-X-1),  X<Y

  with the usual equivalences:

    stack-set(1) = discardN-preserve-tos(1)
    stack-ref(0) = dup
    discard(0) = discardN-preserve-tos(0) = no-op

  This rule hoists stack reduction to where it is more likely to be
  exploited further, may reduce the op size through smaller
  immediates, and sometimes removes either or both operations
  outright.

  The rule is inhibited by an immediately following `return` op
  because other rules will produce better code in that case.

- Add the rule

    (discardN-preserve-tos|dup) OP return --> OP return

  where OP is a unary operation such as `not` or `car`.

- Generalise a previous rule to

    NOEFFECT PRODUCER return  -->  PRODUCER return

  where PRODUCER is now any op that pushes a value without looking at
  the stack: const, varref, point etc.
2023-02-11 12:52:18 +01:00
Mattias Engdegård
680bc20553 Flatten nested concat calls
* lisp/emacs-lisp/byte-opt.el (byte-optimize-concat):
Flatten nested forms; concat is associative.  This reduces the number
of calls and may coalesce adjacent constant strings.
2023-02-08 13:45:57 +01:00
Mattias Engdegård
f3fce3a71c Simplify and speed up parts of elisp optimiser
* lisp/emacs-lisp/byte-opt.el (byte-optimize-constant-args): Simplify.
(byte-optimize--constant-symbol-p): Speed up.
(byteopt--eval-const): New.
(byte-optimize-member, byte-optimize-concat, byte-optimize-append):
Use byteopt--eval-const instead of eval which is much slower.
2023-02-08 13:18:32 +01:00
Mattias Engdegård
0f4c7060e4 Fix misleading LAP optimiser debug log message
* lisp/emacs-lisp/byte-opt.el (byte-optimize-lapcode):
Correct message in a conditional jump threading rule.
2023-02-05 16:27:35 +01:00
Mattias Engdegård
17784bbf3f Allow unbind to commute with discardN and discardN-preserve-tos
* lisp/emacs-lisp/byte-opt.el (byte-after-unbind-ops):
Add discardN and discardN-preserve-tos, both of which
commute with unbind.  This enables subsequent optimisations.
2023-02-05 16:27:35 +01:00
Mattias Engdegård
a50d5b219f Remove compatibility hacks in LAP optimiser
* lisp/emacs-lisp/byte-opt.el (byte-optimize-lapcode):
Remove code forcing forward motion after applying certain
transformations; these were only there to keep output identical across
refactorings.
2023-02-05 16:26:45 +01:00
Mattias Engdegård
9926b44f9e LAP optimiser: bind local variables instead of mutating them
This is a refactoring step: there is no change in how the optimiser
works.

* lisp/emacs-lisp/byte-opt.el (byte-optimize-lapcode):
Instead of re-using local variables through mutation, bind them at
point of use.  This ensures that there is no value leakage by mistake
and actually reduces the static size of the bytecode of this function
somewhat.
The lousy variable names (tmp, tmp2 etc) are retained but
can at least now be changed into something more descriptive.
2023-02-05 16:25:23 +01:00
Mattias Engdegård
929099cbb4 Get rid of delq in LAP optimiser
* lisp/emacs-lisp/byte-opt.el (byte-optimize-lapcode):
Instead of using the O(n) `delq' to remove single instructions, use
the O(1) `setcdr'. To do this, anchor the instruction list in a cons
cell and use the predecessor cell in iteration.
2023-02-05 16:24:51 +01:00
Mattias Engdegård
bfd338aad9 LAP peephole optimisation improvements
- Since discardN-preserve-tos(1) and stack-set(1) have the same
  effect, treat them as equivalent in all transformations.

- Move the rule

        discardN-preserve-tos(X) discardN-preserve-tos(Y)
    --> discardN-preserve-tos(X+Y)

  from the final pass to the main iteration since it may enable
  further optimisations.

- Don't apply the rule

    goto(X) ... X: DISCARD --> DISCARD goto(Y) ... X: DISCARD Y:

  when DISCARD could be merged or deleted instead, which is even better.

- Add the rule

    OP const return -> <deleted> const return

  where OP is effect-free.

- Generalise the push-pop annihilation rule to

    PUSH(K) discard(N) -> discard(N-K), N>K
    PUSH(K) discard(N) -> <deleted>,    N=K

  to any N, not just N=1.

- Add the rule

    OP goto(X) Y: OP X: -> <deleted> Y: OP X:

  for any operation OP.

* lisp/emacs-lisp/byte-opt.el (byte-optimize-lapcode):
Make the changes described above.
2023-02-02 14:46:53 +01:00
Mattias Engdegård
f6955482c2 Clean up LAP peephole logging
Make `byte-compile-log-lap` more robust and produce nicer output.
This is of interest for Elisp compiler maintainers only.

* lisp/emacs-lisp/byte-opt.el (bytecomp--log-lap-arg): New.
(byte-compile-log-lap-1): Extract argument conversion and rewrite
in a more modern way, fixing bugs.  In particular, tags are now
displayed as "X:" where X is the tag number, and that tag number
is shown as argument to goto-like ops.
(byte-optimize-lapcode): Clean up and simplify logging, producing
useful information when `byte-optimize-log` is `byte` as intended.
2023-02-02 14:43:10 +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
627ac228b2 Don't inhibit LAP-level DCE when switch ops are present
* lisp/emacs-lisp/byte-opt.el (byte-optimize-lapcode):
Allow removal of unreachable basic blocks in the LAP peephole
optimiser even when switch ops are present.  The origins of
this apparently unnecessary condition are unclear.
2023-01-27 17:27:15 +01:00
Mattias Engdegård
2a85d7a07c Optimise apply with cons in tail argument
* lisp/emacs-lisp/byte-opt.el (byte-optimize-apply): Transform

  (apply F ... (cons X Y)) -> (apply F ... X Y)

This pattern is seen both in hand-written code and in backquote
expansions.
2023-01-16 19:42:31 +01:00
Eli Zaretskii
3c55fbd4ad Merge from origin/emacs-29
cae528457c ; Add 2023 to copyright years.
b394359261 Improve documentation of 'isearch-open-overlay-temporary'
ab3210e709 Document 'use-package' in the 2 main manuals

# Conflicts:
#	etc/refcards/ru-refcard.tex
#	lib/explicit_bzero.c
#	m4/explicit_bzero.m4
2023-01-01 05:47:47 -05:00
Eli Zaretskii
cae528457c ; Add 2023 to copyright years. 2023-01-01 05:31:12 -05:00
Mattias Engdegård
8bb8cc5b49 Fix condition-case body for-effect miscompilation
(condition-case x A (:success B)) should not compile A for-effect even
if the entire form is in for-effect context.

* lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker):
Don't optimise the condition-case body form for effect (potentially
discarding its value) if there is a success handler and a variable.
* test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-tests--test-cases):
Add test cases.
2022-12-24 11:54:47 +01:00
Mattias Engdegård
33af537198 Elide broken but unnecessary if optimisations
* lisp/emacs-lisp/byte-opt.el (byte-optimize-if):
Remove explicit clauses purposing to simplify

    (if X nil t) -> (not X)
    (if X t nil) -> (not (not X))

but never did so because of a coding mistake (eq instead of equal),
found by a recently added warning.  They weren't actually needed
thanks to the optimiser's fixpoint iteration: we eventually get the
same results through

    (if X nil t) -> (if (not X) t nil) -> (if (not X) t) -> (not X)
    (if X t nil) -> (if X t) -> (not (not X))
2022-12-19 13:19:09 +01:00
Stefan Kangas
d468cf91b9 Merge from origin/emacs-29
de2239a584 Revert "alist-get testfn argument evaluation correction"
856d889f3a Revert "Elide broken but unnecessary `if` optimisations"
8e42e20ed7 Revert "Use equal and member instead of eq and memq"
2022-12-19 04:42:18 +01:00
Mattias Engdegård
6283b92334 Elide broken but unnecessary if optimisations
* lisp/emacs-lisp/byte-opt.el (byte-optimize-if):
Remove explicit clauses purposing to simplify

    (if X nil t) -> (not X)
    (if X t nil) -> (not (not X))

but never did so because of a coding mistake (eq instead of equal),
found by a recently added warning.  They weren't actually needed
thanks to the optimiser's fixpoint iteration: we eventually get the
same results through

    (if X nil t) -> (if (not X) t nil) -> (if (not X) t) -> (not X)
    (if X t nil) -> (if X t) -> (not (not X))
2022-12-16 19:18:34 +01:00
Eli Zaretskii
856d889f3a Revert "Elide broken but unnecessary if optimisations"
This reverts commit 13aa376e93.

Please don't install anything on the release branch that is
not a clear bugfix for a known bug.
2022-12-16 19:27:33 +02:00
Mattias Engdegård
b29be11a6f Closures are always non-nil
* lisp/emacs-lisp/byte-opt.el (byte-compile-trueconstp):
Treat closures as true in boolean context.
2022-12-16 17:18:44 +01:00