Commit graph

159 commits

Author SHA1 Message Date
Jens Schmidt
86e8f31505 Silence macro expansion during completion at point
* lisp/emacs-lisp/macroexp.el (macroexp-inhibit-compiler-macros): Add
variable.
(macroexp--compiler-macro): Inspect that new variable and, if it is
non-nil, return the input form unchanged.
* lisp/progmodes/elisp-mode.el (elisp--local-variables): Silence
messages.  Avoid compiler macros.  (Bug#58148)
2023-10-05 14:00:36 -04:00
Mattias Engdegård
f616edb4cc macroexp-parse-body: correct parsing of empty body (bug#66136)
* lisp/emacs-lisp/macroexp.el (macroexp-parse-body):
Return an empty body even when there are declarations present.
Previously, the last declaration was considered part of the body,
which is only correct if the input consists of a single string.

Reported by Jens Schmidt.
2023-09-25 15:04:17 +02:00
Alan Mackenzie
f931cebce7 Insert symbol `debug' into two condition-case handlers
This fixes bug#65622.  Also correct a mismatch between a
function to which advice is added, and that from which it is
removed.

* lisp/emacs-lisp/macroexp.el (internal-macroexpand-for-load):
Add a `debug' to the condition-case handler for `error', so
that a useful backtrace will be produced on a macro expansion
error.

* lisp/progmodes/elisp-mode.el (elisp--local-variables): Add
`debug' to a condition-case handler, as above.  In the
advice-remove call, give the same function, macroexpand-1, as
in the corresponding advice-add call.
2023-09-20 15:51:17 +00:00
Mattias Engdegård
c137b5195b Add byte-compiler warning about useless trailing cond clauses
Warn about clauses after the default clause, as in

    (cond ((= x 0) (say "none"))
          (t (say "some"))
          (say "goodbye"))

because they are very much an indicator of a mistake (such as
misplaced brackets), and since they are deleted by the optimiser, any
other warnings there are lost and the user wouldn't know that
something is wrong otherwise.

* lisp/emacs-lisp/macroexp.el (macroexp--expand-all): Add warning.
* etc/NEWS: Announce.
* test/lisp/emacs-lisp/bytecomp-tests.el
(bytecomp-test--with-suppressed-warnings): Add test case.
2023-09-09 13:24:31 +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
Stefan Monnier
ca4bc9baf9 macroexp.el: Fix missing warning for intermediate expansions
When a macro expanded to a call to an obsolete macro, we failed
to emit a warning for that use of the obsolete macro.

* lisp/emacs-lisp/macroexp.el (macroexp-macroexpand):
Use `macroexpand-1` to check obsolecence of intermediate expansions.

* test/lisp/emacs-lisp/macroexp-tests.el
(macroexp--test-obsolete-macro): New test.
2023-07-21 11:48:42 -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
560c15a04f ; * lisp/emacs-lisp/macroexp.el (macroexp--expand-all): minor tweaks
Don't lose `funcall` symbol position.  Remove outdated comment.
2023-06-12 10:24:32 +02:00
Mattias Engdegård
9c31ee4686 Warn about unwind-protect without unwind forms
`unwind-protect` without unwind forms is not just pointless but often
indicates a mistake where the intended unwind part is misplaced, as in

    (unwind-protect (progn PROT-FORMS UNWIND-FORMS))   ; oops

or

    (unwind-protect PROT-FORM) UNWIND-FORMS            ; also oops

or entirely forgotten for that matter.  Warning about this makes
sense, and the warning can always be silenced by removing the
`unwind-protect` altogether if it shouldn't be there in the first
place.

* lisp/emacs-lisp/macroexp.el (macroexp--expand-all): Implement
warning.
* etc/NEWS: Announce.
* test/lisp/emacs-lisp/bytecomp-tests.el
(bytecomp-test--with-suppressed-warnings): Add test case.
2023-03-29 19:47:03 +02:00
Mattias Engdegård
443c249d85 Warn about condition-case without handlers
Omitting handlers from a `condition-case` form makes it useless
since no errors are caught.

* lisp/emacs-lisp/macroexp.el (macroexp--expand-all): New warning.
* test/lisp/emacs-lisp/bytecomp-tests.el
(bytecomp-test--with-suppressed-warnings): Add test case.
* etc/NEWS: Announce.
2023-02-27 14:34:22 +01:00
Mattias Engdegård
74463909cb * lisp/emacs-lisp/macroexp.el (mapcan): Set funarg-positions. 2023-02-20 13:17:22 +01:00
Mattias Engdegård
1b52eaa190 Better lambda quote warning
* lisp/emacs-lisp/macroexp.el (macroexp--expand-all):
Avoid `...` shown backslash-escaped as a symbol, and render an empty
argument list as `()` instead of `nil`.
2023-01-18 18:50:03 +01:00
Mattias Engdegård
0e1b03bbb8 Styled quotes in compiler warnings
* lisp/emacs-lisp/byte-run.el (byte-run--parse-body)
(byte-run--unescaped-character-literals-warning):
* lisp/emacs-lisp/bytecomp.el (byte-compile-initial-macro-environment)
(byte-compile-form, bytecomp--warn-dodgy-eq-arg):
* lisp/emacs-lisp/cconv.el (cconv--warn-unused-msg):
* lisp/emacs-lisp/cl-macs.el (cl-defstruct):
* lisp/emacs-lisp/easy-mmode.el (define-minor-mode):
* lisp/emacs-lisp/eieio.el (defclass):
* lisp/emacs-lisp/macroexp.el (macroexp--unfold-lambda)
(macroexp--expand-all):
* lisp/emacs-lisp/pcase.el (pcase--u1):
* lisp/subr.el (when, unless, ignore-error, lsh, sit-for)
(with-demoted-errors):
Use format-message to ensure properly styled quotes in compiler
warning messages.
2023-01-03 18:39:06 +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
29d23b7fa0 Consistent empty-body warning messages for let and let*
* lisp/emacs-lisp/macroexp.el (macroexp--expand-all):
* test/lisp/emacs-lisp/bytecomp-tests.el
(bytecomp-test--with-suppressed-warnings):
Make warning messages for let and let* consistent with other
empty-body warnings.
2022-12-29 17:00:01 +01:00
Mattias Engdegård
7c63b632e4 Add empty-body warning for when, unless etc
Warn about code like (when SOME-CONDITION) because these may indicate
bugs.  Warnings currently apply to `when`, `unless`, `ignore-error`,
`with-suppressed-warnings` and (as before) `let` and `let*`.

* lisp/emacs-lisp/byte-run.el (with-suppressed-warnings):
Update doc string.
* lisp/emacs-lisp/bytecomp.el: (byte-compile-warning-types)
(byte-compile-warnings): Add empty-body.
(byte-compile-initial-macro-environment):
Add empty-body warning for with-suppressed-warnings.
* lisp/emacs-lisp/macroexp.el (macroexp--expand-all):
Use the empty-body category for let and let*.
* lisp/subr.el (when, unless, ignore-error): Add empty-body warning.
* test/lisp/emacs-lisp/bytecomp-tests.el
(bytecomp-test--with-suppressed-warnings): Add test cases.
2022-12-29 13:01:47 +01:00
Mattias Engdegård
68fb06f47f Fix compiler macro expansion bug
* lisp/emacs-lisp/macroexp.el (macroexp--expand-all):
When a compiler-macro handler is re-invoked (after macro-expanding
arguments), actually use the result instead of pointlessly dropping it
on the floor.
2022-12-18 14:48:54 +01:00
Stefan Monnier
b01d529e8d * lisp/emacs-lisp/macroexp.el (macroexp--compiler-macro): Soften message
Clarify that the error is "harmless".
2022-09-03 11:03:32 -04:00
Mattias Engdegård
9a7b3673e0 Move while syntax check from optimiser to macroexpand
* lisp/emacs-lisp/byte-opt.el (byte-optimize-while): Move check...
* lisp/emacs-lisp/macroexp.el (macroexp--expand-all): ...here.
2022-08-19 21:23:48 +02:00
Stefan Kangas
935e4da0e1 Display new keybinding in obsolete command warning
* lisp/emacs-lisp/macroexp.el (macroexp--obsolete-warning):
* lisp/simple.el (command-execute): When warning about an obsolete
command, display the keybinding for the new command.
2022-08-19 19:00:24 +02:00
Stefan Monnier
1faeef7924 (compiled-function-p): New function (bug#56648)
* lisp/subr.el (compiled-function-p): New function.

* test/lisp/international/ucs-normalize-tests.el (ucs-normalize-part1):
* lisp/gnus/gnus.el (gnus):
* lisp/mh-e/mh-e.el (mh-version):
* lisp/emacs-lisp/macroexp.el (emacs-startup-hook):
* lisp/emacs-lisp/cl-macs.el (compiled-function):
* lisp/emacs-lisp/bytecomp.el (byte-compile-fdefinition)
(byte-compile, display-call-tree):
* lisp/emacs-lisp/byte-opt.el (<toplevel-end>):
* lisp/emacs-lisp/advice.el (ad-compiled-p):
* lisp/cedet/semantic/bovine.el (semantic-bovinate-stream):
* lisp/loadup.el (macroexpand-all):
* admin/unidata/unidata-gen.el (unidata--ensure-compiled): Use it.

* lisp/emacs-lisp/pcase.el (pcase-mutually-exclusive-predicates):
Add entries for it.
(pcase--split-pred): Use it.

* lisp/help-fns.el (help-fns-function-description-header): Use `functionp`.
(help-fns--var-safe-local): Use `compiled-function-p`.
2022-08-14 12:30:05 -04:00
Stefan Kangas
2a05479c22 ; Fix typos: prefer American spelling 2022-07-14 12:13:31 +02:00
Mattias Engdegård
a68508c10b Don't say that macro-expansion error is a warning
* lisp/emacs-lisp/gv.el:
* lisp/emacs-lisp/macroexp.el (internal-macroexpand-for-load): Since
eager macro-expansion errors are no longer warnings, don't say so.
2022-06-30 15:08:02 +02:00
Lars Ingebrigtsen
80cf13a3d2 Make "eager macro-expansion" warning into an error
* doc/lispref/loading.texi (How Programs Do Loading): Update
documentation.

* lisp/emacs-lisp/macroexp.el:
(internal-macroexpand-for-load): We've been warning about eager
macro expansion for many years, so finally change that into an
error (bug#18154).
2022-06-30 13:18:15 +02:00
Mattias Engdegård
6825e5686a Normalise setq during macro-expansion
Early normalisation of setq during macroexpand-all allows later
stages, cconv, byte-opt and codegen, to be simplified and duplicated
checks to be eliminated.

* lisp/emacs-lisp/macroexp.el (macroexp--expand-all):
Normalise all setq forms to a sequence of (setq VAR EXPR).
Emit warnings if necessary.
* lisp/emacs-lisp/cconv.el (cconv-convert, cconv-analyze-form):
* lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker):
* lisp/emacs-lisp/bytecomp.el (byte-compile-setq):
Simplify.
* test/lisp/emacs-lisp/bytecomp-tests.el: Adapt and add tests.
* test/lisp/emacs-lisp/bytecomp-resources/warn-variable-setq-nonvariable.el;
* test/lisp/emacs-lisp/bytecomp-resources/warn-variable-setq-odd.el:
New files.
2022-06-14 20:19:59 +02:00
Alan Mackenzie
0b9b363dab Byte compiler: Prevent special forms' symbols being replaced by bare symbols
These are symbols with position from source code, which should not be replaced
by bare symbols in, e.g., optimization functions.

* lisp/Makefile.in: (BYTE_COMPILE_FLAGS, compile-first case): Set
max-specpdl-size to 5000 for the benefit of lisp/emacs-lisp/comp.el.

* lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker)
(byte-optimize--rename-var, byte-optimize-if, byte-optimize-letX)
* lisp/emacs-lisp/bytecomp.el (byte-compile-recurse-toplevel)
(byte-compile-lambda)
* lisp/emacs-lisp/cconv.el (cconv-convert)
* lisp/emacs-lisp/macroexp.el (macroexp--expand-all): Preserve, e.g., (car
form) in the byte compiler, when this form's car is a symbol with position of
a special form, rather than replacing the symbol with a bare symbol, e.g.
'cond.
2022-04-22 19:11:31 +00:00
Stefan Monnier
6a480c830b * lisp/emacs-lisp/macroexp.el (macroexp-let2*): Allow common shorthand 2022-04-11 15:10:51 -04:00
Stefan Monnier
f262a6af36 (macroexp-warn-and-return): Fix bug#53618
* lisp/emacs-lisp/macroexp.el (macroexp-warn-and-return):
Reorder arguments to preserve compatibility with that of Emacs-28.
(macroexp--unfold-lambda, macroexp--expand-all):
* lisp/emacs-lisp/pcase.el (pcase-compile-patterns, pcase--u1):
* lisp/emacs-lisp/gv.el (gv-ref):
* lisp/emacs-lisp/eieio.el (defclass):
* lisp/emacs-lisp/eieio-core.el (eieio-oref, eieio-oref-default)
(eieio-oset-default):
* lisp/emacs-lisp/easy-mmode.el (define-minor-mode):
* lisp/emacs-lisp/cl-macs.el (cl-symbol-macrolet, cl-defstruct):
* lisp/emacs-lisp/cl-generic.el (cl-defmethod):
* lisp/emacs-lisp/byte-run.el (defmacro, defun):
* lisp/emacs-lisp/bindat.el (bindat--type): Adjust accordingly.
2022-02-19 14:20:02 -05:00
Alan Mackenzie
3023e7ca3d Remove the remnants of old position mechanism from scratch/correct-warning-pos
Also correct one or two positions in macroexp-warn-and-return invocations.

* lisp/emacs-lisp/bytecomp.el (byte-compile-read-position)
(byte-compile-last-position, byte-compile-set-symbol-position): Remove.
(byte-compile-warning-prefix, byte-compile-function-warn)
(byte-compile-emit-callargs-warn, byte-compile-arglist-warn)
(byte-compile-warn-about-unresolved-functions, compile-defun)
(byte-compile-from-buffer, byte-compile-from-buffer)
(byte-compile-file-form-defmumble, byte-compile-check-lambda-list)
(byte-compile-lambda, byte-compile-form, byte-compile-normal-call)
(byte-compile-check-variable, byte-compile-push-constant)
(byte-compile-subr-wrong-args, byte-compile-negation-optimizer)
(byte-compile-condition-case, byte-compile-defvar, byte-compile-autoload)
(byte-compile-lambda-form): Remove the remnants of the old warning position
mechanism.
(byte-compile-function-warn): Replace byte-compile-last-position by a
symbol-with-pos-pos call.
(compile-defun): Use local variable start-read-position to fulfil purpose of
old byte-compile-read-position.  Push the just read FORM onto
byte-compile-form-stack.

* lisp/emacs-lisp/eieio.el (defclass): New mechanism to get the correct
source warning position to macroexp-warn-and-return.

* lisp/emacs-lisp/macroexp (macroexp--unfold-lambda): Correct the position
argument given to macroexp-warn-and-return.
2022-01-15 17:36:12 +00:00
Alan Mackenzie
d87a34597c Merge branch 'master' into scratch/correct-warning-pos
Merge branch:
commit d29291d665 (HEAD -> master,
origin/master, origin/HEAD)
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Date:   Fri Jan 14 12:26:30 2022 -0500

    (macroexp--expand-all): Fix bug#53227 and bug#46636
2022-01-14 19:28:07 +00:00
Alan Mackenzie
57b698f159 Commit fixes and enhancements to the scratch/correct-warning-pos branch
No longer strip positions from symbols before each use of a form, instead
relying on the low level C routines to do the right thing.  Instead strip them
from miscellaneous places where this is needed.  Stip them alson in
`function-put'.

Push forms onto byte-compile-form-stack and pop them "by hand" rather than by
binding the variable at each pushing, so that it will still have its data
after an error has been thrown and caught by a condition case.  This gives an
source position to the ensuing error message.

* lisp/emacs-lisp/byte-run.el (byte-run--ssp-seen, byte-run--circular-list-p)
(byte-run--strip-s-p-1, byte-run-strip-symbol-positions): New functions and
variables, which together implement stripping of symbol positions.  The latest
(?final) version modifies the argument in place rather than making a copy.
(function-put): Strip symbol positions from all of the arguments before doing
the `put'.

* lisp/emacs-lisp/bytecomp.el (byte-compile--form-stack): has been renamed to
byte-compile-form-stack and moved to macroexp.el.
(byte-compile-initial-macro-environment (eval-and-compile)): Replace
macroexpand-all-toplevel with macroexpand--all-toplevel.
(displaying-byte-compile-warnings): bind byte-compile-form-stack here.
(byte-compile-toplevel-file-form, byte-compile-form): Push the top level form
onto byte-compile-form-stack (whereas formally the variable was bound at each
pushing).  Manually pop this from of the variable at the end of the function.

* lisp/emacs-lisp/cl-macs.el (cl-define-compiler-macro): Remove the symbol
stripping.

* lisp/emacs-lisp/comp.el (comp--native-compile): Set max-specpdl-size to at
least 5000 (previously it was 2500).  Bind print-symbols-bare to t.

* lisp/emacs-lisp/macroexp.el (byte-compile-form-stack): Definition move here
from bytecomp.el for easier compilation.
(byte-compile-strip-symbol-positions and associated functions): Removed.
(macro--expand-all): push argument FORM onto byte-compile-form-stack at the
start of this function, and pop it off at the end.
(internal-macroexpand-for-load): No longer strip symbol positions.  Bind
symbols-with-pos-enabled and print-symbols-bare to t.

* lisp/help.el (help--make-usage): Strip any position from argument ARG.

* src/fns.c (Fput): No longer strip symbol positions from any of the
arguments.
2022-01-14 19:06:04 +00:00
Stefan Monnier
d29291d665 (macroexp--expand-all): Fix bug#53227 and bug#46636
* lisp/emacs-lisp/macroexp.el (macroexp--expand-all): Don't mis-expand
invalid funcalls.
2022-01-14 12:26:30 -05:00
Alan Mackenzie
2128cd8c08 Merge branch 'master' into scratch/correct-warning-pos 2022-01-11 21:57:54 +00:00
Eli Zaretskii
dcd76bd48d Merge from origin/emacs-28
836be7a112 ; * etc/refcards/ru-refcard.tex: Update Copyright year.
86cbc6ee4a * lisp/net/tramp-sh.el: Adapt copyright year
ebe8772f65 ; Minor fixes related to copyright years
23c1ee6989 ; * test/manual/etags/ETAGS.good_N: Adjust to copyright ye...
8d3fc7ec89 * src/xfaces.c (face_for_font): Make 'hash' be uintptr_t.
19dcb237b5 ; Add 2022 to copyright years.

# Conflicts:
#	etc/NEWS
#	etc/refcards/ru-refcard.tex
#	lib/cdefs.h
#	lisp/erc/erc-dcc.el
#	lisp/erc/erc-imenu.el
#	lisp/erc/erc-replace.el
#	lisp/image-dired.el
#	lisp/progmodes/xref.el
#	m4/alloca.m4
#	m4/byteswap.m4
#	m4/errno_h.m4
#	m4/getopt.m4
#	m4/gnulib-common.m4
#	m4/inttypes.m4
#	m4/stddef_h.m4
#	m4/stdint.m4
#	m4/sys_socket_h.m4
2022-01-01 07:03:03 -05:00
Eli Zaretskii
19dcb237b5 ; Add 2022 to copyright years. 2022-01-01 02:45:51 -05:00
Alan Mackenzie
ff9af1f1f6 Miscellaneous enhancements to scratch/correct-warning-pos.
1. Check the type (symbol with position) of the argument given to the native
compiled version of SYMBOL_WITH_POS_SYM.
2. Handle infinite recursion caused by circular lists, etc., in
macroexp-strip-symbol-positions by using hash tables.
3. Read byte compiled functions without giving symbols positions.

* lisp/emacs-lisp/comp.el (comp-finalize-relocs): Add symbol-with-pos-p into
the list of relocated symbols.

* lisp/emacs-lisp/macroexp.el (macroexp--ssp-conses-seen)
(macroexp--ssp-vectors-seen, macroexp--ssp-records-seen): Renamed, and
animated as hash tables.
(macroexp--strip-s-p-2): Optionally tests for the presence of an argument in
one of the above hash tables, so as to handle otherwise infinite recursion.
(byte-compile-strip-s-p-1): Add a condition-case to handle infinite recursion
caused by circular lists etc., using the above hash tables as required.

* src/comp.c (comp_t): New element symbol_with_pos_sym.
(emit_SYMBOL_WITH_POS_SYM): Amend just to call the new SYMBOL_WITH_POS_SYM.
(emit_CHECK_SYMBOL_WITH_POS, define_SYMBOL_WITH_POS_SYM): New functions.
(Fcomp__init_ctxt): Register an emitter for Qsymbol_with_pos_p.
(Fcomp__compile_ctxt_to_file): Call define_SYMBOL_WITH_POS_SYM.
(syms_of_comp): Define Qsymbol_with_pos_p.

* src/data.c (syms_of_data): Define a new error symbol Qrecursion_error, an
error category for the new error symbols Qexcessive_variable_binding and
Qexcessive_lisp_nesting.

* src/eval.c (grow_specpdl): Change the signal_error call to an xsignal0 call
using the new error symbol Qexcessive_variable_binding.
(eval_sub, Ffuncall): Change the `error' calls to xsignal using the new error
symbol Qexcessive_lisp_nesting.

* src/lread.c (read1): When reading a compiled function, read the components
of the vector without giving its symbols a position.
2021-12-31 21:21:46 +00:00
Alan Mackenzie
1cd188799f Make symbols with positions work with native compilation
This version of the software should bootstrap Emacs successfully with native
compilation enabled.

* lisp/emacs-lisp/bytecomp.el (byte-compile-strip-s-p-1)
(byte-compile-strip-symbol-positions): Rename and move to macroexp.el.  Rename
calls to these functions throughout the file.
(byte-compile-initial-macro-environment): In the code sections for
eval-when-compile and eval-and-compile, call macroexp-strip-symbol-positions
before evaluating code.
(byte-compile-file, byte-compile-output-file-form)
(byte-compile-file-form-defmumble, byte-compile, batch-byte-compile): Call
macroexp-strip-symbol-positions from code being passed to the native compiler.

* lisp/emacs-lisp/cl-macs.el (cl-macs--strip-s-p-1)
(cl-macs--strip-symbol-positions): Remove, replacing them with the renamed
functions in macroexp.el.
(cl-define-compiler-macro): Apply macroexp-strip-symbol-positions to ARGS and
BODY.

* lisp/emacs-lisp/comp.el (comp-limplify-lap-inst): Use `null' to compile
byte-not rather than a compilation of `eq'.
(comp--native-compile): bind symbols-with-pos-enabled to t.

* lisp/emacs-lisp/macroexp.el (byte-compile--ssp-conses-seen)
(byte-compile--ssp-vectors-seen, byte-compile--ssp-records-seen): Provisional
auxiliary variables to support the following functions.
(macroexp--strip-s-p-2, byte-compile-strip-s-p-1)
(macroexp-strip-symbol-positions): Functions moved from bytecomp.el, renamed,
and further developed.
(macroexp--compiler-macro): Bind symbol-with-pos-enabled to t around the call
to `handler'.
(internal-macroexpand-for-load): Strip symbol positions from the form being
eagerly expanded for macros.

* src/comp.c (F_SYMBOLS_WITH_POS_ENABLED_RELOC_SYM): New macro for a
relocation symbol.
(comp_t): New elements bool_ptr_type, f_symbols_with_pos_enabled_ref,
lisp_symbol_with_position, lisp_symbol_with_position_header,
lisp_symbol_with_position_sym, lisp_symbol_with_position_pos,
lisp_symbol_with_position_type, lisp_symbol_with_position_ptr_type,
get_symbol_with_position.
(helper_GET_SYMBOL_WITH_POSITION): New function.
(emit_BASE_EQ): Function rename from emit_EQ.
(emit_AND, emit_OR, emit_BARE_SYMBOL_P, emit_SYMBOL_WITH_POS_P)
(emit_SYMBOL_WITH_POS_SYM): New functions.
(emit_EQ): New function which handles symbols with position correctly.
(emit_NILP): Use emit_BASE_EQ rather than emit_EQ.
(emit_limple_insn): When emitting a conditional branch, check each operand for
being a literal Qnil, and if one of them is, use emit_BASE_EQ rather than
emit_EQ.
(declare_runtime_imported_funcs): Declare helper_GET_SYMBOL_WITH_POSITION.
(emit_ctxt_code): Export the global F_SYMBOLS_WITH_POS_ENABLED_RELOC_SYM.
(define_lisp_symbol_with_position, define_GET_SYMBOL_WITH_POSITION): New
functions.
(Fcomp__init_ctxt): Initialise comp.bool_ptr_type, call the two new
define_.... functions.
(load_comp_unit): Initialise **f_symbols_with_pos_enabled_reloc.

* src/fns.c (Fput): Strip positions from symbols in PROPNAME and VALUE.
2021-12-30 10:14:58 +00:00
Mattias Engdegård
8706f6fde1 Add macroexp--dynamic-variable-p
This predicate can be used for discriminating between lexically and
dynamically bound variables during macro-expansion (only).
It is restricted to internal use for the time being.

* lisp/emacs-lisp/bytecomp.el (byte-compile-initial-macro-environment):
Use macroexpand--all-toplevel.
* lisp/emacs-lisp/macroexp.el (macroexp-dynamic-variable-p): New.
(macroexp--expand-all): Maintain macroexp--dynvars.
(macroexpand-all): Rebind macroexp--dynvars.
(macroexpand--all-toplevel): New.
(internal-macroexpand-for-load): Use macroexpand--all-toplevel.
* src/eval.c (eval_sub): Transfer defvar declarations from
Vinternal_interpreter_environment into macroexp--dynvars during
lazy macro-expansion.
* src/lread.c (readevalloop): Rebind macroexp--dynvars around
read-and-evaluate operations.
(syms_of_lread): Define macroexp--dynvars.
* test/lisp/emacs-lisp/macroexp-resources/vk.el: New file.
* test/lisp/emacs-lisp/macroexp-tests.el (macroexp-tests--run-emacs)
(macroexp-tests--eval-in-subprocess)
(macroexp-tests--byte-compile-in-subprocess)
(macroexp--tests-dynamic-variable-p): Add tests.
2021-12-20 16:26:02 +01:00
Lars Ingebrigtsen
4c7faf3377 Fix previous macroexp--warn-wrap change
* lisp/emacs-lisp/macroexp.el (macroexp--warn-wrap): Don't call
byte-compile-warning-enabled-p with zero parameters.
2021-12-02 16:47:49 +01:00
Stefan Monnier
c6dd8dd223 * lisp/emacs-lisp/macroexp.el: Improve last change
Don't burp when `byte-compile-warning-enabled-p` is not yet defined.
And use the call that we had already instead of adding a new one.

(macroexp--warn-wrap): Allow `category`
to be a list to pass to `byte-compile-warning-enabled-p`.
(macroexp-macroexpand): Simplify accordingly.
2021-12-01 22:51:55 -05:00
Alan Mackenzie
8f1106ddf2 Several amendments to scratch/correct-warning-pos.
The position return by read-positioning-symbols is now the position in the
buffer, rather than the offset from the start of a form, enabling warning
positions in other parts of the buffer to be output.

* src/lisp.h (lisp_h_EQ): Add XLI casts so that it compiles cleanly.

* src/data.c (Fremove_pos_from_symbol): New DEFUN.

* src/lread.c (readchar_count): renamed to readchar_offset.
(read_internal_start) Initialize readchar_offset to the buffer's point when
STREAM is a buffer.

* lisp/emacs-lisp/bytecomp.el (byte-compile-warning-prefix): Amend to use
OFFSET as a buffer position, not an offset from the start of a form.
(byte-compile-warn): Remove symbol positions from any shape of ARGS, not just
a symbol with position.

* lisp/emacs-lisp/cconv.c (cconv-convert): In the :unused case, position the
new IGNORE symbol with the VAR it has replaced.

* lisp/emacs-lisp/macroexp.el (macroexp--warn-wrap, macroexp-warn-and-return):
Add an extra position parameter to each.

* lisp/emacs-lisp/bindat.el (bindat-type), lisp/emacs-lisp/byte-run.el
(defmacro, defun), lisp/emacs-lisp/cconv.el (cconv--convert-func-body)
(cconv-convert), lisp/emacs-lisp/cl-generic.el (cl-defmethod),
lisp/emacs-lisp/cl-macs.el (cl-symbol-macrolet, cl-defstruct),
lisp/emacs-lisp/easy-mmode.el (define-minor-mode),
lisp/emacs-lisp/eieio-core.el (eieio-oref, eieio-oref-default)
(eieio-oset-default), lisp/emacs-lisp/eieio.el (defclass),
lisp/emacs-lisp/gv.el (gv-ref), lisp/emacs-lisp/macroexp.el
(macroexp-macroexpand, macroexp--unfold-lambda, macroexp--expand-all),
lisp/emacs-lisp/pcase.el (pcase-compile-patterns, pcase--u1): Add an extra
position argument to each call of macroexp-warn-and-return.
2021-12-01 20:03:44 +00:00
Lars Ingebrigtsen
5fb9a033f8 Allow inhibiting warnings about obsolete macros again
* lisp/emacs-lisp/macroexp.el (macroexp-macroexpand): Inhibit
warning if requested (bug#50984).
2021-11-30 14:38:15 +01:00
Alan Mackenzie
368570b3fd First commit of scratch/correct-warning-pos.
This branch is intended to generate correct position information in warning
and error messages from the byte compiler, and is intended thereby to fix bugs

It introduces a new mechanism, the symbol with position.  This is taken over
from the previous git branch scratch/accurate-warning-pos which was abandoned
for being too slow.  The main difference in the current branch is that the
symbol `nil' is never given a position, thus speeding up NILP markedly.

* lisp/emacs-lisp/byte-opt.el (byte-compile-inline-expand)
(byte-optimize-form-code-walker, byte-optimize-let-form, byte-optimize-while)
(byte-optimize-apply): Use byte-compile-warn-x in place of byte-compile-warn.

* lisp/emacs-lisp/bytecomp.el (byte-compile--form-stack): New variable.
(byte-compile-strip-s-p-1, byte-compile-strip-symbol-positions): New
functions.
(byte-compile-recurse-toplevel, byte-compile-initial-macro-environment)
(byte-compile-preprocess, byte-compile-macroexpand-declare-function): Bind
print-symbols-bare to non-nil.
(byte-compile--first-symbol, byte-compile--warning-source-offset): New
functions.
(byte-compile-warning-prefix): Modify to output two sets of position
information, the old (incorrect) set and the new set.
(byte-compile-warn): Strip positions from symbols before outputting.
(byte-compile-warn-x): New function which outputs a correct position supplied
in an argument.
(byte-compile-warn-obsolete, byte-compile-emit-callargs-warn)
(byte-compile-format-warn, byte-compile-nogroup-warn)
(byte-compile-arglist-warn, byte-compile-docstring-length-warn)
(byte-compile-warn-about-unresolved-functions, byte-compile-file)
(byte-compile--check-prefixed-var, byte-compile--declare-var)
(byte-compile-file-form-defvar-function, byte-compile-file-form-defmumble)
(byte-compile-check-lambda-list, byte-compile--warn-lexical-dynamic)
(byte-compile-lambda, byte-compile-form, byte-compile-normal-call)
(byte-compile-check-variable, byte-compile-free-vars-warn)
(byte-compile-subr-wrong-args, byte-compile-fset, byte-compile-set-default)
(byte-compile-condition-case, byte-compile-save-excursion)
(byte-compile-defvar, byte-compile-autoload)
(byte-compile-make-variable-buffer-local, byte-compile-define-symbol-prop)
(byte-compile-define-keymap): Replace byte-compile-warn with
byte-compile-warn-x.
(byte-compile-file, compile-defun): Bind symbols-with-pos-enabled to non-nil.
(compile-defun, byte-compile-from-buffer): Use `read-positioning-symbols'
rather than plain `read'.
(byte-compile-toplevel-file-form, byte-compile-form): Dynamically bind
byte-compile--form-stack.
(byte-compile-file-form-autoload, byte-compile-file-form-defvar)
(byte-compile-file-form-make-obsolete, byte-compile-lambda)
(byte-compile-push-constant, byte-compile-cond-jump-table)
(byte-compile-define-keymap, byte-compile-annotate-call-tree):
Strip positions from symbols where they are unwanted.
(byte-compile-file-form-defvar): Strip positions from symbols using
`bare-symbol'.
(byte-compile-file-form-defmumble): New variable bare-name, a version of name
without its position.
(byte-compile-lambda): Similarly, new variable bare-arglist.
(byte-compile-free-vars-warn): New argument arg supplying position information
to byte-compile-warn-x.
(byte-compile-push-constant): Manipulation of symbol positions.
(display-call-tree): Strip positions from symbols.

* lisp/emacs-lisp/cconv.el (cconv-convert, cconv--analyze-use)
(cconv--analyze-function, cconv-analyze-form): Replace use of
byte-compile-warn with byte-compile-warn-x.

* lisp/emacs-lisp/cl-generic.el (cl-defmethod): New variable org-name which
  will supply position information to a new macroexp-warn-and-return.

  * lisp/emacs-lisp/cl-macs.el (cl-macs--strip-s-p-1)
  (cl-macs--strip-symbol-positions): New functions to strip positions from
  symbols in an expression.  These duplicaate similarly named functions in
  bytecomp.el.

  * lisp/emacs-lisp/macroexpand.el (macroexp--warn-wrap): Calls
  byte-compile-warn-x in place of byte-compile-warn.
  (macroexp-warn-and-return): Commented out new position parameter _arg.

* src/.gdbinit: Add in code to handle symbols with position.

* src/alloc.c (XPNTR, set_symbol_name, valid_lisp_object_p, purecopy)
(mark_char_table, mark_object, survives_gc_p, symbol_uses_obj): Use
BARE_SYMBOL_P and XBARE_SYMBOL in place of the former SYMBOLP and XSYMBOL.
(build_symbol_with_pos): New function.
(Fgarbage_collect): Bind Qsymbols_with_pos_enabled to nil around the call to
garbage_collect.

* src/data.c (Ftype_of): Add case for PVEC_SYMBOL_WITH_POS.
(Fbare_symbol_p, Fsymbol_with_pos_p, Fbare_symbol, Fsymbol_with_pos_pos)
(Fposition_symbol): New functions.
(symbols_with_pos_enabled): New boolean variable.

* src/fns.c (internal_equal, hash_lookup): Handle symbols with position.

* src/keyboard.c (recursive_edit_1): Bind Qsymbols_with_pos_enabled and
Qprint_symbols_bare to nil.

* src/lisp.h (lisp_h_PSEUDOVECTORP): New macro.
(lisp_h_BASE_EQ): New name for the former lisp_h_EQ.
(lisp_h_EQ): Extended to handle symbols with position.
(lisp_h_NILP): Now uses BASE_EQ rather than EQ.
(lisp_h_SYMBOL_WITH_POS_P, lisp_h_BARE_SYMBOL_P): New macros.
(lisp_h_SYMBOLP): Redefined to handle symbols with position.
(BARE_SYMBOL_P, BASE_EQ): New macros.
(SYMBOLP (macro)): Removed.
(SYMBOLP (function), XSYMBOL, make_lisp_symbol, builtin_lisp_symbol)
(c_symbol_p): Moved to later in file.
(struct Lisp_Symbol_With_Pos): New data type.
(pvec_type): PVEC_SYMBOL_WITH_POS: New type code.
(PSEUDOVECTORP): Redefined to use the lisp_h_PSEUDOVECTORP.
(BARE_SYMBOL_P, SYMBOL_WITH_POS_P, SYMBOLP, XSYMBOL_WITH_POS, XBARE_SYMBOL)
(XSYMBOL, make_lisp_symbol, builtin_lisp_symbol, c_symbol_p, CHECK_SYMBOL)
(BASE_EQ): New functions, or functions moved from earlier in the file.
(SYMBOL_WITH_POS_SYM, SYMBOL_WITH_POS_POS): New INLINE functions.

* src/lread.c (read0, read1, read_list, read_vector, read_internal_start)
(list2): Add a new bool parameter locate_syms.
(Fread_positioning_symbols): New function.
(Fread_from_string, read_internal_start, read0, read1, read_list): Pass around
suitable values for locate_syms.
(read1): Build symbols with position when locate_syms is true.

* src/print.c (print_vectorlike): Add handling for PVEC_SYMBOL_WITH_POS.
(print_object): Replace EQ with BASE_EQ.
(print_symbols_bare): New boolean variable.
2021-11-29 11:19:31 +00:00
Stefan Kangas
25ebb9374b ; More minor docfixes found by checkdoc 2021-09-14 07:57:14 +02:00
Eli Zaretskii
3edc4fb5d8 ; * lisp/emacs-lisp/macroexp.el (macroexp-warn-and-return): Doc fix. 2021-07-22 10:31:14 +03:00
Stefan Monnier
52187012f1 * lisp/emacs-lisp/macroexp.el (macroexp-warn-and-return): Add arg category
Use it to obey `byte-compile-warnings`.

(macroexp--warn-wrap): Add arg `category`.
(macroexp-macroexpand, macroexp--expand-all): Use it.

* lisp/emacs-lisp/cconv.el (cconv--convert-funcbody, cconv-convert):
Mark the warnings as `lexical`.

* lisp/emacs-lisp/eieio-core.el (eieio-oref, eieio-oref-default)
(eieio-oset-default):
* lisp/emacs-lisp/eieio.el (defclass): Adjust to new calling convention.
2021-07-21 11:11:50 -04:00
Lars Ingebrigtsen
e7cdbc1d1d Make previous empty-body warning disabling more robust
* lisp/emacs-lisp/macroexp.el (macroexp--expand-all):
`byte-compile-warning-enabled-p' may not be defined here.
2021-07-06 22:01:55 +02:00
Lars Ingebrigtsen
43fba076c9 Allow inhibiting warnings about unused variables and empty bodies
* lisp/emacs-lisp/cconv.el (cconv--warn-unused-msg): Allow
inhibiting warnings about unbound variables (bug#26486).

* lisp/emacs-lisp/macroexp.el (macroexp--expand-all): Allow
inhibiting warnings about empty bodies.
2021-07-06 16:43:49 +02:00