From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#60953: The :match predicate with large regexp in tree-sitter font-lock seems inefficient Date: Tue, 31 Jan 2023 02:44:53 +0200 Message-ID: References: <7624dddc-4600-9a03-ac8b-d3c9e0ab618c@yandex.ru> <83wn5ag4nc.fsf@gnu.org> <01b5d074-fb12-6b1f-cbfb-5e759833b854@yandex.ru> <838rhpg57n.fsf@gnu.org> <5026D975-983F-4D18-8690-BE139C92825D@gmail.com> <83pmb1emxi.fsf@gnu.org> <6f318afc-ca71-8b7e-c822-52e6635b5718@yandex.ru> <83sffxcfxw.fsf@gnu.org> <83pmb1cbg5.fsf@gnu.org> <2da844d3-ea31-289e-2821-aa174e365ffd@yandex.ru> <6784f9e7-844b-374d-2a1e-8a61cebe0d7e@yandex.ru> <83zga03yne.fsf@gnu.org> <373a575f-c683-1581-c3e6-502e9897fb04@yandex.ru> <83mt603vrc.fsf@gnu.org> <83e58a1b-2e4a-356a-36d8-c756ff105b62@yandex.ru> <83bkmf52va.fsf@gnu.org> <33cad4c1-4af5-37bb-05bc-79a4d9c1a700@yandex.ru> <83wn533lut.fsf@gnu.org> <19892f55-498e-1109-2229-2ddd984849a4@yandex.ru> <83tu073ksp.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14750"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Cc: Eli Zaretskii , 60953@debbugs.gnu.org To: Yuan Fu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jan 31 01:46:30 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 1pMen8-0003fx-3Z for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 31 Jan 2023 01:46:30 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pMemk-0000C0-Iv; Mon, 30 Jan 2023 19:46:06 -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 1pMemh-0000BP-BN for bug-gnu-emacs@gnu.org; Mon, 30 Jan 2023 19:46: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 1pMemg-0006Ly-Pb for bug-gnu-emacs@gnu.org; Mon, 30 Jan 2023 19:46:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pMemg-0004I7-Jl for bug-gnu-emacs@gnu.org; Mon, 30 Jan 2023 19:46:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 31 Jan 2023 00:46:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60953 X-GNU-PR-Package: emacs Original-Received: via spool by 60953-submit@debbugs.gnu.org id=B60953.167512590416418 (code B ref 60953); Tue, 31 Jan 2023 00:46:02 +0000 Original-Received: (at 60953) by debbugs.gnu.org; 31 Jan 2023 00:45:04 +0000 Original-Received: from localhost ([127.0.0.1]:50938 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pMelj-0004Gh-BR for submit@debbugs.gnu.org; Mon, 30 Jan 2023 19:45:03 -0500 Original-Received: from mail-wm1-f45.google.com ([209.85.128.45]:34671) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pMelh-0004Fv-GL for 60953@debbugs.gnu.org; Mon, 30 Jan 2023 19:45:02 -0500 Original-Received: by mail-wm1-f45.google.com with SMTP id q10-20020a1cf30a000000b003db0edfdb74so36669wmq.1 for <60953@debbugs.gnu.org>; Mon, 30 Jan 2023 16:45:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:from:to:cc:subject:date:message-id:reply-to; bh=Uk/JF6SFA8vlxSzOJ+gI01Cx1Low37nl9eKiJxXDVUc=; b=LaM/2P8QitDBO5amsRAEO+krnaC2sl3YppYckdtsU+kV3fTyrTRffHyJUXohOnXHpM e/E/TiCZsJBNbdKvlvdyIFnNTE8BvO4Dx6smAzw9eSQT+8hC7nQxCl8/GLQoKgnggFiT Z0JR4MKhM7FGMREaBd0L/f415eoSmGdNQt3CdDAmBdG1HiNGMdoXile+PzUfCeemJWGS hx+H6pQxZtBWHiDdce6U0OS+GFeNQGxWLWYlnATKSVcfkFgHuxgAfohUehGKYpy9UyDy 6F+g+OHXwMV7IficOUNCkVNGFkopbFNvQLf++9raJDLahmQlJKwcaWcM9WohkJxbu+VR DK0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Uk/JF6SFA8vlxSzOJ+gI01Cx1Low37nl9eKiJxXDVUc=; b=5jOojnc1MWJnw/ErhNBMZ+uWzJ0cBLKLUR8+7VbosYnpCdryyFfWOxm8Pgc50F0vxs W2SlQQzopZaD2ZUshec5AlwG64JJAIJdzF9g/eo2DRxzJtUG5Q0+LHqjhR8JN3m1KjWS 6Mc2gI4HoEx2P1JL7ZOMVa0UskB0RbAjchgky0EYZu/uyzpWttDfGXhe/QQv/eN/oxTq ecB9Q6ZEqfFW4k/gaO9eG50/lNB1GrlCabX44f/eI++gGQYgtpBoFSA9K89xSWsALjX0 EhBLs9YlTqd1I2YWbw8j3I+TYWb71SN1h884a+h1ECEOy4QKxM27XmlnBpQhsHOU8xCX lnrQ== X-Gm-Message-State: AO0yUKUwDqm/0ZgA4YRfHLD4Nlok8GMEQ+3VUmxdES00an5lz9gI3VWv UMIlzy6OSi3qyG+tM3A541w= X-Google-Smtp-Source: AK7set+gPewOxAq38/g5RAYfmOe9TD1/j1FSlaTw9xqMynj8u2a5YHW5dkCGElV5sh2U7Ci7yiJfIQ== X-Received: by 2002:a05:600c:1d97:b0:3dc:5009:bc74 with SMTP id p23-20020a05600c1d9700b003dc5009bc74mr8611250wms.7.1675125895454; Mon, 30 Jan 2023 16:44:55 -0800 (PST) Original-Received: from [192.168.0.2] ([46.251.119.176]) by smtp.googlemail.com with ESMTPSA id i27-20020a05600c4b1b00b003dc54d9aeeasm5816107wmp.36.2023.01.30.16.44.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Jan 2023 16:44:54 -0800 (PST) Content-Language: en-US In-Reply-To: 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:254495 Archived-At: On 31/01/2023 01:57, Yuan Fu wrote: > > >> On Jan 30, 2023, at 11:58 AM, Dmitry Gutov wrote: >> >> On 30/01/2023 21:05, Eli Zaretskii wrote: >>>> Date: Mon, 30 Jan 2023 21:01:02 +0200 >>>> Cc:casouri@gmail.com,60953@debbugs.gnu.org >>>> From: Dmitry Gutov >>>> >>>> But that doesn't answer the question "Could it?". >>> I don't understand what you are asking. "Could" in what sense? >> >> Like, would it make sense to try to modify it that way, or extract a function that would do that, without writing it from scratch. >> >> Or create a new function which would reuse some common code. >> >> We would call the new function something like match_buffer_substring. Optionally, also expose it to Lisp. > > Another option is to change user/programmer’s expectation of the anchor: we could say that the regexp must match the entirety of the node text. IOW, \\` \\' are implied. Huh, I guess that's an option too. A couple reasons not to do that would be: - Potential breakage in all existing TS modes, a week (?) before we're going to release Emacs 29 pretest. Maybe that's okay, I can't say. But the breakage from that kind of change could be subtle. - Compatibility reasons? People writing TS modes for Emacs might be coming from other editors/TS integrations. While TreeSitter docs say the predicates are not handled by it, it does show this example: (#match? @constant "^[A-Z][A-Z_]+") The use of '^' anchor seems to imply that the regexp doesn't have to otherwise match the whole node text (OTOH it's not clear why the example doesn't just say "^[A-Z]" or "^[A-Z][A-Z_]"). The doc also references the Rust crate and WebAssembly binding which support #match?. IIUC Rust uses "re.is_match", which is documented to use "implicit .*? at the beginning and end". Which matches our current semantics. WebAssembly uses "regex.test", same effect.