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 — no shared memory, no locks, no data races. Actors communicate through typed message passing, and 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
<-operator:worker <- 42
actor ChatRoom { members: i32, message_count: i32, receive fn join(user_id: i32) -> i32 { self.members = self.members + 1 self.members } receive fn post_message(content: String) -> i32 { self.message_count = self.message_count + 1 self.message_count }}Memory Model
Hew is RAII-based with no garbage collector. Memory is reclaimed deterministically via the Drop trait at scope exit. Each actor owns its own heap — when an actor terminates, its entire heap is freed in one operation. Cross-actor messages use copy-on-send semantics: values are deep-copied so no references ever cross actor boundaries.
- ▸ RAII-based, no garbage collector
- ▸ Deterministic destruction via Drop trait
- ▸ Per-actor heap ownership
- ▸ Copy-on-send for cross-actor messages
supervisor ServiceCluster { strategy: one_for_one, max_restarts: 10, window: 60, children: [DatabasePool, CacheLayer, ApiHandler]}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 prevent cascade failures
- ▸ 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. Spawn tasks with scope.spawn — when a parent scope ends, all child tasks are joined or cancelled. No orphan threads. No leaked goroutines. Cooperative cancellation is built into the runtime.
- ▸
Task<T>— typed concurrent computation - ▸
scope.spawnfor lifetime-bounded tasks - ▸ M:N work-stealing scheduler across CPU cores
- ▸ Cooperative cancellation via
scope.cancel() - ▸ Automatic join — scope waits for all children
fn process_batch(items: Vec<Job>) -> Vec<Result<Output, Error>> { scope { let tasks = items .map((job) => scope.spawn { job.run() }); tasks.map((t) => await t) }}Concurrency Patterns
Hew provides first-class language constructs for common concurrency patterns. select waits for the first of several operations, race runs tasks concurrently and returns the first result, and join runs tasks concurrently and collects all results. All support after timeouts.
- ▸
select— wait for the first ready branch - ▸
race— first result wins, cancel the rest - ▸
join— run all, collect all results - ▸
aftertimeout clauses on all patterns
// Wait for the first response, with timeoutlet result = select { resp <- primary.fetch(key) => resp, resp <- fallback.fetch(key) => resp, after 500ms => Err("timeout"),};// Run tasks concurrently, collect all resultslet (users, posts) = join { db.get_users(), db.get_posts(),};// First result wins, cancel the restlet fastest = race { server_a.query(q), server_b.query(q),};wire UserProfile @1 { @1 name: String, @2 email: String, @3 age: i32, @4 verified: bool = false,}Wire Contracts
Network protocols are first-class types in Hew. Wire types define serialization format, field numbering, and schema evolution rules. The compiler enforces compatibility — add fields, never remove them.
- ▸ 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 prevents data races at compile time. No intra-actor borrow checker — single-threaded actors make it unnecessary. Types carry Send + Frozen capability traits for cross-actor safety. Bidirectional type inference minimizes annotations while 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 — no boxing, no vtables.
Send + Frozen capability traits
Types carry capabilities that the compiler enforces. Send for cross-actor transfer, Frozen for shared immutable access. No intra-actor borrow checker — single-threaded actors make it unnecessary.
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 foreign functions with full type safety at the boundary.
Option<T> and Result<T, E>
No null pointers. Optional values and error handling are explicit in the type system, not runtime surprises.
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 current toolchain supports C transpilation and LLVM IR generation, with WASM planned.