Commit graph

906 commits

Author SHA1 Message Date
Arthur Miller
dea67939b6 Add support for GCC compiler command-line options
* lisp/emacs-lisp/comp.el ('native-comp-compiler-options): New option.
* lisp/emacs-lisp/bytecomp.el (byte-compile-from-buffer): Add support
for new 'native-comp-compiler-options'.
* src/comp.c (Fcomp_native_compiler_options_effective_p): New function.
(add_compiler_options): New function.
(Fcomp__compile_ctxt_to_file): Call 'add_compiler_options'.
2021-09-10 21:04:41 +02:00
Mattias Engdegård
bba48d6ee5 More robust optimisation of ignore
Treat `ignore` as any other function during source-level optimisation,
to avoid having its warning-suppression effects cancelled by repeated
passes.  Instead, define a custom code generation function.

* lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker):
Don't treat `ignore' specially here.
(side-effect-free-fns): Don't mark `ignore` as side-effect-free
or error-free (although it is), since that would allow the optimiser
to elide calls.
* lisp/emacs-lisp/bytecomp.el (ignore, byte-compile-ignore):
Define and register a code-gen function.
2021-09-06 16:47:13 +02:00
Lars Ingebrigtsen
4015fb6e69 Improve byte-compile-warnings doc string
* lisp/emacs-lisp/bytecomp.el (byte-compile-warnings): Mention
'byte-compile-docstring-max-column'.
2021-08-23 02:04:55 +02:00
Mattias Engdegård
566e29f78c Single source optimiser entry point
Make the optimiser aware of lexical arguments.  Otherwise we cannot
know for sure whether a variable is lexical or dynamic during
traversal.

* lisp/emacs-lisp/byte-opt.el (byte-optimize-one-form): New optimiser
entry point, replacing the recursive byte-optimize-form.
* lisp/emacs-lisp/bytecomp.el (byte-optimize-one-form): Autoload.
(byte-compile-keep-pending, byte-compile-top-level):
Use byte-optimize-one-form.
2021-07-30 09:54:29 +02:00
Lars Ingebrigtsen
c9c1460342 Make byte-recompile-directory less brittle
* lisp/emacs-lisp/bytecomp.el (byte-recompile-directory): Don't
interpret files named "~" as $HOME (bug#49758).
2021-07-28 18:10:59 +02:00
Mattias Engdegård
949dd41c31 Fix mistake in switch-case generation of null (bug#49746)
Reported by Gregor Zattler.

* lisp/emacs-lisp/bytecomp.el (byte-compile--cond-switch-prefix):
Be more careful in the selection of equality.
* test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-tests--test-cases):
Add test case.
2021-07-27 17:32:23 +02:00
Mattias Engdegård
109ca1bd00 Warn about arity errors in inlining calls (bug#12299)
Wrong number of arguments in inlining function calls (to `defsubst` or
explicitly using `inline`) did not result in warnings, or in very
cryptic ones.

* lisp/emacs-lisp/byte-opt.el (byte-compile-inline-expand): Add calls
to `byte-compile--check-arity-bytecode`.
* lisp/emacs-lisp/bytecomp.el (byte-compile-emit-callargs-warn)
(byte-compile--check-arity-bytecode): New functions.
(byte-compile-callargs-warn): Use factored-out function.
* test/lisp/emacs-lisp/bytecomp-resources/warn-callargs-defsubst.el:
* test/lisp/emacs-lisp/bytecomp-tests.el ("warn-callargs-defsubst.el"):
New test case.
2021-07-23 15:19:01 +02:00
Mattias Engdegård
51a86b6a05 Count (not X) as a switch condition
* lisp/emacs-lisp/bytecomp.el (byte-compile--cond-switch-prefix):
Treat (not VAR) and (null VAR) as (eq VAR nil) when computing the
extent of switch ops.
2021-07-20 19:21:00 +02:00
Basil L. Contovounesios
044742bfe8 Avoid invalid regexp in wide docstring check
* lisp/emacs-lisp/bytecomp.el (byte-compile--wide-docstring-p):
Avoid constructing an invalid regexp during byte-compilation by
limiting the number of columns to the current RE_DUP_MAX of 65535.
This protects against pathological values of fill-column, for
example (bug#49426).
2021-07-06 18:56:15 +01:00
Lars Ingebrigtsen
ed15f3954c Ignore .dir-locals-2.el files more
* lisp/emacs-lisp/shadow.el (load-path-shadows-find):
* lisp/emacs-lisp/bytecomp.el (byte-recompile-directory): Ignore
.dir-locals-2.el, too (bug#23257).
2021-07-04 16:23:46 +02:00
Andrea Corallo
a4fb5811fa * Do not attempt to write .elc files when not necessary (bug#49118)
* lisp/emacs-lisp/bytecomp.el (byte-compile-file): Do not attempt to
write .elc files when not necessary.
2021-06-21 12:20:19 +02:00
Lars Ingebrigtsen
1756e4757c Fix false positives in docstring width warning with (fn...) constructs.
* lisp/emacs-lisp/bytecomp.el (byte-compile--wide-docstring-p):
Don't consider the function signature when determining whether the
doc string is too wide (bug#49007).  (The signature is folded
later when displaying help.)
2021-06-15 15:33:19 +02:00
Andrea Corallo
663fb3b774 * Do not produce .elc temporary file when unnecessary (bug#48978)
* lisp/emacs-lisp/bytecomp.el (byte-compile-file): Produce .elc
temporary files only when non native compiling or when native
compiling but `byte+native-compile' is non nil.
2021-06-14 15:02:17 +02:00
Andrea Corallo
31d40cab78 ;* lisp/emacs-lisp/bytecomp.el (byte-native-compiling): Typo fix. 2021-06-14 14:18:06 +02:00
Andrea Corallo
9389742eb6 * lisp/emacs-lisp/bytecomp.el (byte+native-compile): Update docstring. 2021-06-14 14:18:06 +02:00
Andrea Corallo
c4b02dad9b Rename batch-byte-native-compile-for-bootstrap (bug#48743)
* lisp/Makefile.in : Rename `batch-byte-native-compile-for-bootstrap'
-> `batch-byte+native-compile.
* lisp/emacs-lisp/bytecomp.el (byte+native-compile)
(byte-compile-file): Rename
`batch-byte-native-compile-for-bootstrap' ->
`batch-byte+native-compile + `byte-native-for-bootstrap' ->
`byte+native-compile'.
* lisp/emacs-lisp/comp.el (comp-spill-lap-function, comp-final)
(batch-native-compile, batch-byte+native-compile): Likewise.
* lisp/emacs-lisp/bytecomp.el (byte+native-compile)
(byte-compile-file): Likewise.
* test/src/comp-tests.el (comp-tests-bootstrap): Rename
`byte-native-for-bootstrap' -> `byte+native-compile'.
2021-06-01 18:11:37 +02:00
Philipp Stephani
42950e9e46 Fix a few Edebug specifications where code is wrapped in lambdas.
As the Info node `(elisp) Specification List' explains, it is not
correct to use `body' or t for a piece of code that the macro wraps in
a `lambda' form.  These should use `def-body' instead.

* lisp/info-xref.el (info-xref-with-file):
* lisp/subr.el (subr--with-wrapper-hook-no-warnings, track-mouse)
(combine-change-calls, with-eval-after-load):
* lisp/emacs-lisp/bytecomp.el (displaying-byte-compile-warnings):
* lisp/emacs-lisp/cl-macs.el (cl-do-symbols, cl-progv):
* lisp/emacs-lisp/ert-x.el (ert-with-test-buffer):
* lisp/emacs-lisp/gv.el (gv-letplace):
* lisp/emacs-lisp/nadvice.el (define-advice):
* lisp/emacs-lisp/thunk.el (thunk-delay):
* lisp/vc/vc-dispatcher.el (vc-run-delayed): Use 'def-body' instead of
t or 'body' where applicable.

* lisp/emacs-lisp/package.el (package--with-response-buffer): Remove
evaluation of the body altogether.  I have no idea how to write it
correctly in this case.
2021-05-17 10:09:43 +02:00
Andrea Corallo
8c429a42c4 Rename comp-native-driver-options → native-comp-driver-options
* src/comp.c (add_driver_options, syms_of_comp): Rename
comp-native-driver-options → native-comp-driver-options.
* lisp/emacs-lisp/comp.el (native-comp-driver-options)
(comp-ctxt, comp-spill-lap-function, comp-final)
(comp-run-async-workers): Likewise.
* lisp/emacs-lisp/bytecomp.el (byte-compile-from-buffer): Likewise.
2021-05-06 17:16:08 +02:00
Andrea Corallo
94c69eb1d7 Rename comp-debug -> native-comp-debug
* src/comp.c (emit_ctxt_code, syms_of_comp): Rename comp-debug ->
native-comp-debug.
* lisp/emacs-lisp/comp.el (native-comp-debug, comp-ctxt)
(comp-spill-lap-function, comp-run-async-workers): Likewise.
* lisp/emacs-lisp/bytecomp.el (byte-compile-from-buffer): Likewise.
* test/src/comp-tests.el (comp-tests-bootstrap): Likewise.
2021-05-06 17:16:07 +02:00
Andrea Corallo
43f29696ad Rename comp-speed -> native-comp-speed
* lisp/emacs-lisp/bytecomp.el (byte-compile-from-buffer): Rename
comp-speed -> native-comp-speed.
* lisp/emacs-lisp/comp.el (native-comp-speed, comp-ctxt, comp-func,
comp-spill-lap-function, comp-trampoline-compile,
comp-run-async-workers): Likewise.
* src/comp.c (emit_ctxt_code, load_comp_unit, syms_of_comp): Likewise.
* test/src/comp-tests.el (comp-tests-tco, comp-tests-fw-prop-1)
(comp-tests-check-ret-type-spec, comp-tests-pure): Likewise.
2021-05-06 17:16:07 +02:00
Nikolay Kudryavtsev
65fe1777e6 Don't use pdumper-stats with unexec
* lisp/emacs-lisp/bytecomp.el (byte-compile-refresh-preloaded): Check if
pdumper-stats is bound before using it.
2021-05-02 13:15:50 +03:00
Andrea Corallo
b5c76530fa Merge remote-tracking branch 'savannah/master' into native-comp 2021-04-19 18:46:50 +02:00
Mattias Engdegård
7893945cc8 Add condition-case success handler (bug#47677)
Allow a condition-case handler on the form (:success BODY) to be
specified as the success continuation of the protected form, with
the specified variable bound to its result.

* src/eval.c (Fcondition_case): Update the doc string.
(internal_lisp_condition_case): Implement in interpreter.
(syms_of_eval): Defsym :success.
* lisp/emacs-lisp/bytecomp.el (byte-compile-condition-case):
Implement in byte-compiler.
* lisp/emacs-lisp/cl-macs.el (cl--self-tco): Allow self-TCO
from success handler.
* doc/lispref/control.texi (Handling Errors): Update manual.
* etc/NEWS: Announce.
* test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-tests--test-cases)
(bytecomp-condition-case-success):
* test/lisp/emacs-lisp/cl-macs-tests.el (cl-macs--labels):
Add test cases.
2021-04-15 15:41:13 +02:00
Andrea Corallo
c6c7b30e4b Merge remote-tracking branch 'savannah/master' into native-comp 2021-03-25 16:29:07 +01:00
Stefan Monnier
bf210251ea * lisp/emacs-lisp/bytecomp.el: Remember location of unresolved calls
I've gotten tired of seeing the "function foo not known to be defined"
warning without any line number information.  So this patch adds as
line number the position of the first use of that function in the file
(well, approximately, as usual).

(byte-compile-unresolved-functions): Add POSITIONs in the alist.
(byte-compile-function-warn): Store the current position in
`byte-compile-unresolved-functions`.
(byte-compile-arglist-warn): Adjust accordingly.
(byte-compile-print-syms): Delete unused function.
(byte-compile-warn-about-unresolved-functions): Use the stored position
to give more precise warnings.
2021-03-19 18:33:46 -04:00
Andrea Corallo
3e133cc050 Fix `no-byte-compile' native compilation interaction (bug#47169)
* lisp/emacs-lisp/comp.el (comp-spill-lap-function): Throw
	no-native-compile when `byte-native-qualities' are null.
	* lisp/emacs-lisp/bytecomp.el (byte-compile-from-buffer): No need
	to consider `no-byte-compile'.
2021-03-16 19:02:57 +01:00
Andrea Corallo
f3abb17118 Have no-byte-compile' implies also no-native-compile'.
* lisp/emacs-lisp/comp.el (no-native-compile): Update doctring.
	* lisp/emacs-lisp/bytecomp.el (byte-compile-from-buffer): when
	`no-byte-compile' is set to non-nil it overrides this.
2021-03-16 09:12:46 +01:00
Andrea Corallo
7f74ed4912 * lisp/emacs-lisp/bytecomp.el: Fix native re-compilation (bug#47161). 2021-03-15 16:46:16 +01:00
Andrea Corallo
82bd6d57d5 Merge remote-tracking branch 'savannah/master' into native-comp 2021-03-12 16:42:51 +01:00
Andrea Corallo
d9cd55a4f1 Implement `no-native-compile' (bug#46983)
* lisp/emacs-lisp/bytecomp.el (byte-compile-from-buffer): Capture
	`no-native-compile'.
	* lisp/emacs-lisp/comp.el (no-native-compile): Define new
	variable.
	(comp-spill-lap-function): Throw when `no-native-compile' was
	captured non-nil.
	(comp--native-compile): Catch `no-native-compile' if necessary and
	return nil in case.
2021-03-12 13:11:45 +01:00
Andrea Corallo
43b0df62cd Merge commit '9cbdf20316' into native-comp 2021-03-09 10:03:47 +01:00
Stefan Monnier
251dea693a * lisp/emacs-lisp/bytecomp.el: Warn about unprefixed vars in boundp
(byte-compile--check-prefixed-var): New fun,
extracted from `byte-compile--declare-var`.
(byte-compile--declare-var): Use it.
(byte-compile-maybe-guarded): Use it as well.
2021-03-07 19:00:47 -05:00
Andrea Corallo
dbdc44db15 Allow for `comp-native-driver-options' to work as a file-local variable. 2021-03-07 20:19:20 +01:00
Pip Cet
2b069c67d7 Compile closures that modify their bound vars correctly (Bug#46834)
* lisp/emacs-lisp/bytecomp.el (byte-compile--reify-function): Don't
move let bindings into the lambda. Don't reverse list of
bindings. (byte-compile): Evaluate the return value if it was
previously reified.
* test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-reify-function):
Add tests.
2021-03-02 07:14:13 +00:00
Stefan Monnier
082b431e62 * lisp/emacs-lisp/bytecomp.el: Fix minor regression introduced by pdump
After `rm **/*.elc; make` we'd sometimes get loads and loads of unnecessary
"Reloading ...".

(byte-compile-refresh-preloaded): Don't reload files that are more
recent than `temacs` but older than the `.pdmp` file.
2021-02-27 12:28:17 -05:00
Stefan Monnier
a350ae058c * lisp/emacs-lisp/cconv.el: Improve line-nb info of unused var warnings
Instead of warning about unused vars during the analysis phase of
closure conversion, do it in the actual closure conversion by
annotating the code with "unused" warnings, so that the warnings
get emitted later by the bytecomp phase, like all other warnings,
at which point the line-number info is a bit less imprecise.

Take advantage of this change to wrap the expressions of unused
let-bound vars inside (ignore ...) so the byte-compiler can better
optimize them away.

Finally, promote `macroexp--warn-and-return` to "official" status
by removing its "--" marker.

(cconv-captured+mutated, cconv-lambda-candidates): Remove vars.
(cconv-var-classification): New var to replace them.
(cconv-warnings-only): Delete function.
(cconv--warn-unused-msg, cconv--var-classification): New functions.
(cconv--convert-funcbody): Add warnings for unused args.
(cconv-convert): Add warnings for unused vars in `let` and `condition-case`.
(cconv--analyze-use): Don't emit an "unused var" warning any more,
but instead remember the fact in `cconv-var-classification`.

* lisp/emacs-lisp/bytecomp.el (byte-compile-force-lexical-warnings):
Remove variable.
(byte-compile-preprocess): Remove corresponding case.

* lisp/emacs-lisp/pcase.el (pcase--if): Don't throw away `test` effects.
(\`):
* lisp/emacs-lisp/cl-macs.el (cl--do-arglist): Use `car-safe` instead
of `car`, so it can more easily be removed by the optimizer if the
result is not used.

* lisp/emacs-lisp/macroexp.el (macroexp--warn-wrap): New function.
(macroexp-warn-and-return): Rename from `macroexp--warn-and-return`.
2021-02-26 20:24:52 -05:00
Andrea Corallo
5c922cc3a4 Merge remote-tracking branch 'savannah/master' into native-comp 2021-02-26 19:54:59 +01:00
Stefan Monnier
b7f67d432b * lisp/emacs-lisp/macroexp.el (macroexp-file-name): Work in eval-buffer
Rely on `current-load-list` instead of `load-file-name`.

* lisp/emacs-lisp/bytecomp.el (byte-compile-close-variables):
Change the var we override accordingly.
2021-02-24 17:16:00 -05:00
Stefan Monnier
2766f9fdb9 * lisp/emacs-lisp/macroexp.el (macroexp-file-name): New function.
Yes, finally: a function that tells you the name of the file where
the code is located.  Finding this name is non-trivial in practice,
as evidenced by the "4 shift/reduce conflicts" warning when compiling
CEDET's python.el, because its `wisent-source` got it wrong in that
case, thinking the grammar came from `python.el` instead of
`python-wy.el`.

While at it, also made `macroexp-compiling-p` public, since it's
useful at various places.

(macroexp-compiling-p): Rename from `macroexp--compiling-p`.

* lisp/emacs-lisp/bytecomp.el (byte-compile-close-variables):
Bind `load-file-name` to nil so we can distinguish a load that calls
the byte compiler from a byte compilation which causes a load.

* lisp/cedet/semantic/wisent/python.el (wisent-python--expected-conflicts):
Remove; it was just a workaround.
* lisp/subr.el (do-after-load-evaluation): Avoid `byte-compile--` vars.
* lisp/cedet/semantic/fw.el (semantic-alias-obsolete):
Use `macroexp-compiling-p` and `macroexp-file-name`.
* lisp/cedet/semantic/wisent/comp.el (wisent-source): Use `macroexp-file-name`
(wisent-total-conflicts): Tighten regexp.
* lisp/emacs-lisp/cl-lib.el (cl--compiling-file): Delete function
and variable.  Use `macroexp-compiling-p` instead.
* lisp/progmodes/flymake.el (flymake-log):
* lisp/emacs-lisp/package.el (package-get-version):
* lisp/emacs-lisp/ert-x.el (ert-resource-directory):
Use `macroexp-file-name`.
2021-02-24 13:52:45 -05:00
Mattias Engdegård
88a02e4c89 Fix compilation of closures with nontrivial doc strings
* lisp/emacs-lisp/bytecomp.el (byte-compile-make-closure):
Use the supplied doc string if it's a literal; fall back to the old
slow way of building a closure otherwise.
2021-02-22 11:46:04 +01:00
Andrea Corallo
cf1e8e792f Merge remote-tracking branch 'savannah/master' into HEAD 2021-02-21 22:08:01 +01:00
Mattias Engdegård
d0c47652e5 Faster, more compact, and readable closure creation
Simplify closure creation by calling a single function at run time
instead of putting it together from small pieces.  This is faster
(by about a factor 2), takes less space on disk and in memory, and
makes internal functions somewhat readable in disassembly listings again.

This is done by creating a prototype function at compile-time whose
closure variables are placeholder values V0, V1... which can be seen
in the disassembly.  The prototype is then cloned at run time using
the new make-closure function that replaces the placeholders with
the actual closure variables.

* lisp/emacs-lisp/bytecomp.el (byte-compile-make-closure):
Generate call to make-closure from a prototype function.
* src/alloc.c (Fmake_closure): New function.
(syms_of_alloc): Defsubr it.
* src/data.c (syms_of_data): Defsym byte-code-function-p.
2021-02-21 21:58:25 +01:00
Stefan Monnier
b6eccad06c * lisp/emacs-lisp/bytecomp.el: Don't warn for repeated _ args
(byte-compile-check-lambda-list): Skip warnings of repeated arg for
those that are declared as unused anyway.
2021-02-19 12:51:36 -05:00
Andrea Corallo
f92bb788a0 Merge remote-tracking branch 'savannah/master' into native-comp 2021-02-17 22:26:28 +01:00
Lars Ingebrigtsen
0324ec1737 Fix recently introduced bug in `byte-compile-lambda'
* lisp/emacs-lisp/bytecomp.el (byte-compile-lambda): Fix recently
introduced error when compiling non-lexical commands (bug#46589).
2021-02-17 17:12:31 +01:00
Lars Ingebrigtsen
58e0c8ee86 Extend the syntax of `interactive' to list applicable modes
* doc/lispref/commands.texi (Using Interactive): Document the
extended `interactive' form.
* doc/lispref/loading.texi (Autoload): Document list-of-modes
form.

* lisp/emacs-lisp/autoload.el (make-autoload): Pick the list of
modes from `interactive' out of the functions.

* lisp/emacs-lisp/bytecomp.el (byte-compile-lambda): Allow for the
extended `interactive' form.

* src/callint.c (Finteractive): Document the extended form.

* src/data.c (Finteractive_form): Return the interactive form in
the old format (even when there's an extended `interactive') to
avoid having other parts of Emacs be aware of this.
(Fcommand_modes): New defun.

* src/emacs-module.c (GCALIGNED_STRUCT): Allow for modules to
return command modes.

* src/lisp.h: New function module_function_command_modes.
2021-02-14 13:21:24 +01:00
Andrea Corallo
2fcb85c3e7 Merge remote-tracking branch 'savannah/master' into HEAD 2021-02-10 21:56:55 +01:00
Stefan Monnier
04fb1664a8 * lisp/emacs-lisp/macroexp.el: Break cycle with bytecomp/byte-opt
The recent change in macroexp triggered a cyclic dependency error
during eager macroexpansion when neither `bytecomp` nor `byte-opt` had
been byte-compiled yet.  This fixes it by moving the offending
function to macroexp.el.

* lisp/emacs-lisp/macroexp.el (macroexp--unfold-lambda): Move from
byte-opt.el and rename.
(macroexp--expand-all): Use it.

* lisp/emacs-lisp/byte-opt.el (byte-compile-unfold-lambda): Move to
macroexp.el.
(byte-compile-inline-expand, byte-optimize-form-code-walker):
* lisp/emacs-lisp/bytecomp.el (byte-compile-form):
Use `macroexp--unfold-lambda` instead.
2021-02-09 12:02:25 -05:00
Andrea Corallo
b8d3ae78c5 Merge remote-tracking branch 'savannah/master' into native-comp 2021-01-24 21:05:33 +01:00
Stefan Monnier
b9511362f5 * lisp/emacs-lisp/bytecomp.el (byte-compile--declare-var): Fix warning
Make sure the "declared after first use" is under the control of
the `lexical` option.
2021-01-20 20:17:11 -05:00