From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Vincenzo Pupillo Newsgroups: gmane.emacs.bugs Subject: bug#71681: 29.3.50; tree-sitter crash Date: Sun, 30 Jun 2024 16:28:53 +0200 Message-ID: <4943193.OV4Wx5bFTl@fedora> References: <86h6dny3om.fsf@mail.linkov.net> <25A37A53-DD48-4E34-ABD7-1BACECCD8CEC@gmail.com> Mime-Version: 1.0 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="11503"; mail-complaints-to="usenet@ciao.gmane.io" Cc: casouri@gmail.com To: juri@linkov.net, 71681@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jun 30 16:30:24 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 1sNvZQ-0002lx-8r for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 30 Jun 2024 16:30:24 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sNvZ7-0007r2-UB; Sun, 30 Jun 2024 10:30:07 -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 1sNvZ5-0007qi-7o for bug-gnu-emacs@gnu.org; Sun, 30 Jun 2024 10:30:03 -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 1sNvZ4-0008W4-Tz for bug-gnu-emacs@gnu.org; Sun, 30 Jun 2024 10:30:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sNvZ4-0005s7-PD for bug-gnu-emacs@gnu.org; Sun, 30 Jun 2024 10:30:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Vincenzo Pupillo Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 30 Jun 2024 14:30:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71681 X-GNU-PR-Package: emacs X-Debbugs-Original-To: Juri Linkov , bug-gnu-emacs@gnu.org X-Debbugs-Original-Cc: Yuan Fu , 71681@debbugs.gnu.org Original-Received: via spool by 71681-submit@debbugs.gnu.org id=B71681.171975779822525 (code B ref 71681); Sun, 30 Jun 2024 14:30:02 +0000 Original-Received: (at 71681) by debbugs.gnu.org; 30 Jun 2024 14:29:58 +0000 Original-Received: from localhost ([127.0.0.1]:58622 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sNvZ0-0005rF-7X for submit@debbugs.gnu.org; Sun, 30 Jun 2024 10:29:58 -0400 Original-Received: from mail-ej1-f48.google.com ([209.85.218.48]:55322) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sNvYx-0005r6-S8 for 71681@debbugs.gnu.org; Sun, 30 Jun 2024 10:29:56 -0400 Original-Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a689ad8d1f6so250447966b.2 for <71681@debbugs.gnu.org>; Sun, 30 Jun 2024 07:29:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719757735; x=1720362535; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YAp8aCFvHnb3pV1dewhzoQ2ljD8HZMV5DmVna7+zUSM=; b=SljGRjyK9PARvdkVnIlMDVZRvEfbS762tQ4KtlZ/ezRVgxnk/aNglG8ge/n5TCU9nJ gdtylJxV/NCXZeZJr1nyqMy8Q/oiHNyra2PbSa8/HcnSr8X6l4WfK0I1B7xhTHKIIpnK 6vrmIFJ26xLe5//MoNIAxfMea4dnXX/5bu4jYtJ/y2sj4RjEKDV28ISa4muX8fXFOZuZ Ngor0kGCG1mOCiKmR92qle2ZZlYnD0skf6J8n5e+VgClq/OwAl5Fv/Y7OQbPxNdWmKjT JuD9oKc9XRIU9ti3mpwFd+zoI50cXG3CrY880q7ydN6zUCj//sajEvfFTFISzBtKCVvb EJCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719757735; x=1720362535; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YAp8aCFvHnb3pV1dewhzoQ2ljD8HZMV5DmVna7+zUSM=; b=detD0BmHT1YNUuviF8HxtcD+zrT7PYo6dQPpLEqZAmRjTLG8MVybh/wBI5Mt9iz/pU ZIiLBpE3CoysAeujrLLjM06rC7YClbB5jwpWBQl4S9e9OLWDbxwHUx2sp12VCZlR0ooh XxVKXBSLgjYYNiVAYtqE+DBZ1DqN364AbkdjRZQ8vwaIrz+qyO/MQ8RAgp87x5N18u4a kR+kPmBsLDGOL4TGDmHP65LhwRK7IxtWu5aCGptv0fPfYCCCSCVcCK9LMCAuyIj7MLl5 5rp/t0cbM+ryjswOozafurD9/bZhEZ6o5h0KM6YYoOU0p45C7m6PkEXMvq1+8KJYjj0z UOmg== X-Gm-Message-State: AOJu0YzgtoE8EtN0zIB6xXV30KcQdDwYE/OJgrxtI8TFLqcfzHqZYDPn 8SnHnAWdlMafL9vuTxpbxo3lM0hL9jM3UxMDXD2+z5aHScKlMsrh X-Google-Smtp-Source: AGHT+IEt+PhydDjLXFZ13npeF1vfQrVSe2rTVHMPU4y/rDH1nWH4slEv8GghOdVSFW90AptWznuP/g== X-Received: by 2002:a17:907:104b:b0:a72:65e5:3e7 with SMTP id a640c23a62f3a-a7514441510mr201068166b.55.1719757734714; Sun, 30 Jun 2024 07:28:54 -0700 (PDT) Original-Received: from fedora.localnet (2-230-139-124.ip202.fastwebnet.it. [2.230.139.124]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a72aaf1843fsm244440666b.39.2024.06.30.07.28.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jun 2024 07:28:54 -0700 (PDT) In-Reply-To: <25A37A53-DD48-4E34-ABD7-1BACECCD8CEC@gmail.com> 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:288194 Archived-At: Today I did a git pull of the master branch. Is it possible that this patch is the cause of this error? Error muted by safe_call: (treesit--font-lock-mark-ranges-to-fontify ((1 .= =20 8867)) #) signaled (wrong-type-argument treesit-nod= e-p=20 #) Error during redisplay: (jit-lock-function 1) signaled (wrong-type-argument= =20 treesit-node-p #) Vincenzo In data domenica 30 giugno 2024 01:54:39 CEST, Yuan Fu ha scritto: > > On Jun 25, 2024, at 11:04=E2=80=AFPM, Yuan Fu wrote: > >> On Jun 24, 2024, at 12:46=E2=80=AFAM, Yuan Fu wrot= e: > >>> On Jun 23, 2024, at 10:38=E2=80=AFAM, Juri Linkov w= rote: > >>>>> Evaluating this expression causes a crash: > >>>>>=20 > >>>>> (progn > >>>>> (find-file (expand-file-name "src/treesit.c" installation-directory= )) > >>>>> (c-ts-mode) > >>>>> (font-lock-ensure 63209 63387)) > >>>>>=20 > >>>>> in latest master, but not in latest emacs-29 (only in 5-months old > >>>>> emacs-29). > >>>>>=20 > >>>>> If this is not reproducible, I could provide more details. > >>>>>=20 > >>>>> libtree-sitter is at the latest version. > >>>>=20 > >>>> Hmm, I can=E2=80=99t reproduce with latest master and libtree-sitter= =2E Maybe you > >>>> can send me the exact commits that you used? > >>>>=20 > >>>> Here=E2=80=99s mine: > >>>>=20 > >>>> Emacs: 72f2b01e318 > >>>> Tree-sitter: 6ec478c1 > >>>=20 > >>> Probably reproducibility depends on the content of the src/treesit.c > >>> file. > >>> Then the most reliable way to reproduce it is this: > >>>=20 > >>> 0. emacs -Q > >>> 1. eval: (add-to-list 'major-mode-remap-alist '(c-mode . c-ts-mode)) > >>> 2. C-x v L > >>> 3. in the *vc-change-log* buffer move point to the commit 20af58d3a13 > >>> 4. type D > >>> 5. crash caused by diff-font-lock-syntax fontification that uses tree= sit > >>>=20 > >>> The numbers in (font-lock-ensure 63209 63387) above were extracted > >>> from diff hunk boundaries that might be different when the file was > >>> edited. > >>=20 > >> I reproduce it once with the first set of commits you provided, but for > >> some reason couldn=E2=80=99t reproduce it again. I=E2=80=99m sure it= =E2=80=99s something wrong > >> that I did. I=E2=80=99ll report back when I make progress. TBH it seem= s like > >> something wrong with tree-sitter itself, but I=E2=80=99ll make sure to= figure > >> out what=E2=80=99s the problem exactly. > >>=20 > >> Yuan > >=20 > > Ok, I can reproduce it now. Looking into it=E2=80=A6 >=20 > Finally figured out why. It=E2=80=99s not tree-sitter=E2=80=99s problem, = but ours. I reduced > the crash to a signal and pushed the fix to emacs-30. Next I=E2=80=99ll m= ake sure > the signal is properly handled. Below quoting the commit message: >=20 > The immediate cause of the crash is that tree-sitter accessed a node's > tree, but the tree is already deleted. >=20 > What happended, I think, is this: >=20 > 1. Buffer modified, parser->need_reparse set to true, > parser->timestamp incremented. > 2. A node is created from the parser, this node has the old tree but > the _new_ timestamp (bad!). > 3. Parser re-parses (treesit_ensure_parsed), new tree created, old > tree deleted. > 4. Ftreesit_query_capture accessed the old node, and the old tree, > crash. >=20 > We shouldn't bump the parser timestamp when we set > parser->need_reparse to true; instead, we should bump the timestamp > when we actually reparsed and created a new tree. >=20 > Yuan