pxp-lang / pxp

A suite of high-performance tools for PHP developers – includes a code formatter, static analyser, language server and superset language.
https://pxplang.org
Other
784 stars 0 forks source link

Parse fails with stack overflow when performed on a thread #68

Closed joehoyle closed 3 months ago

joehoyle commented 3 months ago

Doing somehtign like :

spawn(move || {
    parser::parse(code);
})

Causes, in some cases

thread '<unknown>' has overflowed its stack
fatal runtime error: stack overflow

I think I head that PXP Symbol is not thread safe, but I assumed that meant cross-thread communication rather than not working from anything but the main thread?

ryangjchandler commented 3 months ago

Yeah, so the SymbolTable implementation isn't thread-safe at all, can only be used from the main thread.

This is by design right now. Simplest implementation, fastest way to get moving.

Thread safety is on the roadmap but I need to make sure it doesn't have a huge impact on performance, so rather than just putting a Mutex or Lock on it, I want to do some serious digging and benchmarking.

Hope that clears it up!

ryangjchandler commented 3 months ago

Adding on to this, there is some ways to work around this but I'm on my phone and on vacation so can't easily share them. 😁

joehoyle commented 3 months ago

Ok got you, do you know per chance if it's possible to parse on the main thread and send Vec<Statement> across threads?

joehoyle commented 3 months ago

Ah no worries, have a good vacation!

ryangjchandler commented 3 months ago

If you want, hop in the Discord and we can chat about things in more detail, or Twitter, whatever is easiest!

ryangjchandler commented 3 months ago

@joehoyle Going to close this issue – I've actually removed the SymbolTable logic completely, so anywhere a Symbol was previously is now just a ByteString.