The contract is code
spec states the input, output, requires, ensures
and decreases. The verifier proves it, refutes it with a counterexample, or
says “cannot decide” — never “looks fine”.
Baga is a systems language with Bulgarian roots. Worlds give an entire data
graph one lifecycle — ownership, freeze, move, free. Effects live in the type. And
--verify either proves the contract or returns a concrete counterexample.
spec abs_val {
input:
x: i64
output: i64
ensures:
output >= 0
}
fn abs_val(x: i64) -> i64 {
if x < 0 {
return 0 - x
}
return x
}
--verify output · baga 1.4.2 · verdicts in Bulgarian
Baga does not bolt verification on as an external tool. spec, effects and
regions are in the language, and the compiler refuses a program that contradicts them.
spec states the input, output, requires, ensures
and decreases. The verifier proves it, refutes it with a counterexample, or
says “cannot decide” — never “looks fine”.
str !IO !NotFound is a different type from str. ?
propagates effects, catch handles them. A missing effect does not compile.
Worlds are regions with ownership, freeze and move. The compiler catches dangling pointers before they become a production incident.
// Декларираме ефекти в return типа
fn прочети_файл(път: str) -> str !IO !NotFound {
return "съдържание"
}
fn обработи(път: str) -> str !IO !NotFound {
// ? propagate-ва ефектите нагоре
let данни = прочети_файл(път)?
return данни
}
fn main() {
// catch обработва ВСЯКО измерение
let резултат = прочети_файл("данни.txt")
catch !NotFound => "празно"
catch !IO => "грешка"
print(резултат)
}
fn фибоначи(n: i64) -> i64 {
let mut a: i64 = 0
let mut b: i64 = 1
let mut i: i64 = 0
while i < n {
let temp = b
b = a + b
a = temp
i = i + 1
}
return a
}
fn main() {
for i in 0..6 {
print(фибоначи(i))
}
}
for i in 0..6 is a half-open range (0…5)let is immutable; let mut is mutablePlan caches, snapshots, documents, statistics: structures that are born, frozen, shared and destroyed together. Worlds turn that lifecycle into one value with a checked protocol — on both the C and the LLVM backend.
world_free(w) — frees the whole chain at once; any access afterwards is REFUTED.chan_send moves it to another thread.Vec/Map is a compile error — across function boundaries, generics,
vec_slice/vec_concat and map_keys.W2.14, same machine. Regions are not free: the tax is a few nanoseconds per access and is documented in docs/worlds-bg.md §4–5.
// Регионът се пълни, замразява, дампи, освобождава
// и зарежда отново: офсетите са позиционни.
fn main() {
let w = world_new()
let v = wvec_new(w)
wvec_push_str(w, v, "hello")
wvec_push_str(w, v, "world")
world_freeze(w)
print(wvec_get_str(w, v, 0))
print(wvec_get_str(w, v, 1))
let dump = world_dump(w)
world_free(w)
let w2 = world_load(dump)
let v2 = wvec_new(w2)
wvec_push_str(w2, v2, "reloaded")
print(wvec_get_str(w2, v2, 0))
world_free(w2)
}
The verifier is small and deliberately honest: outside the proven fragment it says CANNOT DECIDE. That is the difference between proof and hope.
The claim holds for every input in the fragment. Termination is proven with decreases.
There is an input where the claim is false. The verifier returns a concrete counterexample, not an accusation.
Outside the proven fragment. An honest “I don’t know” beats a false “proven”.
spec abs_val {
input:
x: i64
output: i64
ensures:
output >= 0
}
fn abs_val(x: i64) -> i64 {
if x < 0 {
return 0 - x
}
return x
}
The contract is proven for all x. But 0 - x overflows at
INT64_MIN — and the verifier does not hide it: that is a separate verdict with a
concrete counterexample. M31 induction
and M32 CDCL
run in CI alongside 138/138 gates; --json exposes the same verdicts to agents.
rocksbaga — a durable LSM KV engine written in pure Baga — against official RocksDB: same keys, values and operation count, on a real disk. This is a speed bar under a specific harness, not feature parity.
| Mode | Operation | rocksbaga | RocksDB | % of RocksDB |
|---|---|---|---|---|
| durable | PUT | 762 ops/s | 612 ops/s | 124% |
| GET_SEQ | 555k ops/s | 437k ops/s | 127% | |
| GET_RND | 555k ops/s | 486k ops/s | 114% | |
| batch | PUT | 116k ops/s | 140k ops/s | 82% |
| GET_SEQ | 714k ops/s | 501k ops/s | 142% | |
| GET_RND | 714k ops/s | 483k ops/s | 148% |
Durable: fsync on every PUT. Batch: bulk load. One writer, pure engine, no RESP/TCP. Batch PUT was 82% in this run — numbers move; the command and raw artifacts are in the scorecard.
/metrics gauges in a frozen world via WMet.wcache for terminal statuses; the disk stays source of truth.rocksbaga, raftbaga and txnbaga keep state under their own synchronisation; the map explains why.docs/app-worlds-bg.md — the map of where worlds help and where they do not.
Every package is a real product, not a demo: built with sandak, run in CI, and exercising the language — IO, concurrency, memory.
Dozens more packages under app-product/ — the full list is in the
README.
No external libraries: a C compiler and make are enough. The LLVM backend is optional;
make self checks that the compiler compiles itself to a fixed point.
# clone and build git clone https://github.com/katehonz/baga-lang.git cd baga-lang make && make sandak # first program ./baga -I . -I app-product examples/zdravei.baga # Здравей, багатуре. Боят започва. # interactive shell make repl # the first counterexample ./baga -I . -I app-product --verify examples/verify/abs_val.baga
Declarations and let bindings persist between lines; an
expression prints itself. The model is compile-and-run, not an interpreter.
Worlds as checked memory, an honest head-to-head with RocksDB, a REPL, and where the verifier stands.
Read →Worlds, RocksDB numbers and the REPL — the Bulgarian version of the November update.
Read →The founding essay: why specifications should be code, and what a counterexample means.
Read →