From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?Gerd_M=C3=B6llmann?= Newsgroups: gmane.emacs.devel Subject: MPS: treesit Date: Tue, 25 Jun 2024 07:27:16 +0200 Message-ID: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40818"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Eli Zaretskii , Helmut Eller To: Emacs Devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Jun 25 07:28:08 2024 Return-path: Envelope-to: ged-emacs-devel@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 1sLyit-000AUJ-Km for ged-emacs-devel@m.gmane-mx.org; Tue, 25 Jun 2024 07:28:07 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLyiE-0004i0-Nm; Tue, 25 Jun 2024 01:27:26 -0400 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 1sLyiB-0004hm-2L for emacs-devel@gnu.org; Tue, 25 Jun 2024 01:27:24 -0400 Original-Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLyi9-0004so-Eq; Tue, 25 Jun 2024 01:27:22 -0400 Original-Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-a689ad8d1f6so640819766b.2; Mon, 24 Jun 2024 22:27:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719293239; x=1719898039; darn=gnu.org; h=mime-version:user-agent:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=pT46BF2Q9opt/8CzkT3X5pay1IFoFrgmFzhDv5DCq1E=; b=O9VJ32N2nswj4EUD2u+aQajUgGEEA+plb+YgJh5uvwqB6lT7zJDNxJgvZ8NteoZgo/ Zm66W75b8gbg2cgIFgCq7+wzbFidR0N3IA5odpJP63dKfGx+zY9Vft/9yS8X0tHSlewZ GRG1WqFL5tIk8YrzgxxoAMnHTd3VW14bbT4Lo47u8UJAnDECfRw3u1MwnENVwPXYRXgL uxDUVh8Aysu2B2Z1Bqjnf5U3o7Zc11lr5YYIbcx1DQzdFF0IPI8ngQR5kQHHnC3O7qNJ 3Y+6nUY76EBk3/tqKIEEzYsLfXRrK4+r19CqgGVTVq6+hmQxNuzROmMKEniCFxKen2bC Zj5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719293239; x=1719898039; h=mime-version:user-agent:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pT46BF2Q9opt/8CzkT3X5pay1IFoFrgmFzhDv5DCq1E=; b=pNMa5QaYDk7lLHigCWHtGEpLtTPQUc1j1Mtg9bUd2prE83KI5oUOc+V6rqLnIgWAzU d5Xj8U9VxsHAvyQh67moz9SAgyyvQVxtBga+5nVbMMy+FzrnS3QgZ9lJ58EYVbDCjXD2 zipd7DhUULZbvgIgG60N714oDw2fGlsgeUyJHjMXodXhoaQml1fGR1KVtWMU7jVvawbk BikAcxxP9L/6gaZAvAMfjx0zf0OLsK4Shcq5SyN1FdkbCn8wxPSsH+WpmipsXCGYuWUB ShUNkncliXQd6ZVHaAyOOA31S3D8bK9R8Z0Katntq+Z82IDxPJ6/2bguWyEDQJ7POab+ Ab1g== X-Gm-Message-State: AOJu0Yypa6bya/u6xLZQ4nBU6FgdxZ6u9CFkxBDQ7KFB7WvKH0oz0jjF uIwS4Gx4duFu2n0l0b8F1jqdMT5FbMzV0fWDIMReg3z39kLpJK7+Hy0C5g== X-Google-Smtp-Source: AGHT+IGFzFxIwsplfs8uFDzIFQE0kJ5h+D6uDbP4+TTnQ6lJiT8XwzTLkiUH/psaTfqfKTgLqqptXw== X-Received: by 2002:a17:907:c5ce:b0:a72:4c32:7d89 with SMTP id a640c23a62f3a-a724c327e82mr454296366b.54.1719293238278; Mon, 24 Jun 2024 22:27:18 -0700 (PDT) Original-Received: from pro2.fritz.box (pd9e36681.dip0.t-ipconnect.de. [217.227.102.129]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7248aa03ffsm246398966b.27.2024.06.24.22.27.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jun 2024 22:27:17 -0700 (PDT) Received-SPF: pass client-ip=2a00:1450:4864:20::636; envelope-from=gerd.moellmann@gmail.com; helo=mail-ej1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:320625 Archived-At: 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