Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type instability in CSTParser #325

Open
ChenNingCong opened this issue Jan 30, 2022 · 1 comment
Open

Type instability in CSTParser #325

ChenNingCong opened this issue Jan 30, 2022 · 1 comment

Comments

@ChenNingCong
Copy link

ChenNingCong commented Jan 30, 2022

Hi! I am working on a static compiler prototype for Julia (as a student project, check this branch: link.) It's based on LLVM's new linker JITLink and can produce binary (so to reduce latency completely). I test it on Tokenize and CSTParser because they are just like a static C library and every function is well typed. The result is promising. The only latency left is the latency to loading precompilation cache (.ji) of the packages, because function definitions and type definitions are not cached in the form of binary code.

However I identified some type instabilities in this library and they are hard to get compiled right now. Type instability will generate abstract types or partially applied types, which are currently unhandled in my prototype. Anyway, fixing them can improve compilation speed and precompilation cache, even if we don't want to compile CSTParser statically.

There are mainly two sources of instabilities:

  1. Functional programming, for example the has_error in src/util.jl. It calls any(has_error, x.trivia) and doesn't specialize on has_error and leads to a generic call. This may due to that has_error has two methods.

    Another example is the broadcast operator of to_codeobject in src/conversion.jl. Because to_codeobject returns Any,to_codeobject.(x.args)... will be inferred as AbstractVector, not Vector{Any}. Here we should

  2. The Union{Nothing, ...} field in EXPR (trivia, head). Many function directly access these fields and they don't test . Beside, EXPR is mutable, so even if we have asserted that x.args isn't nothing, the following use of x.args is still type unstable, because x.args may change. A good news is that this doesn't block static compiling, because union splitting works pretty fine and we only need to generate a runtime type check.

If needed, I'd like to make PRs to improve type instability in CSTParser. What's your opinion about this improvement?

@davidanthoff
Copy link
Member

I think such contributions would be fantastic. One long term goal of ours is to be able to compile the entire language server into a self-contained (small!) binary and ship that with the Julia VS Code extension, so that things work even if the user doesn't have Julia installed at all, and also to help with latency. Plus, in general, getting rid of type instabilities is always good :) So, PRs are welcome, I'd say :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants