Subject: bug#25295: 26.0.50; Represent eieio objects using object-print in backtraces and edebug

From: Stefan Monnier <[email-masked]>
Date: Thu, 02 Mar 2017 02:00:53 -0500

> Objects have an `object-print' method which produces the #<foo>
> representation, but this appears to only sometimes be used in edebug,
> and never in backtraces.

I've installed a cl-print.el package into Emacs's master branch which is
like EIEIO's object-print but more thorough.  This is now used in
edebug, so it should hopefully fix the "only sometimes" part (and it
additionally knows about cl-defstructs as well, rather than only EIEIO
objects).

Using it in backtraces should be a simple matter of applying the patch
below.  I haven't installed it because I'm afraid of the potential
breakage and slowdown of using cl-prin1, so I'd rather wait and see how
it fares in Edebug first.  My experiments seem to indicate that it might
be "good enough" but it might also suffer from the overhead of
cl-generic (mostly the fact that a call to a generic-function ends up
going through some &rest+apply which in cl-print's case end up
generating a lot of garbage: in one of my tests, the cl-print code was
twice slower than the C code but the added time was almost entirely
spent in the GC and that seemed to come exclusively from the lists
allocated for &rest.  I.e. if we could change cl-generic so it doesn't
use &rest+apply as much there's a chance it could potentially be about
as fast as the C code).

        Stefan

diff --git a/lisp/subr.el b/lisp/subr.el
index ea159e733c..68bfceb8d2 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -4660,10 +4660,10 @@ backtrace--print-frame
   (princ (if (plist-get flags :debug-on-exit) "* " "  "))
   (cond
    ((and evald (not debugger-stack-frame-as-list))
-    (prin1 func)
-    (if args (prin1 args) (princ "()")))
+    (cl-prin1 func)
+    (if args (cl-prin1 args) (princ "()")))
    (t
-    (prin1 (cons func args))))
+    (cl-prin1 (cons func args))))
   (princ "\n"))
 
 (defun backtrace ()