unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#69952: [PATCH] Support pdumping compiled queries by dumping their source
@ 2024-03-23  3:27 Sergey Vinokurov
  2024-03-23  7:08 ` Eli Zaretskii
  0 siblings, 1 reply; 16+ messages in thread
From: Sergey Vinokurov @ 2024-03-23  3:27 UTC (permalink / raw)
  To: 69952

[-- Attachment #1: Type: text/plain, Size: 540 bytes --]

Hello,

This patch aims to allow more things to be dumped. In particular, 
compiled treesitter queries can be easily dumped by storing their source 
so that they will be recompiled on load.

I noticed that in my config compiled quires are created somewhere which 
prevents me dumping with standard Emacs build. But with this patch I can 
dump successfully and not bother finding out who produced the queries.

It seems like there should be no drawbacks in allowing more things to be 
dumped, please correct me if I'm wrong.

Regards,
Sergey

[-- Attachment #2: pdump.patch --]
[-- Type: text/x-patch, Size: 2016 bytes --]

From 8b7263181ed358fe88a358355c2269b93379703c Mon Sep 17 00:00:00 2001
From: Sergey Vinokurov <serg.foo@gmail.com>
Date: Sun, 6 Aug 2023 16:24:29 +0100
Subject: [PATCH] Support compiled queries in pdump by dumping source

* src/pdumper.c (dump_vectorlike): Dump compiled queries
* src/pdumper.c (dump_treesit_compiled_query): New function
---
 src/pdumper.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/pdumper.c b/src/pdumper.c
index c7ebb38dea5..f2dd24c56a6 100644
--- a/src/pdumper.c
+++ b/src/pdumper.c
@@ -44,6 +44,7 @@
 #include "systime.h"
 #include "thread.h"
 #include "bignum.h"
+#include "treesit.h"
 
 #ifdef CHECK_STRUCTS
 # include "dmpstruct.h"
@@ -2215,6 +2216,21 @@ dump_finalizer (struct dump_context *ctx,
   return finish_dump_pvec (ctx, &out->header);
 }
 
+#ifdef HAVE_TREE_SITTER
+static dump_off
+dump_treesit_compiled_query (struct dump_context *ctx,
+			     struct Lisp_TS_Query *query)
+{
+  START_DUMP_PVEC (ctx, &query->header, struct Lisp_TS_Query, out);
+  dump_field_lv (ctx, &out->language, query, &query->language, WEIGHT_STRONG);
+  dump_field_lv (ctx, &out->source, query, &query->source, WEIGHT_STRONG);
+  /* Recompile these after load */
+  out->query = NULL;
+  out->cursor = NULL;
+  return finish_dump_pvec (ctx, &out->header);
+}
+#endif
+
 struct bignum_reload_info
 {
   dump_off data_location;
@@ -3108,6 +3124,12 @@ dump_vectorlike (struct dump_context *ctx,
           return DUMP_OBJECT_IS_RUNTIME_MAGIC;
         }
       break;
+#ifdef HAVE_TREE_SITTER
+    case PVEC_TS_COMPILED_QUERY:
+      return dump_treesit_compiled_query (ctx, XTS_COMPILED_QUERY (lv));
+#else
+    case PVEC_TS_COMPILED_QUERY:
+#endif
     case PVEC_WINDOW_CONFIGURATION:
     case PVEC_OTHER:
     case PVEC_XWIDGET:
@@ -3122,7 +3144,6 @@ dump_vectorlike (struct dump_context *ctx,
     case PVEC_FREE:
     case PVEC_TS_PARSER:
     case PVEC_TS_NODE:
-    case PVEC_TS_COMPILED_QUERY:
       break;
     }
   char msg[60];
-- 
2.43.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* bug#69952: [PATCH] Support pdumping compiled queries by dumping their source
  2024-03-23  3:27 bug#69952: [PATCH] Support pdumping compiled queries by dumping their source Sergey Vinokurov
@ 2024-03-23  7:08 ` Eli Zaretskii
  2024-03-23 12:53   ` Sergey Vinokurov
  2024-04-13  7:41   ` Eli Zaretskii
  0 siblings, 2 replies; 16+ messages in thread
From: Eli Zaretskii @ 2024-03-23  7:08 UTC (permalink / raw)
  To: Sergey Vinokurov; +Cc: 69952, Daniel Colascione, Yuan Fu

> Date: Sat, 23 Mar 2024 03:27:18 +0000
> From: Sergey Vinokurov <serg.foo@gmail.com>
> 
> This patch aims to allow more things to be dumped. In particular, 
> compiled treesitter queries can be easily dumped by storing their source 
> so that they will be recompiled on load.
> 
> I noticed that in my config compiled quires are created somewhere which 
> prevents me dumping with standard Emacs build. But with this patch I can 
> dump successfully and not bother finding out who produced the queries.
> 
> It seems like there should be no drawbacks in allowing more things to be 
> dumped, please correct me if I'm wrong.

Thanks.  I added Daniel and Yuan to the discussion, in case they have
comments.

And I have a question: what happens if the pdumper file dumped with
tree-sitter available is loaded by an Emacs session in which
tree-sitter is not available?  That can happen on Windows, for
example, if the tree-sitter library or the grammar library required
for recomputing the query is not available.  I think we need some code
to prevent Emacs from crashing on startup in that case.





^ permalink raw reply	[flat|nested] 16+ messages in thread

* bug#69952: [PATCH] Support pdumping compiled queries by dumping their source
  2024-03-23  7:08 ` Eli Zaretskii
@ 2024-03-23 12:53   ` Sergey Vinokurov
  2024-03-23 13:09     ` Eli Zaretskii
  2024-04-13  7:41   ` Eli Zaretskii
  1 sibling, 1 reply; 16+ messages in thread
From: Sergey Vinokurov @ 2024-03-23 12:53 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 69952, Daniel Colascione, Yuan Fu

On 23/03/2024 07:08, Eli Zaretskii wrote:
>> Date: Sat, 23 Mar 2024 03:27:18 +0000
>> From: Sergey Vinokurov <serg.foo@gmail.com>
>>
>> This patch aims to allow more things to be dumped. In particular,
>> compiled treesitter queries can be easily dumped by storing their source
>> so that they will be recompiled on load.
>>
>> I noticed that in my config compiled quires are created somewhere which
>> prevents me dumping with standard Emacs build. But with this patch I can
>> dump successfully and not bother finding out who produced the queries.
>>
>> It seems like there should be no drawbacks in allowing more things to be
>> dumped, please correct me if I'm wrong.
> 
> Thanks.  I added Daniel and Yuan to the discussion, in case they have
> comments.
> 
> And I have a question: what happens if the pdumper file dumped with
> tree-sitter available is loaded by an Emacs session in which
> tree-sitter is not available?  That can happen on Windows, for
> example, if the tree-sitter library or the grammar library required
> for recomputing the query is not available.  I think we need some code
> to prevent Emacs from crashing on startup in that case.

According to c2ecb08775dc24618de507d2d1ce0f9b0debe17e, treesitter 
queries are compiled lazily on fist use. When loading dump file in an 
Emacs with missing grammar library the user should encounter an error on 
first use of the query.

Quick testing shows that dump file can be loaded even with grammar 
definitions removed. Compiled queries are still there in elisp and 
there's no error during load.





^ permalink raw reply	[flat|nested] 16+ messages in thread

* bug#69952: [PATCH] Support pdumping compiled queries by dumping their source
  2024-03-23 12:53   ` Sergey Vinokurov
@ 2024-03-23 13:09     ` Eli Zaretskii
  0 siblings, 0 replies; 16+ messages in thread
From: Eli Zaretskii @ 2024-03-23 13:09 UTC (permalink / raw)
  To: Sergey Vinokurov; +Cc: 69952, dancol, casouri

> Date: Sat, 23 Mar 2024 12:53:37 +0000
> Cc: 69952@debbugs.gnu.org, Daniel Colascione <dancol@dancol.org>,
>  Yuan Fu <casouri@gmail.com>
> From: Sergey Vinokurov <serg.foo@gmail.com>
> 
> On 23/03/2024 07:08, Eli Zaretskii wrote:
> >> Date: Sat, 23 Mar 2024 03:27:18 +0000
> >> From: Sergey Vinokurov <serg.foo@gmail.com>
> >>
> >> This patch aims to allow more things to be dumped. In particular,
> >> compiled treesitter queries can be easily dumped by storing their source
> >> so that they will be recompiled on load.
> >>
> >> I noticed that in my config compiled quires are created somewhere which
> >> prevents me dumping with standard Emacs build. But with this patch I can
> >> dump successfully and not bother finding out who produced the queries.
> >>
> >> It seems like there should be no drawbacks in allowing more things to be
> >> dumped, please correct me if I'm wrong.
> > 
> > Thanks.  I added Daniel and Yuan to the discussion, in case they have
> > comments.
> > 
> > And I have a question: what happens if the pdumper file dumped with
> > tree-sitter available is loaded by an Emacs session in which
> > tree-sitter is not available?  That can happen on Windows, for
> > example, if the tree-sitter library or the grammar library required
> > for recomputing the query is not available.  I think we need some code
> > to prevent Emacs from crashing on startup in that case.
> 
> According to c2ecb08775dc24618de507d2d1ce0f9b0debe17e, treesitter 
> queries are compiled lazily on fist use. When loading dump file in an 
> Emacs with missing grammar library the user should encounter an error on 
> first use of the query.
> 
> Quick testing shows that dump file can be loaded even with grammar 
> definitions removed. Compiled queries are still there in elisp and 
> there's no error during load.

OK, thanks.





^ permalink raw reply	[flat|nested] 16+ messages in thread

* bug#69952: [PATCH] Support pdumping compiled queries by dumping their source
  2024-03-23  7:08 ` Eli Zaretskii
  2024-03-23 12:53   ` Sergey Vinokurov
@ 2024-04-13  7:41   ` Eli Zaretskii
  2024-04-20  8:08     ` Yuan Fu
  1 sibling, 1 reply; 16+ messages in thread
From: Eli Zaretskii @ 2024-04-13  7:41 UTC (permalink / raw)
  To: dancol, casouri; +Cc: serg.foo, 69952

Ping!  Daniel and Yuan, any comments on this proposal?

> Cc: 69952@debbugs.gnu.org, Daniel Colascione <dancol@dancol.org>,
>  Yuan Fu <casouri@gmail.com>
> Date: Sat, 23 Mar 2024 09:08:21 +0200
> From: Eli Zaretskii <eliz@gnu.org>
> 
> > Date: Sat, 23 Mar 2024 03:27:18 +0000
> > From: Sergey Vinokurov <serg.foo@gmail.com>
> > 
> > This patch aims to allow more things to be dumped. In particular, 
> > compiled treesitter queries can be easily dumped by storing their source 
> > so that they will be recompiled on load.
> > 
> > I noticed that in my config compiled quires are created somewhere which 
> > prevents me dumping with standard Emacs build. But with this patch I can 
> > dump successfully and not bother finding out who produced the queries.
> > 
> > It seems like there should be no drawbacks in allowing more things to be 
> > dumped, please correct me if I'm wrong.
> 
> Thanks.  I added Daniel and Yuan to the discussion, in case they have
> comments.
> 
> And I have a question: what happens if the pdumper file dumped with
> tree-sitter available is loaded by an Emacs session in which
> tree-sitter is not available?  That can happen on Windows, for
> example, if the tree-sitter library or the grammar library required
> for recomputing the query is not available.  I think we need some code
> to prevent Emacs from crashing on startup in that case.
> 
> 
> 
> 





^ permalink raw reply	[flat|nested] 16+ messages in thread

* bug#69952: [PATCH] Support pdumping compiled queries by dumping their source
  2024-04-13  7:41   ` Eli Zaretskii
@ 2024-04-20  8:08     ` Yuan Fu
  2024-04-20  9:32       ` Eli Zaretskii
  0 siblings, 1 reply; 16+ messages in thread
From: Yuan Fu @ 2024-04-20  8:08 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: serg.foo, dancol, 69952



> On Apr 13, 2024, at 12:41 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
> Ping!  Daniel and Yuan, any comments on this proposal?
> 
>> Cc: 69952@debbugs.gnu.org, Daniel Colascione <dancol@dancol.org>,
>> Yuan Fu <casouri@gmail.com>
>> Date: Sat, 23 Mar 2024 09:08:21 +0200
>> From: Eli Zaretskii <eliz@gnu.org>
>> 
>>> Date: Sat, 23 Mar 2024 03:27:18 +0000
>>> From: Sergey Vinokurov <serg.foo@gmail.com>
>>> 
>>> This patch aims to allow more things to be dumped. In particular, 
>>> compiled treesitter queries can be easily dumped by storing their source 
>>> so that they will be recompiled on load.
>>> 
>>> I noticed that in my config compiled quires are created somewhere which 
>>> prevents me dumping with standard Emacs build. But with this patch I can 
>>> dump successfully and not bother finding out who produced the queries.
>>> 
>>> It seems like there should be no drawbacks in allowing more things to be 
>>> dumped, please correct me if I'm wrong.
>> 
>> Thanks.  I added Daniel and Yuan to the discussion, in case they have
>> comments.
>> 
>> And I have a question: what happens if the pdumper file dumped with
>> tree-sitter available is loaded by an Emacs session in which
>> tree-sitter is not available?  That can happen on Windows, for
>> example, if the tree-sitter library or the grammar library required
>> for recomputing the query is not available.  I think we need some code
>> to prevent Emacs from crashing on startup in that case.

Yeah, being able to dump queries is certainly nice. There will be problems if the Emacs session that later loads the query either have a different grammar version loaded, or a difference grammar library for the same language, or outright doesn’t have tree-sitter like Eli mentioned. I don’t know if they are big enough problems to give up dumping queries, though.

Yuan




^ permalink raw reply	[flat|nested] 16+ messages in thread

* bug#69952: [PATCH] Support pdumping compiled queries by dumping their source
  2024-04-20  8:08     ` Yuan Fu
@ 2024-04-20  9:32       ` Eli Zaretskii
  2024-04-20 22:50         ` Yuan Fu
  0 siblings, 1 reply; 16+ messages in thread
From: Eli Zaretskii @ 2024-04-20  9:32 UTC (permalink / raw)
  To: Yuan Fu; +Cc: serg.foo, dancol, 69952

> From: Yuan Fu <casouri@gmail.com>
> Date: Sat, 20 Apr 2024 01:08:15 -0700
> Cc: dancol@dancol.org,
>  serg.foo@gmail.com,
>  69952@debbugs.gnu.org
> 
> 
> 
> > On Apr 13, 2024, at 12:41 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> >> 
> >> And I have a question: what happens if the pdumper file dumped with
> >> tree-sitter available is loaded by an Emacs session in which
> >> tree-sitter is not available?  That can happen on Windows, for
> >> example, if the tree-sitter library or the grammar library required
> >> for recomputing the query is not available.  I think we need some code
> >> to prevent Emacs from crashing on startup in that case.
> 
> Yeah, being able to dump queries is certainly nice. There will be problems if the Emacs session that later loads the query either have a different grammar version loaded, or a difference grammar library for the same language, or outright doesn’t have tree-sitter like Eli mentioned. I don’t know if they are big enough problems to give up dumping queries, though.

Giving up: no.  But I think the code which loads the queries from the
pdumper file should be protected from crashing in those cases.  Can
you suggest how to do that?





^ permalink raw reply	[flat|nested] 16+ messages in thread

* bug#69952: [PATCH] Support pdumping compiled queries by dumping their source
  2024-04-20  9:32       ` Eli Zaretskii
@ 2024-04-20 22:50         ` Yuan Fu
  2024-04-21  4:53           ` Eli Zaretskii
  0 siblings, 1 reply; 16+ messages in thread
From: Yuan Fu @ 2024-04-20 22:50 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: serg.foo, Daniel Colascione, 69952



> On Apr 20, 2024, at 2:32 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Sat, 20 Apr 2024 01:08:15 -0700
>> Cc: dancol@dancol.org,
>> serg.foo@gmail.com,
>> 69952@debbugs.gnu.org
>> 
>> 
>> 
>>> On Apr 13, 2024, at 12:41 AM, Eli Zaretskii <eliz@gnu.org> wrote:
>>>> 
>>>> And I have a question: what happens if the pdumper file dumped with
>>>> tree-sitter available is loaded by an Emacs session in which
>>>> tree-sitter is not available?  That can happen on Windows, for
>>>> example, if the tree-sitter library or the grammar library required
>>>> for recomputing the query is not available.  I think we need some code
>>>> to prevent Emacs from crashing on startup in that case.
>> 
>> Yeah, being able to dump queries is certainly nice. There will be problems if the Emacs session that later loads the query either have a different grammar version loaded, or a difference grammar library for the same language, or outright doesn’t have tree-sitter like Eli mentioned. I don’t know if they are big enough problems to give up dumping queries, though.
> 
> Giving up: no.  But I think the code which loads the queries from the
> pdumper file should be protected from crashing in those cases.  Can
> you suggest how to do that?

Would Emacs crash? If the dump file just contains the query (which is a string), then Emacs would just compile the query with treesit-query-compile, it could fail (due to the reasons I mentioned), but shouldn’t crash Emacs.

Yuan




^ permalink raw reply	[flat|nested] 16+ messages in thread

* bug#69952: [PATCH] Support pdumping compiled queries by dumping their source
  2024-04-20 22:50         ` Yuan Fu
@ 2024-04-21  4:53           ` Eli Zaretskii
  2024-04-21 23:41             ` Yuan Fu
  0 siblings, 1 reply; 16+ messages in thread
From: Eli Zaretskii @ 2024-04-21  4:53 UTC (permalink / raw)
  To: Yuan Fu; +Cc: serg.foo, dancol, 69952

> From: Yuan Fu <casouri@gmail.com>
> Date: Sat, 20 Apr 2024 15:50:36 -0700
> Cc: Daniel Colascione <dancol@dancol.org>,
>  serg.foo@gmail.com,
>  69952@debbugs.gnu.org
> 
> >>> On Apr 13, 2024, at 12:41 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> >>>> 
> >>>> And I have a question: what happens if the pdumper file dumped with
> >>>> tree-sitter available is loaded by an Emacs session in which
> >>>> tree-sitter is not available?  That can happen on Windows, for
> >>>> example, if the tree-sitter library or the grammar library required
> >>>> for recomputing the query is not available.  I think we need some code
> >>>> to prevent Emacs from crashing on startup in that case.
> >> 
> >> Yeah, being able to dump queries is certainly nice. There will be problems if the Emacs session that later loads the query either have a different grammar version loaded, or a difference grammar library for the same language, or outright doesn’t have tree-sitter like Eli mentioned. I don’t know if they are big enough problems to give up dumping queries, though.
> > 
> > Giving up: no.  But I think the code which loads the queries from the
> > pdumper file should be protected from crashing in those cases.  Can
> > you suggest how to do that?
> 
> Would Emacs crash? If the dump file just contains the query (which is a string), then Emacs would just compile the query with treesit-query-compile, it could fail (due to the reasons I mentioned), but shouldn’t crash Emacs.

Can Emacs compile a query if the tree-sitter shared library and/or the
grammar library is not available?





^ permalink raw reply	[flat|nested] 16+ messages in thread

* bug#69952: [PATCH] Support pdumping compiled queries by dumping their source
  2024-04-21  4:53           ` Eli Zaretskii
@ 2024-04-21 23:41             ` Yuan Fu
  2024-04-22  5:47               ` Eli Zaretskii
  0 siblings, 1 reply; 16+ messages in thread
From: Yuan Fu @ 2024-04-21 23:41 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: serg.foo, Daniel Colascione, 69952



> On Apr 20, 2024, at 9:53 PM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Sat, 20 Apr 2024 15:50:36 -0700
>> Cc: Daniel Colascione <dancol@dancol.org>,
>> serg.foo@gmail.com,
>> 69952@debbugs.gnu.org
>> 
>>>>> On Apr 13, 2024, at 12:41 AM, Eli Zaretskii <eliz@gnu.org> wrote:
>>>>>> 
>>>>>> And I have a question: what happens if the pdumper file dumped with
>>>>>> tree-sitter available is loaded by an Emacs session in which
>>>>>> tree-sitter is not available?  That can happen on Windows, for
>>>>>> example, if the tree-sitter library or the grammar library required
>>>>>> for recomputing the query is not available.  I think we need some code
>>>>>> to prevent Emacs from crashing on startup in that case.
>>>> 
>>>> Yeah, being able to dump queries is certainly nice. There will be problems if the Emacs session that later loads the query either have a different grammar version loaded, or a difference grammar library for the same language, or outright doesn’t have tree-sitter like Eli mentioned. I don’t know if they are big enough problems to give up dumping queries, though.
>>> 
>>> Giving up: no.  But I think the code which loads the queries from the
>>> pdumper file should be protected from crashing in those cases.  Can
>>> you suggest how to do that?
>> 
>> Would Emacs crash? If the dump file just contains the query (which is a string), then Emacs would just compile the query with treesit-query-compile, it could fail (due to the reasons I mentioned), but shouldn’t crash Emacs.
> 
> Can Emacs compile a query if the tree-sitter shared library and/or the
> grammar library is not available?

No. You need both tree-sitter library and the grammar library.

Yuan




^ permalink raw reply	[flat|nested] 16+ messages in thread

* bug#69952: [PATCH] Support pdumping compiled queries by dumping their source
  2024-04-21 23:41             ` Yuan Fu
@ 2024-04-22  5:47               ` Eli Zaretskii
  2024-04-22  6:04                 ` Yuan Fu
  0 siblings, 1 reply; 16+ messages in thread
From: Eli Zaretskii @ 2024-04-22  5:47 UTC (permalink / raw)
  To: Yuan Fu; +Cc: serg.foo, dancol, 69952

> From: Yuan Fu <casouri@gmail.com>
> Date: Sun, 21 Apr 2024 16:41:54 -0700
> Cc: Daniel Colascione <dancol@dancol.org>,
>  serg.foo@gmail.com,
>  69952@debbugs.gnu.org
> 
> 
> 
> > On Apr 20, 2024, at 9:53 PM, Eli Zaretskii <eliz@gnu.org> wrote:
> > 
> >> From: Yuan Fu <casouri@gmail.com>
> >> Date: Sat, 20 Apr 2024 15:50:36 -0700
> >> Cc: Daniel Colascione <dancol@dancol.org>,
> >> serg.foo@gmail.com,
> >> 69952@debbugs.gnu.org
> >> 
> >>>>> On Apr 13, 2024, at 12:41 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> >>>>>> 
> >>>>>> And I have a question: what happens if the pdumper file dumped with
> >>>>>> tree-sitter available is loaded by an Emacs session in which
> >>>>>> tree-sitter is not available?  That can happen on Windows, for
> >>>>>> example, if the tree-sitter library or the grammar library required
> >>>>>> for recomputing the query is not available.  I think we need some code
> >>>>>> to prevent Emacs from crashing on startup in that case.
> >>>> 
> >>>> Yeah, being able to dump queries is certainly nice. There will be problems if the Emacs session that later loads the query either have a different grammar version loaded, or a difference grammar library for the same language, or outright doesn’t have tree-sitter like Eli mentioned. I don’t know if they are big enough problems to give up dumping queries, though.
> >>> 
> >>> Giving up: no.  But I think the code which loads the queries from the
> >>> pdumper file should be protected from crashing in those cases.  Can
> >>> you suggest how to do that?
> >> 
> >> Would Emacs crash? If the dump file just contains the query (which is a string), then Emacs would just compile the query with treesit-query-compile, it could fail (due to the reasons I mentioned), but shouldn’t crash Emacs.
> > 
> > Can Emacs compile a query if the tree-sitter shared library and/or the
> > grammar library is not available?
> 
> No. You need both tree-sitter library and the grammar library.

That's what I thought.  So starting Emacs in that case will attempt to
call a function from the tree-sitter library, and will segfault,
right?  If so, we should have some protection in the code in
pdumper.c that loads queries, which tests that tree-sitter is
availabale, and if not does something to prevent the segfault, like
not loading the query, perhaps?





^ permalink raw reply	[flat|nested] 16+ messages in thread

* bug#69952: [PATCH] Support pdumping compiled queries by dumping their source
  2024-04-22  5:47               ` Eli Zaretskii
@ 2024-04-22  6:04                 ` Yuan Fu
  2024-04-22  6:18                   ` Eli Zaretskii
  0 siblings, 1 reply; 16+ messages in thread
From: Yuan Fu @ 2024-04-22  6:04 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: serg.foo, Daniel Colascione, 69952



> On Apr 21, 2024, at 10:47 PM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Sun, 21 Apr 2024 16:41:54 -0700
>> Cc: Daniel Colascione <dancol@dancol.org>,
>> serg.foo@gmail.com,
>> 69952@debbugs.gnu.org
>> 
>> 
>> 
>>> On Apr 20, 2024, at 9:53 PM, Eli Zaretskii <eliz@gnu.org> wrote:
>>> 
>>>> From: Yuan Fu <casouri@gmail.com>
>>>> Date: Sat, 20 Apr 2024 15:50:36 -0700
>>>> Cc: Daniel Colascione <dancol@dancol.org>,
>>>> serg.foo@gmail.com,
>>>> 69952@debbugs.gnu.org
>>>> 
>>>>>>> On Apr 13, 2024, at 12:41 AM, Eli Zaretskii <eliz@gnu.org> wrote:
>>>>>>>> 
>>>>>>>> And I have a question: what happens if the pdumper file dumped with
>>>>>>>> tree-sitter available is loaded by an Emacs session in which
>>>>>>>> tree-sitter is not available?  That can happen on Windows, for
>>>>>>>> example, if the tree-sitter library or the grammar library required
>>>>>>>> for recomputing the query is not available.  I think we need some code
>>>>>>>> to prevent Emacs from crashing on startup in that case.
>>>>>> 
>>>>>> Yeah, being able to dump queries is certainly nice. There will be problems if the Emacs session that later loads the query either have a different grammar version loaded, or a difference grammar library for the same language, or outright doesn’t have tree-sitter like Eli mentioned. I don’t know if they are big enough problems to give up dumping queries, though.
>>>>> 
>>>>> Giving up: no.  But I think the code which loads the queries from the
>>>>> pdumper file should be protected from crashing in those cases.  Can
>>>>> you suggest how to do that?
>>>> 
>>>> Would Emacs crash? If the dump file just contains the query (which is a string), then Emacs would just compile the query with treesit-query-compile, it could fail (due to the reasons I mentioned), but shouldn’t crash Emacs.
>>> 
>>> Can Emacs compile a query if the tree-sitter shared library and/or the
>>> grammar library is not available?
>> 
>> No. You need both tree-sitter library and the grammar library.
> 
> That's what I thought.  So starting Emacs in that case will attempt to
> call a function from the tree-sitter library, and will segfault,
> right?  If so, we should have some protection in the code in
> pdumper.c that loads queries, which tests that tree-sitter is
> availabale, and if not does something to prevent the segfault, like
> not loading the query, perhaps?

Right, it can use Ftreesit_available_p (we can define a C equivalent if pdumper can’t call lisp), and decide whether to compile the query or just keep the query as a string, or signal an error?

Yuan






^ permalink raw reply	[flat|nested] 16+ messages in thread

* bug#69952: [PATCH] Support pdumping compiled queries by dumping their source
  2024-04-22  6:04                 ` Yuan Fu
@ 2024-04-22  6:18                   ` Eli Zaretskii
  2024-04-22  6:25                     ` Yuan Fu
  0 siblings, 1 reply; 16+ messages in thread
From: Eli Zaretskii @ 2024-04-22  6:18 UTC (permalink / raw)
  To: Yuan Fu; +Cc: serg.foo, dancol, 69952

> From: Yuan Fu <casouri@gmail.com>
> Date: Sun, 21 Apr 2024 23:04:47 -0700
> Cc: Daniel Colascione <dancol@dancol.org>,
>  serg.foo@gmail.com,
>  69952@debbugs.gnu.org
> 
> >> No. You need both tree-sitter library and the grammar library.
> > 
> > That's what I thought.  So starting Emacs in that case will attempt to
> > call a function from the tree-sitter library, and will segfault,
> > right?  If so, we should have some protection in the code in
> > pdumper.c that loads queries, which tests that tree-sitter is
> > availabale, and if not does something to prevent the segfault, like
> > not loading the query, perhaps?
> 
> Right, it can use Ftreesit_available_p (we can define a C equivalent if pdumper can’t call lisp), and decide whether to compile the query or just keep the query as a string, or signal an error?

We cannot safely signal an error at that point, I think, so just
keeping the query as a string should do, as it will then signal an
error at run time when that query is used, is that right?





^ permalink raw reply	[flat|nested] 16+ messages in thread

* bug#69952: [PATCH] Support pdumping compiled queries by dumping their source
  2024-04-22  6:18                   ` Eli Zaretskii
@ 2024-04-22  6:25                     ` Yuan Fu
  2024-05-04  9:39                       ` Eli Zaretskii
  0 siblings, 1 reply; 16+ messages in thread
From: Yuan Fu @ 2024-04-22  6:25 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: serg.foo, dancol, 69952



> On Apr 21, 2024, at 11:18 PM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Sun, 21 Apr 2024 23:04:47 -0700
>> Cc: Daniel Colascione <dancol@dancol.org>,
>> serg.foo@gmail.com,
>> 69952@debbugs.gnu.org
>> 
>>>> No. You need both tree-sitter library and the grammar library.
>>> 
>>> That's what I thought.  So starting Emacs in that case will attempt to
>>> call a function from the tree-sitter library, and will segfault,
>>> right?  If so, we should have some protection in the code in
>>> pdumper.c that loads queries, which tests that tree-sitter is
>>> availabale, and if not does something to prevent the segfault, like
>>> not loading the query, perhaps?
>> 
>> Right, it can use Ftreesit_available_p (we can define a C equivalent if pdumper can’t call lisp), and decide whether to compile the query or just keep the query as a string, or signal an error?
> 
> We cannot safely signal an error at that point, I think, so just
> keeping the query as a string should do, as it will then signal an
> error at run time when that query is used, is that right?

Yes, most likely a function-undefined signal, since all the treesit.c functions like treesit-query-capture or treesit-query-compile will be nonexistent. And usually the Lisp program trying to use the query would check for tree-sitter availability with treesit-available-p before trying to use any tree-sitter functions; so that signal will be usually avoided as well.

Yuan




^ permalink raw reply	[flat|nested] 16+ messages in thread

* bug#69952: [PATCH] Support pdumping compiled queries by dumping their source
  2024-04-22  6:25                     ` Yuan Fu
@ 2024-05-04  9:39                       ` Eli Zaretskii
  2024-05-04 21:29                         ` Yuan Fu
  0 siblings, 1 reply; 16+ messages in thread
From: Eli Zaretskii @ 2024-05-04  9:39 UTC (permalink / raw)
  To: Yuan Fu, serg.foo; +Cc: 69952, dancol

> From: Yuan Fu <casouri@gmail.com>
> Date: Sun, 21 Apr 2024 23:25:10 -0700
> Cc: dancol@dancol.org,
>  serg.foo@gmail.com,
>  69952@debbugs.gnu.org
> 
> > On Apr 21, 2024, at 11:18 PM, Eli Zaretskii <eliz@gnu.org> wrote:
> > 
> > 
> > We cannot safely signal an error at that point, I think, so just
> > keeping the query as a string should do, as it will then signal an
> > error at run time when that query is used, is that right?
> 
> Yes, most likely a function-undefined signal, since all the treesit.c functions like treesit-query-capture or treesit-query-compile will be nonexistent. And usually the Lisp program trying to use the query would check for tree-sitter availability with treesit-available-p before trying to use any tree-sitter functions; so that signal will be usually avoided as well.

Can you suggest such an addition to the patch?





^ permalink raw reply	[flat|nested] 16+ messages in thread

* bug#69952: [PATCH] Support pdumping compiled queries by dumping their source
  2024-05-04  9:39                       ` Eli Zaretskii
@ 2024-05-04 21:29                         ` Yuan Fu
  0 siblings, 0 replies; 16+ messages in thread
From: Yuan Fu @ 2024-05-04 21:29 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: serg.foo, dancol, 69952



> On May 4, 2024, at 2:39 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Sun, 21 Apr 2024 23:25:10 -0700
>> Cc: dancol@dancol.org,
>> serg.foo@gmail.com,
>> 69952@debbugs.gnu.org
>> 
>>> On Apr 21, 2024, at 11:18 PM, Eli Zaretskii <eliz@gnu.org> wrote:
>>> 
>>> 
>>> We cannot safely signal an error at that point, I think, so just
>>> keeping the query as a string should do, as it will then signal an
>>> error at run time when that query is used, is that right?
>> 
>> Yes, most likely a function-undefined signal, since all the treesit.c functions like treesit-query-capture or treesit-query-compile will be nonexistent. And usually the Lisp program trying to use the query would check for tree-sitter availability with treesit-available-p before trying to use any tree-sitter functions; so that signal will be usually avoided as well.
> 
> Can you suggest such an addition to the patch?

Let me take a look.

Yuan




^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2024-05-04 21:29 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-23  3:27 bug#69952: [PATCH] Support pdumping compiled queries by dumping their source Sergey Vinokurov
2024-03-23  7:08 ` Eli Zaretskii
2024-03-23 12:53   ` Sergey Vinokurov
2024-03-23 13:09     ` Eli Zaretskii
2024-04-13  7:41   ` Eli Zaretskii
2024-04-20  8:08     ` Yuan Fu
2024-04-20  9:32       ` Eli Zaretskii
2024-04-20 22:50         ` Yuan Fu
2024-04-21  4:53           ` Eli Zaretskii
2024-04-21 23:41             ` Yuan Fu
2024-04-22  5:47               ` Eli Zaretskii
2024-04-22  6:04                 ` Yuan Fu
2024-04-22  6:18                   ` Eli Zaretskii
2024-04-22  6:25                     ` Yuan Fu
2024-05-04  9:39                       ` Eli Zaretskii
2024-05-04 21:29                         ` Yuan Fu

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).