Skip to main content

Compiler

Hew source lowers through HIR and MIR to LLVM IR, then to a native binary.

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.

Compilation pipeline

Source → Lexer → Parser → Type Check → HIR → MIR → LLVM IR → Native

Ownership decisions — which values need dropping, what has moved — are resolved in MIR, so codegen carries those facts into LLVM IR instead of re-deriving them.

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.
  • 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.

Tools built on the pipeline

The same 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.