Spur is a domain-specific language for specifying distributed protocols.
This repository provides a compiler frontend in Rust that is used in Turnpike for consistency (linearizability, etc.) refutation.
- Role-based architecture: define distributed nodes with persistent state and message handlers
- First-class RPCs: native support for both asynchronous and synchronous RPCs
- Static, strong type system: comprehensive type checking with primitives, structs, and optional types
The language design is detailed in language.md. On the compiler side, we most importantly achieve:
- Compilation to a CFG (control-flow graph, see cfg.rs)
- Helpful error messages throughout all compilation phases
See the specs directory. For brevity, we provide a short example here:
type Command = int;
role Node {
var db: map<string, Command> = {};
fn Write(key: string, value: Command): bool {
db = db[key] := value;
return true;
}
}
ClientInterface {
fn Write(node: Node, key: string, value: Command) {
<-node->Write(key, value);
}
}
This project uses Rust and cargo. To build the compiler:
cargo build --releaseThe compiler takes a Spur specification file and outputs a JSON representation of the compiled control flow graph.
Example:
# Compile the simple key-value store
cargo run -- specs/simple.spur output.json- There is a VSCode extension for syntax highlighting.