AST to AST JIT Backend

James Lu jamtlu at gmail.com
Tue Sep 1 22:06:30 UTC 2020


On Tuesday, 1 September 2020 at 21:36:13 UTC, Francesco Mecca 
wrote:
> On Tuesday, 1 September 2020 at 00:15:24 UTC, James Lu wrote:
>> I have an idea, one way we can get faster compiles for Dlang 
>> is by compiling to an existing JITted language, which could be 
>> easier to build a proof of concept for than a full optimizing 
>> JIT compiler.
>>
>> Perhaps we could compile Dlang to Lua, targeting LuaJIT or 
>> JavaScript, targeting V8.
>>
>> I personally know to write highly performant JavaScript very 
>> well. Combined with Dlang's natural type information, it could 
>> result in fast machine code, fast. Backends for the Nim 
>> language tend to output poor (slow) JavaScript code.
>>
>> In an earlier thread, I showed that the V8 JavaScript engine 
>> could generate decent quality machine code much faster than 
>> LLVM D Compiler.
>
> Over the years I have made some experiments in ast-to-ast 
> conversions for luajit, there is even a nice tool to do that 
> easily here:
> https://github.com/franko/luajit-lang-toolkit
>
> The results weren't always satisfying because most of the time 
> the luajit optimizer expects idiomatic lua code.
> To be more precise, luajit is so powerful because it is 
> optimized for the kind of ast that is emitted from idiomatic 
> lua code when compiled.
> It is very difficult to reproduce that for non trivial snippets 
> of code.

I have experience writing high-performance JavaScript code, 
because I've microbenchmarked lots of JavaScript and understand 
engine internals. Care to link me to what idiomatically fast Lua 
looks like? Or, should we, as you suggest, try microbenchmarking 
myself? And should we base AST to AST translation off your work? 
(I presume to use Lua or JavaScript as a fast JIT intermediate 
language, one needs to de-abstract the AST a bit to get something 
easier to translate into a faster Lua/JS AST.)


More information about the Digitalmars-d mailing list