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#71681: 29.3.50; tree-sitter crash Date: Sat, 29 Jun 2024 16:54:39 -0700 Message-ID: <25A37A53-DD48-4E34-ABD7-1BACECCD8CEC@gmail.com> References: <86h6dny3om.fsf@mail.linkov.net> <9D0E4C93-9CCC-4C0E-BDF7-CB6F09132C23@gmail.com> <86o77rpnjz.fsf@mail.linkov.net> <74F62063-1C20-4257-92BA-F2CF02B9A588@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.600.62\)) 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="2168"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 71681@debbugs.gnu.org To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jun 30 01:56: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 1sNhvb-0000KG-TR for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 30 Jun 2024 01:56:24 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sNhvI-0004hg-Vj; Sat, 29 Jun 2024 19:56: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 1sNhvH-0004hV-Rn for bug-gnu-emacs@gnu.org; Sat, 29 Jun 2024 19:56: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 1sNhvH-0003v5-J1 for bug-gnu-emacs@gnu.org; Sat, 29 Jun 2024 19:56:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sNhvG-0005x6-48 for bug-gnu-emacs@gnu.org; Sat, 29 Jun 2024 19:56:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 29 Jun 2024 23:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71681 X-GNU-PR-Package: emacs Original-Received: via spool by 71681-submit@debbugs.gnu.org id=B71681.171970536022872 (code B ref 71681); Sat, 29 Jun 2024 23:56:02 +0000 Original-Received: (at 71681) by debbugs.gnu.org; 29 Jun 2024 23:56:00 +0000 Original-Received: from localhost ([127.0.0.1]:54153 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sNhvE-0005wq-Bb for submit@debbugs.gnu.org; Sat, 29 Jun 2024 19:56:00 -0400 Original-Received: from mail-oo1-f47.google.com ([209.85.161.47]:47145) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sNhvA-0005wb-VF for 71681@debbugs.gnu.org; Sat, 29 Jun 2024 19:55:58 -0400 Original-Received: by mail-oo1-f47.google.com with SMTP id 006d021491bc7-5c405dad8b6so836617eaf.2 for <71681@debbugs.gnu.org>; Sat, 29 Jun 2024 16:55:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719705291; x=1720310091; 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=kdD0Jv2bTEw+Ke3+PejQMTzqeolRrdAg250gz9l899E=; b=RJKoN1dxwXlnWTeVelFBIJxeZgHJWmxi9xJwknJXN1ahspDHWCJ9hi+KAn1zZcwVnp Tvrdbb9HFrsEBXBAf5oYHQ98XBS0D0viXkgh+WcBzKqGuIGSiMGE4YVK0eV0qlJg7n5v PQGN4uTjoJNwK23njy64jNfIQUvq4/XP0dEYWmmcDoVssWyklzQ5rPzqcgxvQTnCk/Js ODoVEiVcPx+73hJxTcsGUVLzYgTIad32jL07IvvfltUQqiC+iFMJWPrxeJP8suzuRtmO RqRvqgg+cB5XVtFxoYS5TOio4iS9ZGDsCOJF5aaO7ICoGqCP//SYAPKwFeVlbI658u5e LDSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719705291; x=1720310091; 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=kdD0Jv2bTEw+Ke3+PejQMTzqeolRrdAg250gz9l899E=; b=aWj8GqT07Y57a4GEkS8+TrGDb4yyU2yj1BK5kvoYldvRX07WiwP5wHmQpWBpZP/2/l XjpmMD9upgjNhQM4BNExXnjJmJNestIKveib9HIIDkeftQsEEMxWtqt74IeIA4oXYHtU irHebff0XzD0JiorVanVqC4IIoI8HI5A6vYeg3cbO0NPe2T2mCoLJDe8O6HwSCeoxSpW Uc3Q+Rd/I2M1CNwxWw8cPNXRQgfSYlnsuETVUiHTj2LHB6qfroa3Mfj3md0Hy6/DISny A8pJCPmy7v8ttaz8Eg0RGZaaGduWcEGq0YcjzRX1awN7gRjGi+fGD063XJkmWW1pN1FL CFrw== X-Gm-Message-State: AOJu0Yy2XGUgX7Hztw/YfrMjA+XyM8Bb6uwnOfL3KFN1U9N0sxG33meX ASwXfLJ5iAlsqCrTyH1GG2xtDVtAn57ER+4WBoi+afS2oW/EfLJI X-Google-Smtp-Source: AGHT+IE/FKoOMYTUKQBed6/qvPADxoAtw0Zs2dOCXUxOcZvDkuVacpwNL56NRKSz2VzxfPLVwFUqkQ== X-Received: by 2002:a05:6870:648a:b0:25c:4d88:3d70 with SMTP id 586e51a60fabf-25db35cda8cmr1979249fac.59.1719705291250; Sat, 29 Jun 2024 16:54:51 -0700 (PDT) Original-Received: from smtpclient.apple ([2601:646:8f81:6120:905e:641:dacc:2f83]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c91ce16888sm3918798a91.2.2024.06.29.16.54.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Jun 2024 16:54:50 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.3774.600.62) 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:288140 Archived-At: > On Jun 25, 2024, at 11:04=E2=80=AFPM, Yuan Fu = wrote: >=20 >=20 >=20 >> On Jun 24, 2024, at 12:46=E2=80=AFAM, Yuan Fu = wrote: >>=20 >>=20 >>=20 >>> On Jun 23, 2024, at 10:38=E2=80=AFAM, Juri Linkov = wrote: >>>=20 >>>>> 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. 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 = treesit >>>=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 seems 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 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 make sure the signal is properly handled. = Below quoting the commit message: The immediate cause of the crash is that tree-sitter accessed a node's tree, but the tree is already deleted. What happended, I think, is this: 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. 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. Yuan=