From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#67455: (Record source position, etc., in doc strings, and use this in *Help* and backtraces.) Date: Sun, 10 Mar 2024 19:22:04 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8684"; mail-complaints-to="usenet@ciao.gmane.io" Cc: acm@muc.de, Eli Zaretskii , 67455@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Mar 10 20:23:05 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rjOlE-00025q-Md for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 10 Mar 2024 20:23:04 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rjOkh-00089N-8a; Sun, 10 Mar 2024 15:22:31 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rjOkf-000890-Hz for bug-gnu-emacs@gnu.org; Sun, 10 Mar 2024 15:22:29 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rjOkf-0002HL-9k for bug-gnu-emacs@gnu.org; Sun, 10 Mar 2024 15:22:29 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rjOlC-0002NL-Ci for bug-gnu-emacs@gnu.org; Sun, 10 Mar 2024 15:23:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 10 Mar 2024 19:23:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67455 X-GNU-PR-Package: emacs Original-Received: via spool by 67455-submit@debbugs.gnu.org id=B67455.17100985679100 (code B ref 67455); Sun, 10 Mar 2024 19:23:02 +0000 Original-Received: (at 67455) by debbugs.gnu.org; 10 Mar 2024 19:22:47 +0000 Original-Received: from localhost ([127.0.0.1]:37893 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rjOkw-0002Mi-Nh for submit@debbugs.gnu.org; Sun, 10 Mar 2024 15:22:47 -0400 Original-Received: from mail.muc.de ([193.149.48.3]:49142) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rjOku-0002MO-K7 for 67455@debbugs.gnu.org; Sun, 10 Mar 2024 15:22:45 -0400 Original-Received: (qmail 85040 invoked by uid 3782); 10 Mar 2024 20:22:05 +0100 Original-Received: from acm.muc.de (pd953a236.dip0.t-ipconnect.de [217.83.162.54]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Sun, 10 Mar 2024 20:22:04 +0100 Original-Received: (qmail 20945 invoked by uid 1000); 10 Mar 2024 19:22:04 -0000 Content-Disposition: inline In-Reply-To: X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:281430 Archived-At: Hello, Stefan. On Sun, Mar 10, 2024 at 13:19:03 -0400, Stefan Monnier wrote: > > I've got a version almost ready which actually does something, namely > > prefixes "anonymous" lines of a backtrace with the name of the defining > > symbol, like {foo} . It'll soon be time to start seriously thinking > > about what information ought to go there for the live version. > Cool! I've finally got something to show. I've just committed a merge and a fix for it to branch feature/positioned-lambdas at savannah. With this Emacs running, type the following into *scratch* (defun foo () "foo doc" (lambda (bar) "lambda doc" (car bar))) .. Either evaluate this or byte compile it with compile-defun. Then do M-: (funcall (foo) 'baz) .. This will produce a backtrace like: Debugger entered--Lisp error: (wrong-type-argument listp baz) car(baz) {foo} #f(compiled-function (bar) "lambda doc" #)(baz) funcall({foo} #f(compiled-function (bar) "lambda doc" #) baz) (progn (funcall (foo) 'baz)) eval((progn (funcall (foo) 'baz)) t) elisp--eval-last-sexp(nil) {eval-last-sexp} #f(compiled-function () #)() eval-last-sexp(nil) funcall-interactively(eval-last-sexp nil) command-execute(eval-last-sexp) .. Note the {eval-last-sexp} and {foo} on the anonymous functions. :-) > >> - Testing `byte-compile-in-progress` can't be right. Do you to test > >> whether the result of this backquote will be byte-compiled or do you > >> really mean to test whether this backquote happens to be executed > >> during compilation (which could be because the compiler ends up > >> loading code while executing `eval-when-compile` or `require`)? > > Quite simply, during compilation, all symbols (except nil) get read with > > position, so to strip their positions here would be wrong. > This isn't quite right: during compilation, some code is read with > positions (the code that we will compile), but some code is read in the > normal way (the code we load for the purpose of running). > The distinction is important. OK, I wasn't really counting code that we load as "during compilation", but I take the point. > >> - My gut tells me that changing backquote can't be right. > > I tend to agree. I put the code into backquote-process when having > > problems with things like: > > (mapatoms #'(lambda (,(car spec)) ,@body) > > in cl-macs.el, where it's impossible to know where the doc string (if > > any) is until after the expansion of the backquotes, or even at run time > > (as here). In the latter case, rather than "posifying" the doc string > > at macro expansion time, we have to generate code to do it at run time. > Hmm... here what you call "run time" is really some later > macro-expansion, right? The `lambda` symbol comes from the first > macro-expansion (ME1), but the docstring comes from the second (ME2). Yes. I often get confused between lots of different macro expansion times, compile time and run time. It's a lot easier in C. ;-) > IIUC the problem you face is that you want to get the function's > position info from the `lambda` symbol, which here would be wrong (even if we > try to preserve it long enough), is that it? Something like that. The lambda's position currently gets preserved in the generated code so that ME2 can use it. > [ Tho, in more complex cases it becomes debatable whether the function's > position should point to the position corresponding to ME1 or to that > of ME2. ] The code currently preserves both positions. :-) But only one buffer name. My latest thoughts on that are perhaps two file names (relative to the Emacs top directory) would be better than one buffer name. Then I could put buttons on the backtrace display which on being clicked would open either of the source files at the right position. > More generally: what goes wrong in the above example if you just treat > that as a list of symbol (stripping them all of their position info). > AFAICT when *that* macro is expanded (i.e. ME2) you'll presumably get > code like > (mapatoms #'(lambda (FOO/p) (DO/p SOME/p (THING/p)))) > right? [ where "/p" means that the symbol has a sympos. ] > Isn't that sufficient info to add a docstring with position? It's the lambda which has a position rather than the expanded bits from ME2. > >> (lambda (f) ..) *can* appear within a backquote without it being an > >> actual lambda expression. > >> What alternatives have you considered? > > Not a lot of them, as yet. Maybe testing for (function (lambda ...)) > > would be safer. > No matter how many extra tests you add to reduce the frequency, you're > fundamentally adding a bug :-( Yes. I'll see what I can do to remove that extra code from backquote-process. > Stefan -- Alan Mackenzie (Nuremberg, Germany).