by grashalm · 2y ago · 0 comments
https://github.com/oracle/graal/tree/master/truffle
Disclaimer: graalvm dev here.
Edit: typo
I know it's partly on me for not knowing the domain, but I honestly suspected somebody is trying to make fun of me with some concentrated technobabble.
Especially since I wouldn't expect the topic (configuration languages) to require complex mathematical machinery to work with. Now I have something interesting to dig into.
I once saw a demo where someone took a simple operation in Ruby using inefficient-but-elegant syntax (including creating and sorting an array, where a simple loop would have been the appropriate approach in C). He compiled that using TruffleRuby and the entire array construction and sorting was completely optimized out of the generated bytecode.
Here is one of the many: https://youtu.be/bf5pQVgux3c?si=S8Dm5d_GXYXgJtnY
If you go looking for more you will find many more marbles.
https://en.wikipedia.org/wiki/Partial_evaluation#Futamura_pr...
Even now the OG comment says “Fuamura” but the quote in the GP comment has the original “Futurama” written in it.
Especially the Futamura projections. It's almost magic and very few people have even heard of them.
I think that too, "Futamura projections" are important but they are very very far from "complex mathematical machinery" as you may hear it. They are indeed very simple (even mathematically trivial) and require no special background to understand.
Let me tell about a revolutionary device called a Turbo encabulator.
And the (original, I think), Pokémon or Tech Term: https://docs.google.com/forms/d/e/1FAIpQLSfsG7AEFLvlW68aIVIs...
not Futurama :D
What now?
GraalVM is an alternate JDK that can, among other things, do ahead-of-time compilation for Java.
Truffle is a framework for building languages, that sits on top of Graal.
Futamura Projections are a particularly interesting use case for compile-time partial evaluation.
With partial evaluation you have static (known at compile time) arguments to your function, and dynamic (known at runtime) arguments.
When “your function” is an interpreter, and your static arguments are source code, the output is effectively a self-contained compiled binary.
When your function is an interpreter, and the static arguments are the source code for the interpreter itself, that “self-contained compiled binary” is now itself a compiler.
It seems like they did not aim to make yet another mvp configuration language, but something that can scale across a wide range of usage scenarios spanning all the way from short-lived processes reading a number from a file to huge libraries of default/override hierarchies. Lack of universality sets an upper bound for the value of a configuration language, particularly when seen through the lens of configuring heterogeneous tech stacks.
That's pretty clever... How is this implemented in actual code though? I can't even begin to imagine how that magic machinery works.
wtf is Graal? That sounds like a supporting character from Beowulf.
Polyglot and native compilation enabled runtime for JVM, can run Js, Python, Ruby and more.
Cue chase montage shenanigans with Under The Boardwalk playing in the background
Do you smell toast.
thanks, that will help improve the output.
I ask cause the Project Galahad page on openjdk.org is a bit sparse on details.
Some background on the recent changes there: https://medium.com/graalvm/truffle-unchained-13887b77b62c
Of course, I know those two frameworks are one of the engineering marble of the age and would understand even if they decided to go without any concrete needs for it.
In other words antlr and truffle are a great fit. We even use this pairing for our example language simplelanguage.