From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#59574: 29.0.50; Emacs crashes when using tree-sitter-based mode in an empty buffer Date: Sat, 26 Nov 2022 16:31:59 +0200 Message-ID: <83k03hss68.fsf@gnu.org> References: <837czjulc4.fsf@gnu.org> <6350D0DE-63CD-410A-AA48-56D924ED67EA@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9559"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 59574-done@debbugs.gnu.org To: Yuan Fu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 26 15:32:31 2022 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 1oywEI-0002E9-Cn for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 26 Nov 2022 15:32:30 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oywDx-0004fo-68; Sat, 26 Nov 2022 09:32:09 -0500 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 1oywDu-0004fS-L8 for bug-gnu-emacs@gnu.org; Sat, 26 Nov 2022 09:32:08 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oywDq-0003l3-EX for bug-gnu-emacs@gnu.org; Sat, 26 Nov 2022 09:32:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oywDq-0005Jz-BL for bug-gnu-emacs@gnu.org; Sat, 26 Nov 2022 09:32:02 -0500 Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Sat, 26 Nov 2022 14:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 59574 X-GNU-PR-Package: emacs Mail-Followup-To: 59574@debbugs.gnu.org, eliz@gnu.org, eliz@gnu.org Original-Received: via spool by 59574-done@debbugs.gnu.org id=D59574.166947310220425 (code D ref 59574); Sat, 26 Nov 2022 14:32:02 +0000 Original-Received: (at 59574-done) by debbugs.gnu.org; 26 Nov 2022 14:31:42 +0000 Original-Received: from localhost ([127.0.0.1]:38326 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oywDV-0005JN-PS for submit@debbugs.gnu.org; Sat, 26 Nov 2022 09:31:42 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:49922) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oywDU-0005JA-Az for 59574-done@debbugs.gnu.org; Sat, 26 Nov 2022 09:31:40 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oywDO-0003gG-KV; Sat, 26 Nov 2022 09:31:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=1+KuwH6EBF4cflVptiDxNCb7IlGjQqaqSYuQixPBdDQ=; b=dfY61H6iIqYbhrg71SSU of+qtPuBJaGiu4VgbhoeiaSbhvkjk1YlrBbu1pM6OHrxJ7hnfLAF6fhOCxfd5TzwkW03y2iOQMSif fQaXs0Hs9ebyKaUsAU0hXYO+tndzTkuYS+QHRx/YRavfEg5G4mSBbkRNeG1IhdRGyV7mxhjec7a4B iuayll0g9axWozrpMZygxBWRCvBOP6iFW2COtwpN9oxca/k73oq3gcjamTiMLaVnycikmrW/13wHH C+91MVLtNh5gcfZfblwRG73IiAuDbACMhbwmJTWM6jq6wQ9JNb1jVboSHWHjyYvLq9hKRGKxD/H8K puY+T7JWikT+kQ==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oywDN-0006f5-0s; Sat, 26 Nov 2022 09:31:33 -0500 In-Reply-To: <6350D0DE-63CD-410A-AA48-56D924ED67EA@gmail.com> (message from Yuan Fu on Fri, 25 Nov 2022 19:18:09 -0800) 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:249098 Archived-At: > From: Yuan Fu > Date: Fri, 25 Nov 2022 19:18:09 -0800 > Cc: 59574@debbugs.gnu.org > > > There's also something strange in treesit_record_change: when it is called > > for the first time in a buffer which was empty and you insert one character, > > we bypass the updating of visible_beg and visible_end fields of the Lisp > > parser object, because XTS_PARSER (lisp_parser)->tree is NULL. But it looks > > to me that we should still update these two fields regardless, no? Only the > > call to treesit_tree_edit_1 needs the tree. (I thought that maybe this lack > > of update explains the assertion, but even if I move the condition to guard > > only treesit_tree_edit_1, the assertion still happens, so I guess my > > hypothesis eats dust.) > > We don’t need to update visible_beg/end in treesit_record_change if tree is NULL, because visible_beg/end represents the range of buffer that the tree sees, so if there is no tree, visible_beg/end can be considered uninitialized. However you are right about needing to update visible_beg/end, but in treesit_ensure_position_synced (I renamed it to treesit_sync_visible_region): that’s where we ensure visible_beg/end equals to BUF_BEGV_BYTE/friends. > > The problem is we don’t update visible_beg/end for the very first parse, when tree is NULL. > > I also added some comments, hopefully they sufficiently explain everything. Thanks, the problem is gone, so I'm closing the bug.