Subject: bug#40335: 27.0.90; elp-not-profilable not up to date

From: Štěpán Němec <[email-masked]>
Date: Mon, 13 Apr 2020 16:52:17 +0200

On Mon, 30 Mar 2020 23:25:01 +0200
Philipp Stephani wrote:

> emacs -Q -eval '(elp-instrument-list (quote (float-time eq)))'
>
> Then something like C-x d leads to infinite recursion.  It looks like
> the list `elp-not-profilable' is outdated and should be regenerated.

The list (as well as the comment) is definitely out of date, given that
since its last modification elp has been updated to use nadvice.el, also
the `float-time' weren't originally being used, OTOH some of the
original functions listed aren't used by elp any more.

But I can't tell which functions should really be on it. The comment
says that functions directly or indirectly used by the wrapper should be
avoided, but from my anecdotal testing, the only of those that cause
problems are `apply', `error', `current-time' and `float-time'.

All the others can be removed AFAICT, and none of `eq', `get', `aref' or
`time-subtract', also called by the wrapper lambdas
(`elp--make-wrapper'), seemed to cause issues for me.

IIUC advice has no effect for calls from C functions to C functions, but
I don't understand what makes e.g. `float-time' (which breaks) different
from `aref' or `get' (which apparently don't) in that respect.

Here's what seems to work for me:

diff --git a/lisp/emacs-lisp/elp.el b/lisp/emacs-lisp/elp.el
index 7dd3cbd1a2..f357783256 100644
--- a/lisp/emacs-lisp/elp.el
+++ b/lisp/emacs-lisp/elp.el
@@ -202,16 +202,9 @@ elp-master
   "Master function symbol.")
 
 (defvar elp-not-profilable
-  ;; First, the functions used inside each instrumented function:
-  '(called-interactively-p
-    ;; Then the functions used by the above functions.  I used
-    ;; (delq nil (mapcar (lambda (x) (and (symbolp x) (fboundp x) x))
-    ;;                   (aref (symbol-function 'elp-wrapper) 2)))
-    ;; to help me find this list.
-    error call-interactively apply current-time
-    ;; Andreas Politz reports problems profiling these (Bug#4233):
-    + byte-code-function-p functionp byte-code subrp
-    indirect-function fboundp)
+  ;; functions used inside each instrumented function cause infinite
+  ;; recursion:
+  '(apply current-time error float-time)
   "List of functions that cannot be profiled.
 Those functions are used internally by the profiling code and profiling
 them would thus lead to infinite recursion.")