On 16.06.2022 21:03, Yuan Fu wrote:
Hey,

I’ve just finished with Real Life and got back to tree-sitter. I’ll reply to individual messages separately, but here is a summary of all the latest changes pushed to feature/tree-sitter

- Now one can compile a query, compiled query is much faster than uncompiled queries.
- Traversal functions now have a parameter that controls how deep to traverse.
- Removed the ltree-sitter setting in configure.ac
- Consolidated all the parser creation functions into one: treesit-parser-create, that means treesit-get-parser and treesit-get-parser-create are removed.

I think these are all the pending requests (sans highlight-paren), please let me know if I missed anything.

Moving forward, I want to make treesit-parser-list internal and turn it into a function that returns the parser list. And add a function to remove a parser from the parser list. Because I’m not comfortable letting users to remove and re-add parsers into the list anymore. Previously we determined that if a user wants to do the wrong thing, so be it. But now I realized that there could be danger in crashing Emacs if user fiddle with treesit-parser-list incorrectly (and violates some of the assertions I put in).

Can I just add a new Lisp_Object field in struct buffer? I assume that’s how you add an internal buffer-local data?

Yuan

Nice update! Good work!

Trying latest source from emacs feature/tree-sitter branch though, and updating my code to use treesite-parser-create rather than treesit-get-parser-create... I have emacs segfaulting because of a double-free.
jostein@ThinkPad-T14s:~/build/emacs$ emacs
double free or corruption (out)
Fatal error 6: Aborted
Running it through gdb gets me this result:

jostein@ThinkPad-T14s:~/build/emacs$ gdb /home/jostein/build/emacs/src/emacs
GNU gdb (Ubuntu 12.0.90-0ubuntu1) 12.0.90
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /home/jostein/build/emacs/src/emacs...
(gdb) r
Starting program: /home/jostein/build/emacs/src/emacs
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff11bc640 (LWP 54902)]
[New Thread 0x7ffff086d640 (LWP 54903)]
[New Thread 0x7fffebf3d640 (LWP 54904)]
[New Thread 0x7fffeb5b4640 (LWP 54905)]
[New Thread 0x7fffeadb3640 (LWP 54906)]
[New Thread 0x7fffea50c640 (LWP 54907)]
[Thread 0x7fffea50c640 (LWP 54907) exited]
[New Thread 0x7fffea50c640 (LWP 54908)]
[New Thread 0x7fffe9d0b640 (LWP 54909)]
[Thread 0x7fffea50c640 (LWP 54908) exited]
[Thread 0x7fffe9d0b640 (LWP 54909) exited]
[New Thread 0x7fffe9d0b640 (LWP 54910)]
[New Thread 0x7fffea50c640 (LWP 54911)]
[Thread 0x7fffe9d0b640 (LWP 54910) exited]
[Thread 0x7fffea50c640 (LWP 54911) exited]
[Thread 0x7fffeadb3640 (LWP 54906) exited]
[Detaching after vfork from child process 54913]
[Detaching after vfork from child process 54914]
[Detaching after vfork from child process 54922]
[Detaching after vfork from child process 54924]
[Detaching after vfork from child process 54929]
[Detaching after vfork from child process 54930]
[Detaching after vfork from child process 54964]
[Detaching after vfork from child process 54965]
[Detaching after vfork from child process 54994]
[Detaching after vfork from child process 54995]
[Detaching after vfork from child process 54996]
[Detaching after vfork from child process 54997]
[Detaching after vfork from child process 54998]
[Detaching after vfork from child process 54999]
[Detaching after vfork from child process 55001]
[Detaching after vfork from child process 55003]
[Detaching after vfork from child process 55004]
[Thread 0x7fffeb5b4640 (LWP 54905) exited]
[Detaching after vfork from child process 55044]
[Detaching after vfork from child process 55045]
[Detaching after vfork from child process 55046]
[Detaching after vfork from child process 55047]
[Detaching after vfork from child process 55048]

Thread 1 "emacs" received signal SIGSEGV, Segmentation fault.
0x00007ffff58de39f in ts_query_delete () from /usr/local/lib/libtree-sitter.so.0
(gdb) bt
#0  0x00007ffff58de39f in ts_query_delete () at /usr/local/lib/libtree-sitter.so.0
#1  0x000055555573e849 in cleanup_vector (vector=<optimized out>) at alloc.c:3184
#2  sweep_vectors () at alloc.c:3259
#3  0x0000555555743a50 in gc_sweep () at alloc.c:7413
#4  garbage_collect () at alloc.c:6259
#5  0x0000555555743f11 in maybe_garbage_collect () at alloc.c:6108
#6  0x0000555555765e85 in maybe_gc () at /home/jostein/build/emacs/src/lisp.h:5539
#7  Ffuncall (nargs=nargs@entry=2, args=args@entry=0x7fffffff9310) at eval.c:2961
#8  0x0000555555764751 in internal_condition_case_n
     (bfun=0x555555765cf0 <Ffuncall>, nargs=nargs@entry=2, args=args@entry=0x7fffffff9310, handlers=handlers@entry=0x30, hfun=hfun@entry=0x5555555ded20 <safe_eval_handler>) at eval.c:1565
#9  0x00005555555c9e13 in safe__call (inhibit_quit=inhibit_quit@entry=false, nargs=nargs@entry=2, func=func@entry=0xb160, ap=ap@entry=0x7fffffff9390) at xdisp.c:3015
#10 0x00005555555dd3b6 in safe_call (nargs=nargs@entry=2, func=func@entry=0xb160) at xdisp.c:3030
#11 0x00005555555fed32 in safe_call1 (arg=0x55555643771d, fn=0xb160) at xdisp.c:3041
#12 display_mode_lines (w=w@entry=0x555556437718) at xdisp.c:26098
#13 0x0000555555614869 in redisplay_window (window=<optimized out>, just_this_one_p=<optimized out>) at xdisp.c:19894
#14 0x0000555555618063 in redisplay_window_0 (window=window@entry=0x55555643771d) at xdisp.c:17148
#15 0x00005555557645fc in internal_condition_case_1
    (bfun=bfun@entry=0x555555618030 <redisplay_window_0>, arg=arg@entry=0x55555643771d, handlers=<optimized out>, hfun=hfun@entry=0x5555555c8ee0 <redisplay_window_error>) at eval.c:1509
#16 0x00005555555caf49 in redisplay_windows (window=0x55555643771d) at xdisp.c:17128
#17 0x00005555555ffe0d in redisplay_internal () at xdisp.c:16595
#18 0x0000555555601414 in redisplay_preserve_echo_area (from_where=from_where@entry=9) at xdisp.c:16944
#19 0x00005555557bdc4f in wait_reading_process_output
    (time_limit=time_limit@entry=0, nsecs=nsecs@entry=0, read_kbd=read_kbd@entry=-1, do_display=true, wait_for_cell=wait_for_cell@entry=0x0, wait_proc=wait_proc@entry=0x0, just_wait_proc=0) at process.c:5334
#20 0x00005555556df7a7 in kbd_buffer_get_event (end_time=0x0, used_mouse_menu=0x7fffffffdb2b, kbp=<synthetic pointer>) at keyboard.c:3953
#21 read_event_from_main_queue (end_time=<optimized out>, local_getcjmp=0x7fffffffd810, used_mouse_menu=0x7fffffffdb2b) at keyboard.c:2225
#22 0x00005555556e55bb in read_decoded_event_from_main_queue (used_mouse_menu=<optimized out>, prev_event=<optimized out>, local_getcjmp=<optimized out>, end_time=<optimized out>) at keyboard.c:2288
#23 read_char (commandflag=1, map=0x555558bfd8f3, prev_event=0x0, used_mouse_menu=0x7fffffffdb2b, end_time=0x0) at keyboard.c:2919
#24 0x00005555556e7326 in read_key_sequence (keybuf=<optimized out>, prompt=0x0, dont_downcase_last=<optimized out>, can_return_switch_frame=true, fix_current_buffer=true, prevent_redisplay=<optimized out>)
    at keyboard.c:9965
#25 0x00005555556e8fbc in command_loop_1 () at keyboard.c:1391
#26 0x0000555555764567 in internal_condition_case (bfun=bfun@entry=0x5555556e8d70 <command_loop_1>, handlers=handlers@entry=0x90, hfun=hfun@entry=0x5555556dc5b0 <cmd_error>) at eval.c:1485
#27 0x00005555556d4c7e in command_loop_2 (handlers=handlers@entry=0x90) at keyboard.c:1132
#28 0x00005555557644a9 in internal_catch (tag=tag@entry=0xf6c0, func=func@entry=0x5555556d4c50 <command_loop_2>, arg=arg@entry=0x90) at eval.c:1208
#29 0x00005555556d4c19 in command_loop () at keyboard.c:1110
#30 0x00005555556dc108 in recursive_edit_1 () at keyboard.c:719
#31 0x00005555556dc4b0 in Frecursive_edit () at keyboard.c:802
#32 0x00005555555adf54 in main (argc=<optimized out>, argv=<optimized out>) at emacs.c:2518
(gdb)

This is on "plain" Ubuntu 22.04, x86_64.

Emacs compiled using: ./configure --with-tree-sitter && make -j4

No other features or "experimental" things enabled.



--
Vennlig hilsen
Jostein Kjønigsen

jostein@kjonigsen.net 🍵 jostein@gmail.com
https://jostein.kjønigsen.no