-
Notifications
You must be signed in to change notification settings - Fork 37
Description
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:
-
Functional programming, for example the
has_errorinsrc/util.jl. It callsany(has_error, x.trivia)and doesn't specialize onhas_errorand leads to a generic call. This may due to thathas_errorhas two methods.Another example is the broadcast operator of
to_codeobjectinsrc/conversion.jl. Becauseto_codeobjectreturnsAny,to_codeobject.(x.args)...will be inferred asAbstractVector, notVector{Any}. Here we should -
The
Union{Nothing, ...}field inEXPR(trivia,head). Many function directly access these fields and they don't test . Beside,EXPRis mutable, so even if we have asserted thatx.argsisn'tnothing, the following use ofx.argsis still type unstable, becausex.argsmay 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?