IR = Intermediate Representation https://en.wikipedia.org/wiki/Intermediate_representation
Thank you, half way through the article and I am thinking infrared.
JSIR: A High-Level IR for JavaScript
11–20 of 33 posts
Re: JSIR: A High-Level IR for JavaScript
#12This is exciting stuff! My interpretation: If the JSIR project can successfully prove bi-directional source to MLIR transformation, it could lead to a new crop of source to source compilers across different languages (as long as they can be lowered to MLIR and back). Imagine transmorphing Rust to Swift and back. Of course you’d still need to implement or shim any libraries used in the source language. This might help…
JSIR is optimizing for round-trips back to JavaScript source. But since in language to language conversion teh consumer is a backend emitter (C# in my case), instead of preserving source structure perfectly, my IR preserves resolved semantic facts: types, generic substitutions, overload decisions, package/binding resolution, and other lowering-critical decisions.
I could be wrong, but I suspect transpilers are easier to build if it's lowering oriented (for specific targets).
Re: JSIR: A High-Level IR for JavaScript
#13Interesting timing. We have been working on something that takes the opposite design philosophy. JSIR is designed for high-fidelity round-trips back to source, preserving all information a human author put in. That makes sense when the consumer is a human-facing tool like a deobfuscator or transpiler. We have been exploring what an IR looks like when the author is an AI and the consumer is a compiler, and no human ne…
> when the author is an AI and the consumer is a compiler, and no human needs to read the output at all. This seems like a big bet on the assumption that fully autonomous codegen without humans in the loop is imminent if not already present - frankly, I hope you are wrong. Even if that comes to pass in some cases, I also find it hard to believe that an LLM will ever be able to generate code in any new language at the…
We don't have real AI & no one is anywhere near anything that can consistently generate code of moderate complexity w/o bugs or accidental issues like deleting files during basic data processing (something I ran into recently while writing a local semantic search engine for some of my PDFs using open source neural networks).
Re: JSIR: A High-Level IR for JavaScript
#14Re: JSIR: A High-Level IR for JavaScript
#15And my dumb brain still don't understand how IR is "better" than AST after reading this post. Current AST based JS tools working reasonably well, and it's not clear to me how introducing this JSIR helps tool authors or downstream users, when there are all those roadblocks mentioned at the end.
Re: JSIR: A High-Level IR for JavaScript
#16> Industry trend of building high-level language-specific IRs "Trend"? This was always the best practice. It's not a "trend".
It seems to me that there's a certain "blindness" between two compiler worlds. Compiler engineers for mostly linear-memory languages tend to only think in terms of SSA, and assume it's the only reasonable way to perform optimizations. That transpires in this particular article: the only difference between an AST and what they call IR is that the latter is SSA-based. So it's like for them something that's not SSA is n…
You usually compile from SSA to WASM bytecode, and then immediately JIT (Cranelift) by reconstructing an SSA-like graph IR. If you look at the flow, it's basically:
Graph IR -> WASM (stack-based bytecode) -> Graph IR
So the stack-based IR is used as a kind of IR serialization layer. Then I realized that this works well because a stack-based IR is just a linearized encoding of a dataflow graph. The data dependencies are implicit in the stack discipline, but they can be recovered mechanically. Once you see that, the blindness mostly disappears, since the difference between SSA/graph IRs and expression/stack-based IRs is about how the dataflow (mostly around def-use chains) is represented rather than about what optimizations are possible.
Fom there it becomes fairly obvious that graph IR techniques can be applied to expression-based structures as well, since the underlying information is the same, just represented differently.
Didn't look close enough to JSIR, but from looking around (and from building a restricted Source Graph IR on JS for some code transforms), it basically shows you have at least a homomorphic mapping between expression-oriented JS and graph IR, if not even a proper isomorphism (at least in a structured and side-effect-constrained subsets).
Re: JSIR: A High-Level IR for JavaScript
#17That seems a bit disingenuous given this is not a source-preserving IR! All comments and nonstandard spacing would be completely removed from your code if you gave it a round trip through this format. That doesn't sound like 99.9% source recovery to me...
Re: JSIR: A High-Level IR for JavaScript
#18It's funny they bother to bring up the half dead "Google Closure Compiler" as an example. And my dumb brain still don't understand how IR is "better" than AST after reading this post. Current AST based JS tools working reasonably well, and it's not clear to me how introducing this JSIR helps tool authors or downstream users, when there are all those roadblocks mentioned at the end.
Re: JSIR: A High-Level IR for JavaScript
#19Earlier quoted context omitted.
> when the author is an AI and the consumer is a compiler, and no human needs to read the output at all. This seems like a big bet on the assumption that fully autonomous codegen without humans in the loop is imminent if not already present - frankly, I hope you are wrong. Even if that comes to pass in some cases, I also find it hard to believe that an LLM will ever be able to generate code in any new language at the…
I recently wrote a simple interpreter for a stack based virtual machine for a Firefox extension to do some basic runtime programming b/c extensions can't generate & evaluate JavaScript at runtime. None of the consumer AIs could generate any code for the stack VM of any moderate complexity even though the language specification could fit on a single page. We don't have real AI & no one is anywhere near anything that c…
I go subsystem by subsystem.
Writing the interpreter for a stack vm is as simple as it gets.
Re: JSIR: A High-Level IR for JavaScript
#20Earlier quoted context omitted.
It seems to me that there's a certain "blindness" between two compiler worlds. Compiler engineers for mostly linear-memory languages tend to only think in terms of SSA, and assume it's the only reasonable way to perform optimizations. That transpires in this particular article: the only difference between an AST and what they call IR is that the latter is SSA-based. So it's like for them something that's not SSA is n…
I think the WASM world is a clear example that bridges the gap you're describing. You usually compile from SSA to WASM bytecode, and then immediately JIT (Cranelift) by reconstructing an SSA-like graph IR. If you look at the flow, it's basically: Graph IR -> WASM (stack-based bytecode) -> Graph IR So the stack-based IR is used as a kind of IR serialization layer. Then I realized that this works well because a stack-b…