tree-sitter-sql icon indicating copy to clipboard operation
tree-sitter-sql copied to clipboard

Generated WASM file not working

Open Vokturz opened this issue 1 year ago • 5 comments

Hi, I'm trying to use the generated wasm file with web-tree-sitter and the following error appears when trying to parse code:

RuntimeError: null function or function signature mismatch
    at tree-sitter.wasm:0x7960
    at tree-sitter.wasm:0x2a996
    at Parser.parse (web-tree-sitter.js?v=a1488891:676:29)

To make the wasm I'm doing:

  1. npm install --save-dev tree-sitter-cli @derekstride/tree-sitter-sql
  2. npx tree-sitter build --wasm node_modules/@derekstride/tree-sitter-sql

Did I skip any steps? I previously tried with tree-sitter-javascript and everything works perfectly.

Vokturz avatar Jul 31 '24 16:07 Vokturz

I cannot reproduce this. I did a fresh clone, using node 22 and I can build the wasm file without errors.

Building it with the rust cli also works.

matthias-Q avatar Aug 01 '24 07:08 matthias-Q

Can you check again. We had some releases in between, which might have solved this issue.

matthias-Q avatar Aug 15 '24 08:08 matthias-Q

maybe function pointer convert problem

I build tree-sitter, tree-sitter-sql and rust bindings, one build arg is very is import which may involved with this.

-sEMULATE_FUNCTION_POINTER_CASTS=1

duhbbx avatar Sep 26 '24 07:09 duhbbx

Could be the same issue I'm having. I did the same thing I'd done for other grammars:

git clone https://github.com/DerekStride/tree-sitter-sql
cd tree-sitter-sql
..\tree-sitter generate
..\tree-sitter build
..\tree-sitter build --wasm
..\tree-sitter playground

The tree is not generating, What I get in Chrome dev. console is this:

playground.js:324 Uncaught TypeError: Cannot read properties of null (reading 'rootNode')
    at handleCursorMovement (playground.js:324:23)
    at later (playground.js:451:30)
handleCursorMovement @ playground.js:324
later @ playground.js:451
setTimeout
(anonymous) @ playground.js:455
(anonymous) @ codemirror.min.js:1
(anonymous) @ codemirror.min.js:1
Gn @ codemirror.min.js:1
(anonymous) @ codemirror.min.js:1
playground.js:324 Uncaught TypeError: Cannot read properties of null (reading 'rootNode')
    at handleCursorMovement (playground.js:324:23)
    at later (playground.js:451:30)
handleCursorMovement @ playground.js:324
later @ playground.js:451
setTimeout
(anonymous) @ playground.js:455
(anonymous) @ codemirror.min.js:1
(anonymous) @ codemirror.min.js:1
Gn @ codemirror.min.js:1
(anonymous) @ codemirror.min.js:1
playground.js:324 Uncaught TypeError: Cannot read properties of null (reading 'rootNode')
    at handleCursorMovement (playground.js:324:23)
    at later (playground.js:451:30)
handleCursorMovement @ playground.js:324
later @ playground.js:451
setTimeout
(anonymous) @ playground.js:455
(anonymous) @ codemirror.min.js:1
(anonymous) @ codemirror.min.js:1
Gn @ codemirror.min.js:1
(anonymous) @ codemirror.min.js:1
playground.js:371 resume_parsing
playground.js:371 process version:0, version_count:1, state:1, row:0, col:0
playground.js:371 reduce sym:program, child_count:0
playground.js:371 accept
playground.js:371 done
tree-sitter.wasm:0x7960 Uncaught (in promise) RuntimeError: null function or function signature mismatch
    at tree-sitter.wasm:0x7960
    at tree-sitter.wasm:0x2a996
    at Parser.parse (tree-sitter.js:1:49283)
    at handleCodeChange (playground.js:113:28)
    at it (codemirror.min.js:1:17760)
    at jn (codemirror.min.js:1:65062)
    at codemirror.min.js:1:61536
    at codemirror.min.js:1:61545
    at codemirror.min.js:1:61216
    at Gn (codemirror.min.js:1:61222)
$ts_parser_reset @ tree-sitter.wasm:0x7960
$ts_parser_parse_wasm @ tree-sitter.wasm:0x2a996
parse @ tree-sitter.js:1
handleCodeChange @ playground.js:113
it @ codemirror.min.js:1
jn @ codemirror.min.js:1
(anonymous) @ codemirror.min.js:1
(anonymous) @ codemirror.min.js:1
(anonymous) @ codemirror.min.js:1
Gn @ codemirror.min.js:1
Xn @ codemirror.min.js:1
Vl.poll @ codemirror.min.js:1
(anonymous) @ codemirror.min.js:1
playground.js:324 Uncaught TypeError: Cannot read properties of null (reading 'rootNode')
    at handleCursorMovement (playground.js:324:23)
    at later (playground.js:451:30)
handleCursorMovement @ playground.js:324
later @ playground.js:451
setTimeout
(anonymous) @ playground.js:455
(anonymous) @ codemirror.min.js:1
(anonymous) @ codemirror.min.js:1
Gn @ codemirror.min.js:1
Xn @ codemirror.min.js:1
Vl.poll @ codemirror.min.js:1
(anonymous) @ codemirror.min.js:1

gregnis avatar Oct 14 '24 17:10 gregnis

BTW, I tried using -sEMULATE_FUNCTION_POINTER_CASTS=1, and it didn't help. In fact, it broke other grammars, so I reset it back.

gregnis avatar Oct 14 '24 19:10 gregnis

I did some debugging, and I'm pretty sure the signature mismatch in question is of the tree_sitter_sql_external_scanner_destroy function. According to the docs it should be void tree_sitter_sql_external_scanner_destroy(void *payload) but it is void *tree_sitter_sql_external_scanner_destroy(void *payload). Notice the return type should be void and not a void pointer.

https://github.com/DerekStride/tree-sitter-sql/blob/8a4578bd200fd1ed73e8cbecbe3c5053a4bcf2f8/src/scanner.c#L24-L32

So this is a genuine error in the scanner, but usually doesn't cause any problems. Wasm checks function signatures of indirect calls at runtime though, so it becomes an issue there.

RubixDev avatar Feb 28 '25 19:02 RubixDev