From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#73041: 30.0.90; track-changes-mode logs warnings (#70541 regression? not actually fixed?) Date: Sat, 21 Sep 2024 12:11:21 +0300 Message-ID: <86r09d4bie.fsf@gnu.org> References: <87ed5yfcve.fsf@pretzelnet.org> <86zfom2okl.fsf@gnu.org> 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="14605"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 73041@debbugs.gnu.org To: epg@pretzelnet.org, Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Sep 21 11:11:48 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 1srw9c-0003d5-Gw for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 21 Sep 2024 11:11:48 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1srw9Y-0006ba-5C; Sat, 21 Sep 2024 05:11:44 -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 1srw9V-0006bK-VZ for bug-gnu-emacs@gnu.org; Sat, 21 Sep 2024 05:11:42 -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 1srw9V-00069u-ME for bug-gnu-emacs@gnu.org; Sat, 21 Sep 2024 05:11:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-version:References:In-Reply-To:From:Date:To:Subject; bh=56cdcE3e3m02tD8SqawW7+hZ+PDFOFJRQueP3hq5GrY=; b=QXLXb81UUHrvk7ZnXmjwYiVB3vZ5m77vIL+CLv609xZexkrNnYrQOpH2ztL8flr2AgGoWDP/VpqHEUOwifAz2e3wXG5LYQWwG6pihqDqQiQobxqYsuqw3oQ8XwPTT8lna8+ZdtiYdy/NJrXxb7jMvgPnhnDcFQZ9MuGW5ZlPy7rG/ixrh/TilARLeABlZIVi1fbO7IMcKOML6xnlmiELEvoox416SS9zo/hsPXCSJpN9SlzIMPzY3aCopZuKaEQBr2DucN3qbnCFfPuJtZHKEbnwhtZmXkKr/2WaQVVO4n6lRi6sIuEB24eT2mZEa1NDX77AMAStOyzBiVMO2rOUmA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1srw9p-0001qA-K7 for bug-gnu-emacs@gnu.org; Sat, 21 Sep 2024 05:12:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 21 Sep 2024 09:12:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 73041 X-GNU-PR-Package: emacs Original-Received: via spool by 73041-submit@debbugs.gnu.org id=B73041.17269099147058 (code B ref 73041); Sat, 21 Sep 2024 09:12:01 +0000 Original-Received: (at 73041) by debbugs.gnu.org; 21 Sep 2024 09:11:54 +0000 Original-Received: from localhost ([127.0.0.1]:37159 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1srw9h-0001pm-SW for submit@debbugs.gnu.org; Sat, 21 Sep 2024 05:11:54 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:37042) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1srw9f-0001pW-8j for 73041@debbugs.gnu.org; Sat, 21 Sep 2024 05:11:52 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1srw9F-00069B-F7; Sat, 21 Sep 2024 05:11:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=56cdcE3e3m02tD8SqawW7+hZ+PDFOFJRQueP3hq5GrY=; b=Lr0wvQRI+eFGcPQv1GNy 52ByKXJxEz+vvNpbHJzuMiqsi1OrCYmKGEooM2MG3cBSnBLoKEDqaO29mXMJVMNE0cPQijefZqp8F yqQa2uXuN+eObf43GRKEIKUzDSC64FDnXHMNiSlmHS7pb5dOzbddbPhLoQNGxgvPiYRFh7D0hqq/m fYUJIZr+Kf7rfVYGO2kCMVNoIqDsifwbhwqdIwA8Wi0rQTUGIv+RSh2VD//VFzEUgxL4ib19WD5H5 q2HvAcWg3iNhfrQarlWUIMcPHjA6q+8HwnZBUoiBEBovQ0YmTb9w2GX2J4tlHACzFXOxUwV/vDZk+ xb9QHm3ODfOVaQ==; In-Reply-To: (message from Stefan Monnier on Sun, 08 Sep 2024 19:06:09 -0400) 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:292158 Archived-At: Ping! epg, could you please try Stefan's patches and report back? > From: Stefan Monnier > Cc: epg@pretzelnet.org, 73041@debbugs.gnu.org > Date: Sun, 08 Sep 2024 19:06:09 -0400 > > > >> I wish I could describe exactly what happened. I found > >> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=70541 which sounds > >> very much like what I'm seeing, but I don't use any input method. > > Thanks for your description of the problem. A reproducible recipe is of > course better, but sadly, we can't always have what we want. > Let's hope we find that eventually we'll get what we need. > > >> Eventually, this pops into *Messages*: > >> > >> #+begin_quote > >> cl--assertion-failed: Assertion failed: (or track-changes--before-no (<= > >> track-changes--before-beg (track-changes--state-beg track-changes--state) > >> beg end (track-changes--state-end track-changes--state) > >> track-changes--before-end)) > >> #+end_quote > > Hmm... this clearly points to a bug in track-changes. > > >> #+begin_quote > >> ⛔ Warning (emacs): Missing/incorrect calls to ‘before/after-change-functions’!! > >> Details logged to ‘track-changes--error-log’ > >> #+end_quote > > Barring bugs in track-changes, this points to a bug in some other part > of Emacs, which prevents track-changes from getting the info it needs. > Track-changes (and Eglot) are supposedly equipped to deal with such > problems, because we know we still have many of them. > > >> Over time, they just keep repeating, > > Hmm... `track-changes--recover-from-error` should (as the name suggests) > "recover" so they shouldn't just keep repeating, unless the source of > the problem keeps repeating as well. Or unless there's a bug in > track-changes. > > >> although I think killing the > >> buffer and reopening the file makes it stop. > >> > >> If I have inspected ‘track-changes--error-log’ correctly, this is > >> what it contains (looks like some binary, hope it comes through > >> in some useful fashion or another): > > It's a list of debug info, one per "recovery". Each debug info is made > of the buffer name, the inconsistency encountered, then a backtrace, and > an extract of (raw) `view-lossage`. Here's your data reformatted: > > (("lib.rs" (buffer-size 5254 5218) > ((t track-changes--recover-from-error ... nil) > (t track-changes-fetch ... nil) > (t eglot--track-changes-fetch ... nil) > (t eglot--signal-textDocument/didChange nil nil) > (t eglot--signal-textDocument/didSave nil nil) > (t run-hooks ... nil) > (t basic-save-buffer ... nil) > (t save-buffer ... nil) > (t funcall-interactively ... nil) > (t call-interactively ... nil) > (t command-execute ... nil)) > [111 (nil . other-window) > 103 (nil . recompile) > 121 (nil . undefined) > 24 96 (nil . next-error) > 1 (nil . move-beginning-of-line) > 11 ...]) > ("lib.rs" (buffer-size 5256 5254) > ((t track-changes--recover-from-error ... nil) > (t track-changes-fetch ... nil) > (t eglot--track-changes-fetch ... nil) > (t eglot--signal-textDocument/didChange nil nil) > (t eglot--signal-textDocument/didSave nil nil) > (t run-hooks ... nil) > (t basic-save-buffer ... nil) > (t save-buffer nil nil) > (t #[257 "r\211q\210\300 )\207" [save-buffer] 2 ...] > (t map-y-or-n-p ... nil) > (t save-some-buffers ... nil) > (t recompile ... nil) > ...) > [19 (nil . save-buffer) > 24 24 (nil . exchange-point-and-mark) > 23 (nil . kill-region) > 24 19 (nil . save-buffer) > backspace (nil . delete-backward-char) ...]) > ("lib.rs" (buffer-size 5278 5256) > ((t track-changes--recover-from-error ... nil) > (t track-changes-fetch ... nil) > (t eglot--track-changes-fetch ... nil) > (t eglot--signal-textDocument/didChange nil nil) > (t eglot--signal-textDocument/didSave nil nil) > (t run-hooks ... nil) > (t basic-save-buffer ... nil) > (t save-buffer ... nil) > (t funcall-interactively ... nil) > (t call-interactively ... nil) > (t command-execute ... nil)) > [(nil . backward-word) > 2 (nil . backward-char) > 67108896 (nil . set-mark-command) > 134217734 (nil . forward-sexp) > 23 (nil . kill-region) > 24 19 (nil . save-buffer) > ...]) > ("lib.rs" (buffer-size 5324 5278) > ((t track-changes--recover-from-error ... nil) > (t track-changes-fetch ... nil) > (t eglot--track-changes-fetch ... nil) > (t eglot--track-changes-signal ... nil) > (t #[771 "\211^BZ\211^HG^E] ...) > ...) > ...) > ...) > > This suggests the error is always detected "late" when we find that the > buffer-size is not the one we expected, so some buffer change presumably > happened without informing track-changes. > That doesn't explain the assertion failure. > > Also, I don't see anything "unusual" in the view-lossage. > > >> I wish I could reliably repeat it. Given that it occurs after > >> many hours of work, `emacs -Q` isn't an option. > > Thanks. > I stared at the code for a bit trying to see how that assertion failure > can occur, but nothing came to mind yet. I think we'll need more data. > > Can you try to install the patch below, then run with > `debug-on-error` enabled? > Hopefully when the error occurs, this will give us more info (ideally > including a backtrace). > > > Stefan > > diff --git a/lisp/emacs-lisp/track-changes.el b/lisp/emacs-lisp/track-changes.el > index 92d14959763..325a92317ca 100644 > --- a/lisp/emacs-lisp/track-changes.el > +++ b/lisp/emacs-lisp/track-changes.el > @@ -229,6 +229,7 @@ track-changes-register > (push tracker track-changes--clean-trackers) > (when disjoint > (push tracker track-changes--disjoint-trackers)) > + (cl-assert (track-changes--sane-state-p)) > tracker)) > > (defun track-changes-unregister (id) > @@ -253,7 +254,8 @@ track-changes-unregister > track-changes--buffer-size > track-changes--before-clean > track-changes--state)) > - (remove-hook 'after-change-functions #'track-changes--after t))) > + (remove-hook 'after-change-functions #'track-changes--after t)) > + (cl-assert (track-changes--sane-state-p))) > > (defun track-changes-fetch (id func) > "Fetch the pending changes for tracker ID pass them to FUNC. > @@ -372,7 +374,8 @@ track-changes-fetch > (funcall func beg end (or before lenbefore))) > ;; Re-enable the tracker's signal only after running `func', so > ;; as to avoid nested invocations. > - (cl-pushnew id track-changes--clean-trackers)))) > + (cl-pushnew id track-changes--clean-trackers) > + (cl-assert (track-changes--sane-state-p))))) > > (defun track-changes-inconsistent-state-p () > "Return whether the current buffer is in an inconsistent state. > @@ -387,6 +390,19 @@ track-changes-inconsistent-state-p > > ;;;; Auxiliary functions. > > +(defun track-changes--sane-state-p () > + (and (equal track-changes--buffer-size (buffer-size)) > + (or track-changes--before-no > + (pcase track-changes--before-clean > + ('unset t) > + ('set (<= track-changes--before-beg track-changes--before-end)) > + ('nil > + (<= track-changes--before-beg > + (track-changes--state-beg track-changes--state) > + (track-changes--state-end track-changes--state) > + track-changes--before-end)) > + (_ nil))))) > + > (defun track-changes--clean-state () > (cond > ((null track-changes--state) > @@ -551,7 +567,8 @@ track-changes--before > (length track-changes--before-string)))))) > (setf track-changes--before-end new-bend) > (cl-callf concat track-changes--before-string > - (buffer-substring-no-properties old-bend new-bend))))))))) > + (buffer-substring-no-properties old-bend new-bend)))))))) > + (cl-assert (track-changes--sane-state-p))) > > (defun track-changes--after (beg end len) > (cl-assert track-changes--state) > @@ -576,10 +593,26 @@ track-changes--after > ;; BEG..END is not covered by previous `before-change-functions'!! > (track-changes--recover-from-error `(unexpected-after ,beg ,end ,len)) > ;; Note the new changes. > + (let ((orig-beg (track-changes--state-beg track-changes--state)) > + (orig-end (track-changes--state-end track-changes--state))) > (when (< beg (track-changes--state-beg track-changes--state)) > (setf (track-changes--state-beg track-changes--state) beg)) > (cl-callf (lambda (old-end) (max end (+ old-end offset))) > (track-changes--state-end track-changes--state)) > + (cl-assert (or track-changes--before-no > + (<= track-changes--before-beg > + (track-changes--state-beg track-changes--state))) > + nil "<=? %S %S (was %S)" > + track-changes--before-beg > + (track-changes--state-beg track-changes--state) > + orig-beg) > + (cl-assert (or track-changes--before-no > + (<= (track-changes--state-end track-changes--state) > + track-changes--before-end)) > + nil "<=? %S %S (was %S)" > + (track-changes--state-end track-changes--state) > + track-changes--before-end > + orig-end)) > (cl-assert (or track-changes--before-no > (<= track-changes--before-beg > (track-changes--state-beg track-changes--state) > @@ -591,7 +624,8 @@ track-changes--after > (if (track-changes--tracker-immediate tracker) > (funcall (track-changes--tracker-signal tracker) tracker) > (run-with-timer 0 nil #'track-changes--call-signal > - (current-buffer) tracker))))) > + (current-buffer) tracker)))) > + (cl-assert (track-changes--sane-state-p))) > > (defun track-changes--call-signal (buf tracker) > (when (buffer-live-p buf) > diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el > index 82e99a2c920..a2c9f73fc73 100644 > --- a/lisp/progmodes/eglot.el > +++ b/lisp/progmodes/eglot.el > @@ -2813,6 +2813,8 @@ eglot--signal-textDocument/didChange > > (defun eglot--signal-textDocument/didOpen () > "Send textDocument/didOpen to server." > + ;; Flush any potential pending change. > + (eglot--track-changes-fetch eglot--track-changes) > (setq eglot--recent-changes nil > eglot--versioned-identifier 0 > eglot--TextDocumentIdentifier-cache nil)