What it does
static-explicit(C, Go, Zero): declared types on parameters, returns, fields, constants, and globals; local inference forletfrom initializers and for unsuffixed literals; primitive, tuple, array, slice, reference, pointer, function, nullable, map, record, sum, and class types; every OPS operation typed by its operand types, with policy legality (promoteis rejected on statically typed results); calls with named, default, variadic, and spread arguments; fields and methods throughimplblocks, classes, and base classes;if,match, loops, labelled blocks, closures,async/await/spawn, generators,try/catchwith type tests, casts, and intrinsics.dynamic(Python, Lua, Mox): every value isany; only the errors that are certain whatever the run-time values are reported (wrong argument count to a known function, unknown named arguments, constructor patterns of the wrong length, unknown record fields).- Host declarations: a language's library lives outside the unit;
Checkertakes the types of extern names, other units' definitions, named intrinsics, and members of host types.
Not in this release, and reported as Unsupported rather than guessed: generic items and arguments, traits and interfaces used as types, associated types (all 0.5.0). Not this crate's job: name resolution (resolve-lang), precise pattern exhaustiveness (match-lang: the checker verifies top-level constructor coverage and lists the rest in Typed::deferred_matches), and mutability and ownership (capabilities over typed HIR).
What each guarantee rests on:
| Guarantee | How it is checked |
|---|---|
| Well-typed programs check clean, with exactly the types they should have. | A typed generator builds random well-typed programs (arithmetic, comparisons, if, blocks, calls, tuples, arrays, records, sums with match, constructor calls, method calls, field access, indexing); property tests require no diagnostic, the generated type for every expression, and the right method for every method call. |
| One mistake, one diagnostic, at the mistake. | Property: replacing one numeric literal of a well-typed program with true yields exactly one diagnostic, on that literal. Property: replacing any leaf with an error node yields none. |
| Checking never panics and always terminates. | Property: random HIR of every form, repaired by hir-lang's lenient validation, checks without panicking under three profiles, types every live expression and pattern, and is deterministic; under any step budget it finishes or returns BudgetExceeded. |
| Shared type structure is never expanded (type-lang's ISSUES M39). | Types are hash-consed terms in a union-find store. Unifying two Pair(v, v) doubling chains is linear: step counts are compared at 2,000 and 4,000 levels, and 50,000 levels check in a test. |
| Work is linear in the program. | Step counts at 2,000 and 20,000 functions differ by the size factor. Deep input is checked on an explicit stack: tests cover 100,000-deep expressions, 50,000 nested blocks and ifs, 30,000-deep types and patterns, 20,000-long alias chains, and 5,000-deep inheritance. |
Installation
[]
= "0.2"
Without the standard library:
[]
= { = "0.2", = false }
Quick start
use ;
use Interner;
use ;
let mut names = new;
let mut b = new;
// fn main() { let x = 1 + true; }
let one = b.int;
let yes = b.lit;
let sum = b.op;
let x = b.new_binder;
let pat = b.bind;
let stmt = b.let_stmt;
let body = b.block;
let main = b.func;
let root = b.module;
let hir = b.finish?;
// Static: one diagnostic, at `true`; `x` is the error type, so nothing
// that uses it is reported again.
let typed = check.unwrap;
let d = typed.diagnostics;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
// Dynamic: no static errors; every value is `any`.
let typed = check.unwrap;
assert!;
assert_eq!;
# Ok::
Profiles start from a preset and adjust toggles:
use ;
let kraken_like = static_explicit
.with_records
.with_subtyping
.with_numeric_widening
.with_string_add;
assert!;
Host declarations go through Checker:
use ;
use Interner;
use ;
let mut names = new;
let print = names.intern;
let mut b = new;
// fn main() { print("hi") } -- `print` is bound by the host
let path = b.resolved_path;
let callee = b.expr;
let hi = b.str_lit;
let call = b.call;
let stmt = b.expr_stmt;
let body = b.block;
let main = b.func;
let root = b.module;
let hir = b.finish?;
let mut checker = new;
let print_ty = checker.types_mut.func;
checker.declare_extern;
let typed = checker.check.unwrap;
assert!;
# Ok::
Runnable programs: cargo run --example quickstart, cargo run --example host.
Performance
cargo bench --bench bench, release profile, Windows x86_64. Library only: the HIR is built before timing starts. Measured on a machine shared with concurrent builds (CPU at 100%), so these are ranges across runs and upper bounds; re-measure on an idle machine before quoting them.
| Benchmark | Time | Throughput |
|---|---|---|
static-explicit, 100k HIR nodes |
14.7–17.1 ms | 5.7–6.6 M nodes/s |
static-explicit, 1M HIR nodes |
130–200 ms | 4.8–7.5 M nodes/s |
dynamic, 100k HIR nodes |
3.6–5.7 ms | 17–27 M nodes/s |
dynamic, 1M HIR nodes |
49–80 ms | 12–20 M nodes/s |
| Doubling chain, 100k levels (1.4M nodes) | 227–347 ms | 4.0–6.2 M nodes/s |
Platforms
Linux, macOS, and Windows. The crate uses no operating-system facilities: a program checks the same way, with the same type ids and diagnostics, on every platform.
Contributing
See REPS.md for the engineering standards every change is held to, dev/DIRECTIVES.md for the definition of done, and dev/ROADMAP.md for the plan. Before a PR: cargo fmt --all, cargo clippy --all-targets --all-features -- -D warnings, and cargo test --all-features must be clean.