Skip to content
elle-lispPublic

About

Modern rust-native lisp with fibers, signals, capabilities, jit, and more...

Topics

Resources

Contributing

Stars

28 stars

Watchers

0 watching

Forks

Repository files navigation

Elle

A Lisp whose compiler infers what each function does and where each value dies, and runs on those facts.

CI

Before any code runs, Elle's compiler resolves every binding, finds what every closure captures, infers the signals every function can raise, and infers the point where every value dies. Most Lisps discover these facts at run time or never. Elle uses them for four things: typed control flow, capability sandboxing, cooperative concurrency, and memory management with no garbage collector.

None of it asks the programmer for annotations. Languages with this much control, speed or soundness ask for lifetimes, types and async markers, and an Elle program writes none of them. The few declarations Elle has, such as (silent!) and (immutable!), state a fact the compiler then checks. They guard a program; they never enable one.

This file explains those ideas, what works today, and what we are building toward. Elle is under active development, and its syntax changes between epochs. The open issues list what is broken.

Contents

The compiler's facts are data

A program can ask the compiler what it inferred about source text, without running that text:

(def src "(defn pick [b x y] (if b x y))
          (defn fetch [url] (emit :yield url))
          (defn apply-to [f x] (f x))")
(def facts (compile/analyze src {:file "example.lisp"}))

(assert (get (compile/signal facts :pick) :silent))    ; raises nothing
(assert (get (compile/signal facts :fetch) :yields))   ; suspends its caller
(assert (not (get (compile/signal facts :apply-to) :silent)))
; apply-to raises whatever its argument f raises

The same queries answer which bindings a closure captures, what a function calls, and the whole call graph (portrait). An MCP server, in the mcp submodule, loads these facts for a whole codebase into an RDF graph that a coding agent can query with SPARQL.

Signals flow up

A signal is a keyword a function raises to its caller: :error, :yield, :io, or one the program declares. The compiler infers, for every function, the set of signals it can raise. A function is silent, yields, or is polymorphic, which means it raises whatever its function arguments raise. Nobody writes these annotations.

The inference is what makes functions colorless. A function that suspends needs no async marker, and neither do its callers. The compiler knows which calls can suspend and compiles each call to match.

A fiber catches the signals its mask names. A generator is a fiber that yields:

(defn produce [] (emit :yield 1) (emit :yield 2) (emit :yield 3))
(def gen (fiber/new produce |:yield|))

(fiber/resume gen)
(assert (= (fiber/value gen) 1))
(fiber/resume gen)
(assert (= (fiber/value gen) 2))

(silent!) declares a ceiling, and the compiler enforces it. A silent function cannot call an argument, because the argument might signal. It can bound the argument instead, but the bound is checked when the function is called, and that check may raise:

(def refused (protect (eval '(defn tight [f x] (silent!) (f x)))))
(assert (not (first refused)))                 ; a compile error

(def bounded
  (protect (eval '(defn tight [f x] (attune! :error) (bound f ||) (f x)))))
(assert (first bounded))                       ; f is bounded, so it compiles

The signal documents cover inference, user signals, and the protocol.

Capabilities flow down

A parent fiber can withhold capabilities from a child: :io, :fs, :ffi, :exec and the rest. When the child calls a primitive that needs a withheld capability, the primitive does not run. The child raises a denial instead, and the parent decides what happens next. The parent can perform the operation on the child's behalf, or it can refuse, and the child sees an ordinary error at its own call site:

(with-temp-dir dir
  (let [target (path/join dir "notes")
        child (fiber/new
                (fn []
                  (let [[ok? err] (protect (file/write target "x"))]
                    [:refused (not ok?) err]))
                |:fs :error|
                :deny |:fs|)]
    (fiber/resume child)                ; the child asks to write; it is denied
    (fiber/refuse child :not-permitted)
    (assert (= (fiber/value child) [:refused true :not-permitted]))))

A child inherits every restriction its parent carries, and threads inherit them too. The capability document states what a denial confines, and what it does not.

Fibers

A fiber is an execution context with its own stack and signal mask. Fibers are cooperative: one runs at a time, so shared data needs no locks. Top-level code runs inside an async scheduler, so I/O suspends only the fiber that asked. The scheduler uses io_uring on Linux.

Structured concurrency sits on top of the scheduler:

(defn load-users [] [:ada :grace])
(defn load-settings [] {:theme :dark})

(def page
  (ev/scope (fn [spawn]
    (let [users (spawn load-users)
          settings (spawn load-settings)]
      {:users (ev/join users) :settings (ev/join settings)}))))

(assert (= (get page :users) [:ada :grace]))

Janet's fibers are the model we started from. The process library builds Erlang-style processes from the same fibers, in Elle alone: mailboxes, links, monitors, GenServers and supervisors. See concurrency and processes.

Memory without a collector

Elle has no tracing collector and no GC pause. Every value is born in a region: a set of pages the compiler assigns from its analysis. The compiler emits the release of each region at the point where its values die. Nobody calls free.

  • Escape analysis places each release. The compiler bounds each value's lifetime statically, and emits the release of its region at the value's last use. Every region is born with a reference count, and an allocation counts each region the new value refers to.
  • Mutation adds reference counts. A store into a mutable container can point anywhere, at a time no static analysis can see. So a store counts a reference to the stored value's region, at run time.
  • Ownership reclaims whole subtrees. A region the compiler proves has one owner joins an ownership forest rooted at an activation or a fiber. It frees with its owner, interior cycles included.

A value's region lives exactly as long as the value, so nothing needs a copy to outlive its maker. Copies are absent by construction, not elided by an optimizer. A store, a return and a yield all pass the same 16-byte Value, and the bytes stay in the pages where they were born. arena/page-bytes counts the bytes of every page the heap claims, so a copy shows in it:

(def blob (string/repeat "x" 100000))    ; 100 KB, born in one region
(def inbox @[])
(def child (fiber/new (fn [] (emit :yield blob)) |:yield|))

(def before (arena/page-bytes))
(push inbox blob)                        ; a store into a container
(fiber/resume child)                     ; a yield out of another fiber
(assert (= (fiber/value child) blob))
(assert (< (- (arena/page-bytes) before) 1024))   ; neither one copied the blob

(def copy (string blob "!"))             ; a copy the program asks for
(assert (> (- (arena/page-bytes) before) 100000))

I/O follows the same design. A read hands the kernel a buffer in the caller's region, and a write hands the kernel its payload in the pages where it lives, so neither one copies. A value that crosses to another thread is deep-copied, where it could move with its regions instead (#1247).

Freed pages return to a small per-thread cache, and pages past that cache go back to the operating system at once. So a long-running program's resident memory falls when its live data falls.

This is where most of the current work goes. The project measures leaks with gauges and closes them one class at a time. Two costs remain visible today:

  • A region owns at least one 4 KiB page. A value that keeps a region of its own (for example, each element a loop pushes into an @array) therefore costs about 4 KB. Region merging gives values with one lifetime one region, but today it merges only a fresh pair into the pair that stores it.
  • The region table grows to the largest number of regions alive at once, and does not shrink.

Write code against the region model. The memory map is the implementor's guide.

Images

A region is a set of pages, so a region can be written to a file and mapped back. An image is a compacted region plus a relocation table. Loading one maps its pages privately and rewrites its pointers in one pass. No value is decoded, and pages that nothing touches are never read from disk.

The boot image holds the whole standard library as one region. A release binary that make release builds carries its boot image inside the executable, so its first start loads it too. Any other build compiles the library at its first start and stores the image in the cache directory, and every later start loads it. From an image, Elle starts in under 10 ms with 13 MB resident. Loading the library from the bytecode cache takes 45 ms and 45 MB, and compiling it from source takes 270 ms and 100 MB. --boot-image=off compiles at every start:

elle --boot-image=off script.lisp

A closure loaded from an image carries its LIR and the body a graft reads, so the library compiles on the JIT and a call to + becomes its body under either boot. A thread a program spawns loads the image its parent holds. Saving and loading a user session as an image comes next, and then fleet: running a function on other machines by shipping its image. The image design holds the details.

Hygienic macros

Macros transform syntax objects that carry scope sets, as in Racket. A name a macro introduces cannot capture a name at its call site:

(defmacro my-swap (a b)
  `(let [tmp ,a] (assign ,a ,b) (assign ,b tmp)))

(def @tmp 100)
(def @x 1)
(def @y 2)
(my-swap x y)
(assert (= [x y tmp] [2 1 100]))   ; the macro's tmp is not the caller's tmp

The macro guide covers the rest.

Epochs

A breaking change to the language gets an epoch number. A file can declare the epoch it was written for with (elle/epoch N), and the compiler migrates older syntax before it expands macros. elle rewrite applies the same migration to the source file. See epochs.

A library declares its own version the same way, with (elle/version "X.Y.Z"), and elle semver checks that a release's version bump matches its change of surface (versioning).

Where Elle is going

  • Region merging. Collapse regions that die together, so a collection and its elements share pages. This removes most of the per-value page cost.
  • Performance. A call to a function the compiler can see becomes that function's body, and the guards the proven types decide are deleted (grafting a call). So (+ a b) over proven integers is one VM instruction, and the JIT compiles the function around it. On a release build, a recursive fib of 32 takes 0.18 s, where Janet takes 0.17 s and Lua 0.13 s. With the JIT off it takes 2.9 s. A call to + with three operands still reaches the variadic library function, which the JIT cannot compile. Dissolution already fuses chains of map, filter and fold over proven arrays into single loops.
  • Ownership in place of counting. Extend the ownership forest, in the direction of Project Verona's regions, so fewer mutable stores need a reference count.
  • Heterogeneous execution. Lower dissolved kernels through MLIR automatically, keep device data in region-based device pools, and migrate regions between host and GPU. This replaces today's hand-driven Vulkan path.
  • Environment images and fleet, described under Images.
  • WASM. The WebAssembly backend was set aside during the memory rewrite. Under --wasm=full it frees no memory and fails about half of the language suite.

Using Elle

Build with a stable Rust toolchain. The install guide lists the system libraries and the other builds.

make release                            # the release binary, its boot image inside
./target/release/elle script.lisp       # run a file
./target/release/elle notes.md          # run the lisp blocks of a markdown file
./target/release/elle -e '(+ 1 2)'      # evaluate an expression
./target/release/elle                   # start the REPL

Read the quickstart before you write Elle. It lists the traps: nil is not (), # does not start a comment, and assign mutates while set builds a set. Coming from another language maps Elle onto the language you know.

The tools ship in the same binary: elle fmt formats source, elle lint runs the compiler's diagnostics, elle lsp serves an editor over the Language Server Protocol, and elle rewrite migrates source between epochs.

The standard library and the Rust plugins are written against the same primitives. The plugins and the MCP server live in submodules:

git submodule update --init plugins mcp

The contributing guide describes how to work on Elle and which tests to run. The full make smoke takes about 30 minutes on a release build.

License

MIT

About

Modern rust-native lisp with fibers, signals, capabilities, jit, and more...

Topics

Resources

Contributing

Stars

28 stars

Watchers

0 watching

Forks

Used by

Contributors

Languages