Replies: 5 comments 1 reply
-
Complier transforms are also the most exciting part of Jax too. I know from playing with writing Arborist.jl recursive AST tranforms are, not a useful thing at least in julia (even though it is the natural extension of julia's macros). idk how Jax does its code tranforms user interface wise. |
Beta Was this translation helpful? Give feedback.
-
Great question! Yes, all code transformations such as AD (as well as optimization passes) are implemented in Haskell as part of the compiler. Now, we have briefly discussed that we are interested in surfacing this functionality, but it is not immediately clear how to do that in the short-term. Our focus is in supporting (mostly dense) flat collections of data with structure that is well visible to the compiler, because this is the scenario where generating code for accelerators and the such is the most feasible. Most metaprogramming facilities are on the complete other end of the spectrum, requiring recursive data structures and heavily branching logic, so it does diverge a bit from our original goal. They do not have to be contradictory of course. We could allow a richer, and slower, language that makes it possible to implement macros and rewrites, with the eventual programs we emit being stripped away of all this inefficiency. But I think that it would require a fair amount of extensions to the language. Finally, my biggest worry would be with the fact that our internal program representations are somewhat unstable, and we do not want to commit to surfacing them as a user API, because that would require more stability. Dex is still a research project! |
Beta Was this translation helpful? Give feedback.
-
Thanks for the response. Yeah, this makes sense. I haven’t looked at dex’s compilation model, yet, so I have no informed opinions on how feasible it is. You’re right you would at the very least need to able to represent and manipulate an AST (I see #331), but I doin’t think it would need to be particularly optimized in these areas. As for the program representations, does it pose additional problems over any other interface? Julia has a few IRs, and in the cases when they’ve changed, people have updated accordingly. @oxinabox’s raises a good point, in Julia we haven’t quite found the right interface yet. Either you have to work at the low level IR, or at high level method dispatch. In PL theory, semantics are often expressed compositionally in terms of rules in the grammar. I wonder if something like that could work — a bit like Cassette but able to handle control flow and constructs other than function application. Anyway, it was just a thought! Definitely a nice-to-have feature, but at the same time, I think if addressed early could heavily shape the future of the language. Maybe I’ll take a look at it myself at some point. |
Beta Was this translation helpful? Give feedback.
-
One possibility would be to have such compiler tranformed implemented by the user in Haskell -- kind of the opposite of homoiconic. Maybe something that takes in some form of IR or AST and outputs the same. Having a nice place in the compilation stack to put it, is also thing.
I don't think we need to worry about this too much. |
Beta Was this translation helpful? Give feedback.
-
On further thought. But Dex being functional doesn't have much control flow. It wouldn't let you write optimisation passes. But you could write ADs, I think, and debuggers in the style of MagneticReadHead.jl. |
Beta Was this translation helpful? Give feedback.
-
I just got around to looking at dex more closely after meeting with @froystig at LAFI, and I'm impressed!
Correct me if I'm wrong, but it looks as if the AD implementation is currently necessarily in Haskell, as opposed to dex itself?
The point of this post is to discuss the degree to which it is possible and desirable to support these kinds of transformations from within dex itself. One of the most exciting areas of Julia is this trend towards writing compiler transformations from within Julia. This started with Cassette.jl and has grown into a ecosystem of tools that are in the upcoming release of Julia getting first class status within the compiler itself. @oxinabox has written about it here.
From the perspective of someone who likes to implement inference methods through program transformations (for instance, my LAFI talk was on inverting programs), it would be great to be able to do this in a simpler, functional, language like dex.
Beta Was this translation helpful? Give feedback.
All reactions