Trine 1.0
Python-like syntax. Native speed with the safety checks left on. No annotations, no tracing garbage collector, no borrow checker.
Trine is a statically typed language with mutable value semantics: every list, map and record behaves as its own value, so there is no shared mutable state to reason about, yet updates happen in place whenever a value has one owner. Types are inferred everywhere, match must be exhaustive, integers never silently wrap, and programs touch only what they are explicitly granted. Compiled natively, Trine runs in 1.04× C's time and 0.97× Rust's (geometric mean over 7 benchmarks, from 0.35× to 2.24× of Rust's) and 22× faster than CPython, with overflow and bounds checks kept wherever they can't be proved away.
type Shape =
| Circle(r: Float)
| Rect(w: Float, h: Float)
fn area(s): # no annotations: every type is inferred
match s: # exhaustive: a missing case is a compile error
Circle(r) => 3.14159 * r * r
Rect(w, h) => w * h
fn main():
let a = [1, 2, 3]
var b = a # an independent value, never an alias
b[0] = 99 # updated in place when unique, copied otherwise
print([x * 2 for x in b]) # [198, 4, 6]
print(a) # [1, 2, 3]: `a` never changes
print(area(Rect(w: 2.0, h: 3.0))) # 6.0
Try it in your browser · Website · Install · Tutorial · Language card
New here? The tutorial builds a program from nothing to a native binary in half an hour. The tour shows one feature per program, the gallery lists every example, and the language card is the whole language on one page (~2.6k tokens, every example in it run by the tests).
Why Trine?
| Result | How | |
|---|---|---|
| Native speed | 0.97× Rust's time, 1.04× C's; 22× faster than CPython | Type-directed unboxing, generic code specialized per type, compiled through C (benchmarks, method included) |
| Memory without a GC | 95.7–100% of refcount operations removed | Perceus reference counting with borrow inference; unique values are reused in place (Bet 1) |
| Safety, proved cheap | 99.97% of bounds checks erased (166,728 of 166,779) | Symbolic execution, Houdini loop invariants and Fourier–Motzkin; every proof re-checked by Z3 (Bet 2) |
| Speed you can't break | Matmul n=512: 2.86 s → 58 ms (naive Rust: 201 ms) | Kernels written once as plain math; layout, tiling and vectorization go in a separate .sched file that cannot change results (Bet 3) |
| Code that knows itself | Renames rebuild nothing; reviews separate renames from real changes | Definitions are hashed by meaning, not by name, in a .trine/ store git never sees (Bet 4) |
| Least authority | A program reaches only what it's granted | Files, network, processes, C and Python are capabilities: (Str) -> Int can only compute (capabilities, security model) |
<sub>Every figure on this page comes from one command, python3 tools/benchmarks.py, and a test keeps it that way (last run: Intel(R) Xeon(R) Processor @ 2.10GHz, 2 cores, 2026-11-30). The benchmarks are the same programs in Trine, C, Rust and Python with identical output; the gaps are published with their causes.</sub>
Quickstart
1. Install
Prebuilt for Linux, macOS and Windows on x86-64 and arm64; the installers check every download against the release's checksums.
curl -fsSL https://raw.githubusercontent.com/koongipaloongi/trine/main/install.sh | sh # Linux, macOS
irm https://raw.githubusercontent.com/koongipaloongi/trine/main/install.ps1 | iex # Windows (PowerShell)
Manual downloads, Homebrew, winget, verifying a build's origin, and building from source: docs/INSTALL.md.
2. Write a program
trine new hello # a package: trine.toml, main.tr with a test
trine run hello/main.tr # hello from Trine
trine test hello # runs the `test "name":` blocks
trine build hello/main.tr -o hi && ./hi # a native executable (needs a C compiler)
3. Look inside
From a clone of this repository, see what the compiler infers, proves and optimizes:
trine check examples/higher_order.tr # inferred types, zero annotations
trine run examples/values.tr --stats # cost lens: updates done in place vs copied
trine rc examples/calc.tr # reference counting: naive vs Perceus
trine bounds examples/json.tr # which index operations are proved in bounds
trine caps examples/capabilities.tr # what each function can reach in the outside world
trine run examples/raytrace.tr # cached native build; first runs switch to native mid-run
The language
- Values, not aliases.
letis immutable andvaris mutable. Lists, maps ({k: v}, insertion-ordered), sets and records (v.with(y: 0.0)) behave as independent values and update in place when unique (records, collections). - No silent undefined behaviour. Integer overflow, division by zero and out-of-bounds indexing are errors, checked wherever the prover can't rule them out. Bad input is a value:
parse_intreturns anOption, and?passes failures up (generics, text). - Generics and traits, inferred.
type Tree[a] = ...,Option,Result, andtrait/implwith inferred requirements; generic code is specialized per type at compile time (traits). - Capabilities.
main(sys)receives the only system capability. Files are reached throughDirvalues for directories granted with--allow-read=/--allow-write=, which refuse.., absolute paths and symlinks out; the network, other programs, C libraries and Python each need their own grant (capabilities). - Concurrency without data races.
spawn/wait,async fnandpar_mapbehave exactly as if run in order, on every engine (parallel). - Packages and modules.
import "lib/geometry.tr" as geo; git dependencies pinned by commit and content hash intrine.lock(modules, packages). - Interop. Call C libraries with
extern "lib" fnand Python objects by handle, both behind capabilities (C, Python). - Built for tools and AI agents.
--jsongives every error a stable code and machine-applicable fixes, andtrine fix --applyapplies them;trine fmt,lint,doc,repl,testand a language server come with it (agents, editors).
Hashed by meaning
Trine hashes each definition by its normalized structure, with local names erased and references replaced by hashes. A rename changes nothing that needs rebuilding, and a real change shows exactly what depends on it:
$ trine store p.tr # after renaming total -> sum_all and acc -> running
renamed total -> sum_all (same hash c9825e86e557, nothing to rebuild)
$ trine store p.tr # after changing sum_all's body
changed sum_all c9825e86e557 -> 6f8a3b9889b8
changed average e4fa534f09a1 -> 7293f6969514 # dependents re-hash automatically
changed main a748dc9cdf0c -> d13304909b3a
After a merge, unknown name area comes with "area was renamed to surface (same hash)", and trine semdiff separates renames and dependency-only changes from real ones for review.
How it's built
Trine is written in Rust with no dependencies beyond its standard library. Three engines run every program (an interpreter, an ownership-checking VM and native code), and differential fuzzing holds them to identical output.
| Path | Role |
|---|---|
src/lexer.rs, src/parser.rs | Indentation-aware lexer (Python-style INDENT/DEDENT) and recursive-descent parser |
src/types.rs, src/mono.rs | Hindley–Milner inference, exhaustiveness and mutability checks; trait specialization |
src/ir.rs, src/perceus.rs | Ownership IR; dup/drop insertion with liveness and borrow inference (Bet 1) |
src/bounds.rs, tools/z3_check.py | Bounds proofs: symbolic execution, Houdini invariants, Fourier–Motzkin; Z3 cross-check (Bet 2) |
src/sched.rs, tools/sched_fuzz.py | .sched schedules: validation, loop-nest emission, and a shape × schedule fuzzer (Bet 3) |
src/hash.rs | SHA-256 of normalized definitions and the .trine/ store (Bet 4) |
src/interp.rs, src/irvm.rs | Interpreter with the cost lens; IR VM that catches use-after-move, double drops and leaks |
src/cgen.rs, runtime/trine_rt.h | Native backend: ownership IR → C → machine code, with a small-object pool |
src/fuzz.rs, tests/ | Differential and syntax-mutation fuzzers; golden, engine, security and installer tests |
Documentation and stability
- What Trine 1.0 promises: specification (frozen) · compatibility · changelog · charter
- Guides: the trine command · running programs · native builds · testing · performance · security
- Contributing: CONTRIBUTING.md · roadmap · where things stand. Security reports: see docs/SECURITY.md.
License
Trine is licensed under either of the Apache License, Version 2.0 or the MIT license, at your option. Unless you say otherwise, any contribution you submit for inclusion in Trine is licensed the same way, without additional terms.