RCE language specification, draft 0.9
RCE language specification
Abstract. RCE, the Reality Code Engine, is a small programming language whose programs mean one thing everywhere. It exists so that programs can be written, checked, changed and run by machines, in the era of code written by models, with no model in the loop that decides what a program means. A program is turned into a Form: a state machine given by its states, its events, a step function that maps a state and an event to a new state and an outcome, and the log of events. Every runtime that runs the Form must produce the same results bit for bit, and the rules that make this so are checked by machine.
Figure (informative). The pipeline from source to Form, log, emit targets and host. Source: docs/figures.
Three plain points:
- Same answer on every target. Arithmetic, text, floats and concurrency have one defined meaning; there is no undefined behaviour.
- Every program ends. Loops, recursion and iterators are bounded, so the step function always returns.
- Memory is safe by construction. Ownership, second-class borrows, regions and linear handles rule out use-after-free and data races.
Tiny example (a counter that never goes negative: a Dec at zero keeps the state):
Reading map. Files are in spec/book/ and are meant to be read in order:
| File | What it covers |
|---|---|
00-overview.md |
this abstract, status and how the spec is checked |
01-notation.md |
how grammar and typing rules are written; what conformance means |
02-lexical.md |
characters, comments, tokens, keywords, literals, indentation |
03-syntax.md |
the full grammar of declarations, types, statements, expressions |
04-programs.md |
modules, the program's Form, scope |
05-types-ownership.md |
types, contexts, typing rules, ownership, borrowing |
06-regions-effects-extensions.md |
arenas, concurrency, traits, comptime, foreign functions, linear types, device regions, iterators |
07-form-evaluation.md |
the Form of a program, evaluation, exact edge cases of every primitive |
08-steps-loops-concurrency.md |
the step function, errors, hashing, loops, tasks, examples |
09-wellformedness.md |
the list of rules a program must pass to be accepted |
10-theorems.md |
the theorems and what is proved in Lean |
11-decisions.md |
design decisions and the changes per draft |
12-tooling.md |
the rce command line and language server |
13-references.md |
sources |
14-draft06-concurrency.md |
Appendix C: the concurrency part of the language, and the release rule (C.15: a release label names exactly one spec commit) |
15-handler-spec-profile.md |
Appendix D: the engine profile, handler specs and fits, including reads, joins and scans |
16-host-contract.md |
Appendix E: the host contract (one admitter, durable log, capabilities, fabric entries, placement) |
17-draft09.md |
Appendix F: the security, hygiene and contract rules, specified and implemented in part (F.1 to F.12) |
INDEX.md lists every file with its hash; READ-PROTOCOL.md says how an
agent proves it read the spec. RCE-SPEC.md is all of these files joined
into one, generated by rce-book build.
Status. Draft 0.9, 2026-10-17. Status: for review. Appendix F
is specified and implemented in part (F.12) and applies the 2025+ language survey and the security study (transactional
calls, contracts, ghost code, written termination measures, information-flow
labels with robust declassification, a World capability, caretaker
revocation, typed shell and prompt output, constant-time functions, declared
budgets, hash-pinned builds, templates, if let, trait laws and lexical
hygiene), and states as non-goals the four constructs that would break a
theorem (effect handlers, switchable contracts, mutable aliasing across
par, runtime reflection). The reference checker implements a part of it
(Tier 0 hygiene, World, definition hashes with rce api-diff, transactional
calls; F.12 lists the rest, which it reports as requiring change: reserved, not implemented), the Lean files, the
emitters and the tree-sitter port do not, and every theorem it adds
(T42 to T56) is stated (F.9); T48, T51 and T53 are proved of models (RCE/Discharged.lean), and the other twelve are unproved. There is one language: this text. Drafts 0.5 to 0.9 are
labels of past commits of it, not alternatives; # rce-version: is a release label that is
tolerated, ignored and not hashed (2.7), and a label names exactly one spec commit (C.15). The
language of this text is what the reference checker and the Lean files enforce and prove for concurrency
(Appendix C), and a program that an earlier commit accepted may require change under this one when a rule was
added; an implementation of a release implements that release's text. The core is mechanized in Lean 4
(spec/lean/, section 8), a reference type and well-formedness checker
(spec/checker/, rce-check) implements sections 4, 5 and 7 including the
admission gate of 6.9 (examples, checks, comptime and constants are evaluated),
tree-sitter/ is a tree-sitter port of the grammar checked against
the LALR(1) tables of section 3, and grammar-level random programs are checked by
rce-fuzz (spec/checker/). The production compiler has
not been built from this document yet. Changes made while mechanizing are
listed in 9.1 to 9.4. Draft 0.4 follows the language review in
spec/LANGUAGE-REVIEW.md; draft 0.5 applies the changes that review
proposed and draft 0.4 deferred (9.4). The changes per draft are in 9.1 to
9.7, and the decisions taken for draft 0.9 by derivation, with the open
questions each closed, are in 9.7 and 9.8.
RCE is defined by this document. A program is a text; its meaning is a Form P = (S, E, δ, D, λ) (section 6). Runtimes, emitters, harnesses and editors are not part of the language: they are implementations, and an implementation conforms when it accepts exactly the programs this document accepts and gives each one the meaning this document gives it.
Document status. This specification is the only normative text.
SURFACE.md (the native surface design) and the proposals in
spec/proposals/ are informative: two normative texts with two grammars
could disagree, and only one of them is checked by machine. The programs
in SURFACE.md must still be accepted by the reference checker
(spec/checker/tests/surface_status.rs). The Form signature is
6.1.
The normative grammar is section 3, and it is also the machine-readable one:
rce-spec-check (in spec/checker/, Rust only) reads the EBNF of section 3
from book/03-syntax.md, builds its LALR(1) tables and fails on any
shift/reduce or reduce/reduce conflict, then parses every program in
spec/examples/ and requires every program in spec/examples/change/syntax/ to be
reported as requiring change, by the LALR(1) tables, the Rust parser and the tree-sitter port
alike, then runs rce-check over the same files (all examples together
form one program and must be accepted; the 13 syntax rejects, the 49
programs in spec/examples/change/types/ and the 17 in
spec/examples/change/admission/ must be reported as requiring change). Current result (draft 0.9,
the printed output of rce-spec-check, compared with this text by
scripts/claim-counts.py check): the section-3 grammar has 0 conflicts
(104 rules, 512 productions, 1028 states); with the additions of C.2,
0 conflicts (118 rules, 581 productions, 1206 states);
with C.2 and F.13, 0 conflicts (123 rules, 611 productions,
1273 states), accepting the 18 Appendix F examples; grammar 62/62 accepted,
13/13 requiring change; checker 62/62 accepted, 13/13 and 73/73 requiring change (18 of them
inadmissible). Until 2026-10-12 the same grammar was held in
spec/rce.lark and checked with Lark (0 conflicts, 533 rules in Lark's
expansion); that file is retired.
rce-fuzz N SEED generates random type-directed programs from the
grammar's productions, with targeted near-misses. 100,000-program run
(8 parts × 12,500, seeds 1001–1008, spec/fuzz/RESULTS.md, with the former
Python generator and Lark): all 100,000
parsed by LALR(1), exactly one Earley parse each, all accepted by
rce-check; 516,012/516,012 rule near-misses and 392,362/392,362 syntax
near-misses reported as requiring change; 0 failures. That run used the draft 0.4 generator.
From draft 0.5 the generator also covers extern, arena bound, structural
recursion, f32, lane-wise arrays, device regions, byte text, u64, select,
linear structs, LOOP_LIMIT and iterators; a 1,000-program run (seed 2026)
of it has 0 failures. The Rust generator, with the section-3 LALR(1)
tables as a third parser: 1,000 programs (seed 7), 0 failures, tree-sitter
and LALR(1) agree on all 4,977 syntax mutants.
Which version this is. This notebook shows specification draft 0.9, generated from commit 1762fb4b of the RCE source, public main on 20 November 2026; there is one language, the specification at one commit (2.7). It holds 146 example programs: 60 accepted, and 13 syntax, 55 ill-typed and 18 inadmissible programs that require change, each with the rule it breaks. The public repository states theorems T1 to T63, with 64 Lean modules, as read at public commit f87d6af2. Where a chapter quotes a count from an earlier draft, it describes that draft. Counts come from the notebook data and src/data/rce-facts.json.
Chapters
Read them in order. Each chapter opens in plain words, then gives the exact rules. Formal grammar and typing rules sit in cells you can open and close. Every code cell can be edited and run.
- 00RCE Language Specification, draft 0.9: Overview
In the overview's tiny example, what is the name of the event?
- 011. Notation and conformance
In the grammar notation, what does a Repetition `{ ... }` mean, in the spec's words?
- 022. Lexical grammar
Which code point is the horizontal tab, as written in this section?
- 033. Syntactic grammar
Which numbered resolution rule in 3.11 covers `send`? (for example R1)
- 044. Programs, names and scope
What is the outermost scope called? (one word)
- 055. Static semantics
What is the name of the example kind used to illustrate error sets?
- 065 (continued). Static semantics: regions, effects and extensions
What kind of channel does a capacity of 0 give? (one word)
- 076. Dynamic semantics: the mapping into the Form
Which JavaScript function is named for rounding to binary32?
- 086 (continued). Dynamic semantics: steps, loops and concurrency
Name-free hashing uses indices named after which logician? (two words)
- 097. Well-formedness: what requires change at entry
Under which rule does a region with two unguarded steps whose patterns overlap require change?
- 108. Theorems to prove
What is the deep embedding of the emitted Rust subset called?
- 119. Design decisions for review
The decisions list says it decides gaps in which file?
- 1210. Tooling: the `rce` command and the language server
Which JSON-RPC error code does the language server return for a request it does not know? (a number)
- 13References
Who wrote "Communicating Sequential Processes"? (surname)
- 14Appendix C. Concurrency (draft 0.6 and 0.6b; normative)
How many concurrency words does C.1 add to the keywords of 2.4? (a number)
- 15Appendix D. The engine profile: handler specs and fits (normative)
Which compiled node id does `deliverable D1` become? (for example role_R1)
- 16Appendix E. The host contract (normative)
Which fcntl command is the append barrier on macOS? (for example F_SETFL)
- 17Appendix F. Draft 0.9 (normative; implemented in part, see F.12)
Programs and the reading record
- All 146 example programs: the accepted ones, and every syntax, ill-typed and inadmissible program that requires change, with the rule it breaks.
- Read protocol: how a reader, human or AI agent, shows it read each chapter, using the chapter fingerprints and read-receipt questions.
Built from spec commit 1762fb4b. Code cells run the reference checker rce-check, written in Rust and compiled to WebAssembly, inside your browser; nothing is sent to a server. Read-aloud uses the Kokoro-82M model (Apache-2.0), served from this site and run in your browser.