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#59426: 29.0.50; [tree-sitter] Some functions exceed maximum recursion limit Date: Thu, 24 Nov 2022 11:25:58 -0800 Message-ID: References: <87wn7o6c9c.fsf@yahoo.com> <701BF611-6506-403E-B70B-2D93F3339E0C@acm.org> <83v8n82yzl.fsf@gnu.org> <83fsec2qq3.fsf@gnu.org> <83edtw2pz3.fsf@gnu.org> <835yf82oc4.fsf@gnu.org> <942C72E7-3DA9-4E2B-8B40-137B8FB23473@acm.org> <04236EB0-122B-41D0-B696-CC2EFA4B6A93@gmail.com> <6822E77F-3094-4E73-A7E7-EF5C096FC08F@acm.org> <104387C6-BF9A-4243-AD64-1ADCC25CBBA0@acm.org> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.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="2389"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Po Lu , 59426@debbugs.gnu.org, Eli Zaretskii , Stefan Kangas To: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Nov 24 20:27:13 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 1oyHsP-0000T7-Ly for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 24 Nov 2022 20:27:13 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyHsG-0001mC-Aj; Thu, 24 Nov 2022 14:27:04 -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 1oyHsE-0001lz-Ln for bug-gnu-emacs@gnu.org; Thu, 24 Nov 2022 14:27:02 -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 1oyHsE-0001sM-DW for bug-gnu-emacs@gnu.org; Thu, 24 Nov 2022 14:27:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oyHsE-0006pS-2G for bug-gnu-emacs@gnu.org; Thu, 24 Nov 2022 14:27: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: Thu, 24 Nov 2022 19:27:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59426 X-GNU-PR-Package: emacs Original-Received: via spool by 59426-submit@debbugs.gnu.org id=B59426.166931796726186 (code B ref 59426); Thu, 24 Nov 2022 19:27:02 +0000 Original-Received: (at 59426) by debbugs.gnu.org; 24 Nov 2022 19:26:07 +0000 Original-Received: from localhost ([127.0.0.1]:60229 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oyHrL-0006oI-FR for submit@debbugs.gnu.org; Thu, 24 Nov 2022 14:26:07 -0500 Original-Received: from mail-pl1-f174.google.com ([209.85.214.174]:42696) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oyHrK-0006np-H2 for 59426@debbugs.gnu.org; Thu, 24 Nov 2022 14:26:07 -0500 Original-Received: by mail-pl1-f174.google.com with SMTP id b21so2163480plc.9 for <59426@debbugs.gnu.org>; Thu, 24 Nov 2022 11:26:06 -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=kAfS1xg16Dv3dgPqfKIjs5Qtx0X1i/mBqwyQSTKw9xI=; b=Cg68QrrmzqHjE/yVBTMOAg33BomRuUUD/mHN/6CB3hL4qBzmfThm+ojz3u75UvnwTN W1ExlGX4/5YvsSaEmm00x8CLX4C/2CETmqcVSMjY4Pu3EMgZByvail0RwUpPF/cV8bPT DJKs1xf8vpWCQeEmbEWFwg/JuQzGPDKH1pfunSxn/IvrApqkaz7dN/lBzosg5fOcuQhV +g0DmxPzS4H1BUFKQPBMfwh6pv2aZFei4uDrrAFb/F/jEG9UncK1ZDaTWmTCddfyXsob TSXkFO5MmkuX4rlZoPz6H2mxnAENpYU7M4VuWQ2AFmlgwjpmHEnBHIXbaq8AnBebHExl y0lQ== 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=kAfS1xg16Dv3dgPqfKIjs5Qtx0X1i/mBqwyQSTKw9xI=; b=nliEZrj61voFS/wv/QzGRxT8WeweKwtIg+idTNye7+uBiNtRRPV8vP2hd4wGDFZeGD LL8K9aljIL4d7dXO6RLj7qE2RMoKRaTdp/VejXWuzCtbYpeBeS75NnB/3Noq9LSjpD4N eQPTjPFLOjTv+Be24xO7dl7z/Lpno/cAsTyY3utJpkgD/Q3hZBJRcpzmIGI8FPh+9KRi nOlksdE3TfE5Ekt+8vHoAIJPimq+zF8uuwe2tb4O5oaTmBvgjC2re0HTDl1gP3laKYXB dODHjvnZyIFdPOQ7meTHLGz/x2MwMFKBHSeRgI2eqdQNOxhk/CLYucgX+TZMEdPZp52D 0s6g== X-Gm-Message-State: ANoB5pnwMnAGN5zq4i/j9rxeUAyuMtaSk7LRHHdjdA4L3tqaJ2UflJRx wvEjneReAVxpmdwgzFUE52o= X-Google-Smtp-Source: AA0mqf6sW/t6n6XC0loVLdeEvOFkSdO4OqJexEwGcgYqZJrLoe0ULvdtsS/7D4WjybM9sdEeSVnxMA== X-Received: by 2002:a17:902:8e81:b0:188:4f86:e4d5 with SMTP id bg1-20020a1709028e8100b001884f86e4d5mr16617052plb.16.1669317960566; Thu, 24 Nov 2022 11:26:00 -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 nh15-20020a17090b364f00b001fb1de10a4dsm1514660pjb.33.2022.11.24.11.25.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Nov 2022 11:26:00 -0800 (PST) In-Reply-To: <104387C6-BF9A-4243-AD64-1ADCC25CBBA0@acm.org> X-Mailer: Apple Mail (2.3696.120.41.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:248900 Archived-At: > On Nov 24, 2022, at 2:24 AM, Mattias Engdeg=C3=A5rd = wrote: >=20 > 24 nov. 2022 kl. 10.17 skrev Yuan Fu : >=20 >> Does it worth the complexity tho? We only need a stack if we want to = support this scenario, in which case tree-sitter has a wrong parse tree. = Instead of spending the time and resource to go down that deep tree, = it=E2=80=99s better to fail early, and let the user decide to either = give up on weird files, or try some other approximation. >>=20 >> It=E2=80=99s too early to tell if being able to go down arbitrarily = deep into a deep tree is useful. The only use of traversing the whole = tree right now is to generate the imenu indexes, which don=E2=80=99t = really need to go down more than 10 levels, since most defun nodes we = are interested in are either top-level or near top-level. >=20 > You may very well be right about that. That brings us back to the original question: what limit should we use? = I suggest we use a smaller number since normal tree should never be very = tall. Running the following code tells me the height of the tree for = xdisp.c is 30: (defun measure-height (node) (let ((children (treesit-node-children node t))) (if children (1+ (apply #'max (mapcar #'measure-height children))) 1))) ;; In xdisp.c: (measure-height (treesit-buffer-root-node)) Maybe a limit in the range of hundreds or thousands? 800? >=20 >> So I=E2=80=99d prefer we keep it simple and have a hard limit for = now. If we later find that a stack is favorable we can always add it in. >=20 > That sounds good. Maybe the #line snag in the packet-rrc.c example = should be reported upstream? I stole your sample and opened an issue on their GitHub repo:=20 https://github.com/tree-sitter/tree-sitter-c/issues/118 Yuan=