Pre-1.0 · open source · take the tour

Expressive code. Native speed.

Sable is a systems language with a clean, readable syntax, value semantics and automatic reference counting, move-checked resources, and compile-time checks on how memory is used. It compiles ahead of time to native code through LLVM, with no garbage collector.

For macOS and Linux, with Windows in progress. One sable command builds, tests, formats and debugs.

module Tour/// A closed union: a `match` over it must cover every case.union Shape {    Circle(radius: F64)    Rect(width: F64, height: F64)}protocol Describable {    fn describe() -> String}extension Shape: Describable {    var area: F64 => match self {        case .Circle(let r)      => 3.14159 * r * r        case .Rect(let w, let h) => w * h    }    fn describe() -> String => "a shape of area \(area)"}union ShapeError { Negative(side: F64) }/// Errors are typed: callers know exactly what can go wrong.fn square(side: F64) throws(ShapeError) -> Shape {    guard side >= 0.0 else {        throw .Negative(side: side)    }    return .Rect(width: side, height: side)}fn main() {    let shapes: Shape[] = [.Circle(radius: 1.0), .Rect(width: 2.0, height: 3.0)]    var total = 0.0    for shape in shapes {        print(shape.describe())        total += shape.area    }    print("total area: \(total)")    do {        print(try square(side: 4.0).describe())        print(try square(side: -1.0).describe())    } catch .Negative(let side) {        print("a side cannot be \(side)")    }}
3
memory tiers, chosen per type
0
lifetime annotations to write
1
tool to build, test, format and debug
36
standard library modules

Values first, objects when you need them

Structs, unions and protocols carry most programs: values laid out inline and copied, matched exhaustively, and specialised by the compiler. Classes are there for the things that have identity.

values.sb
struct Vec3 { x: F32, y: F32, z: F32 }      // 12 bytes, no headerpublic union Outcome<T, E> {    Ok(T)    Err(E)    fn map<U>(_ f: (T) -> U) -> Outcome<U, E> {        return match self {            case .Ok(let v)  => .Ok(f(v))            case .Err(let e) => .Err(e)        }    }}fn render(v: Int | String | Vec3) -> String {    if v is Int    { return v.toString() }    // narrowed to Int    if v is String { return v }               // narrowed to String    return "\(v.x), \(v.y), \(v.z)"           // only Vec3 is left}fn total(_ values: some Sequence<Int>) -> Int {   // specialised, static    var sum = 0    for v in values { sum += v }    return sum}fn draw(_ shapes: (any Drawable)[]) { }           // boxed, dynamic: you can see it

Memory safety without a collector

Say where memory lives — inline, in a region freed all at once, or counted — and Sable checks that nothing refers to it after it is gone. Most of the safety of a borrow checker, none of the lifetime syntax.

Tier 0

struct

Inline bytes: no header, no reference count, copied on assignment. The default for data.

Costs zero

Tier 1

region

A scoped arena: bump-allocate a thousand values and free them all in one store at the end.

Costs a bump pointer

Tier 2

class

Objects with identity: automatic reference counting, weak and unowned references, full reflection.

Costs a header and ARC

memory.sb
@noncopy struct FileHandle {    private let fd: I32    deinit { sys.close(fd) }        // runs exactly when the last owner goes}let a = FileHandle.open("log.txt")let b = a                           // movesuse(a)                              // error: 'a' was moved to 'b'fn parse(src: String) -> Ast.Module {    region arena {                  // reserve, bump, release in one store        let tokens = arena.alloc(Token[>..]())        lex(src, into: &tokens)        return parseModule(tokens, in: arena).toOwned()    }                               // the whole arena is freed here}fn longest(_ a: String&, _ b: String&) -> String& {    return a.count >= b.count ? a : b   // root inferred as {a, b}: no lifetimes}

What the compiler checks

  • Move-only types for handles, locks and buffers: use after move is a compile error.
  • Exclusive access to mutable state, checked statically where it can be and at run time where it cannot.
  • References with inferred roots: nothing that refers to a value may outlive it, and you never write a lifetime.
  • Escape analysis removes the retain and release pairs a borrowed value does not need.
  • Opt-in inline layout: a value with no absolute pointers, written to disk or a socket as it is.
How memory works in Sable
sable check
error[S3061]: cannot return a reference rooted in local 'tmp'  --> src/parse.sb:41:12   |41 |     return &tmp.name   |            ^^^^^^^^^ 'tmp' dies at the end of this function   |help: three ways to fix this   |  - return an owned value:        return tmp.name.toOwned()   |  - allocate in the caller's region: fn f(in r: region) -> String&   |  - return the whole value:       return tmp

A program that needs a lifetime annotation elsewhere gets a diagnostic that names the fix here.

Errors in the signature

A function says what it can throw, the caller handles exactly that, and the compiler checks that every case is covered.

Typed

throws(E) says exactly what can fail, and a catch that misses a case does not compile.

Cheap

Errors compile to a discriminated return value, not to unwinding tables.

Composable

rethrows, throwing sequences with for try, and throw as an expression.

Separate from panics

precondition, fatalError and unreachable stop the program; errors are values.

errors.sb
union IoError { NotFound(path: String), Denied, Interrupted }fn read(_ path: String) throws(IoError) -> String { }fn load() throws(AppError) {    let text = try read("a.txt")                 // propagates, converted by From    let maybe = try? read("b.txt")               // a String?    let config = try read("c.txt") catch { "" }  // an inline fallback    do {        let notes = try read("d.txt")    } catch .NotFound(let path) {        log.warn("missing \(path)")    } catch {        throw .io(error)    }}let port = configured ?? throw ConfigError.Missing("port")

Structured concurrency, checked

async and await, tasks that cannot outlive their scope, and actors that run one call at a time — with data races on their state a compile error.

service.sb
async fn main() throws {    async let a = fetch(url1)           // starts now, alongside    async let b = fetch(url2)    let both = try await (a, b)         // structured: both awaited here    await withTaskGroup(of: Response?.self) { group in        for u in urls { group.spawn { try? await fetch(u) } }        for await r in group { handle(r) }   // in the order they finish    }}actor Counter {    private var value = 0    fn increment() { value += 1 }       // isolated: callers await    nonisolated let id: UUID            // immutable, read freely}let c = Counter()await c.increment()
  • Child tasks cannot outlive the scope that started them, and are cancelled with it.
  • Cancellation is cooperative, and a sleeping task wakes at once with CancellationError.
  • Sendable is checked at every isolation boundary, at compile time.
  • Threads and parallel loops are there too, under the same Sendable rules.
Concurrency in the guide

And the rest of the toolbox

One tool for the whole job

sable builds, runs, tests, benchmarks, formats, lints, documents and debugs, manages packages and serves the language server. Its manifest is Sable too, so your editor completes it.

  • sable run

    Compile and run a package, or a single file.

  • sable check

    Type-check without generating code: fast.

  • sable test

    @test functions, and with --doc the examples in your doc comments.

  • sable bench

    @bench functions, compared with a baseline.

  • sable fmt

    One format, no options, by design.

  • sable lint · fix

    Lints at the levels your manifest sets, and their fixes.

  • sable doc

    HTML documentation and a JSON symbol graph.

  • sable debug

    A debug build under lldb, with Sable-aware formatters.

  • sable add · publish

    Dependencies and the registry, editing your manifest for you.

  • sable explain

    The full explanation of any compiler diagnostic.

  • sable bindgen

    Sable declarations for a C header.

  • sable lsp

    The language server, for any editor.

package.sb
import Sable.Buildlet manifest = Package {    name: "hello",    version: "0.1.0",    edition: 2027,    dependencies: [        .registry("sable-json", "^1.2"),        .path("shared", "../shared"),        .git("http", "https://github.com/example/http.git", tag: "v0.4.0"),    ],}

In your editor

Diagnostics as you type, completion, go to definition, rename, inlay hints, formatting and debugging.

  • VS Code
  • Vim and Neovim
  • Helix
  • Emacs
  • Sublime Text
  • any LSP editor

Start with the tour

Build the toolchain from source, then read the tour in one sitting. The guide takes it from there.

Shell
git clone https://github.com/Rikarin/Sable.gitcd Sable && dotnet publish src/Sable.Driver -c Release -o ~/.sable/binsable new hello && cd hello && sable run
Sable

A systems language with value semantics, automatic reference counting, move-checked resources and compile-time checks on how memory is used, compiled ahead of time to native code through LLVM.

Sable is pre-1.0: the language, the standard library and the toolchain work end to end, but expect changes between versions.