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#66912: With `require', the byte compiler reports the wrong file for errors. Date: Thu, 7 Nov 2024 15:04:32 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22617"; mail-complaints-to="usenet@ciao.gmane.io" Cc: acm@muc.de, Eli Zaretskii , 66912@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Nov 07 16:05:31 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 1t944g-0005bx-F0 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 07 Nov 2024 16:05:31 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t944J-0004U0-AQ; Thu, 07 Nov 2024 10:05:07 -0500 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 1t944F-0004TV-Mn for bug-gnu-emacs@gnu.org; Thu, 07 Nov 2024 10:05:03 -0500 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 1t944F-0005fa-D3 for bug-gnu-emacs@gnu.org; Thu, 07 Nov 2024 10:05:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=From:In-Reply-To:MIME-Version:References:Date:To:Subject; bh=v0AXpQzsknRc+S2WDogMHgmfI0XwSRfBsxROU2wBjpc=; b=HAgA3MZwWl8Z7cWAbVanlxkgSaEu0gRVFDWTxZQ7o23kNmGldzI0wQIPfdK59Ovl8+qkjF0wKfFg8NW+rz//mA4h4McnMNyfr/EasapJUhOyHpOTIq7pXQxbwI+p+kcvLqf+bf/U2YxJ0OuYcK6nqwH2kxvD8QE0d0ZkoGg/3FfkTW/w1c7OqB9u0c3MN6vKf+WtQvNhX/hhmD+kcfzuScfGiFZkEglPkW2krLPo2iPv0psWVNCPMnh7SSBb79DiUnK0LmsY8wJ6ZeSIol1KOjEpVaCOROdz3TrijnHYBlsPgDpD+jTOizGYJP/F/LgO+TQP6w2uO6ccFHhNki8jZQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t944E-0003tj-Hr for bug-gnu-emacs@gnu.org; Thu, 07 Nov 2024 10:05:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 07 Nov 2024 15:05:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66912 X-GNU-PR-Package: emacs Original-Received: via spool by 66912-submit@debbugs.gnu.org id=B66912.173099188414943 (code B ref 66912); Thu, 07 Nov 2024 15:05:02 +0000 Original-Received: (at 66912) by debbugs.gnu.org; 7 Nov 2024 15:04:44 +0000 Original-Received: from localhost ([127.0.0.1]:49223 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t943w-0003sv-1s for submit@debbugs.gnu.org; Thu, 07 Nov 2024 10:04:44 -0500 Original-Received: from mail.muc.de ([193.149.48.3]:61234) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t943s-0003sf-VA for 66912@debbugs.gnu.org; Thu, 07 Nov 2024 10:04:41 -0500 Original-Received: (qmail 96662 invoked by uid 3782); 7 Nov 2024 16:04:33 +0100 Original-Received: from muc.de (p4fe15e61.dip0.t-ipconnect.de [79.225.94.97]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Thu, 07 Nov 2024 16:04:32 +0100 Original-Received: (qmail 18756 invoked by uid 1000); 7 Nov 2024 15:04:32 -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:295026 Archived-At: Hello again, Stefan. On Wed, Nov 06, 2024 at 18:14:18 -0500, Stefan Monnier wrote: [ .... ] > > At the moment, I think my currently working solution is the best way > > to go. > [ As you can guess, I disagree, mostly because I think the problems of > my suggested approach are "familiar", since the behavior can be > compared to things like the match-data, so we know how to live with > its shortcomings, whereas I can't think of something else we already > have which follows an approach like yours, so we're in new territory > and it's harder to see what the problems could be and what workarounds > to use. ] > Then you'd be better get cracking at the documentation of "survives > unbinding" 🙂 DONE. Here is, perhaps, the final version of my patch, containing the revised doc comment for Vloads_still_in_progress, and for Fprefix_loads_in_progress. Maybe, just maybe, I can commit this as the fix to bug#66912. diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index f058fc48cc7..776083468c6 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -1436,8 +1436,9 @@ byte-compile-report-error when printing the error message." (setq byte-compiler-error-flag t) (byte-compile-log-warning - (if (stringp error-info) error-info - (error-message-string error-info)) + (prefix-load-file-names + (if (stringp error-info) error-info + (error-message-string error-info))) fill :error)) ;;; sanity-checking arglists diff --git a/lisp/emacs-lisp/debug.el b/lisp/emacs-lisp/debug.el index ec947c1215d..4068daf6614 100644 --- a/lisp/emacs-lisp/debug.el +++ b/lisp/emacs-lisp/debug.el @@ -418,7 +418,9 @@ debugger--insert-header ;; Debugger entered for an error. ('error (insert "--Lisp error: ") - (insert (backtrace-print-to-string (nth 1 args))) + (insert + (prefix-load-file-names + (backtrace-print-to-string (nth 1 args)))) (insert ?\n)) ;; debug-on-call, when the next thing is an eval. ('t @@ -426,8 +428,10 @@ debugger--insert-header ;; User calls debug directly. (_ (insert ": ") - (insert (backtrace-print-to-string (if (eq (car args) 'nil) - (cdr args) args))) + (insert + (prefix-load-file-names + (backtrace-print-to-string (if (eq (car args) 'nil) + (cdr args) args)))) (insert ?\n)))) diff --git a/src/keyboard.c b/src/keyboard.c index 6d28dca9aeb..5d615233f15 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -1096,7 +1096,7 @@ DEFUN ("command-error-default-function", Fcommand_error_default_function, Fdiscard_input (); bitch_at_user (); } - + context = Fprefix_load_file_names (context); print_error_message (data, Qt, SSDATA (context), signal); } return Qnil; @@ -1109,6 +1109,11 @@ DEFUN ("command-error-default-function", Fcommand_error_default_function, This level has the catches for exiting/returning to editor command loop. It returns nil to exit recursive edit, t to abort it. */ +static void restore_Vloads_still_in_progress (Lisp_Object arg) +{ + Vloads_still_in_progress = arg; +} + Lisp_Object command_loop (void) { @@ -1137,6 +1142,10 @@ command_loop (void) else while (1) { + specpdl_ref ccount = SPECPDL_INDEX (); + + record_unwind_protect (restore_Vloads_still_in_progress, + Vloads_still_in_progress); internal_catch (Qtop_level, top_level_1, Qnil); internal_catch (Qtop_level, command_loop_2, Qerror); executing_kbd_macro = Qnil; @@ -1144,6 +1153,7 @@ command_loop (void) /* End of file in -batch run causes exit here. */ if (noninteractive) Fkill_emacs (Qt, Qnil); + unbind_to (ccount, Qnil); } } diff --git a/src/lisp.h b/src/lisp.h index 5ef97047f76..e7eecba96f6 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4794,6 +4794,7 @@ #define FLOAT_TO_STRING_BUFSIZE 350 ATTRIBUTE_FORMAT_PRINTF (5, 0); /* Defined in lread.c. */ +extern Lisp_Object Vloads_still_in_progress; extern Lisp_Object intern_1 (const char *, ptrdiff_t); extern Lisp_Object intern_c_string_1 (const char *, ptrdiff_t); extern Lisp_Object intern_driver (Lisp_Object, Lisp_Object, Lisp_Object); diff --git a/src/lread.c b/src/lread.c index ea0398196e3..234f3b1cd25 100644 --- a/src/lread.c +++ b/src/lread.c @@ -234,9 +234,17 @@ #define USE_ANDROID_ASSETS /* A list of file names for files being loaded in Fload. Used to check for recursive loads. */ - static Lisp_Object Vloads_in_progress; +/* The same as the above, but is bound only in the command loop, not in + Fload. It is set to the value of Floads_in_progress at the start and + end of Fload. In the event of an error being signaled and the + binding stack being unwound, this variable keeps its value. Its sole + use is to supplement error messages, giving the names of the stack of + files currently being loaded. See Fprefix_load_file_names in this + file. */ +Lisp_Object Vloads_still_in_progress; + static int read_emacs_mule_char (int, int (*) (int, Lisp_Object), Lisp_Object); @@ -1271,6 +1279,34 @@ close_file_unwind_android_fd (void *ptr) #endif +DEFUN ("prefix-load-file-names", Fprefix_load_file_names, + Sprefix_load_file_names, 1, 1, 0, + doc: /* Prefix the string BASE_STRING with a message about each +file currently being loaded. Return the resulting string and reset the +internal variable holding this information to nil. */) + (Lisp_Object base_string) +{ + if (NILP (Vloads_still_in_progress)) + return base_string; + else + { + Lisp_Object result = build_string (""); + Lisp_Object while_loading = build_string ("While loading "); + Lisp_Object ellipsis = build_string ("... "); + + while (!NILP (Vloads_still_in_progress)) + { + result = concat2 (concat3 (while_loading, + Fcar (Vloads_still_in_progress), + ellipsis), + result); + Vloads_still_in_progress = Fcdr (Vloads_still_in_progress); + } + result = concat3 (result, build_string ("\n"), base_string); + return result; + } +} + DEFUN ("load", Fload, Sload, 1, 5, 0, doc: /* Execute a file of Lisp code named FILE. First try FILE with `.elc' appended, then try with `.el', then try @@ -1516,6 +1552,7 @@ DEFUN ("load", Fload, Sload, 1, 5, 0, signal_error ("Recursive load", Fcons (found, Vloads_in_progress)); record_unwind_protect (record_load_unwind, Vloads_in_progress); Vloads_in_progress = Fcons (found, Vloads_in_progress); + Vloads_still_in_progress = Vloads_in_progress; } /* All loads are by default dynamic, unless the file itself specifies @@ -1615,7 +1652,9 @@ DEFUN ("load", Fload, Sload, 1, 5, 0, val = call4 (Vload_source_file_function, found, hist_file_name, NILP (noerror) ? Qnil : Qt, (NILP (nomessage) || force_load_messages) ? Qnil : Qt); - return unbind_to (count, val); + unbind_to (count, Qnil); + Vloads_still_in_progress = Vloads_in_progress; + return val; } } @@ -1741,6 +1780,8 @@ DEFUN ("load", Fload, Sload, 1, 5, 0, if (!NILP (Ffboundp (Qdo_after_load_evaluation))) call1 (Qdo_after_load_evaluation, hist_file_name) ; + Vloads_still_in_progress = Vloads_in_progress; + for (int i = 0; i < ARRAYELTS (saved_strings); i++) { xfree (saved_strings[i].string); @@ -5772,6 +5813,7 @@ init_lread (void) Vload_true_file_name = Qnil; Vstandard_input = Qt; Vloads_in_progress = Qnil; + Vloads_still_in_progress = Qnil; } /* Print a warning that directory intended for use USE and with name @@ -5819,6 +5861,7 @@ syms_of_lread (void) defsubr (&Sintern_soft); defsubr (&Sunintern); defsubr (&Sget_load_suffixes); + defsubr (&Sprefix_load_file_names); defsubr (&Sload); defsubr (&Seval_buffer); defsubr (&Seval_region); @@ -6138,6 +6181,8 @@ syms_of_lread (void) Vloads_in_progress = Qnil; staticpro (&Vloads_in_progress); + Vloads_still_in_progress = Qnil; + staticpro (&Vloads_still_in_progress); DEFSYM (Qhash_table, "hash-table"); DEFSYM (Qdata, "data"); > Stefan -- Alan Mackenzie (Nuremberg, Germany).