Limen 0.2.0 for macOS and Linux

Code can only do what it was handed.

Limen is a small compiled language with no ambient authority. Files, the network, the clock and other programs are reachable only through capabilities: values a function is given as arguments. So its signature tells you everything it can do.

Read the book
$ curl -fsSL https://limen-lang.org/install | sh
main.lmn
fn main(root: Root) -> Result[(), IoError] {
    let notes = root.fs.under("notes").read_only()
    let text = load(notes)?
    report(root.stdout, count_words(text))
    Ok(())
}

// Can read files under notes/, and nothing else.
fn load(fs: Fs) -> Result[Str, IoError] {
    fs.read("today.txt")
}

// Can only compute: no file, network, clock or output.
fn count_words(text: Str) -> Int {
    text.split(" ").filter(|w| w != "").len()
}

// Can print, and nothing else.
fn report(out: Stdout, n: Int) {
    out.print("{n} words")
}
examples/home-01-caps/main.lmn

Authority in the signature

Read the signature, know the function.

main gets root, the only source of authority, and hands each function the part it needs: load can read files under notes/, report can print, and count_words can do neither.

I wanted a language where that's enough to know what a function can do, without reading its body or anything it calls. The compiler knows it too:

Terminal
$ limen caps main.lmn
main         Root
load         Fs
count_words  pure
report       Stdout

What you get

Six things the compiler holds you to.

  1. 01

    Dependencies on a leash

    Each dependency in limen.toml lists the capabilities it may receive, and the compiler checks every function it exports against that list.

    banner = { path = "vendor/banner", caps = ["stdout"] }
    error[E0320]: dependency `banner` uses capability `Net`,
    which limen.toml does not grant it
  2. 02

    Narrow it, then hand it out

    Hand out less than you hold: a directory instead of the disk, one host instead of the network, a program with only some arguments. Take it back later with revoke().

    let data = root.fs.under("data").read_only()
    let api = root.net.only("api.example.com")
  3. 03

    Concurrency with a shape

    Tasks live inside a group and never outlive it. A deadline cancels whatever is still running, busy loops included, and a panic comes back to the caller.

    let results = group g until root.clock.after(100) {
        g.go(|| fetch(api, "/a"))
        g.go(|| fetch(api, "/b"))
    }
  4. 04

    Native code, through C

    One binary, reference counting, no garbage collector pauses. Single-threaded it runs level with C on the benchmarks in the repo (measured on an Apple silicon Mac).

    fib(40)               0.93x C
    filter, map, fold     0.99x C
    sieve to 100 million  1.01x C
  5. 05

    A sandbox underneath

    The grants also become an operating-system sandbox, so C code and the runtime stay inside what the program was given.

    $ limen run app.lmn --grant fs=data --grant net=api.example.com
  6. 06

    Written in itself

    The compiler is also written in Limen, and builds itself to the same C as the original, byte for byte.

    $ sh selfhost/bootstrap.sh
    fixed point: stages 2 and 3 emit the same C as the
    OCaml compiler (409444 lines)

Install

One line on macOS and Linux.

Apple silicon, and x86-64 or arm64 Linux. The script uses Homebrew on macOS when it's there and the .deb on Debian and Ubuntu, and checks every download against the release's checksums.

Terminal
$ curl -fsSL https://limen-lang.org/install | sh
$ limen run hello.lmn

To do it by hand: brew install alfonsocampodonico/limen/limen, or grab a .deb or binary from the latest release. Limen compiles programs through C, so you need a C compiler: the Xcode Command Line Tools on macOS; on Linux the package brings one.