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#61356: 29.0.60; wrong-type-argument in treesit-indent-region when indenting a C buffer Date: Fri, 24 Feb 2023 21:21:11 -0800 Message-ID: References: <83a61nm96q.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.400.51.1.1\)) 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="2914"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 61356@debbugs.gnu.org, Eli Zaretskii , Theodor Thornhill To: Daniel =?UTF-8?Q?Mart=C3=ADn?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Feb 25 06:22:28 2023 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 1pVn0u-0000Ym-1M for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 25 Feb 2023 06:22:28 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVn0a-0006cq-K1; Sat, 25 Feb 2023 00:22:08 -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 1pVn0W-0006cf-Uu for bug-gnu-emacs@gnu.org; Sat, 25 Feb 2023 00:22:06 -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 1pVn0U-0000g1-Pv for bug-gnu-emacs@gnu.org; Sat, 25 Feb 2023 00:22:04 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pVn0U-0007id-3z for bug-gnu-emacs@gnu.org; Sat, 25 Feb 2023 00:22:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 25 Feb 2023 05:22:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61356 X-GNU-PR-Package: emacs Original-Received: via spool by 61356-submit@debbugs.gnu.org id=B61356.167730249129631 (code B ref 61356); Sat, 25 Feb 2023 05:22:02 +0000 Original-Received: (at 61356) by debbugs.gnu.org; 25 Feb 2023 05:21:31 +0000 Original-Received: from localhost ([127.0.0.1]:38804 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pVmzz-0007hq-3G for submit@debbugs.gnu.org; Sat, 25 Feb 2023 00:21:31 -0500 Original-Received: from mail-pl1-f182.google.com ([209.85.214.182]:39462) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pVmzx-0007hd-D3 for 61356@debbugs.gnu.org; Sat, 25 Feb 2023 00:21:30 -0500 Original-Received: by mail-pl1-f182.google.com with SMTP id i3so1590370plg.6 for <61356@debbugs.gnu.org>; Fri, 24 Feb 2023 21:21:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=79VaWIuE7Ycv4VmPjmJS0sPFXZmfesMQV7wPR8D6HWU=; b=pClS5Tm2Xcbt7ifEFUB4y99UCA9Fsuf/1uP+toWJ2O1IUrDghpNP+1VcNEsJJRG+6b Qz/+0hmlwhLefPJ3j2c1ys6iZfYh5giBAUxSEfQdq6ZXny1kYfQ52erQoOUJXM2BICWg ASiMUbr94hJmPRW60AOeRp4GD7BEiS2mhVwWzRQcmhFboduVFOWxQVIE0FqBccxfTmfi abtc+vHv6mXhgyZ5undY10F2eSp+qS0wnFgHuzndz78OgUPpy5dnk+zgkmVRw2zj0R2U 3ixeZbwPp7pmaA+GI+nJgVZWX7v+A8u2UIninwbGj6Mnbg5wC+CHr2/P3Y4mB9Rl6Ygd bnyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=79VaWIuE7Ycv4VmPjmJS0sPFXZmfesMQV7wPR8D6HWU=; b=g0jTGN7Ejhe/T+azuJsHeZQVF+A7ns7luoxA6BXBuRC/RAzvPiXy/AnPMNzYeWo0cs L9jSdi/hceS7zjQVFbLS16dP9mfo6vEjE7l/DDuZOwLWJHELCKcnGoOJ6oc3bpoy8yCf ioIY5mw73A9xlNK/i9PwB81Uj0PuTTQzYQiBm5U3e+6bzcCi9pFay69aktpGvXSNDitK i4bK+6Ty0MB/kYd8WnJuFW9mrlKtk3vLZ1wRopxor5dfJoLUF/mfva4Y2AHrC51ZzSGV 4v9h/cafa98bFfD/b11+br4uVBoguWLVTOf9LWq3NtNHYz81p3aTBIMqsq4ydxgKlh17 3y0Q== X-Gm-Message-State: AO0yUKUmmIoEC25VW2blyCBmL/2rLZUFzogTick4SYu3s+deFVX2A1Cd sbl62GKTmPCG0zUz2eTIqA8= X-Google-Smtp-Source: AK7set8CSN8gZLAchXfhBe6lWKYKTu1s5UPb47bSWVwVvK4U40N7+1dww2Ogm5188//XBiP9nlY7UA== X-Received: by 2002:a17:90a:1c8:b0:233:d870:f4c7 with SMTP id 8-20020a17090a01c800b00233d870f4c7mr21056756pjd.21.1677302483491; Fri, 24 Feb 2023 21:21:23 -0800 (PST) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id gt15-20020a17090af2cf00b00233aacab89esm474413pjb.48.2023.02.24.21.21.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Feb 2023 21:21:23 -0800 (PST) In-Reply-To: X-Mailer: Apple Mail (2.3731.400.51.1.1) 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:256682 Archived-At: > On Feb 24, 2023, at 6:24 PM, Daniel Mart=C3=ADn = wrote: >=20 > Eli Zaretskii writes: >=20 >>> Date: Tue, 07 Feb 2023 23:20:09 +0100 >>> From: Daniel Mart=C3=ADn via "Bug reports for GNU Emacs, >>> the Swiss army knife of text editors" >>>=20 >>>=20 >>> Steps to reproduce the problem: >>>=20 >>> emacs -Q >>> C-x C-f emacs/src/xdisp.c RET >>> M-x c-ts-mode RET >>> C-x h >>> TAB >>>=20 >>> Expected result: >>>=20 >>> The buffer is reindented. >>>=20 >>> Actual results: >>>=20 >>> The operation fails with this error: >>>=20 >>> Debugger entered--Lisp error: (wrong-type-argument = integer-or-marker-p nil) >>> treesit-indent-region(1 1214226) >>> indent-region(1 1214226) >>> indent-for-tab-command(nil) >>> funcall-interactively(indent-for-tab-command nil) >>> call-interactively(indent-for-tab-command nil nil) >>> command-execute(indent-for-tab-command) >>=20 >> Thank you for your report. >>=20 >> Yuan and Theo, could you please look into this? I briefly stepped >> through the code involved in the problem, and it sounds like it makes >> some assumptions regarding the nodes which are not necessarily true = in >> Real Life. >=20 > c-ts-mode from the tip of the emacs-29 branch can indent xdisp.c = without > failures if I apply the patch from bug#61691 and the patch attached to > this email message. >=20 > It is very slow, though, compared to c-mode. I have a very fast = machine > and it took around 10 minutes to indent the whole file, while c-mode > indented the file in 30-40 seconds. I guess the algorithm in > treesit-indent-region doesn't scale very well for very big files like > xdisp.c. >=20 Thanks, I applied the patch. What you observed is certainly a regression = due to, from what I can see from profiling, = c-ts-common-statement-offset. It is added for more accurate indenting, = by going up the parse tree and =E2=80=9Ccount brackets=E2=80=9D, more or = less. This is probably a pretty inefficient when calculating indentation = for every line. A change I just pushed helps a bit (in a block, make the = first child calculate indentation as before, and children after than = uses the previous sibling=E2=80=99s indentation), but still not enough. I have some ideas to improve this, and get back once I have something. Yuan