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#59426: 29.0.50; [tree-sitter] Some functions exceed maximum recursion limit Date: Mon, 21 Nov 2022 15:19:09 +0200 Message-ID: <837czo4f8y.fsf@gnu.org> References: Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27036"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 59426@debbugs.gnu.org To: Yuan Fu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Nov 21 14:20:28 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 1ox6ip-0006ob-K1 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 21 Nov 2022 14:20:27 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ox6iV-0006xR-Sx; Mon, 21 Nov 2022 08:20: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 1ox6iR-0006x3-02 for bug-gnu-emacs@gnu.org; Mon, 21 Nov 2022 08:20:03 -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 1ox6iQ-0002yl-ND for bug-gnu-emacs@gnu.org; Mon, 21 Nov 2022 08:20:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ox6iQ-0000MB-IO for bug-gnu-emacs@gnu.org; Mon, 21 Nov 2022 08:20:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 21 Nov 2022 13:20: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.16690367451303 (code B ref 59426); Mon, 21 Nov 2022 13:20:02 +0000 Original-Received: (at 59426) by debbugs.gnu.org; 21 Nov 2022 13:19:05 +0000 Original-Received: from localhost ([127.0.0.1]:45756 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ox6hU-0000Kw-Kr for submit@debbugs.gnu.org; Mon, 21 Nov 2022 08:19:04 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:57452) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ox6hT-0000KS-4M for 59426@debbugs.gnu.org; Mon, 21 Nov 2022 08:19:03 -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 1ox6hN-0002n5-Se; Mon, 21 Nov 2022 08:18:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=QoM6cToA6a4khyHy2Zznv7QPuo5KzqqcwoPqkciZpeI=; b=kQEeRWOr+4CU kyJAVLLpQnT6WVav8ohUKL7NvfBmMSTC0K/ukza++m71vfx77Xjzgm8G58SLVPWdbrrgbAdT1Nuxr oERXIT9gex5ijxK57IbK/LPRZpt0KlXa5iKZhHSdQ+B8bQNItDoZWJQOvomImyF8f2GTQCy4saYD0 Dabr9QS980VD7eOKOD0HvUZKU/sKbxSElLaRt/CII+DrW4QCHpVgFS/yfjPasXg13P4vqBavDgNcz 74iFCk0VzN6+VzEolG1EEE/kNo/9fzCnsGIkvYpDhMuppGAUSvuSA8uDIyqb2AM6vCxr0/FcVJ0MD v5zaH9fhckUuWwwOKxJVdQ==; 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 1ox6hN-00034x-6y; Mon, 21 Nov 2022 08:18:57 -0500 In-Reply-To: (message from Yuan Fu on Sun, 20 Nov 2022 16:53:45 -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:248526 Archived-At: > From: Yuan Fu > Date: Sun, 20 Nov 2022 16:53:45 -0800 > > > Emacs crashed on a very large C file when c-ts-mode is on, because > the function building the imenu list tries to walk through the whole > parse tree, and end up recusing ~10k times because of how deep the parse > tree is. These recursive functions should have a built-in limit. Does > Emacs already have some way to determined the max recursion limit on > each system? Or should we come up with some hard-coded numbers? Is the recursion in our code, or is it in libtree-sitter? If the former, one solution, albeit a crude one, is to track the recursion level and error out if it becomes too deep. Another solution is to handle the stack in our code, in which case the stack can be allocated on the heap. Yet another solution is to replace stack-based recursive algorithm with queue-based iteration, like if you replace depth-first search with breadth-first search. I'm sure there are other ideas as well.