From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.bugs Subject: bug#62333: 30.0.50; Issue with tree-sitter syntax tree during certain changes Date: Fri, 24 Mar 2023 00:34:58 -0700 Message-ID: <8FC25A01-6934-43BB-899C-CA5926BEA3CF@gmail.com> References: <87fs9yur7r.fsf@gmail.com> <2fd8f2b8-d9c4-c825-a789-f2d42324859f@yandex.ru> <09539C5E-23DA-4B00-A3F6-873A41D6A2CE@gmail.com> <83h6uc549z.fsf@gnu.org> <665745A2-FDC8-45DE-BFF5-2F688FC85431@gmail.com> <491b788f-c3c3-4877-daa0-f515be9f3a17@yandex.ru> <83sfduelab.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.400.51.1.1\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38280"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Wilhelm Kirschbaum , 62333@debbugs.gnu.org, Dmitry Gutov To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Mar 24 23:05:49 2023 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 1pfpXg-0009jG-Tg for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 24 Mar 2023 23:05:49 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pfpTO-0004Dg-1D; Fri, 24 Mar 2023 18:01:22 -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 1pfpTE-00044u-GF for bug-gnu-emacs@gnu.org; Fri, 24 Mar 2023 18:01:12 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pfpTE-0000eY-6i for bug-gnu-emacs@gnu.org; Fri, 24 Mar 2023 18:01:12 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pflEo-000896-Lm for bug-gnu-emacs@gnu.org; Fri, 24 Mar 2023 13:30:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 24 Mar 2023 17:30:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62333 X-GNU-PR-Package: emacs Original-Received: via spool by 62333-submit@debbugs.gnu.org id=B62333.167967898831265 (code B ref 62333); Fri, 24 Mar 2023 17:30:02 +0000 Original-Received: (at 62333) by debbugs.gnu.org; 24 Mar 2023 17:29:48 +0000 Original-Received: from localhost ([127.0.0.1]:41293 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pflEa-00088D-2a for submit@debbugs.gnu.org; Fri, 24 Mar 2023 13:29:48 -0400 Original-Received: from mail-oa1-f46.google.com ([209.85.160.46]:40476) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pflEY-000880-AN for 62333@debbugs.gnu.org; Fri, 24 Mar 2023 13:29:46 -0400 Original-Received: by mail-oa1-f46.google.com with SMTP id 586e51a60fabf-177b78067ffso2429329fac.7 for <62333@debbugs.gnu.org>; Fri, 24 Mar 2023 10:29:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679678980; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=0wh8vtLxCD59fYLdcRR50zDpjMDB2oYF7D7a45ram7s=; b=MrhzNWTDG38zh8R9BgIgUT0Yeohf3ROoeceW8NePQ1d9ZHl1gMv6C6GDkIsD7qjC61 knvvIAhIIbi0kM7SaX9DKAQ9PC3EZ0xgwhGuYE9Z47rAbzANROF9l2SotMAuLYtKqqU9 yMPoKy1K0kOFJ8Hnqo0PZxPq7gMAWy3rR83p0KpAqEw3qJ2RP4APTHxsTPEyY0Xkj89/ 8nWzSGgqsNm46cxld6pc/fD87fJCss1VIA0pAnuRmEX29dwZNOoywXBWmuC0HlmfSgqJ 6AhG3gvAE6zMCYRZ/66I5ZjS7VWaoC5UzcnwLdoe68+hCgZCAU2oEpq40lncFI5NJ785 I1Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679678980; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0wh8vtLxCD59fYLdcRR50zDpjMDB2oYF7D7a45ram7s=; b=K2XOHXC/CzNtRKuf1Pi0+7/otu7mlFA6NySoj7YmJ3ndfKoGojvCPFfTVD9EBq9eZj Vk86F92ngSb3v+8loQVASHrg5ZtDHw5qDBFMMJ5qacBu+wocAlfjKMSXdEQgQWG+r6zU 0/hJQi6V+0SvB6uDWDHlqhHtG0NnO37oveHKf01By/VH040wPDPEWcvqAxdT6ZW57zNx bm+L8pKyNoD395sUA+ovZpRtVut3VC+bZKmEvoT82MkOUzIpXdGdDatcY+88XZaSh5SP o1bzxlIaQanpz45TuZZewivRBfRHBf+gTB0mKoxyREvlx6QZ4vvzCuP0oMOtMjqIyMVc fneg== X-Gm-Message-State: AAQBX9fEuKCp7sKYw9vdVdb16C/jOD8vcip0OWTcgh/U+nUsZA9dMC2Q Cb2QHhwFZC7nzihmHK59SpqnsUb4ZrM= X-Google-Smtp-Source: AKy350YKwyZR8UQBJR1rqpYW4lLU+Yn2NY3Yby7gpgsEf3GUxpYnYnVjSp1FDUUvr0eqEh5QD5ASzA== X-Received: by 2002:a17:902:fa0c:b0:1a0:6690:d3d1 with SMTP id la12-20020a170902fa0c00b001a06690d3d1mr1406833plb.6.1679643309917; Fri, 24 Mar 2023 00:35:09 -0700 (PDT) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id p6-20020a1709028a8600b00194c2f78581sm13496621plo.199.2023.03.24.00.35.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Mar 2023 00:35:09 -0700 (PDT) In-Reply-To: <83sfduelab.fsf@gnu.org> X-Mailer: Apple Mail (2.3731.400.51.1.1) 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:258529 Archived-At: > On Mar 23, 2023, at 11:05 PM, Eli Zaretskii wrote: >=20 >> From: Yuan Fu >> Date: Thu, 23 Mar 2023 16:59:28 -0700 >> Cc: Eli Zaretskii , >> Wilhelm Kirschbaum , >> 62333@debbugs.gnu.org >>=20 >>> On Mar 23, 2023, at 3:06 PM, Dmitry Gutov wrote: >>>=20 >>> On 23/03/2023 23:18, Yuan Fu wrote: >>>> I guess the question now is why redisplay is triggered in = blink-matching-open >>>=20 >>> blink-matching-open calls sit-for after adjusting overlays. >>>=20 >>> sit-for starts with a redisplay. >>=20 >> But it=E2=80=99s not called when narrow-to-region is in effect. >=20 > Exactly. So the question is now: why does treesit.c see ZV changed, > if by the time it is supposed to be called from redisplay the > restriction is restored? >=20 > Is the problematic code in treesit.c really called from redisplay > triggered by sit-for in blink-matching-open? Can you show the C and > Lisp backtrace from the call that "sees that BUF_ZV_BYTE is smaller > than its visible_end"? Ah, I made a mistake, it isn=E2=80=99t that it doesn=E2=80=99t reproduce = on Linux, but rather it doesn=E2=80=99t reproduce on emacs-29. Since = I=E2=80=99m able to reproduce it on Linux, I set a breakpoint and the = backtrace explains it: blink-match-open calls forward-sexp, which calls = elixir-ts=E2=80=94forward-sexp, which accesses the parse tree, which = causes tree-sitter to reparse in the narrowed context. But normally tree-sitter will reparse again when redisplay fontifies the = buffer, because now the visible portion is back to the whole buffer. = Tree-sitter didn=E2=80=99t do that because I made a mistake when = modifying treesit_ensure_parsed. I moved the code that checks for the = need_reparse flag before treesit_sync_visible_region, which sets the = need_reparse flag if it detects that narrow situation has changed. Well, this is a bit embarrassing, there is even a comment warning this = mistake, but anyway, I pushed a fix, once it gets merged into master, = the problem should go away.=20 As things stands right now, every time blink-match-open blinks the = matching parenthesis, tree-sitter would reparse the buffer twice, = that=E2=80=99s not exactly ideal. Blink-match-open=E2=80=99s use of = narrowing is legit, and we can=E2=80=99t just automatically widen in = tree-sitter functions. Yuan