From: Yuan Fu <casouri@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 59693@debbugs.gnu.org, Stefan Monnier <monnier@iro.umontreal.ca>,
miha@kamnitnik.top
Subject: bug#59693: 29.0.50; treesitter in base buffer doesn't respond to modifications in indirect buffer correctly
Date: Sun, 4 Dec 2022 15:21:10 -0800 [thread overview]
Message-ID: <DF79D7AF-9602-453D-B11D-61CC60A199EC@gmail.com> (raw)
In-Reply-To: <83sfhvbohm.fsf@gnu.org>
> On Dec 3, 2022, at 11:46 PM, Eli Zaretskii <eliz@gnu.org> wrote:
>
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Sat, 3 Dec 2022 23:20:59 -0800
>> Cc: miha@kamnitnik.top,
>> 59693@debbugs.gnu.org
>>
>>>>> We don’t want indirect buffer and base buffers to share parsers, since they can have different narrowing, and semantically indirect buffers should share anything but the text with the base buffer.
>>>>
>>>> Yes, the parsers should not be shared.
>>>>
>>>>> How about this: we change current_buffer->parser_list from a plain list of parsers to a cons (PARSER-LIST . INDIRECT-PARSER-LIST), where PARSER-LIST is as before. But for base buffers, INDIRECT-PARSER-LIST includes all the parsers of its indirect buffers; and for indirect buffers, INDIRECT-PARSER-LIST is nil.
>>>>
>>>> You can maybe have the indirect buffers in the list, not their parsers.
>>>> That could make it easier to access other treesit-related information of the
>>>> indirect buffers, if needed.
>>>
>>> Good idea, it’s easier to know when to remove the reference with buffers, aka when buffer is killed.
>>
>> I now have a patch that fixes this problem. WDYT? I added a new buffer field since it’s cleaner than turning ts_parser_list into a cons, hopefully that’s not frowned upon.
>
> Thanks.
>
> If we are adding to the buffer object a field that holds the list of
> indirect buffers, then:
>
> . the name of the field should not include "treesit" in it, and it
> shouldn't be conditioned on HAVE_TREE_SITTER
I made it tree-sitter specific and stated that it doesn’t necessarily contain all indirect buffers to simply the implementation. Right now new indirect buffer are added to the list only when a parser is created in an indirect buffer. And dead indirect buffers are discarded only when treesit_record_change runs. Do we really need a proper indirect buffer list? After all, no one complained about its absence ever since indirect buffer were added.
> . I wonder if a flat list is a good idea, i.e. scalable enough? also,
> treesit_reap_indirect_buffers conses a lot as result
AFAIK in most cases only a handful of indirect buffer are created, so I didn’t worry about that. For tree-sitter’s case, we need to iterate through every indirect buffer anyway so that’s always O(n). Adding and removing a buffer from the list is O(n) but they are done infrequently. The add operation is called every time a parser is created, and the remove operation is called once when an indirect buffer is killed.
We could use a hash table, but I doubt if that’s necessary, at least while the indirect buffer list is only used for tree-sitter. For tree-sitter, the common path is when we update each parser of buffer changes, which is always O(n) regardless of the data structure.
> . I vaguely remember that adding built-in fields to the buffer object had
> some caveats, but I don't recall the details (did you bootstrap?)
I built from git clean, so yeah.
>
> Stefan, any comments on this? Are there better ideas of how to track buffer
> text changes in indirect buffers?
Specifically, when any one of the base and indirect buffers change, we want all parsers in all base and indirect buffers to be updated.
Yuan
next prev parent reply other threads:[~2022-12-04 23:21 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-29 20:21 bug#59693: 29.0.50; treesitter in base buffer doesn't respond to modifications in indirect buffer correctly miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-30 10:17 ` Yuan Fu
2022-11-30 14:05 ` Eli Zaretskii
2022-12-02 5:05 ` Yuan Fu
2022-12-02 8:33 ` Eli Zaretskii
2022-12-03 1:01 ` Yuan Fu
2022-12-04 7:20 ` Yuan Fu
2022-12-04 7:46 ` Eli Zaretskii
2022-12-04 23:21 ` Yuan Fu [this message]
2022-12-05 3:49 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-05 8:19 ` Eli Zaretskii
2022-12-05 15:29 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-05 15:44 ` Eli Zaretskii
2022-12-05 20:14 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-06 2:15 ` Yuan Fu
2022-12-06 3:57 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-06 12:17 ` Eli Zaretskii
2022-12-07 23:13 ` Yuan Fu
2022-12-08 6:47 ` Eli Zaretskii
2022-12-10 1:41 ` Yuan Fu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DF79D7AF-9602-453D-B11D-61CC60A199EC@gmail.com \
--to=casouri@gmail.com \
--cc=59693@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=miha@kamnitnik.top \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.