]> git.eshelyaron.com Git - emacs.git/commit
Add "defining symbols" to backtrace lines with lambdas.
authorAlan Mackenzie <acm@muc.de>
Mon, 17 Jul 2023 09:55:04 +0000 (09:55 +0000)
committerAlan Mackenzie <acm@muc.de>
Mon, 17 Jul 2023 09:55:04 +0000 (09:55 +0000)
commit603ac9505d5d0eebf27798620d1826788739fad8
tree08f70cb6ae712f36dd867a5fdf01be1b0da2cdc7
parentf17bdee79b1987f23f61719a827934e678ec0ba5
Add "defining symbols" to backtrace lines with lambdas.

This is achieved by enhancing the structures of the
interpreted, byte compiled, and native compiled functions to
include the defining symbol in them.  It is intended that the
older forms of such functions will still run OK in the current
Emacs.

* lisp/emacs-lisp/byte-run.el (byte-run--strip-list)
(byte-run--strip-vector/record)
(byte-run-strip-symbol-positions, function-put)
(byte-run--set-advertised-calling-convention)
(byte-run--set-obsolete, byte-run--set-interactive-only)
(byte-run--set-pure, byte-run--set-side-effect-free)
(byte-run--set-compiler-macro, byte-run--set-doc-string)
(byte-run--set-indent, byte-run--set-speed)
(byte-run--set-completion, byte-run--set-modes)
(byte-run--set-interactive-args, byte-run--set-debug)
(byte-run--set-no-font-lock-keyword, byte-run--parse-body)
(byte-run--parse-declarations, defmacro)
* lisp/emacs-lisp/debug-early.el (debug-early-backtrace)
(debug-early): Add in the defining symbol to the source of all
these explicit defalias's.

* lisp/emacs-lisp/byte-run.el (defmacro, defun): Insert the
NAME parameter as defining symbol into the resulting form.
(lambda-arglist, lambda-body): New macros.

* lisp/emacs-lisp/byte-opt.el (byte-optimize--rename-var)
* lisp/emacs-lisp/bytecomp.el
(byte-compile-docstring-style-warn)
(byte-compile--reify-function, byte-compile-lambda)
(byte-compile-out-toplevel, byte-compile-make-closure)
(byte-compile-file-form-defalias)
* lisp/emacs-lisp/cconv.el (cconv--convert-function)
(cconv-convert, cconv-analyze-form)
(cconv-make-interpreted-closure)
* lisp/emacs-lisp/cl-generic.el (cl-generic-define)
(cl--generic-lambda, cl-generic-define-method)
* lisp/emacs-lisp/cl-macs.el (cl-labels)
(cl--sm-macroexpand-1)
* lisp/emacs-lisp/loaddefs-gen.el
(loaddefs-generate--make-autoload)
* lisp/emacs-lisp/macroexp.el (macroexp--expand-all)
* lisp/emacs-lisp/oclosure.el (oclosure--fix-type)
* lisp/help.el (help-function-arglist)
* lisp/progmodes/elisp-mode.el (elisp--local-variables-1)
(elisp--eval-defun-1)
* lisp/simple.el (function-documentation): Amend to handle
possible or actual defining symbols in forms.

* lisp/emacs-lisp/bytecomp.el (byte-compile-from-buffer): Bind
defining-symbol to t.  Call byte-compile-flush-pending after
each top-level form to ensure the defining-symbol mechanism
works.
(byte-compile-file-form-defvar, byte-compile-defvar): bind
defining-symbol to the variable being defined for the benefit
of any forms in the value.
(byte-compile-file-form-defmumble): New parameter defsym.  Add
the defining symbol to the form passed to byte-compile-lambda.
(byte-compile, byte-compile-sexp, byte-compile-top-level): Bind
defining-symbol to t.
(byte-compile-lambda, byte-compile-make-closure): Amend the
arguments to make-byte-code.

* lisp/emacs-lisp/cconv.el (cconv--convert-function): New
parameter defsym.
(cconv-fv, cconv-make-interpreted-closure): Use lambda-body.

* lisp/emacs-lisp/cl-generic.el (cl--generic-lambda): New
parameter defsym.
(cl-defmethod): Insert defining symbol into generated code.
(cl--generic-get-dispatcher): New parameter `name'.  Add this
symbol as the defining symbol in generated code.
(cl--generic-make-function, cl--generic-make-next-function):
New parameter `name'.

* lisp/emacs-lisp/cl-macs.el (cl--sm-macroexpand-1): bind
pcase-max-duplicate to nil around this function to prevent the
creation of pcase-n functions which lead to infinite recursion.

* lisp/emacs-lisp/cl-print.el (cl-print-object/cons): For a
lambda function, print the defining symbol in braces.  This is
the main point of these changes.
(cl-print-compiled): Add extra value, `full', meaning print out
a (byte-compiled) function in full.
(cl-print-object/compiled-function): Print the defining symbol
in the pertinent function.  Add in code for (eq
cl-print-compiled 'full).

* lisp/emacs-lisp/comp.el (comp-func): New field
defining-symbol.
(comp-spill-lap-function/symbol)
(comp-spill-lap-function/lambda): Fill in the new field
defining-symbol of func.  Use lambda-arglist in the lambda
version.
(comp-spill-lap) Add a mention of lambda form to the doc
string.
(comp-emit-for-top-level/form)
(comp-emit-for-top-level/lambda): Emit the defining symbol as
the last element of the subr being created.
(comp-limplify-top-level): Add one of the two rigid
possibilities for the defining symbol into the func structure.
(comp-native-compile): Remove the condition-case to ease
debugging the compiler.

* lisp/emacs-lisp/ert.el (ert-batch-backtrace-right-margin):
Change from 70 to nil.
(ert-batch-print-length): Change from 10 to nil.
(ert-batch-print-level): Change from 5 to nil.
All these changes were to get half-usable backtraces.

* lisp/emacs-lisp/macroexp.el (macroexp--unfold-lambda): Use
lambda-arglist and lambda-body.
(macroexp--expand-all): Add in a pcase handler for defalias,
which binds defining-symbol during the expansion of the form's
contents.  Likewise add a pcase handler for defvar and
defconst, which does the same.

* lisp/emacs-lisp/nadvice.el (advice--equal): New function.
This function is, as yet, incomplete, needing code for both
interpreted functions and subrs.
(advice--member-p, advice--remove-function): Use advice--equal
rather than equal to avoid unnecessarily failing to match when
defining-symbols are not the same.

* lisp/emacs-lisp/pcase.el (pcase-max-duplicates): New
variable, replaces a constant 2
(pcase--expand): Compare `count' with the new variable rather
than the constant 2.

* lisp/progmodes/compile.el (compilation-directory-properties)
(compilation-error-properties): Check a position is not
(point-min) before testing a text-property on the position
before.

* lisp/subr.el (lambda): Ensure there is a defining symbol
(usually the variable defining-symbol) in the resultant form.

* src/bytecode.c (Fbyte_code): Add an extra (as yet unused)
parameter defsym.
(exec_byte_code): Replace a call to error with one to xsignal1.

* src/comp.c (make_subr): New parameter defining_symbol.  Set
the new field in "struct subr" to this value.
(Fcomp__register_lambda, Fcomp__register_subr)
(Fcomp__late_register_subr): New parameter defining_symbol,
passed to one of the above functions.

* src/data.c (Fsubr_native_defining_symbol): New DEFUN.
(Finteractive_form, Fcommand_modes): Amend to handle the
possible presence of a defining_symbol field.

* src/eval.c (Ffunction, Fcommandp, funcall_lambda)
(lambda_arity): Handle the possible presence of a defining
symbol.
(defvar, defconst): Bind defining_symbol to the sym parameter.

* src/lisp.h (struct Lisp_Subr): New field defining_symbol.
(enum Lisp_Compiled): Amend COMPILED_INTERACTIVE, introduce
COMPILED_DEFINIG_SYM.

* src/lread.c (defsubr): Set subr's defining_symbol field.

* test/Makefile.in (check-doit): Set
ert-batch-backtrace-right-margin to zero.

* test/lisp/emacs-lisp/bytecomp-tests.el
(bytecomp-function-attributes): Amend for the extra field in
the bytecomp structure.

* test/lisp/emacs-lisp/cconv-tests.el
(cconv-convert-lambda-lifted)
(cconv-closure-convert-remap-var): Amend the expected
structure of macro-expanded lambda expressions.

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch feature/named-lambdas
# Changes to be committed:
# modified:   lisp/Makefile.in
# modified:   lisp/emacs-lisp/byte-opt.el
# modified:   lisp/emacs-lisp/byte-run.el
# modified:   lisp/emacs-lisp/bytecomp.el
# modified:   lisp/emacs-lisp/cconv.el
# modified:   lisp/emacs-lisp/cl-generic.el
# modified:   lisp/emacs-lisp/cl-macs.el
# modified:   lisp/emacs-lisp/cl-print.el
# modified:   lisp/emacs-lisp/comp.el
# modified:   lisp/emacs-lisp/debug-early.el
# modified:   lisp/emacs-lisp/ert.el
# modified:   lisp/emacs-lisp/loaddefs-gen.el
# modified:   lisp/emacs-lisp/macroexp.el
# modified:   lisp/emacs-lisp/nadvice.el
# modified:   lisp/emacs-lisp/oclosure.el
# modified:   lisp/emacs-lisp/pcase.el
# modified:   lisp/help.el
# modified:   lisp/progmodes/compile.el
# modified:   lisp/progmodes/elisp-mode.el
# modified:   lisp/simple.el
# modified:   lisp/subr.el
# modified:   src/bytecode.c
# modified:   src/comp.c
# modified:   src/data.c
# modified:   src/eval.c
# modified:   src/lisp.h
# modified:   src/lread.c
# modified:   test/Makefile.in
# modified:   test/lisp/emacs-lisp/bytecomp-tests.el
# modified:   test/lisp/emacs-lisp/cconv-tests.el
#
# Untracked files:
# .gitignore.acm
# .gitignore.backup
# .timestamps.txt
# 20230315.outerr
# 20230317.parallel.out
# 20230320.outerr
# 20230322.parallel.out
# bytecomp.20230407.el.diff
# diff.20230228.diff
# diff.20230313b.diff
# diff.20230408.diff
# diff.20230608.diff
# diff.20230608b.diff
# diff.20230705.diff
# diff.20230706.diff
# diff.20230715.diff
# diff.20230716.diff
# diff.20230716b.diff
# doc/lispref/files.20201010.techsi
# find-quoted-lambdas.el
# lisp/diff.20230314.diff
# lisp/emacs-lisp/bo-primitives.el
# lisp/emacs-lisp/bytecomp.20230406.eeel
# lisp/emacs-lisp/bytecomp.20230407.eeel
# lisp/emacs-lisp/bytecomp.20230608.eeel
# lisp/emacs-lisp/bytecomp.20230608.no-b-c.eeel
# lisp/emacs-lisp/cconv.20230608.eeelsee
# lisp/emacs-lisp/cl-generic.20230716.eeelsee
# outerr.20230716.txt
# scratch.20230715.el
# src/diff.20230314.diff
# src/eval.20230518.see
# src/eval.20230716.see
# src/fingerprint.c
# src/syntax.20201010.see
# stderr.20230712.txt
# stdout.20230712.txt
#
30 files changed:
lisp/Makefile.in
lisp/emacs-lisp/byte-opt.el
lisp/emacs-lisp/byte-run.el
lisp/emacs-lisp/bytecomp.el
lisp/emacs-lisp/cconv.el
lisp/emacs-lisp/cl-generic.el
lisp/emacs-lisp/cl-macs.el
lisp/emacs-lisp/cl-print.el
lisp/emacs-lisp/comp.el
lisp/emacs-lisp/debug-early.el
lisp/emacs-lisp/ert.el
lisp/emacs-lisp/loaddefs-gen.el
lisp/emacs-lisp/macroexp.el
lisp/emacs-lisp/nadvice.el
lisp/emacs-lisp/oclosure.el
lisp/emacs-lisp/pcase.el
lisp/help.el
lisp/progmodes/compile.el
lisp/progmodes/elisp-mode.el
lisp/simple.el
lisp/subr.el
src/bytecode.c
src/comp.c
src/data.c
src/eval.c
src/lisp.h
src/lread.c
test/Makefile.in
test/lisp/emacs-lisp/bytecomp-tests.el
test/lisp/emacs-lisp/cconv-tests.el