unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Gerd Möllmann" <gerd.moellmann@gmail.com>
To: Emacs Devel <emacs-devel@gnu.org>
Cc: Eli Zaretskii <eliz@gnu.org>, Helmut Eller <eller.helmut@gmail.com>
Subject: MPS: treesit
Date: Tue, 25 Jun 2024 07:27:16 +0200	[thread overview]
Message-ID: <m2y16tvbgr.fsf@pro2.fritz.box> (raw)

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



             reply	other threads:[~2024-06-25  5:27 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-25  5:27 Gerd Möllmann [this message]
2024-06-25  7:44 ` MPS: treesit 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2y16tvbgr.fsf@pro2.fritz.box \
    --to=gerd.moellmann@gmail.com \
    --cc=eliz@gnu.org \
    --cc=eller.helmut@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).