all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Yuan Fu <casouri@gmail.com>
To: mail@ssbb.me
Cc: Wilhelm Kirschbaum <wkirschbaum@gmail.com>,
	Eli Zaretskii <eliz@gnu.org>,
	72863@debbugs.gnu.org
Subject: bug#72863: 30.0.50; tree-sitter elixir-ts-mode hangs and memory leak on some elixir and heex code
Date: Sat, 7 Sep 2024 22:44:53 -0700	[thread overview]
Message-ID: <6B5BA7D6-743D-4B12-903B-2852423A3C00@gmail.com> (raw)
In-Reply-To: <9B6747A4-4959-464C-82C2-3B58B2C04266@gmail.com>



> On Sep 4, 2024, at 9:32 PM, Yuan Fu <casouri@gmail.com> wrote:
> 
> 
> 
>> On Sep 4, 2024, at 12:42 AM, mail@ssbb.me wrote:
>> 
>> I can confirm that I never had such problems in heex-ts-mode but only with inline heex in elixir-ts-mode.
>> 
>>> On Sep 4, 2024, at 10:39 AM, Wilhelm Kirschbaum <wkirschbaum@gmail.com> wrote:
>>> 
>>> 
>>> 
>>> On Thu, Aug 29, 2024 at 8:14 AM Yuan Fu <casouri@gmail.com> wrote:
>>> 
>>> 
>>>> On Aug 28, 2024, at 10:09 PM, Eli Zaretskii <eliz@gnu.org> wrote:
>>>> 
>>>>> From: mail@ssbb.me
>>>>> Date: Thu, 29 Aug 2024 06:57:38 +0400
>>>>> 
>>>>> Code in attached file cause Emacs to hang and memory leak infinitely
>>>>> while editing. Try to open this code in elixir-ts-mode and move cursor
>>>>> on line 6 (between <:loading>  </:loading>) and type char by char:
>>>>> 
>>>>> <.some_component a={
>>>>> 
>>>>> (for some reason it does not happen with electric-pair-mode when {}
>>>>> inserted automatically).
>>>>> 
>>>>> I am able to reproduce this with -Q on few different machines (Linux and
>>>>> MacOS) and Emacs 29, 30.0.5 and current HEAD.
>>>>> 
>>>>> C-g does nothing (including with debug-on-quit and sending SIGUSR2)
>>>>> 
>>>>> At the same time I can't reproduce this in other tree-sitter based editors.
>>>>> 
>>>>> I got this sample code sample from elixir-ts-mode repo but now it's moved
>>>>> to the Emacs core so seems to be out of scope of Github repo issues.
>>>>> 
>>>>> Attaching samle code and LLDB backtrace. 
>>>>> Also attaching report from built-in MacOS crash reporting tool just in case.
>>>> 
>>>> Thanks.
>>>> 
>>>> Wilhelm and Yuan, could you please look into this soon?
>>> 
>>> That’s bizarre, might have some bug around ranges. I’m looking into this. Hopefully I can figure it out in a few days :-(
>>> 
>>> Yuan
>>> 
>>> I can reproduce the issue by following the above instructions, but need to do some digging. It only seems to be the case with embedded heex and not with heex-ts-mode by itself. 
>>> 
>>> WIlhelm
>>> 
> 
> At the moment I’m still not able to pinpoint the culprit, but here’s what I found: I can reproduce the issue by simply creating a heex parser, set the ranges to [108,240], [300,572], [820,1346] (these are byte position, aka one less than character position), then make it parse the buffer (with the "<.some_component a={" part already typed in. I instrumented the buffer reader and the program hangs after reading the character at byte position 908 (end of "phx-click={“). Also the hang appears in ts_parser_parse.
> 
> I wrote a C program that does exactly that, but the program runs fine without hanging. I haven’t found what Emacs does differently that causes the hang to happen.
> 
> Also I found some other range bug, but fixing those didn’t help this issue.

Still don’t have much progress. The buffer’s gap is at the beginning, and there’s no narrowing, which means the parser is really just reading a continues chunk of memory, there’s no reason why it should behave differently. At this point I might have to read tree-sitter’s source :-(

Meanwhile, I want to push the fix for the other bug I discovered to emacs-30. Eli, I wrote a debugging function that prints parser states, naturally this function isn’t called anywhere so there’ll be a compiler warning, what should I do in this case?

Yuan




  reply	other threads:[~2024-09-08  5:44 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-29  2:57 bug#72863: 30.0.50; tree-sitter elixir-ts-mode hangs and memory leak on some elixir and heex code mail
2024-08-29  5:09 ` Eli Zaretskii
2024-08-29  6:13   ` Wilhelm Kirschbaum
2024-08-29  6:14   ` Yuan Fu
2024-09-04  6:39     ` Wilhelm Kirschbaum
2024-09-04  7:42       ` mail
2024-09-05  4:32         ` Yuan Fu
2024-09-08  5:44           ` Yuan Fu [this message]
2024-09-08  5:54             ` Eli Zaretskii
2024-09-08  5:57               ` Yuan Fu
2024-09-08  7:02                 ` Eli Zaretskii
2024-09-08  7:48                   ` Yuan Fu
2024-09-11  3:45                     ` Yuan Fu
2024-09-11 19:22                       ` mail
2024-09-12  7:47                         ` Yuan Fu
2024-09-16  6:58                           ` Wilhelm Kirschbaum

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=6B5BA7D6-743D-4B12-903B-2852423A3C00@gmail.com \
    --to=casouri@gmail.com \
    --cc=72863@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=mail@ssbb.me \
    --cc=wkirschbaum@gmail.com \
    /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.