Commit graph

7572 commits

Author SHA1 Message Date
Stefan Kangas
ce35760b19 ; Minor license statement fixes 2021-02-08 09:10:57 +01:00
Mattias Engdegård
7e48430a43 ; * lisp/emacs-lisp/byte-opt.el: improved comment 2021-02-07 12:24:40 +01:00
Mattias Engdegård
765ffeb545 ; Improved commentary in the variable constprop mechanism
* lisp/emacs-lisp/byte-opt.el (byte-optimize--lexvars)
(byte-optimize--vars-outside-condition)
(byte-optimize-form-code-walker, byte-optimize-let-form):
Clarify various aspects in the variable constant-propagation code,
as kindly pointed out by Stefan Monnier.
2021-02-07 10:35:36 +01:00
Mattias Engdegård
83983b6b7a Constprop of lexical variables
Lexical variables bound to a constant value (symbol, number or string)
are substituted at their point of use and the variable then eliminated
if possible.  Example:

  (let ((x (+ 2 3))) (f x))  =>  (f 5)

This reduces code size, eliminates stack operations, and enables
further optimisations.  The implementation is conservative, and is
strongly curtailed by the presence of variable mutation, conditions
and loops.

* lisp/emacs-lisp/byte-opt.el
(byte-optimize-enable-variable-constprop)
(byte-optimize-warn-eliminated-variable): New constants.
(byte-optimize--lexvars, byte-optimize--vars-outside-condition)
(byte-optimize--vars-outside-loop, byte-optimize--dynamic-vars):
New dynamic variables.
(byte-optimize--substitutable-p, byte-optimize-let-form):
New functions.
(byte-optimize-form-code-walker): Adapt clauses for variable
constprop, and add clauses for 'setq' and 'defvar'.
* test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-test-var)
(bytecomp-test-get-var, bytecomp-test-identity)
(byte-opt-testsuite-arith-data): Add test cases.
2021-02-06 20:22:24 +01:00
Lars Ingebrigtsen
c4a6f81ca4 Fix previous change in testcover.el
* lisp/emacs-lisp/testcover.el
(testcover-analyze-coverage-edebug-after): The wrapper macro is
called `1value', not `testcover-1value'.
2021-02-06 15:04:52 +01:00
Lars Ingebrigtsen
cf0869d22b Rename the `1value' symbol in testcover.el
* lisp/emacs-lisp/testcover.el: Rename the symbol `1value'
throughout the file to `testcover-1value' to allow using the
variable in code that's to be tested (bug#25471).
2021-02-06 12:28:46 +01:00
Lars Ingebrigtsen
f853f2d428 Avoid a compilation warning in iter-do
* lisp/emacs-lisp/generator.el (iter-do): Avoid a compilation
warning on using variables marked for not using (bug#31641).
Eg. (iter-do (_ i))
2021-02-06 11:31:18 +01:00
Stefan Monnier
431b098a20 * lisp/emacs-lisp/pcase.el (let): Reimplement as a pcase macro
(pcase--macroexpand, pcase--u1): Remove handling of `let` from
`pcase`s core.
2021-02-05 15:07:47 -05:00
Stefan Kangas
6bd9dbf959 * lisp/emacs-lisp/checkdoc.el: Doc fix; don't mention built-ins. 2021-02-05 02:52:52 +01:00
Lars Ingebrigtsen
9bf367e184 Improve filling of Emacs Lisp doc strings
* lisp/emacs-lisp/lisp-mode.el (lisp-fill-paragraph): When filling
a Lisp string, try to avoid filling bits that follow it
(bug#28937).
2021-02-04 16:12:41 +01:00
Lars Ingebrigtsen
e1d54bb638 Allow a :variable keyword in define-globalized-minor-mode
* doc/lispref/modes.texi (Defining Minor Modes): Document it.
* lisp/emacs-lisp/easy-mmode.el (define-globalized-minor-mode):
Allow specifying a :variable to be used if the underlying mode has
a divergent variable to store the state (bug#29081).
2021-02-04 15:22:40 +01:00
Stefan Kangas
0d8e15757e Remove some unnecessary references to Emacs 19
* lisp/emacs-lisp/elp.el:
* lisp/mouse-copy.el:
* lisp/mouse-drag.el:
* lisp/progmodes/simula.el (simula-mode-map):
* lisp/term.el (term-matching-input-from-input-string):
* lisp/vcursor.el: Doc fix; don't mention Emacs 19.
2021-02-04 05:28:00 +01:00
Stefan Kangas
fd9516238a Remove XEmacs compat code from edebug.el
* lisp/emacs-lisp/edebug.el (edebug-window-live-p, edebug-mark):
Make obsolete.  Update callers.
2021-02-04 05:27:45 +01:00
Stefan Monnier
04ab3904ed * lisp/gnus/gnus-art.el: Fix misuse of standard-value.
* lisp/custom.el (custom--standard-value): New function.

* lisp/gnus/gnus-art.el: (gnus-article-browse-html-parts)
(gnus-article-browse-html-article):
* lisp/dired-aux.el (dired-do-find-regexp-and-replace):
* lisp/emacs-lisp/package-x.el (package-upload-buffer-internal):
* lisp/startup.el (command-line): Use it.
2021-02-02 14:39:28 -05:00
Stefan Monnier
5f612d8a1f * lisp/emacs-lisp/lisp-mode.el (lisp-mode): Also set comment-end-skip 2021-02-02 10:08:44 -05:00
chuntaro
a2de694d8a Fix |# fontification in lisp-mode
* lisp/emacs-lisp/lisp-mode.el (lisp-mode): Give the |# the
correct (font-lock-comment-delimited-face) face (bug#39820).

Copyright-paperwork-exempt: yes
2021-02-02 10:18:28 +01:00
Stefan Kangas
5f69c222f4 Prefer defvar-local in emacs-lisp/*.el
* lisp/emacs-lisp/chart.el (chart-local-object):
* lisp/emacs-lisp/easy-mmode.el (define-minor-mode)
(define-globalized-minor-mode):
* lisp/emacs-lisp/edebug.el:
* lisp/emacs-lisp/generic.el (generic-font-lock-keywords):
* lisp/emacs-lisp/re-builder.el (reb-regexp, reb-regexp-src)
(reb-overlays):
* lisp/emacs-lisp/syntax.el
(syntax-propertize-extend-region-functions): Prefer defvar-local.
2021-01-31 14:55:53 +01:00
Lars Ingebrigtsen
867b99d68f Revert "Improve fontifying of #| ... |# in `lisp-mode'"
This reverts commit 1275dc4711.

Setting comment-end isn't the correct thing to do -- it makes M-; insert that string.
2021-01-31 07:59:40 +01:00
Andrea Corallo
a8b8d220b4 Merge remote-tracking branch 'savannah/master' into native-comp 2021-01-30 14:09:37 +01:00
Lars Ingebrigtsen
1275dc4711 Improve fontifying of #| ... |# in `lisp-mode'
* lisp/emacs-lisp/lisp-mode.el (lisp-mode): Fontify the end
delimiter in #| ... |# correctly (bug#39820).
2021-01-29 07:40:06 +01:00
Lars Ingebrigtsen
0b80935d37 Fix position in empty buffers in checkdoc-file-comments-engine
* lisp/emacs-lisp/checkdoc.el (checkdoc-file-comments-engine):
Don't give invalid positions on empty buffers (bug#39987).
2021-01-29 07:04:47 +01:00
Stefan Monnier
991c8946b6 Use lexical-binding in all of lisp/emacs-lisp
* lisp/emacs-lisp/bindat.el: Use lexical-binding.
(bindat--unpack-group, bindat--length-group, bindat--pack-group):
Declare `last` and `tag` as dyn-scoped.
(bindat-unpack, bindat-pack): Bind `bindat-raw` and `bindat-idx` via
`let` rather than via the formal arglist.

* lisp/emacs-lisp/package-x.el:
* lisp/emacs-lisp/generic.el:
* lisp/emacs-lisp/eieio-opt.el:
* lisp/emacs-lisp/derived.el:
* lisp/emacs-lisp/crm.el: Use lexical-binding.

* lisp/emacs-lisp/helper.el: Use lexical-binding.
(Helper-help-map): Move initialization into declaration.

* lisp/emacs-lisp/regi.el: Use lexical-binding.
(regi-interpret): Remove unused var `tstart`.
Declare `curframe`, `curentry` and `curline` as dyn-scoped.

* lisp/emacs-lisp/shadow.el: Use lexical-binding.
(load-path-shadows-find): Remove unused var `file`.
Tighten a regexp, use `push`.

* lisp/emacs-lisp/tcover-ses.el: Use lexical-binding.  Require `ses`.
Remove correspondingly redundant declarations.
(ses--curcell-overlay): Declare.
(ses-exercise): Use `dlet` and use a properly-prefixed var name.
Fix name of `curcell-overlay` variable.

* lisp/emacs-lisp/unsafep.el: Use lexical-binding.
(unsafep): Bind `unsafep-vars` via `let` rather than via the formal arglist.
2021-01-28 14:42:21 -05:00
Stefan Monnier
30914167fd * lisp/emacs-lisp/macroexp.el (macroexp-if): Fix typo 2021-01-27 18:53:58 -05:00
Stefan Monnier
d93bca0197 * lisp/emacs-lisp/pcase.el (pcase--split-pred): Handle memq pred.
Improve handling of the `member` tests generated from (or 'a 'b 'c).
This will expand

    (pcase EXP ((and (or 1 2 3) (guard (FOO))) EXP1) (1 EXP2) (6 EXP3))

to

    (cond ((memql '(3 2 1) EXP)
           (cond ((FOO) EXP1) ((eql EXP 1) EXP2)))
          ((eql EXP 6) EXP3))

rather than to

    (cond ((memql '(3 2 1) EXP)
           (cond ((FOO) EXP1) ((eql EXP 1) EXP2) ((eql EXP 6) EXP3)))
          ((eql EXP 1) EXP2)
          ((eql EXP 6) EXP3))
2021-01-27 18:51:09 -05:00
Stefan Monnier
d168110a32 * lisp/emacs-lisp/macroexp.el (macroexp--expand-all): Perform β-reduction
Also, in `funcall` macroexpand the function before checking to see if
we can remove the `funcall`.

(macroexp-if): Trim trailing `nil` in the generated code while we're at it.
2021-01-27 18:47:28 -05:00
Lars Ingebrigtsen
a10c74fbea Fontify special forms and macros the same
* lisp/emacs-lisp/lisp-mode.el (lisp--el-match-keyword): Handle
special forms and macros the same way (bug#43265).  This makes
things like (setq a '(if a b)) be fontified correctly (i.e., not
fontified as a keyword).
2021-01-25 07:44:29 +01:00
Lars Ingebrigtsen
9503f8d96c Rewrite lisp--el-funcall-position-p to be inverse of the -not function
* lisp/emacs-lisp/lisp-mode.el (lisp--el-funcall-position-p):
Rename and rewrite to return the inverse value.  Non-inverted
predicate functions are easier to reason about.
(lisp--el-non-funcall-position-p): Make obsolete.
2021-01-24 23:25:52 +01:00
Lars Ingebrigtsen
196be2bf12 Fix macro fontification in `condition-case' handler bodies
* lisp/emacs-lisp/lisp-mode.el (lisp--el-non-funcall-position-p):
Fontify macros in the BODY of HANDLERS in `condition-case'
correctly (bug#43265).
2021-01-24 21:43:25 +01:00
Lars Ingebrigtsen
8f28a1b9da Tweak `condition-case' keyword highlights
* lisp/emacs-lisp/lisp-mode.el (lisp--el-non-funcall-position-p):
Tweak `condition-case' position check to skip the VAR form.
2021-01-24 21:31:09 +01:00
Andrea Corallo
b8d3ae78c5 Merge remote-tracking branch 'savannah/master' into native-comp 2021-01-24 21:05:33 +01:00
Stefan Monnier
1559cc445a Fix missing file&line info in "Unknown defun property" warnings
* lisp/emacs-lisp/byte-run.el (defmacro, defun): Use
`macroexp--warn-and-return` rather than `message`.

* lisp/emacs-lisp/macroexp.el: Fix `macroexp--compiling-p`.
(macroexp--warn-and-return): Don't try and detect repetition on forms
like `nil`.
(macroexp-macroexpand): Don't forget to bind `macroexpand-all-environment`.
2021-01-23 16:04:36 -05:00
Stefan Monnier
b41b4add7b Fix spurious "Lexical argument shadows the dynamic variable" due to inlining
Before this patch doing:

    rm lisp/calendar/calendar.elc
    make lisp/calendar/cal-hebrew.elc

would spew out lots of spurious such warnings about a `date` argument,
pointing to code which has no `date` argument in sight.  This was
because that code had calls to inlinable functions (taking a `date`
argument) defined in `calendar.el`, and while `date` is a normal
lexical var at the site of those functions' definitions, it was
declared as dynbound at the call site.

* lisp/emacs-lisp/byte-opt.el (byte-compile-inline-expand):
Don't impose our local context onto the inlined function.

* test/lisp/emacs-lisp/bytecomp-tests.el: Add matching test.
2021-01-21 13:15:05 -05: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
Lars Ingebrigtsen
61b716bd30 checkdoc-spellcheck-documentation-flag doc string improvement
* lisp/emacs-lisp/checkdoc.el
(checkdoc-spellcheck-documentation-flag): Mention
`ispell-kill-ispell' (bug#6221).
2021-01-20 22:15:38 +01:00
Lars Ingebrigtsen
1a6ed932d9 Revert "Always send Lisp words to checkdoc-ispell-init"
This reverts commit 93141d5813.

This would make checkdoc words be used in other flyspell
buffers.
2021-01-20 22:11:38 +01:00
Lars Ingebrigtsen
93141d5813 Always send Lisp words to checkdoc-ispell-init
* lisp/emacs-lisp/checkdoc.el (checkdoc-ispell-init): Always send
the Lisp words to the process (bug#6221).  This allows an existing
ispell process to be correctly initialised.
2021-01-20 22:01:08 +01:00
Juri Linkov
5065698c81 Move the ‘declare’ form before the interactive spec in 10 functions.
* lisp/emacs-lisp/package.el (package-menu-hide-package):
* lisp/font-lock.el (font-lock-debug-fontify):
* lisp/image.el (image-jpeg-p):
* lisp/mail/flow-fill.el (fill-flowed-test):
* lisp/mh-e/mh-speed.el (mh-speed-toggle, mh-speed-view):
* lisp/progmodes/project.el (project-async-shell-command)
(project-shell-command, project-compile):
* lisp/progmodes/sh-script.el (sh-assignment):
Fix special forms to follow in this order: docstring, declare, interactive.
2021-01-20 21:19:23 +02:00
Stefan Monnier
0d3635536d * lisp/emacs-lisp/subr-x.el (named-let): New macro 2021-01-20 14:13:15 -05:00
Stefan Monnier
66439d31ad * lisp/emacs-lisp/byte-opt.el (byte-optimize-lapcode): Add 2 new opts
This introduces two new optimizations.  They're designed for code like

    (while
        (let (...)
          (if ... (progn blabla t) (progn blabla nil)))
      ...)

and they allow the elimination of the test internal to `while` since
we can immediately know when we return `t` or `nil` what the result
of the test will be.

`cl-labels` tends to generate this kind of code when it applies the
tail-call optimization.
2021-01-20 14:13:15 -05:00
Stefan Monnier
4dfebf25c7 * lisp/emacs-lisp/byte-opt.el (byte-optimize-lapcode): Move some opts.
This moves two optimizations from the final pass to the main loop.
Both may enable further optimizations (and the second can be applied
repeatedly but "from the end", so the loop in the final pass only gets
to apply it once).
2021-01-20 14:13:15 -05:00
Stefan Monnier
09bfb12edc * lisp/emacs-lisp/byte-opt.el (byte-optimize-lapcode): Re-indent 2021-01-20 14:13:15 -05:00
Andrea Corallo
0ffb3dfaa4 Do not add unnecesary arg constraints (bug#45812 bug#45705 bug#45751).
These have the effect of bloating the IR for no effect killing compile
time.  The typical cases for that are extremely long backuoted lists.

	* lisp/emacs-lisp/comp-cstr.el (comp-cstr-t): New var.
	* lisp/emacs-lisp/comp.el (comp-add-call-cstr): No need to add
	arg call constraints if this is t.
2021-01-19 21:58:53 +01:00
Andrea Corallo
39b3bcd324 * Run dead code removal always before fwprop, optim bootstrap time (~20% less)
* lisp/emacs-lisp/comp.el (comp-passes): Remove `comp-dead-code'.
	(comp-fwprop): Call `comp-dead-code'.
	(comp-dead-code): Remove fake arg.
2021-01-17 22:42:19 +01:00
Andrea Corallo
339b4a754b * Introduce `comp-fwprop-max-insns-scan' as heuristic threshold
* lisp/emacs-lisp/comp.el (comp-fwprop-max-insns-scan): New
	constant.
	(comp-fwprop*): Give-up when `comp-fwprop-max-insns-scan' is
	exceeded.
2021-01-17 22:33:02 +01:00
Andrea Corallo
883d937320 Make `comp-enable-subr-trampolines' effective for advices (bug#45854)
* src/comp.c: Copyright update.
	(syms_of_comp): Update `comp-enable-subr-trampolines' doc.
	* lisp/emacs-lisp/comp.el (comp-subr-trampoline-install): Check
	for `comp-enable-subr-trampolines'.
2021-01-17 17:01:51 +01:00
Stefan Monnier
25e1b73294 * lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker): Use pcase 2021-01-16 14:21:57 -05:00
Stefan Monnier
0ab56a4e93 * lisp/emacs-lisp/pcase.el: Add support for not to pred
(pcase--split-pred, pcase--funcall): Adjust for `not`.
(pcase--get-macroexpander): New function.
(pcase--edebug-match-macro, pcase--make-docstring)
(pcase--macroexpand): Use it.

* lisp/emacs-lisp/radix-tree.el (radix-tree-leaf): Use it!

* doc/lispref/control.texi (The @code{pcase} macro): Document it.

* lisp/emacs-lisp/ert.el (ert--explain-equal-rec): Remove redundant test.
2021-01-16 14:21:57 -05:00
Philip Brown
88100bed0a * Set `backtrace-line-length' in async worker processes
Philip Brown <pdbrown.git@gmail.com>

	* lisp/emacs-lisp/comp.el (comp-run-async-workers): Set
	backtrace-line-length in async worker processes.

Copyright-paperwork-exempt: yes
2021-01-16 13:32:04 +01:00
Andrea Corallo
0a7ac0b550 Merge remote-tracking branch 'savannah/master' into native-comp 2021-01-16 13:26:10 +01:00
Glenn Morris
0a26f47915 * lisp/emacs-lisp/seq.el (seq-concatenate): Unautoload (merge fix).
gitmerge-skip-regexp does not handle line breaks.
2021-01-15 09:38:20 +00:00