Renyi

Learn

How it works

Each of the four promises drawn as the mechanism that keeps it, and one real session at the terminal.

One session

The program below reads todo.txt, but its main declares only console. The checker refuses it and says what to write. After the fix it checks clean, renyi record runs it and writes run.json, and with the input file deleted renyi run --replay still answers every effect from the recording, narrated by --explain. Every line of output is what the binary printed.

module todo
  purpose: Count the items of a to-do list.

import std.filesystem exposing Path, FileError
import std.console

public function main() or fails with FileError needs console
  purpose: Print how many items the list holds.

  let text be filesystem.read_text(Path("todo.txt")) otherwise fail
  console.print("{text.lines().length()} items")
end
A session at the terminal
todo
$ renyi check todo.ry
todo.ry:10:15: error [capability-missing]: `read_text` needs `filesystem.read`, which `main` does not declare
  fix: add `needs filesystem.read` to the signature of `main`
$ sed -i 's/needs console/&, filesystem.read/' todo.ry
$ renyi check todo.ry
$ renyi record --to run.json todo.ry
3 items
renyi: recorded 2 calls to run.json
$ rm todo.txt
$ renyi run --replay run.json --explain todo.ry
Print how many items the list holds. (main)
  filesystem.read read_text(path: "todo.txt") -> "milk\neggs\nbread\n"
  console "3 items"
$ 
01

The signature is the grant

Every function says what it needs, and a need can be scoped to a path, a host or a variable, budgeted (at most 60 per minute) and guarded (only to). The checker refuses a body that uses a capability its head does not declare and names the fix; the declaration of main is the whole program’s grant. At run time every effect passes one boundary in the VM, which checks the actual path or host against the grant of the running call chain, so a read outside data/ fails with PermissionDenied. --deny, --allow-read and their kin narrow the grant further from the command line, without touching the program.

The signature is the grantA function head: public function load(path: Path), returns Config, or fails with FileError, needs filesystem.read("data/"). At compile time, renyi check refuses a body that uses a capability the head does not declare, with the code capability-missing. At run time, a read under data/ is admitted and a read of keys/id fails with PermissionDenied. public function load(path: Path) returns Configwhat it gives or fails with FileErrorhow it fails needs filesystem.read("data/")what it may do THE GRANT COMPILE TIMErenyi check A body that uses a capabilitythe head does not declare: capability-missingrefused, with the fix RUN TIMEevery effect, at one boundary a read under data/admitted a read of keys/idfails with PermissionDenied
The runtime admits exactly what the signature declares.
02

Every run is evidence

renyi record runs main and writes every effect the run makes, with its result, and the run manifest in the header: the toolchain, the code hash, the dependencies with their versions and hashes, the grant, the arguments, the outcome and the output hash. renyi run --replay runs the program again with every effect answered from the recording, so nothing is written or sent. renyi reproduce replays a recording under its manifest and compares the outcome and the output byte for byte, refusing a program whose code hash is not the manifest’s. --explain narrates a run through the purpose: clauses it passes, and a replays test pins a function to a recording.

Every run is evidencerenyi record runs main and writes run.json: the manifest (toolchain, code hash, dependencies, grant, arguments, outcome, output hash) and every effect in order with its result. Offline, renyi run --replay answers every effect from the recording, and renyi reproduce replays it under the manifest and compares the outcome and the output. renyi recordruns main and writes everyeffect with the manifest run.jsonMANIFEST toolchaincode hashdependencies, hashesgrantargumentsoutcomeoutput hash CALLSevery effect, in order,with its result OFFLINE renyi run --replayanswers every effect fromthe recording; nothing sent renyi reproducereplays under the manifest,compares outcome and output
Same program, same inputs, same result.
03

Dependencies cannot widen

A package’s effect manifest is computed by the tool from its sources, not written by its author, and published with it. renyi add prints the effects a dependency brings; renyi update refuses a version whose effects widen unless --accept-effects is given, and even then takes it only when every main that reaches the package declares the new capability; renyi audit checks every locked dependency against every main that reaches it. On fetch every file is verified against its hash and the manifest recomputed, so a package cannot understate what it does.

Dependencies cannot widenThe effect manifest of greeting 1.1.0 is computed from its sources: console and network.http. The lockfile holds greeting 1.0.0 with console. renyi update compares the two and refuses the update because the effects widen. renyi update --accept-effects takes 1.1.0 only when every main that reaches it declares network.http. PACKAGE SOURCESgreeting 1.1.0its .ry files, eachwith its content hash computednot written EFFECT MANIFESTconsolenetwork.httpnew in 1.1.0 LOCKFILEgreeting 1.0.0console renyi updaterefused:the effects widen renyi update --accept-effectstakes 1.1.0 only when every main that reaches itdeclares network.http
On fetch, every file is checked against its hash and the manifest is recomputed from the sources.
04

One toolchain, written twice

One binary, renyi, written in Rust. The front end lexes, parses, checks and emits bytecode, and it exists twice: in Rust, and written in Renyi under compiler/ and run by the VM. Tests hold the two equal byte for byte (the syntax tree, the diagnostics and the bytecode file) on every program of the corpus, the conformance suite and the compiler itself. The VM runs a function on its template tier from the first call and moves hot code to Cranelift; --interpret keeps a run on the interpreter, as --explain and --profile do. renyi build compiles every function ahead into an image that run, record, test and reproduce load without compiling anything.

One toolchain, written twiceA source file goes through the front end: lexer, parser, checker, emitter, once in Rust under crates/ and once in Renyi under compiler/, run by the VM, held equal byte for byte by tests. The bytecode, a .ryc file, runs on the VM: the interpreter (--interpret), the template tier from the first call, the Cranelift tier when the code is hot. renyi build writes an image, .ryi, with every function as machine code. program.ry THE FRONT END in Rust · crates/ lexer parser checker emitter = held equal, byte for byte, by tests in Renyi · compiler/, run by the VM lexer parser checker emitter bytecode .ryc THE VM interpreter--interpret template tierfrom the first call Cranelift tierwhen the code is hot renyi build writes an image, .ryi: every function as machine code
Tests hold the two front ends equal, byte for byte.

View the source of this page