]> git.eshelyaron.com Git - emacs.git/commit
edebug.el: Better strip instrumentation from backtraces
authorStefan Monnier <monnier@iro.umontreal.ca>
Sat, 23 Mar 2024 23:21:26 +0000 (19:21 -0400)
committerEshel Yaron <me@eshelyaron.com>
Sun, 24 Mar 2024 14:22:09 +0000 (15:22 +0100)
commit8d1a05d5ce626b042843f40acc002b2654dae82d
tree183eed240d815b3f7a6241c605c9eedfd8fa145b
parentfb66ac79afccde7b0492660975a3ac589acbf04a
edebug.el: Better strip instrumentation from backtraces

Rework the code that "cleans" the backtrace for `edebug-pop-to-backtrace`.
The main changes are the following:

- Strip instrumentation from "everywhere" rather than trying to limit the
  effect to "code" and leave "data" untouched.  This is a worthy
  goal, but it is quite difficult to do since code contains data
  (so we ended up touching data anyway) and data can also
  contain code.
  The risk of accidentally removing something because it happens
  to look like instrumentation is very low, whereas it was very common
  for instrumentation to remain in the backtrace.

- Use a global hash-table to remember the work done, instead of
  using separate hash-table for each element.  By using a weak
  hash-table we avoid the risk of leaks, and save a lot of work
  since there's often a lot of subexpressions that appear
  several times in the backtrace.

* lisp/emacs-lisp/edebug.el (edebug-make-enter-wrapper): Tweak code
layout so the comments are more clear.
(edebug-unwrap): Remove redundant patterns for `closure` and `lambda`.
Add `:closure-dont-trim-context` to the `edebug-enter` pattern,
so it also gets removed (this should have been done in commit
750bc57cbb8d).
(edebug--unwrap-cache): New var.
(edebug-unwrap*): Use it.
(edebug--unwrap1): Delete function.  Merged into `edebug-unwrap*`.
Also apply unwrapping to the contents of byte-code functions since they
can refer to lambda expressions captured by the closure.
(edebug--symbol-prefixed-p): Rename from
`edebug--symbol-not-prefixed-p` and adjust meaning accordingly.
(edebug--strip-instrumentation): Adjust accordingly and simplify
a bit by unifying the "lambda" case and the "everything else" case.
(edebug--unwrap-frame): Use `cl-callf` and unwrap arguments even if
they've already been evaluated.

(cherry picked from commit ef859d8b1b285fd22b083955a0e878a74d72ff41)
lisp/emacs-lisp/edebug.el