emacs/lisp/emacs-lisp
Stefan Monnier 1b1ffe0789 (Ffunction): Make interpreted closures safe for space
Interpreted closures currently just grab a reference to the complete
lexical environment, so (lambda (x) (+ x y)) can end up looking like

    (closure ((foo ...) (y 7) (bar ...) ...)
             (x) (+ x y))

where the foo/bar/... bindings are not only useless but can prevent
the GC from collecting that memory (i.e. it's a representation that is
not "safe for space") and it can also make that closure "unwritable"
(or more specifically, it can cause the closure's print
representation to be u`read`able).

Compiled closures don't suffer from this problem because `cconv.el`
actually looks at the code and only stores in the compiled closure
those variables which are actually used.

So, we fix this discrepancy by letting the existing code in `cconv.el` tell
`Ffunction` which variables are actually used by the body of the
function such that it can filter out the irrelevant elements and
return a closure of the form:

    (closure ((y 7)) (x) (+ x y))

* lisp/loadup.el: Preload `cconv` and set
`internal-filter-closure-env-function` once we have a usable `cconv-fv`.

* lisp/emacs-lisp/bytecomp.el (byte-compile-preprocess): Adjust to new
calling convention of `cconv-closure-convert`.
(byte-compile-not-lexical-var-p): Delete function, moved to `cconv.el`.
(byte-compile-bind): Use `cconv--not-lexical-var-p`.

* lisp/emacs-lisp/cconv.el (cconv--dynbound-variables): New var.
(cconv-closure-convert): New arg `dynbound-vars`
(cconv--warn-unused-msg): Remove special case for `ignored`,
so we don't get confused when a function uses an argument called
`ignored`, e.g. holding a list of things that it should ignore.
(cconv--not-lexical-var-p): New function, moved from `bytecomp.el`.
Don't special case keywords and `nil` and `t` since they are already
`special-variable-p`.
(cconv--analyze-function): Use `cconv--not-lexical-var-p`.
(cconv--dynbindings): New dynbound var.
(cconv-analyze-form): Use `cconv--not-lexical-var-p`.
Remember in `cconv--dynbindings` the vars for which we used
dynamic scoping.
(cconv-analyze-form): Use `cconv--dynbound-variables` rather than
`byte-compile-bound-variables`.
(cconv-fv): New function.

* src/eval.c (Fsetq, eval_sub): Remove optimization designed when
`lexical-binding == nil` was the common case.
(Ffunction): Use `internal-filter-closure-env-function` when available.
(eval_sub, Ffuncall): Improve error info for `excessive_lisp_nesting`.
(internal-filter-closure-env-function): New defvar.
2022-10-25 14:24:54 -04:00
..
advice.el (compiled-function-p): New function (bug#56648) 2022-08-14 12:30:05 -04:00
avl-tree.el
backquote.el
backtrace.el Don't bind `s' in the normal backtrace map 2022-09-09 19:29:21 +02:00
benchmark.el ; Silence byte-compiler in benchmark.el 2022-10-07 23:15:13 +02:00
bindat.el Bindat (src, strz): Operate on vectors too 2022-10-21 11:26:36 -04:00
byte-opt.el ; Fix typos (prefer American spelling) 2022-09-29 15:20:07 +02:00
byte-run.el cl-generic: Fix advertised-calling-convention declarations 2022-10-16 12:01:47 -04:00
bytecomp.el (Ffunction): Make interpreted closures safe for space 2022-10-25 14:24:54 -04:00
cconv.el (Ffunction): Make interpreted closures safe for space 2022-10-25 14:24:54 -04:00
chart.el Make XEmacs compat alias face-background-pixmap obsolete 2022-08-23 16:51:31 +02:00
check-declare.el Make 'check-declare-directory' more portable 2022-05-14 19:08:55 +03:00
checkdoc.el Don't use autoloaded functions for safe-local-variable 2022-09-16 12:36:15 +02:00
cl-extra.el Audit some plist uses with new predicate argument 2022-10-22 19:33:12 +03:00
cl-generic.el cl-generic: Fix advertised-calling-convention declarations 2022-10-16 12:01:47 -04:00
cl-indent.el Remove some useless eval-when-compile 2022-07-04 14:56:11 +02:00
cl-lib.el Delete many items obsolete since 24.3 2022-09-09 11:27:30 +02:00
cl-macs.el Improve check for misleading 'cl-case' cases (Bug#57915). 2022-09-19 13:34:51 +02:00
cl-preloaded.el ; Fix typos. 2022-07-02 10:20:23 +02:00
cl-print.el
cl-seq.el cl-reduce doc string improvement 2022-08-18 15:07:08 +02:00
comp-cstr.el * Rename `comp--typeof-builtin-types' 2022-08-18 23:41:39 +02:00
comp.el * Fix async native compilation (bug#58637) 2022-10-19 22:21:03 +02:00
copyright.el
crm.el Fix crm.el compilation warning 2022-07-11 13:34:35 +02:00
cursor-sensor.el
debug-early.el Make debug-early-backtrace more resilient 2022-06-24 11:04:51 +02:00
debug.el Obsolete unused variable in debug.el 2022-09-20 12:40:14 +02:00
derived.el ; Normalize some "Author" headers 2022-07-20 22:38:01 +02:00
disass.el
easy-mmode.el Fix define-minor-mode :keymap obsoletion warning 2022-09-02 14:58:30 +02:00
easymenu.el ; Minor doc fix in easy-menu-{add,remove} 2022-08-23 16:24:54 +02:00
edebug.el Abolish max-specpdl-size (bug#57911) 2022-09-19 19:30:03 +02:00
eieio-base.el * lisp/emacs-lisp/eieio-base.el (eieio-persistent-read): Simplify. 2022-07-31 12:04:17 +02:00
eieio-core.el Fix overly wide docstrings generated by eieio 2022-10-02 17:28:04 +02:00
eieio-custom.el Move EIEIO autoloads to the common loaddefs.el 2022-07-11 14:29:33 +02:00
eieio-datadebug.el
eieio-opt.el New function substitute-quotes 2022-09-10 07:37:36 +02:00
eieio-speedbar.el
eieio.el Fix more overly long docstrings in eieio 2022-10-03 00:04:23 +02:00
eldoc.el Improve and extend documentation of ElDoc 2022-10-21 16:10:08 +03:00
elint.el
elp.el ; Delete not-useful comments referring to Emacs 19. 2022-08-19 18:05:51 +02:00
ert-x.el ; Fix logic of $HOME adjustment for 'ert-remote-temporary-file-directory' 2022-10-03 17:42:37 -07:00
ert.el Simplify code using take, ntake and butlast 2022-08-14 15:43:12 +02:00
ewoc.el
faceup.el
find-func.el Add find-function-setup-keys bindings for find-library commands 2022-06-30 12:49:40 +02:00
float-sup.el
generate-lisp-file.el Inhibit nativecomp of loaddefs files 2022-09-03 14:23:26 +02:00
generator.el
generic.el
gv.el Audit some plist uses with new predicate argument 2022-10-22 19:33:12 +03:00
helper.el Don't show status message in Helper-describe-bindings 2022-08-11 14:35:23 +02:00
hierarchy.el
icons.el * lisp/tab-bar.el: Use customizable button icons (bug#51309, bug#51648) 2022-10-24 10:33:41 +03:00
inline.el
let-alist.el
lisp-mnt.el
lisp-mode.el Get fewer false positives for :keyword and &options 2022-09-20 13:34:42 +02:00
lisp.el ; * lisp/emacs-lisp/lisp.el (end-of-defun-moves-to-eol): Doc fix. 2022-08-06 09:40:07 +03:00
loaddefs-gen.el Fix previous loaddefs-gen fix 2022-10-18 13:17:52 +02:00
macroexp.el * lisp/emacs-lisp/macroexp.el (macroexp--compiler-macro): Soften message 2022-09-03 11:03:32 -04:00
map-ynp.el
map.el Audit some plist uses with new predicate argument 2022-10-22 19:33:12 +03:00
memory-report.el Use file-size-human-readable in memory-report--format 2022-10-15 03:02:17 +02:00
multisession.el
nadvice.el Don't bug out in advice--make-docstring when there's not doc string 2022-10-04 12:50:17 +02:00
oclosure.el cconv.el: Fix interactive closure bug#51695 2022-09-23 16:36:16 -04:00
package-x.el
package.el package.el: Understand a few more variations in tarball formats 2022-10-08 12:19:40 -04:00
pcase.el (compiled-function-p): New function (bug#56648) 2022-08-14 12:30:05 -04:00
pp.el pp--insert-lisp: Don't bug out on certain forms at beginning of buffer 2022-05-28 18:39:43 +02:00
radix-tree.el
range.el
re-builder.el Fit the re-builder window to the buffer 2022-09-05 20:58:27 +02:00
regexp-opt.el Abolish max-specpdl-size (bug#57911) 2022-09-19 19:30:03 +02:00
regi.el ; * lisp/emacs-lisp/regi.el: Delete incorrect "last modified" comment. 2022-07-30 11:36:36 +02:00
ring.el * lisp/emacs-lisp/ring.el (ring): Define as a type 2022-08-14 12:30:06 -04:00
rmc.el Allow read-multiple-choice to do long-form answers 2022-06-24 11:04:51 +02:00
rx.el Reduce internal rx autoloads 2022-07-31 13:01:26 +02:00
seq.el Add 'seq-keep' 2022-10-04 21:44:52 +02:00
shadow.el string-equal-ignore-case: new function 2022-07-26 13:49:28 -04:00
shortdoc.el Mention seq-keep in shortdoc 2022-10-08 13:20:17 +02:00
shorthands.el Remove some useless eval-when-compile 2022-07-04 14:56:11 +02:00
smie.el * lisp/emacs-lisp/smie.el (smie-auto-fill): Fix bug#19342 2022-05-06 11:09:58 -04:00
subr-x.el Autoload string-join 2022-09-17 12:31:24 +02:00
syntax.el (syntax-wholeline-max): New var 2022-06-30 13:20:33 -04:00
tabulated-list.el Prefer pos-bol and pos-eol in tabulated-list.el 2022-08-22 15:08:48 +02:00
tcover-ses.el
testcover.el Remove a nil cl-case case 2022-09-13 18:24:14 +02:00
text-property-search.el
thunk.el
timer-list.el Add quit-window entry to list-timers menu 2022-07-04 22:15:51 +02:00
timer.el time-convert): Deprecate calls without an explicit FORM arg 2022-08-05 18:46:31 -04:00
tq.el
trace.el ; Delete LCD Archive entries 2022-07-28 15:07:34 +02:00
unsafep.el
vtable.el Fix vtable-insert-object line insertion 2022-10-08 15:26:01 +02:00
warnings.el Fix variable types in warnings-suppress 2022-08-15 09:36:06 +02:00