Language Features

Everything you need to build resilient, high-performance services.

Actor Model

Actors are the fundamental unit of computation in Hew. Each actor owns its state exclusively, with isolated heaps and typed message passing. The compiler verifies that all messages are Send-safe at compile time.

  • Zero-cost isolation
  • Compile-time Send checking
  • Single-threaded execution per actor
  • Bounded mailboxes with backpressure
  • Direct method calls: counter.increment(10)
  • Lambda actors with <- send operator: worker <- 42

Memory Model

Hew uses RAII — memory is reclaimed deterministically via the Drop trait at scope exit. Each actor owns its own heap, and when an actor terminates, its entire heap is freed in one operation. Cross-actor messages use copy-on-send semantics: values are deep-copied, keeping each actor's memory fully isolated.

  • RAII-based with deterministic reclamation
  • Deterministic destruction via Drop trait
  • Per-actor heap ownership
  • Copy-on-send for cross-actor messages
memory model
RAII — deterministic destruction via Drop trait
Actor heap — each actor owns its memory
Copy-on-send — messages are deep-copied
Predictable — consistent latency, deterministic cleanup

Supervision Trees

Inspired by Erlang/OTP, Hew makes fault tolerance a language feature. Supervisors automatically restart failed actors with configurable strategies and restart budgets.

  • one_for_one, one_for_all, rest_for_one strategies
  • Restart budgets keep failures contained
  • Supervision hierarchies compose
  • Escalation semantics for unrecoverable failures

Structured Concurrency

Tasks in Hew are always scoped. A Task<T> represents concurrent work within an actor. Launch tasks with s.launch inside a scope |s| { ... } block — when a parent scope ends, it waits for all child tasks to complete before continuing. Every task has an owner, and every owner cleans up. Explicit cancellation is available via s.cancel().

  • Task<T> — typed concurrent computation
  • s.launch inside scope |s| { ... } for lifetime-bounded tasks
  • M:N work-stealing scheduler across CPU cores
  • Cooperative cancellation via s.cancel()
  • Automatic join — scope waits for all children

Concurrency Patterns

Hew provides first-class language constructs for common concurrency patterns. select waits for the first of several operations and join runs tasks concurrently and collects all results. select supports after timeouts for deadline-based fallbacks.

  • select {} — wait for the first ready branch
  • join {} — run all, collect all results
  • after timeout clauses on select

State Machines

Most long-lived actors are state machines at heart. Hew makes that explicit with machine, state, event, and on declarations as language constructs. The compiler validates transitions, checks guard expressions, and verifies state reachability at compile time.

  • machine declarations inside actors
  • Named states with typed events
  • when guards referencing actor fields
  • Compile-time exhaustiveness checking

Distributed Actors

Spawn actors on remote nodes with spawn ... on node. The compiler ensures all arguments and messages are wire-safe. Remote actor handles look identical to local ones — message sends are serialized and dispatched over TCP transparently.

  • spawn Actor(args) on node
  • Transparent local/remote handles
  • Gossip-based cluster membership
  • Compile-time wire-safety for all remote messages

Wire Contracts

Network protocols are first-class types in Hew. Wire types define serialization format, field numbering, and schema evolution rules. The compiler enforces forward-compatible evolution — new fields integrate safely with existing deployments.

  • Hew Binary Format (HBF) — compact binary encoding
  • JSON encoding for external interop
  • Schema evolution with field tags
  • Compile-time compatibility checks

Type System

Hew's type system guarantees actor isolation at compile time. Types carry Send + Frozen capability traits for cross-actor safety, while within an actor you have full mutable freedom. Bidirectional type inference minimizes annotations and generics are monomorphized for zero-cost abstraction.

Generics with monomorphization

Zero-cost generic types and functions. The compiler generates specialized code for each concrete type — fully inlined, fully optimized.

Send + Frozen capability traits

Types carry capabilities that the compiler enforces. Send for cross-actor transfer, Frozen for shared immutable access. Within an actor, you have full mutable freedom — the compiler checks boundaries, where it matters.

Bidirectional type inference

Types flow from calling contexts into lambdas and generics. The compiler infers parameter types from signatures — minimal annotations, full compile-time safety.

Pattern matching with exhaustiveness

Match expressions are checked for completeness at compile time. The compiler ensures every possible case is handled.

C FFI with extern blocks

Call into C libraries directly. Extern blocks declare external functions with full type safety at the boundary.

Option<T> and Result<T, E>

Optional values and error handling are explicit in the type system. Every absence is typed, every failure is handled.

Iterator trait with adapters

Compose lazy transformations over sequences. Map, filter, fold — fused into efficient loops by the compiler.

Compilation

Hew compiles to native machine code. The hew build command drives a Rust frontend and C++ MLIR backend, using progressive lowering through LLVM.

.hew Frontend Type Check MLIR LLVM IR Native Binary