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 01:17:02 -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> 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="36324"; 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 10:18:22 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 1oy8NB-0009B7-Cj for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 24 Nov 2022 10:18:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oy8Mt-0000MO-CC; Thu, 24 Nov 2022 04:18:03 -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 1oy8Ms-0000MF-2q for bug-gnu-emacs@gnu.org; Thu, 24 Nov 2022 04:18: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 1oy8Mr-00081O-Qe for bug-gnu-emacs@gnu.org; Thu, 24 Nov 2022 04:18:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oy8Mr-0004ZH-MW for bug-gnu-emacs@gnu.org; Thu, 24 Nov 2022 04:18:01 -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 09:18:01 +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.166928143317503 (code B ref 59426); Thu, 24 Nov 2022 09:18:01 +0000 Original-Received: (at 59426) by debbugs.gnu.org; 24 Nov 2022 09:17:13 +0000 Original-Received: from localhost ([127.0.0.1]:57244 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oy8M4-0004YF-Sa for submit@debbugs.gnu.org; Thu, 24 Nov 2022 04:17:13 -0500 Original-Received: from mail-pj1-f50.google.com ([209.85.216.50]:44914) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oy8M2-0004Y1-Il for 59426@debbugs.gnu.org; Thu, 24 Nov 2022 04:17:11 -0500 Original-Received: by mail-pj1-f50.google.com with SMTP id b1-20020a17090a7ac100b00213fde52d49so1096398pjl.3 for <59426@debbugs.gnu.org>; Thu, 24 Nov 2022 01:17:10 -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=2mh6xGu6Tuo4yfHuz0HbIt4CwE+IcOTZGywtRtRM1YI=; b=kTP54Tg6jGOr7ZbGdYHPay+K6j4chC9ISNnfGqXi4OCs3orRfnUqO4nZ4ZSXnKFV52 ujz2nba1Rj12CvaLFBM3MHESICU0PAqLli+aK/ddIFqsdMlPDRKSMEprpa1p84v8IrJ1 A6XpqVACRANcUtMlbHjb9aOiGKt6naGXF+F+3spgDDIONPzr9GoRxUB7GacuTjn8hlX7 5Pyi2UqHbA/2GmnAphQ8x3+v/1Cr2m7wUSyW+WIQQzU9/Nmeh/xFF1FU7u3ghPHA97tG 4Xb9RtYdjRFAc7PDPm+a7SLoW5kP2Bild0g1LadQ1NuUAF8A2jUJUC8cCHUCicC6+34/ Gxuw== 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=2mh6xGu6Tuo4yfHuz0HbIt4CwE+IcOTZGywtRtRM1YI=; b=E5kNTVizs7482SmIZ5Qex9VUEQcrdbeut1c4Jxf2qRIwge59XXWeY74OF/zo9lriT2 Gq0ZU36TfbgIybuvIQ3pDy2Qp4yqAHg/FTQ+cW/tHjHr1B6oINBv1AEKf8FqfTRn44IG Nk8w4jTKZVPlCeUl1Y9yCiRN8BG3LlZ6YugWVGAvF90C7rhgdQzIMEiFcqJGYm0VaEyS plIx0450apuoJg48/6r0TT+bnL8W1wLqkhkkK9dDs7MvVOT0/NuuxLEGLARTq4/0EnZi tVLCw2orJ9BMlWua7Cusvk/CnwY/YfHrLvzUJk1A1PHtEZgsC0bMX6C8THSbWdwEHfjV yJWg== X-Gm-Message-State: ANoB5pnhmUiptfvkUeps3XXyYque/a5aIk9mYtNzBRiC3vmJFMPJPmrC KNbeQWL7xbB2CEa9G2CJE40= X-Google-Smtp-Source: AA0mqf43SorSK9ONal/IQ9Dw2lI7Ojf4mrQEIZzI8eG6NJRcRveSF2Dh0ALGwO7CHyNbPW2UyQ/cfQ== X-Received: by 2002:a17:90a:9706:b0:218:7ccd:d487 with SMTP id x6-20020a17090a970600b002187ccdd487mr31653209pjo.18.1669281424657; Thu, 24 Nov 2022 01:17:04 -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 o5-20020a17090aac0500b0020ae09e9724sm719759pjq.53.2022.11.24.01.17.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Nov 2022 01:17:04 -0800 (PST) In-Reply-To: <6822E77F-3094-4E73-A7E7-EF5C096FC08F@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:248835 Archived-At: > On Nov 23, 2022, at 12:01 PM, Mattias Engdeg=C3=A5rd = wrote: >=20 > 23 nov. 2022 kl. 19.46 skrev Yuan Fu : >=20 >> It shouldn=E2=80=99t, but tree-sitter thinks some closing brackets = are erroneous and skips them when parsing (it skips erroneous tokens in = the hope to parse the rest of the file despite local errors). So a 10k = wide tree becomes 10k tall. >>=20 >> We can submit a bug repot to tree-sitter-c (=E2=80=9Cmaybe don=E2=80=99= t skip closing brackets even there is error, or somthing=E2=80=9D), but = that=E2=80=99s another story. >=20 > Thanks for the explanation. In this case it seems that it's the #line = directive that throws a spanner in the works. You probably already = discovered that, but for the record, here is a cut-down example: >=20 > static hf_register_info hf[] =3D { > #line 1 "./asn1/rrc/packet-rrc-hfarr.c" > { &hf_rrc_DL_DCCH_Message_PDU, > { "DL-DCCH-Message", "rrc.DL_DCCH_Message_element", > FT_NONE, BASE_NONE, NULL, 0, > NULL, HFILL }}, > { &hf_rrc_cellIdentity_c_id, > {"Cell Identifier", "rrc.cellIdentity.c_id", > FT_UINT32, BASE_DEC, NULL, 0, > "The Cell Identifier (C-Id) part of the Cell Identity", HFILL }} > }; >=20 > Note how the warning colour of the curly brackets vanishes once the = #line line is removed. > Even if this snag is corrected, there will always be cases where = preprocessor use causes trouble of this or a similar kind. It seems = quite convincing that we should void C recursion in favour of explicit = stacks where possible. >=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. 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. 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. Yuan=