tree-sitter / tree-sitter-haskell

Haskell grammar for tree-sitter.
MIT License
155 stars 36 forks source link

Convert scanner to C for great good (~˘▾˘)~ #62

Closed 414owen closed 2 years ago

414owen commented 2 years ago

This should solve all past and future portability issues, because the C runtime is pretty ubiquitous.

The only generics we were using was in vectors, which I've preserved, with some macros.

C has no u32string, so I've used the vector macros to solve that too.

We lose namespaces ¯\(ツ)/¯.

The code is structurally the exact same.

We seem to have gained a bit of speed, compared to the C++ version (probably not statistically significant):

project % parsed time
effects 100.00% 0.0322s
postgrest 100.00% 0.0769s
ivory 100.00% 0.2119s
polysemy 98.75% 0.0807s
semantic 97.60% 1.0335s
haskell-language-server 99.79% 0.4648s

@wenkokke does this remove the need to patch tree-sitter for your wasm builds?
After this change, stdio.h is only required for -DDEBUG builds.

tek commented 2 years ago

sick! very curious to find out how I will deal with the C when adding features :grin:

wenkokke commented 2 years ago

@414owen realloc is not exported, so this would still require a patch.

wenkokke commented 2 years ago

Running the parser on haskell-language-server errors out with:

RuntimeError: Aborted(Assertion failed: undefined symbol `__assert_fail`. 
    perhaps a side module was not linked in?
    if this global was expected to arrive from a system library,
    try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment)

Which, I think, probably means that you have a failed assertion in there somewhere?

This aligns with my previous observations that the WASM tests would loop indefinitely on haskell-language-server.

tek commented 2 years ago

ugh why are the GA checks not running for PRs from forks

wenkokke commented 2 years ago

I'm working on patching the CI :)

FoamScience commented 2 years ago

I like the pure C too myself, been dealing with C++14 issues for a while now at more than one place!