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 21:22:07 +0200 Message-ID: <2331247.vFx2qVVIhK@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="5257"; 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 21:23:34 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 1sO095-00014A-Fw for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 30 Jun 2024 21:23:31 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sO08d-0001lz-UI; Sun, 30 Jun 2024 15:23:04 -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 1sO08c-0001lg-Ge for bug-gnu-emacs@gnu.org; Sun, 30 Jun 2024 15:23: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 1sO08c-00050N-5l for bug-gnu-emacs@gnu.org; Sun, 30 Jun 2024 15:23:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sO08b-0002l6-NA for bug-gnu-emacs@gnu.org; Sun, 30 Jun 2024 15:23:01 -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 19:23:01 +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 submit@debbugs.gnu.org id=B.171977533710545 (code B ref -1); Sun, 30 Jun 2024 19:23:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 30 Jun 2024 19:22:17 +0000 Original-Received: from localhost ([127.0.0.1]:59135 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sO07s-0002k1-HC for submit@debbugs.gnu.org; Sun, 30 Jun 2024 15:22:16 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:50944) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sO07p-0002js-Ko for submit@debbugs.gnu.org; Sun, 30 Jun 2024 15:22:15 -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 1sO07p-0001i9-AZ for bug-gnu-emacs@gnu.org; Sun, 30 Jun 2024 15:22:13 -0400 Original-Received: from mail-lj1-x233.google.com ([2a00:1450:4864:20::233]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sO07n-0004qa-Lq for bug-gnu-emacs@gnu.org; Sun, 30 Jun 2024 15:22:13 -0400 Original-Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2ebe40673e8so26072141fa.3 for ; Sun, 30 Jun 2024 12:22:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719775329; x=1720380129; darn=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=Yd++WDMhb76Nxx7Q6syZAlRbIUa8FJqYwtlBM1UOEx+5dBbJ3aByDZByO798h+5WLj zCdUVm/OD0WJpB6gKbnRAlXwnKEOPS4a40+t+vXotaUi/n8QEFAbmwwfE7+vjynusEq7 nNE6b8U3ekCVg0GmbMrg7KX7GvG6TVoVTrEpHGqFOHlmJ4IIUbvQ5DmtjYueGqVmzt5Z ZGdblXd2G3J2kOVzQQu6oFJtDjuu3GsEeWoCIjw8G2FhxLp5G+7dElpRb9pVktMKzSbn BEnXTTX4TRd2twuG0AbWSgLvLvKBiqHXr6AR71u/54Oyw2Vnru52H1mu0+a+7KgtA9OY KAQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719775329; x=1720380129; 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=G9PXs6KMibV1zTkPkuAiIC37YMKP2bjw09Q0ja83hwODupBKwLWzLqWm6irVNhGWRN SSKHerxcCvcYUcVdiiX0mU92iatiwxDSjUUnDSDzyYz3xZycQJISwEcHFl5tnnM4NVOc pYLS1F97/mRv3PLpX/BuYTlRWYEBLg6BIvow4PNJMIYsxGxa8RMPojSRvPLf8qFmDHd2 oIaT5iw3K+5v0WiBd5jX7L7puAdv7PL2vAqUikqNNLEG/aWBvugo4FU8fcDr5mGxPsTv r9MroHM3KfZr1VWiJpsg9vpTGZbuR8SvA42GHsGzhjGUZ248BmYux9ZqCF2sE2R8T/Y0 J6zw== X-Forwarded-Encrypted: i=1; AJvYcCXBOrtUDiOCm/S2YjnNYTW+OSdSYQG5pNdPdV3AlGkBNT5EXLc7N5LLPekBUlD2OeVP/LU8IMhEPeQp5/18Y9MAd6SYJ/s= X-Gm-Message-State: AOJu0YzD0CiK0FJPmw5gl+GsHlrnf7efdX4tq6KHMFMf567bNm2r3RXB khpRgKCP6GpOIZHUhNyv3gckzwzmMvHtCchSGE4E3ZbwBFEc0ZekHZaXH305wSk= X-Google-Smtp-Source: AGHT+IFySyKG7EhfRhewJv1fDzW/afOEdgTyMXk0FgIzPf3szhBQ22O/azTAKnBNvMA3O9z2uFv9bg== X-Received: by 2002:a05:6512:31c8:b0:52c:d84c:1182 with SMTP id 2adb3069b0e04-52e82744dc0mr2593075e87.64.1719775329217; Sun, 30 Jun 2024 12:22:09 -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-a72aaf63909sm265225466b.77.2024.06.30.12.22.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jun 2024 12:22:08 -0700 (PDT) In-Reply-To: <25A37A53-DD48-4E34-ABD7-1BACECCD8CEC@gmail.com> Received-SPF: pass client-ip=2a00:1450:4864:20::233; envelope-from=v.pupillo@gmail.com; helo=mail-lj1-x233.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:288220 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