Subject: bug#72863: 30.0.50; tree-sitter elixir-ts-mode hangs and memory leak on some elixir and heex code

From: [email-masked]
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.

In GNU Emacs 30.0.50 (build 1, aarch64-apple-darwin23.2.0, NS
 appkit-2487.30 Version 14.2.1 (Build 23C71)) of 2024-06-23 built on
 Sviatoslavs-MacBook-Pro.local
Windowing system distributor 'Apple', version 10.3.2487
System Description:  macOS 14.2.1

Configured using:
 'configure --disable-dependency-tracking --disable-silent-rules
 --enable-locallisppath=/opt/homebrew/share/emacs/site-lisp
 --infodir=/opt/homebrew/Cellar/emacs-plus@30/30.0.50/share/info/emacs
 --prefix=/opt/homebrew/Cellar/emacs-plus@30/30.0.50 --with-xml2
 --with-gnutls --with-native-compilation --without-compress-install
 --without-dbus --without-imagemagick --with-modules --with-rsvg
 --with-webp --with-ns --disable-ns-self-contained 'CFLAGS=-Os -w -pipe
 -mmacosx-version-min=14
 -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk
 -DFD_SETSIZE=10000 -DDARWIN_UNLIMITED_SELECT
 -I/opt/homebrew/opt/gcc/include -I/opt/homebrew/opt/libgccjit/include'
 'CPPFLAGS=-I/opt/homebrew/opt/zlib/include
 -I/opt/homebrew/opt/jpeg/include -I/opt/homebrew/opt/icu4c/include
 -I/opt/homebrew/opt/sqlite/include -I/opt/homebrew/opt/readline/include
 -isystem/opt/homebrew/include -F/opt/homebrew/Frameworks
 -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk'
 'LDFLAGS=-L/opt/homebrew/opt/zlib/lib -L/opt/homebrew/opt/jpeg/lib
 -L/opt/homebrew/opt/icu4c/lib -L/opt/homebrew/opt/sqlite/lib
 -L/opt/homebrew/opt/readline/lib -L/opt/homebrew/lib
 -F/opt/homebrew/Frameworks -Wl,-headerpad_max_install_names
 -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk
 -L/opt/homebrew/lib/gcc/14 -I/opt/homebrew/opt/gcc/include
 -I/opt/homebrew/opt/libgccjit/include''