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#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 Message-ID: <6B5BA7D6-743D-4B12-903B-2852423A3C00@gmail.com> References: <94F9A716-7D86-42F9-A010-54501ACF9AF8@ssbb.me> <861q27hq4a.fsf@gnu.org> <0F8C0C10-A357-464F-9863-DED85B80D6C8@ssbb.me> <9B6747A4-4959-464C-82C2-3B58B2C04266@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51\)) 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="10277"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Wilhelm Kirschbaum , Eli Zaretskii , 72863@debbugs.gnu.org To: mail@ssbb.me Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Sep 08 07:47:22 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 1snAld-0002UO-AL for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 08 Sep 2024 07:47:21 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1snAlN-0003KM-0e; Sun, 08 Sep 2024 01:47:05 -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 1snAlJ-0003K5-MY for bug-gnu-emacs@gnu.org; Sun, 08 Sep 2024 01:47:02 -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 1snAlI-0008SK-FZ for bug-gnu-emacs@gnu.org; Sun, 08 Sep 2024 01:47:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=References:Date:In-Reply-To:From:Mime-Version:To:Subject; bh=xNE5mRBlC4a7NlvN9jUd+D9lgp5RfMnhEBh5Foue3dY=; b=KLlCgzWqj/qfW/ylkoVSCco8pWfa7STkxFvsX5dn9Lbt2h1h4Un6wMqfAyXNgoCyzuliGAVRr0hZNE2lg5faeKM10FwhLiNtZIfO4eJVP4FBxDHEoHeE6lZS8zqqWYwLCSeYA8r9WkQ/cBoVN576aLEjNQsKa+i7PoI9jUbnV+qkQGwz7NZT6v13mNpZhJlKZYGj9bkrR+SVjApAjbu4mx+4pGKEV3MUNTpcFvKhtdXDsIl0j9CwAIIim2Zqdq0iBybs3brsxL5SOTi2PgNBfA5maDT/f+TZwJ60zcvwhSp3LtSjVHQ4YW1rUiaOeYITGy4/yODiS6n8+IMplfogyw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1snAlJ-0005zN-RZ for bug-gnu-emacs@gnu.org; Sun, 08 Sep 2024 01:47:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 08 Sep 2024 05:47:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72863 X-GNU-PR-Package: emacs Original-Received: via spool by 72863-submit@debbugs.gnu.org id=B72863.172577437722941 (code B ref 72863); Sun, 08 Sep 2024 05:47:01 +0000 Original-Received: (at 72863) by debbugs.gnu.org; 8 Sep 2024 05:46:17 +0000 Original-Received: from localhost ([127.0.0.1]:57856 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1snAkb-0005xw-Bn for submit@debbugs.gnu.org; Sun, 08 Sep 2024 01:46:17 -0400 Original-Received: from mail-oi1-f178.google.com ([209.85.167.178]:51667) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1snAkW-0005xa-IB for 72863@debbugs.gnu.org; Sun, 08 Sep 2024 01:46:15 -0400 Original-Received: by mail-oi1-f178.google.com with SMTP id 5614622812f47-3e034fac53bso1031260b6e.3 for <72863@debbugs.gnu.org>; Sat, 07 Sep 2024 22:46:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725774305; x=1726379105; darn=debbugs.gnu.org; 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=xNE5mRBlC4a7NlvN9jUd+D9lgp5RfMnhEBh5Foue3dY=; b=H6kZQvBbcxKIXwOe0zTqih1cJkqDB7Hs1gRUivoiClZokvcUiBdwn5b/wBkJ3VKVcu 3TrVX9mn50FOgZ47aC2rjeVKm1tWd9y0Zzy2QEf3fxYTELPD2zEJTval+FSZPbB2+ljb WEEPShSQdAZrx/+QtampvpWcyz8BSCIsDID3+igEpylFNXMzues3XReQOQdTEaCj4Fxj jfeZTvM/ulDsy44c3GpnfMUbmlmD/Pt+v7B3f+bnTMCoyHm0YMWV84PcXW/3zqYzkC8p 9n6rw2oLhhCCQOepvqpwhcAcYHrvXkt+SO6BPELBYKDdRmLC2k8Pt4qCbmKHK038paon DEzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725774305; x=1726379105; 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=xNE5mRBlC4a7NlvN9jUd+D9lgp5RfMnhEBh5Foue3dY=; b=Y2tBAPKvUoSplUi9UCzOlbkLIs4/mzneJWYZreW86D5uj58Mg0VR6K/EqKR/Z2BmQ7 rpbN/UVkmwL4w+/dgC0vomuw7RMRVmbtTmW6JhjW3cQaQZPC05CMzx85CgC4aL7RSMoJ 96b1E/KCurVzXvpzhcVptZqtlpoT/SnQ4DgN/i0cVHhdkNUwrRdmEImtdezUGJQzYewO TI4wfl/dpb6EFin/TLxRi0sVcacBcQvAOdK4ELAogAjd2EF+WUn4cTkTq6EI39qnsf17 7lNjZdKnWUJkKh4+RmOZmnzxY8WdiDaHLvgye3lo9qSLaW0luv9Cn2H8AubLxw3DDOha DN7g== X-Forwarded-Encrypted: i=1; AJvYcCVCsLTXd4Lisi+yRInpg2/Ntz16uZUHLjTACcWu65zwQnbQNmeS2Q1ulRAz7Rc8p66+Ka49Ng==@debbugs.gnu.org X-Gm-Message-State: AOJu0YwvPMMnLICXa2Cq1AYcytTeIDpoooj8vHUQ/FpKhAYLAW1F1D1K P7YMY4Hj/4kQ3+FgUZcQzywYHMmq+YSazLpDNwamS+4T29Yr36KT X-Google-Smtp-Source: AGHT+IGMOBmokeZU9LIlgWlCRdfqS4Bs0WLDr5tIcUkV9puNlSDye8qZOfqnp+Ej4TPTIoOZbNyzPg== X-Received: by 2002:a05:6808:16aa:b0:3dc:299d:c505 with SMTP id 5614622812f47-3e02a024920mr8145567b6e.37.1725774304816; Sat, 07 Sep 2024 22:45:04 -0700 (PDT) Original-Received: from smtpclient.apple ([2601:646:8f81:6120:9947:7537:5948:e5a0]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-718e5982c7fsm1617177b3a.151.2024.09.07.22.45.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 Sep 2024 22:45:04 -0700 (PDT) In-Reply-To: <9B6747A4-4959-464C-82C2-3B58B2C04266@gmail.com> X-Mailer: Apple Mail (2.3776.700.51) 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:291419 Archived-At: > On Sep 4, 2024, at 9:32=E2=80=AFPM, Yuan Fu wrote: >=20 >=20 >=20 >> On Sep 4, 2024, at 12:42=E2=80=AFAM, mail@ssbb.me wrote: >>=20 >> I can confirm that I never had such problems in heex-ts-mode but only = with inline heex in elixir-ts-mode. >>=20 >>> On Sep 4, 2024, at 10:39=E2=80=AFAM, Wilhelm Kirschbaum = wrote: >>>=20 >>>=20 >>>=20 >>> On Thu, Aug 29, 2024 at 8:14=E2=80=AFAM Yuan Fu = wrote: >>>=20 >>>=20 >>>> On Aug 28, 2024, at 10:09=E2=80=AFPM, Eli Zaretskii = wrote: >>>>=20 >>>>> From: mail@ssbb.me >>>>> Date: Thu, 29 Aug 2024 06:57:38 +0400 >>>>>=20 >>>>> 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> ) and type char by char: >>>>>=20 >>>>> <.some_component a=3D{ >>>>>=20 >>>>> (for some reason it does not happen with electric-pair-mode when = {} >>>>> inserted automatically). >>>>>=20 >>>>> I am able to reproduce this with -Q on few different machines = (Linux and >>>>> MacOS) and Emacs 29, 30.0.5 and current HEAD. >>>>>=20 >>>>> C-g does nothing (including with debug-on-quit and sending = SIGUSR2) >>>>>=20 >>>>> At the same time I can't reproduce this in other tree-sitter based = editors. >>>>>=20 >>>>> 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. >>>>>=20 >>>>> Attaching samle code and LLDB backtrace.=20 >>>>> Also attaching report from built-in MacOS crash reporting tool = just in case. >>>>=20 >>>> Thanks. >>>>=20 >>>> Wilhelm and Yuan, could you please look into this soon? >>>=20 >>> That=E2=80=99s bizarre, might have some bug around ranges. I=E2=80=99m= looking into this. Hopefully I can figure it out in a few days :-( >>>=20 >>> Yuan >>>=20 >>> 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.=20 >>>=20 >>> WIlhelm >>>=20 >=20 > At the moment I=E2=80=99m still not able to pinpoint the culprit, but = here=E2=80=99s 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=3D{" 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=3D{=E2=80=9C). Also the hang appears in ts_parser_parse. >=20 > I wrote a C program that does exactly that, but the program runs fine = without hanging. I haven=E2=80=99t found what Emacs does differently = that causes the hang to happen. >=20 > Also I found some other range bug, but fixing those didn=E2=80=99t = help this issue. Still don=E2=80=99t have much progress. The buffer=E2=80=99s gap is at = the beginning, and there=E2=80=99s no narrowing, which means the parser = is really just reading a continues chunk of memory, there=E2=80=99s no = reason why it should behave differently. At this point I might have to = read tree-sitter=E2=80=99s 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=E2=80=99t called anywhere so there=E2=80=99ll = be a compiler warning, what should I do in this case? Yuan=