BAGA v1.4.2 · C + LLVM · self-hosted

Memory is a discipline.
The compiler is the judge.

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.

MIT license Linux 200+ tests no external dependencies
abs_val.baga real output
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
}
$./baga --verify abs_val.baga
verify abs_val:
  ensures #1 (output >= 0): ДОКАЗАНО
  аритметика (преливане: (0 - x)): ОБРОЧЕНО
    контрапример: x = -9223372036854775808
fragment of real --verify output · baga 1.4.2 · verdicts in Bulgarian
138/138verify gates in CI
52self-hosting PARITY
C + LLVMtwo backends, one oracle
baga2 == baga3self-host fixed point
MITopen source, no dependencies
01 The language

The claim is part of the code. The check belongs to the compiler.

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.

01 / SPEC

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”.

02 / EFFECTS

Effects are in the type

str !IO !NotFound is a different type from str. ? propagates effects, catch handles them. A missing effect does not compile.

03 / MEMORY

Memory has a protocol

Worlds are regions with ownership, freeze and move. The compiler catches dangling pointers before they become a production incident.

examples/effects.baga
// Декларираме ефекти в 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(резултат)
}
$./baga -I . -I app-product examples/effects.baga
съдържание
the effect is in the signature, not in a comment
? does not hide an effect — it propagates it
catch !NotFound handles only that dimension
02 Memory

An entire data graph — one value.

Plan 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.

mutableowner
→world_freeze
frozenN readers
→chan_send
movedanother thread
world_free(w) — frees the whole chain at once; any access afterwards is REFUTED.
  • The protocol is a conclusion, not a convention. use-after-free, mutate-after-freeze, use-after-move and double-free are refuted with a concrete counterexample.
  • A frozen world is a shared read-only capability. N readers, no copying; chan_send moves it to another thread.
  • dump/load without fixups. Roots and schema live inside the region and offsets are positional. Compact dump: 1.60 MB instead of 4.19 MB for the same world.
  • A seatbelt against dangling pointers. A borrowed value escaping into a Vec/Map is a compile error — across function boundaries, generics, vec_slice/vec_concat and map_keys.
~3 nscached access
~5.7 nsstreaming access
~0.5 nsplain Vec, no checks

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.

examples/worlds.baga
// Регионът се пълни, замразява, дампи, освобождава
// и зарежда отново: офсетите са позиционни.
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)
}
$./baga -I . -I app-product examples/worlds.baga
hello
world
reloaded
escape.baga · --check · real diagnostic (Bulgarian)
контейнерът 'out' държи заемана стойност или ключ от света 'w', който се освобождава тук — след free елементите му са висящи указатели; копирай стойността преди free (concat(s, "") за низ) или освободи контейнера първо (drop(out))
03 Proof

Three possible answers. None of them is “trust me”.

The verifier is small and deliberately honest: outside the proven fragment it says CANNOT DECIDE. That is the difference between proof and hope.

PROVEN

The claim holds for every input in the fragment. Termination is proven with decreases.

REFUTED

There is an input where the claim is false. The verifier returns a concrete counterexample, not an accusation.

CANNOT DECIDE

Outside the proven fragment. An honest “I don’t know” beats a false “proven”.

abs_val.baga
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
}
real output · ./baga --verify abs_val.baga
verify abs_val:
  ensures #1 (output >= 0): ДОКАЗАНО
  аритметика (преливане: (0 - x)): ОБРОЧЕНО
    контрапример: x = -9223372036854775808
  (аритметика: 0/1 операции доказано безопасни — вердиктите за ensures са в идеализирания ℤ модел)
  ефект !Overflow: прелива при x = -9223372036854775808, а !Overflow не е деклариран

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.

04 Measured

The numbers come with the command that produced them.

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.

rocksbaga vs RocksDB

2026-11-01 · btrfs/NVMe · N=5000
ModeOperationrocksbagaRocksDB% of RocksDB
durablePUT762 ops/s612 ops/s124%
GET_SEQ555k ops/s437k ops/s127%
GET_RND555k ops/s486k ops/s114%
batchPUT116k ops/s140k ops/s82%
GET_SEQ714k ops/s501k ops/s142%
GET_RND714k ops/s483k ops/s148%

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.

Worlds in production

  • boilaDB — SQL/HTTP/PG statistics in a frozen world; the hot path takes no global mutex.
  • fmrbaga · metbaga · cloudbaga — /metrics gauges in a frozen world via WMet.
  • queuebaga — read-through wcache for terminal statuses; the disk stays source of truth.
  • Not everything needs a world — 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.

06 Start

From clone to the first counterexample.

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.

terminal
# 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
Honest status: Baga is a working prototype, not a production language. The verifier says “CANNOT DECIDE” outside the proven fragment, general non-linear arithmetic remains open, and the benchmarks are micro-bars, not feature parity. The open problems are public.
бага> fn inc(x: i64) -> i64 {
… return x + 1
… }
(записано)
бага> inc(41)
42
бага> let x = 5
бага> x * 2
10

Declarations and let bindings persist between lines; an expression prints itself. The model is compile-and-run, not an interpreter.