unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* MPS: treesit
@ 2024-06-25  5:27 Gerd Möllmann
  2024-06-25  7:44 ` Gerd Möllmann
  0 siblings, 1 reply; 9+ messages in thread
From: Gerd Möllmann @ 2024-06-25  5:27 UTC (permalink / raw)
  To: Emacs Devel; +Cc: Eli Zaretskii, Helmut Eller

I'm trying to make treesit work with igc, and I'm using c-ts-mode for
that purposes. Or I'm trying to because in a full
debug/checking/mps-debug build I immediately get a crash. I'm BTW
looking at/using treesit for the first time, so please bear with me.

treesit_ensure_parsed gets called, and passes a TSParser * to
ts_parser_parse.

  static void
  treesit_ensure_parsed (Lisp_Object parser)
  {
    struct buffer *buffer = XBUFFER (XTS_PARSER (parser)->buffer);

    /* Before we parse, catch up with the narrowing situation.  */
    treesit_check_buffer_size (buffer);
    /* This function has to run before we check for need_reparse flag,
       because it might set the flag to true.  */
    treesit_sync_visible_region (parser);

    /* Make sure this comes before everything else, see comment
       (ref:notifier-inside-ensure-parsed) for more detail.  */
    if (!XTS_PARSER (parser)->need_reparse)
      return;

    TSParser *treesit_parser = XTS_PARSER (parser)->parser;
    TSTree *tree = XTS_PARSER (parser)->tree;
    TSInput input = XTS_PARSER (parser)->input;

    TSTree *new_tree = ts_parser_parse (treesit_parser, tree, input);

  (lldb) p treesit_parser
  (TSParser *) 0x0000000154838e00

Down the stack I see some functions being called in the treesitter dylib

  frame #5: 0x0000000101464e58 libtree-sitter.0.dylib`ts_parser_parse + 2928
  frame #4: 0x000000010146160c libtree-sitter.0.dylib`ts_lexer_start + 84
  frame #3: 0x000000010146167c libtree-sitter.0.dylib`ts_lexer__get_chunk + 40
  frame #2: 0x00000001003ad184 emacs`treesit_read_buffer(parser=0x0000000105049ea0, byte_index=0, position=(row = 0, column = 0), bytes_read=0x0000000154838e9c) at treesit.c:1111:27

until I land here:

  static const char*
  treesit_read_buffer (void *parser, uint32_t byte_index,
                       TSPoint position, uint32_t *bytes_read)
  {
    struct buffer *buffer = XBUFFER (((struct Lisp_TS_Parser *) parser)->buffer);

Here, XBUFFER aborts with an invalid buffer because of --enable-checking=all.

  (lldb) p parser
  (void *) 0x0000000105049ea0

Note that parser here is not the treesit_parser some frames up that was
passed to the treesitter lib.

Can somone help and explain how this works in treesit.c? Where is the
Lisp_TS_Parser stored and how/where is the TSParser * that gets passed
to the treesiter dylib translated to the Lisp_TS_Parser *?

TIA



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

end of thread, other threads:[~2024-06-26  5:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-25  5:27 MPS: treesit Gerd Möllmann
2024-06-25  7:44 ` Gerd Möllmann
2024-06-25  8:28   ` Gerd Möllmann
2024-06-25 15:23   ` Eli Zaretskii
2024-06-26  4:35     ` Yuan Fu
2024-06-26  4:35   ` Yuan Fu
2024-06-26  4:54     ` Gerd Möllmann
2024-06-26  5:18       ` Yuan Fu
2024-06-26  5:25         ` Gerd Möllmann

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).