Compiler
Hew compiles through a pure-Rust pipeline: HIR and MIR lowering direct to LLVM IR.
Overview
The Hew compiler is written entirely in Rust. The frontend (hew-lexer, hew-parser, hew-types) handles lexing, parsing, and type checking. The typed program then lowers through two intermediate representations — HIR and MIR — before the codegen crate (hew-codegen-rs) generates LLVM IR directly. There is no C++ backend and no MLIR step.
Compilation pipeline
Source code passes through the Rust frontend for lexing, parsing, and type checking. The checker output lowers through HIR (high-level IR) and then MIR (mid-level IR) before codegen emits LLVM IR and drives compilation to a native binary:
Ownership decisions — which values need dropping, what has moved — are resolved in MIR before codegen sees them. The codegen crate emits LLVM IR directly, carrying the already-resolved ownership facts rather than re-deriving them at code-generation time.
Intermediate representations
- HIR — high-level IR: desugared and name-resolved AST, close to surface syntax but with all imports and scopes resolved.
- MIR — mid-level IR: explicit control flow with ownership, drop placement, and suspension points fully resolved. The proving gate for codegen correctness.
- LLVM IR — generated by
hew-codegen-rs, linked and optimised by the system LLVM toolchain.
Runtime library
The Hew runtime provides the infrastructure that actors depend on at execution time:
- M:N work-stealing scheduler — Lightweight actors run across a pool of worker threads.
- Actor lifecycle — Mailboxes, actor groups, supervision, shutdown, and cancellation implement the language's lifecycle rules. See Actor Lifecycle.
- Memory and resources — Actor-local allocation supports isolated state, while ownership and resource cleanup remain language-level guarantees. See Ownership and Affine Values.
- I/O and time — Streams, networking, asynchronous waits, and timers let actors wait without tying up a worker thread.
- Observability — Runtime events feed the Observe tools for live inspection and saved captures.
Current status
The pure-Rust pipeline powers hew check, hew build, hew run, and hew test. The same frontend crates (hew-lexer, hew-parser, hew-types) also power the language server (hew-lsp) for editor diagnostics, completion, hover, and semantic tokens.