Fearless Concurrency • Region-Based Memory • Algebraic Effects • Refinement Proofs
-
Region-Based Memory Management (No explicit
<'a>lifetimes)
Allocations are grouped into compile-time inferred regions (region r { ... }). When a region exits scope, memory is reclaimed en masse in$\mathcal{O}(1)$ without lifetime annotations polluting struct and function definitions. Escape analysis rejects direct region-to-outer escapes and now tracks common indirect escapes through calls: values returned from a callee, stored through an outer destination parameter, or pushed into an outer container are rejected. Direct C callback registration with a region pointer is rejected; arbitrary C code that independently retains pointers, and indirect function-pointer calls (currently unsupported), remain outside static guarantees, so this is still not a full reference-safety guarantee. Seedocs/SYNTAX.md§4. -
Colorless Functions via Algebraic Effects
Noasyncorawaitinfection. Functions declare effect capabilities (yields [Db, IOError, Diagnostics]). Delimited handlers with native machine-level continuations (resume) support synchronous execution, fiber suspension, or pure unit-test mocking. -
Compile-Time Refinement Types
Declare bounded types liketype Health = u8[0..100];andtype Port = u16[1..65535];. The checker rejects out-of-range literal casts and statically rejects division by a refined divisor whose interval spans zero. Casts from variables are not yet range-proven; path-sensitive narrowing is enforced for typedif/whileconditions — see the verified status table indocs/SYNTAX.md§14. -
Linear & Affine Resource Types (Leak Prevention)
linear structenforces exactly-once consumption, including branch convergence acrossif/else: dropping an unconsumed handle is a compile error.affine structcurrently follows the same all-paths consumption rule — automatic drop on earlyreturnis not implemented yet. -
Universal Multi-Target Cross-Compilation
Target Windows GNU (x86_64-pc-windows-gnu), Linux ELF (x86_64-unknown-linux-gnu), Linux AArch64 (aarch64-unknown-linux-gnu), and WebAssembly (wasm32-unknown-unknown) from a single compiler binary via--target. -
Deterministic Package Management & Lockfile (
Forge.lock)
Pure local SemVer resolution (^,*), 3-state DAG cycle detection, alphabetical lockfile determinism, graph closure verification, and transactional dependency mutation viaforge addandforge resolve. -
100% Pure Standalone Self-Hosting Compiler (Independent of Rust, Cargo, & Seed Compilers)
The entire compiler frontend, typechecker, TIR intermediate representation, middle-end optimizer, LLVM code generator, formatter, LSP server, and Forge CLI are written in pure Morrow (compiler/*.mw). The build path contains no Rust or Cargo — but note that the final link step does invokeclangon LLVM IR (and uses the MinGW CRT objects inlib/crton Windows), so clang is a runtime requirement of the toolchain.
This README describes what the released compiler actually does. The full,
tested breakdown lives in docs/SYNTAX.md §14; the short version:
What the self-hosting claim rests on, measured on every release rather than
asserted: a three-stage bootstrap (mwc → stage1 → stage2 → stage3) must close to a
fixed point before anything is tagged — SHA256(stage2.exe.ll) == SHA256(stage3.exe.ll)
and stage2.exe == stage3.exe byte-for-byte. Each release records the resulting
hash in releases/vX.Y.Z.json; if the closure fails, the pipeline refuses to release.
There is no CI involved: the check runs on the machine that builds the binaries.
| Area | Status |
|---|---|
Regions (region r { ... }), _in allocators, O(1) teardown |
✅ implemented, region bodies yield values |
Algebraic effects (effect, yields, perform, handle … with, resume) |
✅ implemented; arms must be fn op(k, args) { resume(k, v); } and cover every op |
Linear resources (linear struct, consume, branch convergence) |
✅ enforced |
Affine resources (affine struct) |
return) |
| Refinements | |
Generics + turbofish (identity::<i64>(42), Pair::<i64> { … }) |
✅ implemented |
| Region escape analysis | *_in results, region-expression values) are rejected on return, on outer-scope assignment, and on struct-field or element stores into an outer-scope value; indirect escapes through ordinary calls are partially detected (return/store/container paths); handler arm bodies are scanned for captured parameter stores; C callback registration with a region pointer is rejected; arbitrary C retention and unsupported indirect calls remain outside |
enum / match, for, nursery/fibers, closures, if-expressions |
❌ not implemented (parse errors) |
| Float literals, float arithmetic | ❌ not implemented; f32/f64 are opaque FFI type names only |
| Debug info (PDB), LTO, section GC | ❌ not implemented (stage-0 Rust only) |
println |
one value per call: literal, integer, or a single {} placeholder |
| Call signatures | callee existence, argument count, and argument/return kinds are enforced; generic parameters are exempt |
std::process |
process_exec and command_status both work natively via default Process effect handler |
Toolchain prerequisite: clang on PATH (the compiler emits LLVM IR and
shells out to clang to link; Windows linking also uses the MinGW CRT in lib/crt).
import std.net;
import std.collections;
// 1. Refinement Types: Bounds proved mathematically at compile-time
type Health = u8[0..100];
type Port = u16[1..65535];
struct Player {
name: String,
hp: Health,
}
// 2. Algebraic Effects instead of 'async' or 'Result'
effect Database {
fn query(sql: String) -> String;
}
fn fetch_player(id: i64) -> Player yields [Database] {
let record = perform Database.query("SELECT name, hp FROM players WHERE id = 1");
Player {
name: "Arthur",
hp: 85 as Health,
}
}
// 3. Scoped Regions: O(1) bulk memory cleanup
fn process_batch() {
region batch_reg {
let mut buffer = string_buffer_new_in(batch_reg);
string_buffer_push_str(&mut buffer, "Processing region batch...", 26);
} // Entire arena memory reclaimed instantly here
}
// 4. Delimited Handlers & Clean Entry Point
fn main() -> i64 {
let p = handle {
fetch_player(42)
} with Database {
fn query(k, sql: String) {
resume(k, "Arthur");
}
};
0
}
Morrow/
├── bin/ # Standalone Production Binaries (Pure Self-Hosted Seed)
│ ├── mwc.exe # Pure Morrow Native Compiler
│ └── forge.exe # Pure Morrow Toolchain & Package Manager
├── compiler/ # Self-Hosting Compiler Subsystems (100% Pure Morrow)
│ ├── ast.mw # AST node data structures and token definitions
│ ├── lexer.mw # High-speed keyword and symbol tokenizer
│ ├── parser.mw # Recursive-descent parser with precedence climbing
│ ├── typeck.mw # Bidirectional typechecker & refinement constraint solver
│ ├── tir.mw # Basic-Block SSA Typed Intermediate Representation
│ ├── opt.mw # Constant folding, DCE, and bounds elimination passes
│ ├── smt.mw # SMT-LIB2 solver bridge (QF_NIA / QF_LIA query generator)
│ ├── codegen.mw # Multi-target LLVM IR emitter, runtime thunks, and ABI bridge
│ ├── fmt.mw # Safety-gated pretty-printer (refuses unsupported files)
│ ├── package.mw # Forge.toml manifest parser, SemVer, and Forge.lock solver
│ ├── json.mw # Pure Morrow JSON serializer and deserializer
│ ├── lsp.mw # Language Server Protocol stdio RPC engine
│ ├── forge.mw # Unified CLI toolchain implementation
│ ├── diagnostics.mw # Algebraic effect diagnostic error reporter
│ ├── interner.mw # Region-backed Robin Hood symbol interner
│ └── main.mw # Compiler driver entry point
├── std/ # Morrow Standard Library (Pure Morrow)
│ ├── collections.mw # Cache-conscious Robin Hood HashMap, Vec, StringBuffer
│ ├── test.mw # Native testing framework (assert, assert_eq, assert_str_eq)
│ ├── fs.mw # Scoped region filesystem operations
│ ├── process.mw # Subprocess spawning and execution
│ ├── refinements.mw # Standard mathematical interval refinements
│ ├── io.mw # Buffered console I/O, BufReader/BufWriter streams
│ ├── net.mw # TCP socket networking
│ ├── http.mw # Zero-copy HTTP/1.1 engine
│ ├── crypto.mw # Hashing, checksums, hex codecs, CSPRNG
│ ├── sql.mw # High-level SQLite connection & transaction wrapper
│ ├── sql_builder.mw # Fluent SQL composition helper (caller-trusted fragments)
│ ├── sqlite.mw # Parameterized database driver (bind untrusted values)
│ ├── sync.mw # Channels and message passing
│ └── time.mw # Monotonic host clock, stopwatch, throughput math
├── tests/ # Pure Morrow Test Suites (21 Native Suites)
│ ├── typeck_refinements.mw # Type checking and interval bounds verification
│ ├── tir_optimizer.mw # SSA constant folding and optimization passes
│ ├── formatter_tests.mw # Pretty-printer output, idempotency, and safety gates
│ ├── package_tests.mw # SemVer, caret constraints, and Forge.lock generation
│ ├── package_negative_test.mw # Cycle detection, conflict rejection, and closure invariants
│ ├── bootstrap_tests.mw # Recursion, arithmetic, and control flow sanity
│ ├── error_handling_tests.mw # Algebraic effect diagnostic reporting
│ ├── win32_gdi_callback_test.mw # Native Win32 C-ABI FFI and callbacks
│ ├── struct_field_layout_test.mw # Dynamic struct field offsets and indexing
│ ├── refinement_test.mw # User-defined refinement syntax and interval solver
│ ├── region_escape_test.mw # Compile-time lexical region escape analysis
│ ├── generics_test.mw # Parametric generics and monomorphization
│ ├── effects_test.mw # Delimited continuations, resumption, and abortive unwinding
│ ├── formal_verification_test.mw # Non-linear SMT intervals, affine & linear resources
│ ├── crypto_test.mw # Hex codecs, standard hashes/checksums, deterministic non-crypto RNG
│ ├── io_test.mw # Integer formatting, BufReader lines, BufWriter assembly
│ ├── sql_test.mw # Query builder composition and SQL rendering
│ ├── lsp_test.mw # JSON-RPC framing, hover, completion, diagnostics
│ ├── http_test.mw # HTTP/1.1 parser edge cases and response formatting
│ ├── net_test.mw # std::net effect plumbing against mock handlers
│ └── time_test.mw # Monotonic clock, stopwatch reset, throughput helper
├── benchmarks/ # Phase 13.3 Runtime Benchmark Suite
│ ├── bench_region_alloc.mw # Region bump allocation vs malloc/free
│ ├── bench_http_parse.mw # std::http parser throughput
│ ├── bench_hashmap.mw # Robin Hood HashMap insert/lookup density
│ └── c/ # Equivalent C baselines (clang -O2, MinGW CRT)
│ ├── bench_region_alloc.c
│ ├── bench_http_parse.c
│ └── bench_hashmap.c
├── examples/ # Flagship Examples & Production Microservices
│ ├── bootstrap_sample.mw# Minimal bootstrap program
│ ├── wasm_sample.mw # WebAssembly computation demo
│ ├── web_service_v2.mw # Fortress v2 Async IOCP Web Server (C100K engine)
│ ├── web_service.mw # Fortress v1 REST API with SQLite & Region Sandboxing
│ └── player.mw # Game demo with effects, refinements, and regions
├── docs/
│ └── SYNTAX.md # Comprehensive Language & Syntax Specification
├── LICENSE.md # Morrow Unified License (MUL) v1.0
├── THIRD-PARTY-NOTICES.md # Upstream attribution for bundled runtime libraries
├── licenses/ # Verbatim GPL-3.0, LGPL-2.1, ZPL-2.1 and GCC RLE texts
└── archive/ # Historical Stage-0 Artifacts
└── stage0-rust/ # Archived legacy Rust bootstrap compiler crates
All developer workflows are executed natively through bin/forge.exe and bin/mwc.exe without any Cargo or Rust dependency.
Run all 22 pure Morrow test suites compiled and executed on the fly, followed by
the compile-fail corpus in tests/negative/ (13 programs that must be rejected
with a specific diagnostic):
.\bin\forge.exe testrunning morrow native test suites...
=== Running Typecheck & Refinement Test Suite === ... ok
=== Running TIR & Optimizer Test Suite === ... ok
=== Running Formatter Test Suite === ... ok
=== Running Package Resolver Test Suite === ... ok
=== Running Package Negative Test Suite === ... ok
=== Running Bootstrap Sanity Test Suite === ... ok
=== Running Error Handling & Diagnostics Test Suite === ... ok
=== Running Win32 FFI & Callbacks Test Suite === ... ok
=== Running Dynamic Struct Field Layout & Indexing Test Suite === ... ok
=== Running Refinement Interval Arithmetic Test Suite === ... ok
=== Running Region Escape Analysis Test Suite === ... ok
=== Running Parametric Generics & Monomorphization Test Suite === ... ok
=== Running Delimited Algebraic Effects Test Suite === ... ok
=== Running Formal Verification & Linear Resources Test Suite === ... ok
=== Running std::crypto Test Suite === ... ok
=== Running std::io Test Suite === ... ok
=== Running std::sql_builder Test Suite === ... ok
=== Running Phase 13.1 LSP Harness Test Suite === ... ok
=== Running std::http Test Suite === ... ok
=== Running std::net Test Suite === ... ok
=== Running std::time Test Suite === ... ok
running morrow negative (compile-fail) suites...
test result: ok. all test suites passed!
# Compile natively for host (Windows x86_64)
.\bin\forge.exe build examples\bootstrap_sample.mw -o target\app.exe
# Or compile directly with the self-hosted compiler
.\bin\mwc.exe examples\bootstrap_sample.mw -o target\app.exeCompile from Windows to Linux ELF, 64-bit ARM, or WebAssembly:
# Linux x86_64 ELF
.\bin\mwc.exe examples\bootstrap_sample.mw --target x86_64-unknown-linux-gnu -o target\app_linux
# Linux AArch64 (64-bit ARM)
.\bin\mwc.exe examples\bootstrap_sample.mw --target aarch64-unknown-linux-gnu -o target\app_arm64.o
# WebAssembly (runnable via Node.js or browser)
.\bin\mwc.exe examples\wasm_sample.mw --target wasm32-unknown-unknown -o target\app.wasm# Add a local dependency with SemVer constraints
.\bin\forge.exe add math_lib --path ../math_lib --version ^1.2.0
# Resolve dependency DAG and generate Forge.lock
.\bin\forge.exe resolve
# Check/verify existing Forge.lock graph closure
.\bin\forge.exe lockPerform instantaneous lexical, syntactical, refinement interval, and region escape checking without code generation:
.\bin\forge.exe check examples\player.mw# Format a comment-free file in the supported subset, in place
.\bin\forge.exe fmt path\to\file.mw
# Check whether a file is already canonical (no write)
.\bin\forge.exe fmt --check path\to\file.mwThe formatter is idempotent (formatting twice is a no-op, and --check passes on
its own output). It is safety-gated: because the AST does not retain comments,
imports, effect declarations, pub, yields, pointer/reference spelling, or
struct-literal field names, forge fmt refuses those files with a diagnostic and
leaves them unchanged rather than dropping declarations. The repository's existing
sources are not written in the current canonical style, so --check across the tree
reports every file as unformatted — format only files in the supported subset before
enabling --check as a CI gate. Full lossless formatting is tracked as Phase 15
P0-1 in ROADMAP.md.
Recompile the entire Morrow compiler using its own binary:
.\bin\mwc.exe compiler\main.mw -o target\stage1.exe
.\target\stage1.exe compiler\main.mw -o target\stage2.exe
.\target\stage2.exe compiler\main.mw -o target\stage3.exeThis produces bitwise identical LLVM IR (SHA256(stage2.exe.ll) == SHA256(stage3.exe.ll)), proving mathematical compiler stability.
Compile and run every benchmark in benchmarks/, then build and run the
equivalent C baselines in benchmarks/c/ with clang -O2 so Morrow's zero-cost
claims can be checked against hand-written C on the same machine:
.\bin\forge.exe benchRepresentative output (best of three runs on a busy developer host, v2.0.1):
running morrow runtime benchmarks...
=== Benchmark: benchmarks/bench_region_alloc.mw ===
=== Morrow Benchmark: Region Allocator vs malloc ===
BENCH morrow_region_bump iterations=1000000 elapsed_ms=17 ops_per_sec=58823529
BENCH morrow_malloc_free iterations=1000000 elapsed_ms=27 ops_per_sec=37037037
=== Benchmark: benchmarks/bench_http_parse.mw ===
=== Morrow Benchmark: std::http Parser Throughput ===
BENCH morrow_http_parse iterations=200000 elapsed_ms=206 ops_per_sec=970873
=== Benchmark: benchmarks/bench_hashmap.mw ===
=== Morrow Benchmark: HashMap Insert/Lookup Density ===
BENCH morrow_hashmap_insert iterations=200000 elapsed_ms=54 ops_per_sec=3703703
BENCH morrow_hashmap_lookup iterations=200000 elapsed_ms=31 ops_per_sec=6451612
=== C baselines (clang -O2) ===
=== C Baseline: malloc/free vs bump allocator ===
BENCH c_malloc_free iterations=1000000 elapsed_ms=27 ops_per_sec=37037037
BENCH c_bump_alloc iterations=1000000 elapsed_ms=14 ops_per_sec=71428571
=== C Baseline: HTTP/1.1 request parser ===
BENCH c_http_parse iterations=200000 elapsed_ms=7 ops_per_sec=28571428
=== C Baseline: open-addressing hash table ===
BENCH c_hashmap_insert iterations=200000 elapsed_ms=19 ops_per_sec=10526315
BENCH c_hashmap_lookup iterations=200000 elapsed_ms=8 ops_per_sec=25000000
bench result: ok. all benchmark programs completed.
Every benchmark program is an ordinary Morrow program, so it can also be run
individually and instrumented with the std::time stopwatch:
.\bin\forge.exe run benchmarks\bench_hashmap.mwEach result line is machine-readable
(BENCH <name> iterations=<n> elapsed_ms=<n> ops_per_sec=<n>), so the suite can
be captured in CI logs and diffed across compiler revisions.