HeadlinesBriefing favicon HeadlinesBriefing.com

JuliaLang PR Unifies All IR Data Structures

Hacker News •
×

Pull Request #62334 by Keno proposes to unify all intermediate representation (IR) data structures in the Julia compiler into a single Unified IR. The design centers on a flat statement table with hybrid regions over a shared storage core, featuring an Attr Graph (kind column + packed two‑mode operand words + tagged operand pool), layout states (builder/dense/editable/floating) with exactly two renaming points, and a namespaced kind registry that reserves dialect IDs for the bootstrap stack (Julia Syntax=1, Julia Lowering=2, formatter=3; core=0). A generic tree porcelain provides Tree/Node List cursors, construction utilities, mapchildren/copy_ast, provenance walks, and compact!‑as‑GC (compact_graph!/collect_syntax!) along with a verifier. Unified IR is bootstrapped into Base before Julia Syntax, which runs on this substrate, and its sources are added to COMPILER_FRONTEND_SRCS so sysimage rebuilds trigger on change.

Julia Lowering and the Unified Backend reuse the existing front‑half pipeline (macro expansion, desugaring, scope analysis, closure conversion) and emit structured Unified IR region form directly (if/loop/try region ops, cells for frame variables, sealed exit terminators) instead of linear goto IR. Every emitted statement carries a :source column linking to the originating syntax tree cursor, enabling graph‑qualified provenance walks that cross from optimized IR back to surface text for highlightable diagnostics. The Backend can be GC‑collected via collect_syntax! against live IR and is baked cleanly in the optional sys‑JL sysimage stage.

In package‑only mode, a provider side supplies converters between Code Info and Unified IR (including exception handling and phi synthesis), an inference port running natively on Unified IR, optimizer passes (SROA, inlining via splice_body!, ADCE, structurization, cell promotion), and a Queries API. Activation occurs through the ordinary compiler‑replacement mechanism (Core.OptimizedGenerics.CompilerPlugins.typeinf owner hook + with_unified_compiler). Loading is demand‑driven via Compiler.load_unified!(), which inserts the port into a Main‑rooted carrier module. The PR also adds test harness integration, a provenance demo, and a NEWS.md entry under compiler/runtime improvements.