Ownership without lifetimes
Parameters say read, lend, or consume. A stored reference is tied to the place it came from. There is no lifetime syntax.
Version 0.21.5. New: one-command install for Windows, Linux, and macOS, and gg update. What changed
Greengold is a statically typed systems language that compiles to native code through LLVM. Ownership is three words on a parameter, mutability is inferred, and every diagnostic can carry a checked fix.
struct Account:
owner: string
balance: i64
fn show(a: read Account):
print(a.owner, a.balance)
fn deposit(a: lend Account, amount: i64):
a.balance += amount
fn close(a: consume Account):
print("closed", a.owner)
fn main():
acct = Account{ owner: string.from("Ada"), balance: 100 }
deposit(acct, 50)
show(acct)
close(acct)The mode is written once, on the parameter. The call stays f(x). After close, acct is gone.
fn parse_digit(c: u8) -> Result[i32, str]:
if c < '0' or c > '9':
return Err("not a digit")
return Ok(i32(c - '0'))
fn add_digits(a: u8, b: u8) -> Result[i32, str]:
x = parse_digit(a)?
y = parse_digit(b)?
return Ok(x + y)
fn main():
match add_digits('3', '4'):
Ok(v):
print(v)
Err(e):
print(e)Optional and Result are prelude enums. ? returns early on Err and stands on its own line.
fn make_adder(k: i32) -> Fn(i32) -> i32:
return fn(x: i32) -> i32 => x + k
fn main():
steps = List[Fn(i32) -> i32]()
steps.push(make_adder(1))
steps.push(make_adder(10))
v = 0
for f in steps:
v = f(v)
print(v, make_adder(5)(1))Fn is an owned closure: it can be returned and stored in a list. A plain fn argument is compiled for the closure, so the call is direct.
enum Shape:
Circle(f64)
Rect(f64, f64)
Empty
fn area(s: Shape) -> f64:
return match s:
Circle(r) => 3.14159 * r * r
Rect(w, h) => w * h
Empty => 0.0
fn main():
print(area(Shape.Rect(2.0, 3.0)))A match must cover every variant. In a pattern a bare name is a variant, so a typo is an error, not a catch-all.
fn clamp(n: i32, lo: i32, hi: i32) -> i32:
if n < lo:
return lo
elif n > hi:
return hi
return n
test:
require clamp(5, 0, 10) == 5
test edges:
require clamp(-3, 0, 10) == 0
require clamp(99, 0, 10) == 10
fn main():
print(clamp(42, 0, 10))A test block belongs to the function above it. gg test runs them; gg test --json reports each one.
read, lend, consumeNative code, value types, and no garbage collector. Six choices define how Greengold reads and fails.
Parameters say read, lend, or consume. A stored reference is tied to the place it came from. There is no lifetime syntax.
Release builds keep bounds and overflow checks and still finish within 5% of C++ and Rust, or ahead of both, on 17 of 18 workloads.
Variables can change by default. One that never changes is treated as fixed, and the editor shows it as an inlay hint.
Integer overflow, division by zero, bad shifts, and out-of-bounds indexes trap, in debug and in --release.
gg check --json returns stable codes and fixes. A fix marked verified was applied to a copy and made the error go away.
One spelling for each construct, one specification, and a list of rejected forms. People and language models read the same language.
The mode is written on the parameter, never at the call.
A shared borrow. The function may read, not assign. The caller keeps the value.
fn show(a: read Account):
print(a.balance)An exclusive borrow. The function may change the value in place; nothing else may touch it during the call.
fn deposit(a: lend Account, n: i64):
a.balance += nTakes ownership. After the call the argument is gone, and using it again is a compile error.
fn close(a: consume Account):
print("closed")A bare parameter of a heap type gets its mode from the body: read when the body only reads it, lend when it changes it, consume when it moves it. Write the mode only when you want to pin it in the signature.
There is no var and no mut on locals. Every variable can change. A variable that nothing changes is treated as fixed, and your editor shows the inferred word as an inlay hint.
fixed to turn the inference into a guarantee.fixed value is a compile error.var is an error that tells you to delete it.fn main():
fixed limit = 3
total = 0
for i in 0..limit:
total += i
fixedname = "gg"
print(name, total)Every diagnostic has a stable GGxxxx code, labels for the definition, the move, and the later use, and a list of fixes.
gg check --json returns the same diagnostic as structured data.verified.$ gg check counter.gg
error: `c` variable was moved (`consume`), can no longer be used.
--> use-after-consume.gg:10:11 GG0301 use-after-consume
|
10 | print(c.value)
| ^^^^^^^
|
9 | finish(c)
| ^ `c` is consumed here
|
8 | c = Counter{ value: 1 }
| ^^^^^^^^^^^^^^^^^^^^^^^^ `c` is declared here
|
4 | fn finish(c: consume Counter):
| ^^^^^^^^ `finish` takes `c` as `consume`
= help: Move a copy with `c.clone()` to keep using `c`, use it before the move, or reassign it after the move.
= fix (verified): Remove `consume` from `c` so the caller keeps ownership
= fix (verified): Move a copy instead: `c.clone()`
= fix (manual): Use `c` before it is consumed, or do not use it afterwards
1 error found.18 workloads against g++ -O3 and rustc -C opt-level=3, measured on 13 October 2026. Greengold's --release keeps bounds checks and integer overflow traps on.
What exists today, and what is outside the safety guarantee.
llvmlite and links with clang or gcc. LLVM is the only backend.gg check, run, build, test, fmt, doc, api, bindgen, and a language server with inlay hints.unsafe: blocks — pointers are not checked for liveness, alignment, or bounds.trust, which skips one bounds check, in unsafe: or a hot fn.--unchecked build flag, which removes bounds checks.std.thread, a pthread wrapper with no Send or Share bound.[]T.Eighteen sections, one example per feature, and the list of forms the compiler rejects. Also available as plain Markdown for tools and models.