These are the programs in spec/examples/. Each cell shows the result the reference checker gives for it. Edit any program and press Run, or Ctrl+Enter, to check your version. In a code cell, Tab inserts four spaces; press Escape and then Tab to leave the cell.
Accepted programs (60)
Each of these is accepted: it parses, type-checks, and every example and check inside it holds.
spec/examples/01_counter.rce
Expected: accepted
intent"a counter that never goes negative"exampleInc, Inc, Dec -> 1exampleDec -> kept: UnderflowexampleDec, Inc -> 1stateCounter
n: u64 = 0eventInceventDecerrorUnderflowstepCounteronInc -> n + 1stepCounteronDec -> try n.checked_sub(1) elseUnderflow
spec/examples/02_hello_main.rce
Expected: accepted
module hello
fn main()
emit"hello, world"
spec/examples/03_fib_loop.rce
Expected: accepted
intent"the n-th Fibonacci number, computed in linear time"check fib(0) == 0check fib(10) == 55fn fib(n: u32) -> u64var a: u64 = 0var b: u64 = 1for _ in0..n
let t = a + b
a = b
b = t
return a
spec/examples/04_bank_account.rce
Expected: accepted
module bank
intent"a bank account that keeps its balance on an overdraft (Insufficient)"exampleDeposit(amount: 50), Withdraw(amount: 20) -> 30exampleWithdraw(amount: 1) -> kept: InsufficientstateAccount
balance: i64 = 0eventDeposit(amount: i64)
eventWithdraw(amount: i64)
errorInsufficient(need: i64)
structWithdrawn
amount: i64stepAccountonDeposit(amount: a) if a > 0 -> balance + a
stepAccountonDeposit(amount: _) -> balance
stepAccountonWithdraw(amount: a)
if a > balance
failInsufficient(need: a - balance)
balance -= a
emitWithdrawn(amount: a)
spec/examples/05_kind_match.rce
Expected: accepted
kindShapeCircle(r: f64)
Rect(w: f64, h: f64)
Emptyfn area(s: &Shape) -> f64match s
Circle(r: r) -> 3.141592653589793 * r * r
Rect(w: w, h: h) -> w * h
Empty -> 0.0
spec/examples/06_option.rce
Expected: accepted
fn first_even(xs: &[i64]) -> i64?
for x in xs
if x % 2 == 0return some(x)
returnnonefn or_zero(v: i64?) -> i64match v
some(x) -> x
none -> 0
fn max_of[T: Ord](xs: &[T]) -> T?
var best: T? = nonefor x in xs
match best
none -> best = some(copy(x))
some(b) if x > b -> best = some(copy(x))
_ -> passreturn best
traitDescribefn describe(&self) -> textimplforall[T: Describe] DescribeforList[T]
fn describe(&self) -> text = ", ".join([x.describe() for x inself])
spec/examples/10_comptime.rce
Expected: accepted
constN: usize = 64constTABLE: [u32; 256] = comptime crc_table()
comptimefn crc_table() -> [u32; 256]
var t = [0; 256]
for i in0..256var c: u32 = i asu32for _ in0..8
c = if c & 1 == 1then0xEDB88320 ^ (c >> 1) else c >> 1
t[i] = c
return t
fn zeros[comptime n: usize]() -> [u8; n]
return [0; n]
spec/examples/11_arena.rce
Expected: accepted
fn word_lengths(s: &text) -> List[u32]
var out: List[u32] = []
witharena scratch
let ws: List[text] @scratch = s.words()
for w in ws
out.append(w.len_bytes() asu32)
return out
spec/examples/12_borrow.rce
Expected: accepted
fn push_all(dst: &mutList[i64], src: &[i64])
for x in src
dst.append(x)
fn demo() -> usizevar a: List[i64] = [1, 2, 3]
let b: List[i64] = [4, 5]
push_all(&mut a, &b)
return a.len()
spec/examples/13_spawn_chan.rce
Expected: accepted
fn producer(out: chani64, n: i64)
for i in0..n
out <- i
out.close()
fn main()
let c = chan[i64](8)
spawn producer(c, 100)
var total = 0loopmatch <- c
some(v) -> total += v
none -> breakemit total
spec/examples/14_select.rce
Expected: accepted
fn merge(a: chantext, b: chantext, out: chantext)
loopbound1000selectrecv some(x) from a -> out <- x
recv some(y) from b -> out <- y
recvnonefrom a -> breakafter10 -> emit"idle"
spec/examples/15_actor.rce
Expected: accepted
eventGet(reply: chani64)
eventAdd(k: i64)
actorTally
total: i64 = 0onAdd(k: k) -> total + k
onGet(reply: r)
r <- total
spec/examples/16_multi_region.rce
Expected: accepted
intent"two regions step on one event: the cart holds the items, the stats count the adds and removes"exampleAddItem(name: "milk"), AddItem(name: "eggs"), RemoveItem(name: "milk"), AddItem(name: "tea"), Reset, AddItem(name: "jam") -> items == ["jam"] and adds == 4and removes == 1exampleAddItem(name: "milk"), AddItem(name: "eggs"), RemoveItem(name: "milk") -> items == ["eggs"] and removes == 1stateCart
items: List[text] = []
stateStats
adds: u64 = 0
removes: u64 = 0eventAddItem(name: text)
eventRemoveItem(name: text)
eventResetstepCartonAddItem(name: n) -> items.with(n)
stepStatsonAddItem(name: _)
adds += 1stepCartonRemoveItem(name: n)
items = [copy(i) for i in items if i != n]
stepStatsonRemoveItem(name: _)
removes += 1stepCartonReset -> []
spec/examples/17_traffic_light.rce
Expected: accepted
intent"a traffic light that cycles on each tick"exampleTick, Tick -> light == YellowkindLightRedGreenYellowstateSignal
light: Light = RedeventTickstepSignalonTickmatch light
Red -> light = GreenGreen -> light = YellowYellow -> light = Red
spec/examples/18_while_bound.rce
Expected: accepted
errorDivergedfn collatz_steps(n: u64) -> u64 ! Divergedvar x = n
var k: u64 = 0while x != 1bound10_000
x = if x % 2 == 0then x / 2else3 * x + 1
k += 1return k
spec/examples/19_floats.rce
Expected: accepted
errorEmptyfn mean(xs: &[f64]) -> f64 ! Emptyif xs.len() == 0failEmptyvar s = 0.0for x in xs
s += x
return s / xs.len() asf64constAVOGADRO: f64 = 6.02214076e23constEPS = 1e-9
spec/examples/20_strings.rce
Expected: accepted
fn shout(s: &text) -> text = s.strip().upper() + "!"fn is_palindrome(s: &text) -> boollet t = [c for c in s.lower().chars() if c.isalpha()]
return t == t.reverse()
fn escapes() -> text = "tab\t newline\n quote\" snow \u{2603}"
spec/examples/21_maps.rce
Expected: accepted
fn freq(words: &[text]) -> Map[text, u32]
var m: Map[text, u32] = {}
for w in words
m[w] = (m.get(w) catch0) + 1return m
fn table() -> Map[text, i64] = {"a": 1, "b": 2,}
spec/examples/22_tuples.rce
Expected: accepted
errorDivByZerofn divmod(a: i64, b: i64) -> (i64, i64) ! DivByZeroif b == 0failDivByZeroreturn (a / b, a % b)
fn use_it() -> i64let (q, r) = divmod(17, 5) catch (0, 0)
let pair = (q, r)
return pair.0 + pair.1
fn popcount(x: u64) -> u32var v = x
var c: u32 = 0while v != 0bound64
v &= v - 1
c += 1return c
fn mix(a: u32, b: u32) -> u32 = (a << 5 | a >> 27) ^ ~b & 0xFF
intent"a door that locks only when closed""the door starts closed and unlocked"exampleOpen, Close, Lock -> locked
exampleOpen, Lock -> kept: DoorOpenstateDoor
open: bool = false
locked: bool = falseeventOpeneventCloseeventLockeventUnlockerrorDoorOpenerrorLockedstepDooronOpenif locked
failLockedstepDooronOpen
open = truestepDooronClose
open = falsestepDooronLockif open
failDoorOpenstepDooronLock
locked = truestepDooronUnlock
locked = false
fn long_call() -> i64let xs = [
1, 2, 3,
4, 5, 6,
]
let total = xs.fold(
0,
fn(a: i64, b: i64) => a + b,
)
return total # comments are allowed here
spec/examples/37_actor_spawn.rce
Expected: accepted
eventPing(n: u64, reply: chanu64)
actorEcho
seen: u64 = 0onPing(n: n, reply: r)
seen += 1
r <- n
fn main()
let e = Echo()
let r = chan[u64](1)
e <- Ping(n: 7, reply: r)
emit <- r
# Structural recursion: each self-call takes a field of a constructor the# function matched, so the depth is bounded by the size of the value.kindTreeLeaf(v: i64)
Node(l: Box[Tree], r: Box[Tree])
fn tree_sum(t: &Tree) -> i64match t
Leaf(v: v) -> return v
Node(l: l, r: r) -> return tree_sum(l) + tree_sum(r)
fn sample_sum() -> i64let t = Node(l: Box(Leaf(v: 2)), r: Box(Node(l: Box(Leaf(v: 3)), r: Box(Leaf(v: 4)))))
return tree_sum(&t)
check sample_sum() == 9
spec/examples/40_extern.rce
Expected: accepted
# A foreign function: C ABI, scalar results, borrowed buffers only.# Only main and task functions may call it; its results enter the log.extern"C"fn crc32(w: &World, data: &[u8], seed: u32) -> u32fn main(w: &World)
let bytes: List[u8] = [1, 2, 3]
emit crc32(w, &bytes, 0)
spec/examples/41_arena_bound_wrapping.rce
Expected: accepted
# An arena with a fixed capacity, and explicit wrapping arithmetic for hashing.fn fnv1a(s: &text) -> u32var h: u32 = 2166136261witharena scratch bound4096let cs: List[text] @scratch = s.chars()
for c in cs
h = (h ^ (c.len_bytes() asu32)).wrapping_mul(16777619)
return h
check (250asu8).wrapping_add(10) == 4check (250asu8).saturating_add(10) == 255
spec/examples/42_f32.rce
Expected: accepted
# f32 arithmetic: computed in f64 and rounded once, so every target agrees bit for bit.fn axpy(a: f32, x: f32, y: f32) -> f32return a * x + y
check axpy(2.0asf32, 0.1asf32, 1.0asf32) == 1.2asf32check (0.1asf32) asf64 != 0.1check (16777217asf32) asi64 == 16777216
# A device region holds fixed-size values only and performs no effects.fn dot4(a: [f32; 4], b: [f32; 4]) -> f32var acc: f32 = 0asf32withdevice gpu bound4096let p: [f32; 4] = a * b
for x in p
acc = acc + x
return acc
check dot4([1.0asf32, 2.0asf32, 3.0asf32, 4.0asf32], [1.0asf32, 1.0asf32, 1.0asf32, 1.0asf32]) == 10.0asf32
spec/examples/45_byte_text.rce
Expected: accepted
# Text is indexed and measured in UTF-8 bytes.fn first_byte(s: &text) -> u8return s[0]
check"héllo".len_bytes() == 6constA: text = "A"check first_byte(&A) == 65check"héllo"[1] == 195check"héllo"[0:1] == "h"check"héllo"[1:3] == "é"
spec/examples/46_u64.rce
Expected: accepted
# Full-range u64 arithmetic, checked against [0, 2^64).constBIG: u64 = 18446744073709551615fn half(x: u64) -> u64return x / 2check half(BIG) == 9223372036854775807checkBIG - 1 == 18446744073709551614check (BIG / 3) * 3 == BIGcheckBIG.checked_add(1).isnone()
# `lalr` is an ordinary name (it was wrongly reserved before 0.5).const lalr: u64 = 1checkBIG - lalr + lalr == BIG
spec/examples/47_select_fair.rce
Expected: accepted
# Two producers on one select: the rotation guarantees neither is starved.fn fan_in(a: chanu64, b: chanu64, out: chanu64)
loopbound1000selectrecv some(x) from a -> out <- x
recv some(y) from b -> out <- y
recvnonefrom a -> break
spec/examples/48_linear_handle.rce
Expected: accepted
# A linear handle must be consumed exactly once on every path.linearstructFile
fd: i32extern"C"fn c_open(w: &World, name: &text) -> Fileextern"C"fn c_close(w: &World, f: File) -> i32extern"C"fn c_write(w: &World, f: File, n: u32) -> Filefn main(w: &World)
let p = "log.txt"let f = c_open(w, &p)
let g = c_write(w, f, 3)
if g.fd < 0let _ = c_close(w, g)
elselet r = c_close(w, g)
emit r
spec/examples/49_loop_limit.rce
Expected: accepted
# A program can raise or lower the default loop limit.constLOOP_LIMIT: u64 = 5000000fn count(n: u64) -> u64var k: u64 = 0while k < n
k += 1return k
check count(2000000) == 2000000
spec/examples/50_iterators.rce
Expected: accepted
# Iterators: push-model generators, bounded by the loop limit.fn evens(n: u64) -> iteru64var i: u64 = 0while i < n
yield i * 2
i += 1fn naturals() -> iteru64var i: u64 = 0loopyield i
i += 1fn first_over(t: u64) -> u64for x in naturals()
if x > t
return x
return0fn total(n: u64) -> u64var s: u64 = 0for x in evens(n)
s += x
return s
check total(4) == 12check evens(3).collect() == [0, 2, 4]
check first_over(100) == 101
spec/examples/51_refined_input.rce
Expected: accepted
module refined
intent"input validation is a declared predicate: an event whose payload is outside its refined type has the kept outcome, state unchanged"exampleSetVolume(pct: 40) -> level == 40exampleRename(name: "ok") -> name == "ok"exampleCode(pin: "0042"), Code(pin: "9999") -> accepted == 2exampleSetVolume(pct: 40), Rename(name: "ok") -> level == 40typePct = u8whereself <= 100typeName = textwhereself.len() >= 1andself.len() <= 2typePin = textwhereself.isdigit() andself.len() == 4stateVolume
level: Pct = 0stateCodes
accepted: u32 = 0stateProfile
name: text = "-"eventSetVolume(pct: Pct)
eventRename(name: Name)
eventCode(pin: Pin)
stepVolumeonSetVolume(pct: p) -> p
stepCodesonCode(pin: _) -> accepted + 1stepProfileonRename(name: n) -> n
spec/examples/52_context_text.rce
Expected: accepted
# rce-version: 0.8module page
intent"untrusted text reaches HTML and SQL only through the context's encoder (5.16): markup and query syntax come from program literals"exampleComment(body: "<script>x</script>") -> html.raw() == "<p><script>x</script></p>"exampleComment(body: "O'Brien") -> query.raw() == "SELECT id FROM users WHERE name = 'O''Brien'"exampleComment(body: "a b&c") -> link.raw() == "/search?q=a%20b%26c"statePage
html: Text[Html] = Html.lit("<p></p>")
query: Text[Sql] = Sql.lit("")
link: Text[Url] = Url.lit("/")
eventComment(body: text)
stepPageonComment(body: b)
html = Html.lit("<p>") + Html.encode(b) + Html.lit("</p>")
query = Sql.lit("SELECT id FROM users WHERE name = ") + Sql.encode(b)
link = Url.lit("/search?q=") + Url.encode(b)
emit html
spec/examples/53_capability.rce
Expected: accepted
# rce-version: 0.8module admin
intent"authority is a value (5.16): a Guarded field is written only by a step whose event carries the capability"exampleSetLimit(admin: (), limit: 50) -> limit == 50exampleSetLimit(admin: (), limit: 50), Spend(amount: 20) -> spent == 20exampleSpend(amount: 5) -> limit == 100structRootstatePolicy
limit: Guarded[u32, Root] = 100stateLedger
spent: u32 = 0eventSetLimit(admin: Cap[Root], limit: u32)
eventSpend(amount: u32)
stepPolicyonSetLimit(admin: _, limit: n) -> n
stepLedgeronSpend(amount: a) -> spent + a
spec/examples/54_secret.rce
Expected: accepted
# rce-version: 0.8module login
intent"secrets are opaque (5.16): no literal can make one, no output can carry one, equality is the one release"exampleEnroll(pw: "s3cret"), Login(pw: "s3cret") -> ok == 1exampleEnroll(pw: "s3cret"), Login(pw: "guess") -> failed == 1stateVault
stored: Secret[text]? = none
ok: u32 = 0
failed: u32 = 0eventEnroll(pw: Secret[text])
eventLogin(pw: Secret[text])
stepVaultonEnroll(pw: p)
stored = some(p)
stepVaultonLogin(pw: p)
if stored == some(p)
ok += 1else
failed += 1
spec/examples/55_rcedb.rce
Expected: accepted
module rcedb
intent"a keyed store written in RCE over the host's durable append (Appendix E.8): puts are state writes, a bound Synced event moves the durable mark, scans are in canonical key order"examplePut(key: "b", val: "2"), Put(key: "a", val: "1"), Synced(upto: 1) -> durable == 1examplePut(key: "k", val: "v"), Delete(key: "k") -> rows.len() == 0exampleDelete(key: "x") -> kept: MissingstateDb
rows: Map[text, text] = {}
writes: u64 = 0
durable: u64 = 0eventPut(key: text, val: text)
eventDelete(key: text)
eventSynced(upto: u64)
eventScan(start: text)
errorMissing(key: text)
structRow
key: text
val: textstepDbonPut(key: k, val: v)
rows[k] = v
writes += 1stepDbonDelete(key: k)
ifnot rows.contains(k)
failMissing(key: k)
let _ = rows.remove(k)
writes += 1stepDbonSynced(upto: n)
if n > durable
durable = n
stepDbonScan(start: f)
var ks = rows.keys()
ks.sort()
for k in ks
if k >= f
let v = rows.get(k) catch""emitRow(key: k.tostr(), val: v)
spec/examples/56_utf8.rce
Expected: accepted
intent"bytes become text only when they are well-formed UTF-8; anything else keeps the state, never substitutes"exampleDec(b: [104, 105]) -> t == "hi"exampleDec(b: [226, 130, 172]) -> t == "€"exampleDec(b: [240, 159, 152, 128]) -> t.len_bytes() == 4stateS
t: text = ""eventDec(b: List[i64])
stepSonDec(b: b) -> b.utf8()
fn ok_ascii() -> text = [104, 105].utf8()
fn ok_empty() -> text = [].utf8()
fn bad_ff() -> text = [255].utf8()
fn bad_overlong() -> text = [192, 175].utf8()
fn bad_surrogate() -> text = [237, 160, 128].utf8()
fn bad_above_max() -> text = [244, 144, 128, 128].utf8()
fn bad_truncated() -> text = [226, 130].utf8()
fn bad_range_high() -> text = [300].utf8()
fn bad_range_neg() -> text = [-1].utf8()
fn ok_bom_kept() -> usize = [239, 187, 191, 97].utf8().len_bytes()
spec/examples/57_float_vectors.rce
Expected: accepted
module floatvec
# Cross-target float vectors (6.3 N3). Every target must reproduce these bits:# the trace hashes each state, so one differing bit changes the parity hash.# Non-finite results (overflow, x / 0.0, sqrt of a negative) trap; examples# cannot state a trap, so tests/float_rules.rs holds those vectors.intent"IEEE 754 binary64 vectors that every target computes bit for bit"exampleMulSub(a: 0.1, b: 10.0, c: 1.0) -> 0.0exampleAdd(a: 0.1, b: 0.2) -> 0.30000000000000004exampleDiv(a: 1.0, b: 3.0) -> 0.3333333333333333exampleSqrt(a: 2.0) -> 1.4142135623730951exampleMul(a: 5e-324, b: 0.5) -> 0.0exampleMul(a: 0.0, b: -1.0) -> -0.0exampleMul(a: 5e-324, b: 3.0) -> 1.5e-323exampleDiv(a: 2.2250738585072014e-308, b: 4503599627370496.0) -> 5e-324exampleMul(a: 2.2250738585072014e-308, b: 0.5) -> 1.1125369292536007e-308exampleAdd(a: 1e16, b: 5.0) -> 10000000000000004.0exampleAdd(a: 1e16, b: 3.0) -> 10000000000000004.0exampleRound(a: 2.5) -> 3.0exampleRound(a: -2.5) -> -3.0exampleConv(n: 9007199254740993) -> 9007199254740992.0exampleF32Mul(a: 0.1, b: 3.0) -> 0.30000001192092896exampleAdd(a: 1.7976931348623157e308, b: 1e291) -> 1.7976931348623157e308stateLab
x: f64 = 0.0eventMulSub(a: f64, b: f64, c: f64)
eventAdd(a: f64, b: f64)
eventMul(a: f64, b: f64)
eventDiv(a: f64, b: f64)
eventSqrt(a: f64)
eventRound(a: f64)
eventConv(n: i64)
eventF32Mul(a: f64, b: f64)
# a * b - c is two roundings (no contraction): 0.1 * 10.0 rounds to 1.0, so# the result is 0; a fused multiply-add would give 5.551115123125783e-17.stepLabonMulSub(a: a, b: b, c: c) -> a * b - c
stepLabonAdd(a: a, b: b) -> a + b
stepLabonMul(a: a, b: b) -> a * b
stepLabonDiv(a: a, b: b) -> a / b
stepLabonSqrt(a: a) -> a.sqrt()
stepLabonRound(a: a) -> a.round()
stepLabonConv(n: n) -> n asf64stepLabonF32Mul(a: a, b: b) -> ((a asf32) * (b asf32)) asf64
spec/examples/58_float_keys.rce
Expected: accepted
module floatkeys
# 6.1 key identity: map keys follow state identity, so -0.0 and 0.0 are two# keys (IEEE 754 totalOrder puts -0.0 first) and every target stores the# same map, hence the same state hash.intent"a tally keyed by float that keeps -0.0 and 0.0 apart"exampleAdd(x: 0.0), Flip(x: 0.0), Add(x: 0.0) -> {-0.0: 1, 0.0: 2}
exampleAdd(x: 1.5), Flip(x: 2.5), Add(x: 1.5) -> {-2.5: 1, 1.5: 2}
stateTally
m: Map[f64, i64] = {}
eventAdd(x: f64)
eventFlip(x: f64)
stepTallyonAdd(x: x)
m[x] = (m.get(x) catch0) + 1stepTallyonFlip(x: x)
let k = x * -1.0
m[k] = (m.get(k) catch0) + 1
spec/examples/59_dim_redundant_field.rce
Expected: accepted
intent"a counter mod 4 that also records the last event, which nothing reads""rce dim (10.11): 8 states explored, 4 behaviours, redundancy 1.00 bit; region DimCounter reports the 1 bit"exampleDimInc, DimInc, DimInc, DimInc -> n == 0exampleDimInc, DimDec -> last_inc == falsestateDimCounter
n: u64 = 0
last_inc: bool = falseeventDimInceventDimDecstepDimCounteronDimInc
n = (n + 1) % 4
last_inc = trueemit n
stepDimCounteronDimDec
n = (n + 3) % 4
last_inc = falseemit n
spec/examples/60_dim_hidden_period.rce
Expected: accepted
intent"a counter mod 6 whose only output is its parity""rce dim (10.11): 6 states explored, 2 behaviours, redundancy 1.58 bits: the state carries a period of 6 but the behaviour has a period of 2"exampleDimStep -> n == 1exampleDimStep, DimStep, DimStep, DimStep, DimStep, DimStep -> n == 0stateDimPhase
n: u64 = 0eventDimStepstepDimPhaseonDimStep
n = (n + 1) % 6emit n % 2
spec/examples/61_dim_minimal.rce
Expected: accepted
intent"a door whose state is exactly its behaviour""rce dim (10.11): 3 states explored (open and locked at once is unreachable), 3 behaviours, redundancy 0.00 bits: every reachable state answers some future event differently"exampleDimOpen, DimClose, DimLock -> locked
exampleDimOpen, DimLock -> kept: DimDoorOpenstateDimDoor
open: bool = false
locked: bool = falseeventDimOpeneventDimCloseeventDimLockeventDimUnlockerrorDimDoorOpenerrorDimLockedstepDimDooronDimOpenif locked
failDimLockedstepDimDooronDimOpen
open = truestepDimDooronDimClose
open = falsestepDimDooronDimLockif open
failDimDoorOpenstepDimDooronDimLock
locked = truestepDimDooronDimUnlock
locked = false
Syntax: requires change (13)
Each of these is not in the language of the grammar, so it requires change before type checking; the result names the rule.
spec/examples/change/syntax/assign_in_expr.rce
Expected: requires change at the parse stage, rule W-SYN-1: line 1: W-SYN-1 expected `)` (found `=`)
fn f() -> i64 = (x = 1)
spec/examples/change/syntax/bad_dedent.rce
Expected: requires change at the parse stage, rule W-LEX-2: line 3: W-LEX-2 inconsistent dedent
fn f() -> i64let x = 1return x
spec/examples/change/syntax/chained_compare.rce
Expected: requires change at the parse stage, rule W-SYN-1: line 1: W-SYN-1 expected end of line (found `<`)
fn f(a: i64) -> bool = 0 < a < 10
spec/examples/change/syntax/class_keyword.rce
Expected: requires change at the parse stage, rule W-SYN-1: line 1: W-SYN-1 expected a declaration (found `class`)
class Foo
x: i64
spec/examples/change/syntax/if_expr_no_else.rce
Expected: requires change at the parse stage, rule W-SYN-1: line 1: W-SYN-1 expected `else` (found end of line)
fn f(a: bool) -> i64 = if a then1
spec/examples/change/syntax/kind_empty.rce
Expected: requires change at the parse stage, rule W-SYN-1: line 2: W-SYN-1 expected indented block (found `fn`)
kindKfn f() -> i64 = 1
spec/examples/change/syntax/law_two_claims.rce
Expected: requires change at the parse stage, rule W-SYN-1: line 12: W-SYN-1 a law has exactly one `always` or `every step` line (found `always`)
# W-SYN-1: a law has exactly one claim (3.2)stateS
n: u8 = 0eventTickstepSonTick
n = 1law small
always n < 2always n < 3
Expected: requires change at the check stage, rule W-DEV-1: line 3: W-DEV-1 emit inside a device region
fn main()
withdevice gpu
emit1
spec/examples/change/types/device_extern.rce
Expected: requires change at the check stage, rule W-WORLD-1: line 1: W-WORLD-1 the foreign function `c_tick` must take `&World` as its first parameter, and only there
extern"C"fn c_tick() -> u32fn main()
withdevice gpu
let t = c_tick()
spec/examples/change/types/device_list.rce
Expected: requires change at the check stage, rule W-DEV-1: line 3: W-DEV-1 a device region holds fixed-size values only, found List[u64]
Expected: requires change at the check stage, rule W-WORLD-1: line 1: W-WORLD-1 the foreign function `c_f` must take `&World` as its first parameter, and only there
Expected: requires change at the check stage, rule W-WORLD-1: line 1: W-WORLD-1 the foreign function `c_rand` must take `&World` as its first parameter, and only there
Expected: requires change at the check stage, rule W-WORLD-1: line 1: W-WORLD-1 the foreign function `c_take` must take `&World` as its first parameter, and only there
Expected: requires change at the check stage, rule W-WORLD-1: line 1: W-WORLD-1 the foreign function `c_work` must take `&World` as its first parameter, and only there
Expected: requires change at the check stage, rule W-WORLD-1: line 1: W-WORLD-1 the foreign function `c_name` must take `&World` as its first parameter, and only there
Expected: requires change at the check stage, rule W-TY-1: line 2: W-TY-1 `*` on f32 and f64: no implicit conversion
fn f(x: f32) -> f32return x * 2.0
spec/examples/change/types/f32_mixed.rce
Expected: requires change at the check stage, rule W-TY-1: line 2: W-TY-1 `+` on f32 and f64: no implicit conversion
fn f(x: f32, y: f64) -> f32return x + y
spec/examples/change/types/fail_not_error.rce
Expected: requires change at the check stage, rule W-TY-1: line 2: W-TY-1 fail needs an error, found ?0
fn f() -> i64fail3
spec/examples/change/types/graph_attention.rce
Expected: requires change at the check stage, rule W-GRAPH-1: line 13: W-GRAPH-1 `tensor.attention_causal`: q [[f64; 2]; 2], k [[f64; 3]; 2], v [[f64; 2]; 2]: k has q's last length, v as many rows as k, and the heads of q are a multiple of those of k and v
# W-GRAPH-1: the keys have rows of 3 elements and the queries rows of 2,# so a query and a key have no dot product.use std.tensor
stateHead
q: [[f64; 2]; 2] = [[1.0, 0.0], [0.0, 1.0]]
k: [[f64; 3]; 2] = [[1.0, 0.0, 0.5], [0.0, 1.0, 0.5]]
y: [[f64; 2]; 2] = [[0.0, 0.0], [0.0, 0.0]]
eventGostepHeadonGo
y = tensor.attention_causal(q, k, q)
spec/examples/change/types/graph_integer.rce
Expected: requires change at the check stage, rule W-GRAPH-2: line 12: W-GRAPH-2 `tensor.exp` takes tensors of f32 or f64, found [i32; 3]
# W-GRAPH-2: exp is an operation on f32 or f64 tensors, and the counts# are i32.use std.tensor
stateCounts
c: [i32; 3] = [1, 2, 3]
y: [i32; 3] = [0, 0, 0]
eventGostepCountsonGo
y = tensor.exp(c)
spec/examples/change/types/graph_level.rce
Expected: requires change at the check stage, rule W-GRAPH-3: line 11: W-GRAPH-3 `tensor.round_bf16` has level lossy, weaker than the level exact in force here; declare it with `tensor.lossy(...)` around the operation
# W-GRAPH-3: round_bf16 lowers precision (level lossy), and no# tensor.lossy around it declares that level.use std.tensor
stateLayer
y: [f64; 2] = [0.0, 0.0]
eventInput(x: [f64; 2])
stepLayeronInput(x)
y = tensor.round_bf16(x)
spec/examples/change/types/graph_operand.rce
Expected: requires change at the check stage, rule W-GRAPH-2: line 11: W-GRAPH-2 an operand of `tensor.relu` has type List[f64]; a tensor is an array of fixed length, possibly nested, of f32, f64, i8 or i32
# W-GRAPH-2: an operand of a tensor operation is a list, whose length is# not fixed, so it is not a tensor.use std.tensor
stateLayer
y: [f64; 2] = [0.0, 0.0]
eventInput(x: List[f64])
stepLayeronInput(x)
y = tensor.relu(x)
spec/examples/change/types/graph_quantize.rce
Expected: requires change at the check stage, rule W-GRAPH-3: line 12: W-GRAPH-3 `tensor.round_q8_0` has level lossy, weaker than the level exact in force here; declare it with `tensor.lossy(...)` around the operation
# W-GRAPH-3: round_q8_0 replaces each block of 32 by the values of its# Q8_0 quantization (level lossy), and no tensor.lossy around it declares# that level.use std.tensor
stateWeights
w: [[f32; 32]; 1] = [[0.0asf32; 32]]
eventQuantizestepWeightsonQuantize
w = tensor.round_q8_0(w)
spec/examples/change/types/graph_shape.rce
Expected: requires change at the check stage, rule W-GRAPH-1: line 11: W-GRAPH-1 `tensor.matvec`: the matrix [[f64; 3]; 2] has 3 columns and the vector [f64; 2] has 2 elements; they must be equal
# W-GRAPH-1: the matrix has 3 columns and the vector 2 elements.use std.tensor
stateLayer
w: [[f64; 3]; 2] = [[0.5, -0.5, 0.5], [-1.0, 1.0, -1.0]]
y: [f64; 2] = [0.0, 0.0]
eventInput(x: [f64; 2])
stepLayeronInput(x)
y = tensor.matvec(w, x)
spec/examples/change/types/int_mismatch.rce
Expected: requires change at the check stage, rule W-TY-1: line 1: W-TY-1 `+` on u8 and i64: no implicit conversion
fn f(a: u8, b: i64) -> i64 = a + b
spec/examples/change/types/iter_effect.rce
Expected: requires change at the check stage, rule W-UNUSED-1: line 1: W-UNUSED-1 `c` is never read; remove it or name it `_c`
fn ticks(c: chanu64) -> iteru64yield1
spec/examples/change/types/iter_stored.rce
Expected: requires change at the check stage, rule W-UNUSED-1: line 5: W-UNUSED-1 `it` is never read; remove it or name it `_it`
Expected: requires change at the check stage, rule W-TY-1: line 2: W-TY-1 expected text, found ?0
fn names() -> itertextyield3
spec/examples/change/types/let_borrow_write.rce
Expected: requires change at the check stage, rule W-OWN-2: line 7: W-OWN-2 `n` is written while `a` (line 6) borrows `n` with `&mut`, and `a` is used again at line 8: end the borrow before this use (5.6 [No-Alias-Write])
fn bump(x: &muti64)
x = x + 1fn bad()
var n: i64 = 0let a = &mut n
n = 5
bump(a)
spec/examples/change/types/linear_copy.rce
Expected: requires change at the check stage, rule W-WORLD-1: line 4: W-WORLD-1 the foreign function `c_close` must take `&World` as its first parameter, and only there
linearstructH
id: i32extern"C"fn c_close(h: H) -> i32fn main()
let h = H(id: 3)
let g = copy(h)
let _ = c_close(h)
let _ = c_close(g)
spec/examples/change/types/linear_field.rce
Expected: requires change at the check stage, rule W-LIN-1: line 4: W-LIN-1 struct field `a` cannot hold a linear value
linearstructH
id: i32structPair
a: H
b: i32
spec/examples/change/types/linear_in_list.rce
Expected: requires change at the check stage, rule W-UNUSED-1: line 4: W-UNUSED-1 `hs` is never read; remove it or name it `_hs`
Expected: requires change at the check stage, rule W-WORLD-1: line 4: W-WORLD-1 the foreign function `c_close` must take `&World` as its first parameter, and only there
linearstructH
id: i32extern"C"fn c_close(h: H) -> i32fn main()
let h = H(id: 3)
for i in0..3let _ = c_close(h)
spec/examples/change/types/linear_one_branch.rce
Expected: requires change at the check stage, rule W-WORLD-1: line 4: W-WORLD-1 the foreign function `c_close` must take `&World` as its first parameter, and only there
linearstructH
id: i32extern"C"fn c_close(h: H) -> i32fn main()
let h = H(id: 3)
if h.id > 0let _ = c_close(h)
spec/examples/change/types/linear_unconsumed.rce
Expected: requires change at the check stage, rule W-WORLD-1: line 4: W-WORLD-1 the foreign function `c_close` must take `&World` as its first parameter, and only there
linearstructH
id: i32extern"C"fn c_close(h: H) -> i32fn main()
let h = H(id: 3)
emit h.id
spec/examples/change/types/loop_limit_type.rce
Expected: requires change at the check stage, rule W-LOOP-1: line 1: W-LOOP-1 LOOP_LIMIT must be declared `const LOOP_LIMIT: u64 = n` with a positive literal n
constLOOP_LIMIT: i64 = 10
spec/examples/change/types/missing_return.rce
Expected: requires change at the check stage, rule W-TY-1: line 1: W-TY-1 `f` can reach its end without returning i64
Expected: requires change at the check stage, rule W-MATCH-1: line 6: W-MATCH-1 match is not exhaustive: missing Green
kindLightRedGreenfn f(l: Light) -> u8match l
Red -> return1
spec/examples/change/types/orphan_impl.rce
Expected: requires change at the check stage, rule W-TRAIT-2: line 1: W-TRAIT-2 orphan impl: neither the trait nor the type is declared in this module
implEqforList[i64]
fn eq(&self) -> bool = true
spec/examples/change/types/pure_send.rce
Expected: requires change at the check stage, rule W-EFF-1: line 2: W-EFF-1 emit in a pure function
fn f(x: i64) -> i64emit x
return x
spec/examples/change/types/rec_not_structural.rce
Expected: requires change at the check stage, rule W-REC-1: line 4: W-REC-1 recursion through countdown has no decreasing measure (6.7): no layers of summed measures, each kept by every call not yet done and shrunk by at least one, leave the remaining calls without a cycle, and a cycle of its calls passes through no function declared with `bound`
Expected: requires change at the check stage, rule W-REC-1: line 1: W-REC-1 recursion through f, g has no decreasing measure (6.7): no layers of summed measures, each kept by every call not yet done and shrunk by at least one, leave the remaining calls without a cycle, and a cycle of its calls passes through no function declared with `bound`
Expected: requires change at the check stage, rule W-UNUSED-1: line 2: W-UNUSED-1 `x` is never read; remove it or name it `_x`
fn f(a: chanu64)
selectrecv some(x) from a -> passafter"soon" -> pass
spec/examples/change/types/simd_len.rce
Expected: requires change at the check stage, rule W-SIMD-1: line 2: W-SIMD-1 lane-wise `+` needs two arrays of one fixed length, found [i32; 3] and [i32; 4]
fn f(a: [i32; 3], b: [i32; 4]) -> [i32; 3]
return a + b
spec/examples/change/types/simd_text.rce
Expected: requires change at the check stage, rule W-SIMD-1: line 2: W-SIMD-1 lane-wise `*` needs numeric lanes, found text
fn f(a: [text; 2], b: [text; 2]) -> [text; 2]
return a * b
spec/examples/change/types/spawn_borrow.rce
Expected: requires change at the check stage, rule W-UNUSED-1: line 1: W-UNUSED-1 `xs` is never read; remove it or name it `_xs`
fn worker(c: chani64, xs: &List[i64])
c <- 1fn main()
let c = chan[i64](1)
let xs: List[i64] = [1]
spawn worker(c, &xs)
spec/examples/change/types/state_no_init.rce
Expected: requires change at the check stage, rule W-STATE-2: line 2: W-STATE-2 field `n` needs a comptime initial value
stateS
n: u64eventEstepSonE -> n
spec/examples/change/types/text_index_char.rce
Expected: requires change at the check stage, rule W-TY-1: line 2: W-TY-1 cannot compare u8 with text
fn f(s: &text) -> boolreturn s[0] == "a"
spec/examples/change/types/u64_mixed.rce
Expected: requires change at the check stage, rule W-TY-1: line 2: W-TY-1 `+` on u64 and i64: no implicit conversion
fn f(a: u64, b: i64) -> u64return a + b
spec/examples/change/types/unchecked_union.rce
Expected: requires change at the check stage, rule W-TY-1: line 6: W-TY-1 expected i64, found i64 ! E
errorEfn g() -> i64 ! EfailEfn f() -> i64 = g()
spec/examples/change/types/unhandled_event.rce
Expected: requires change at the check stage, rule W-STEP-2: line 5: W-STEP-2 event `Dec` is handled by no step or actor: δ would not be total
stateCounter
n: u64 = 0eventInceventDecstepCounteronInc -> n + 1
spec/examples/change/types/unknown_name.rce
Expected: requires change at the check stage, rule W-NAME-1: line 1: W-NAME-1 unknown name `y`
fn f() -> i64 = y + 1
spec/examples/change/types/unreachable_step.rce
Expected: requires change at the check stage, rule W-STEP-4: line 7: W-STEP-4 unreachable: the unguarded step at line 6 already handles S on E
stateS
n: u64 = 0eventEstepSonE -> n + 1stepSonE -> n + 2
spec/examples/change/types/unsafe_name.rce
Expected: requires change at the check stage, rule W-SAFE-1: line 2: W-SAFE-1 `unsafe` is not admitted
fn f() -> i64let unsafe = 1return unsafe
spec/examples/change/types/use_after_move.rce
Expected: requires change at the check stage, rule W-LEN-1: line 1: W-LEN-1 text has no unqualified `len`: use `len_bytes` or `len_chars` (F.5.2)
fn take(s: text) -> u64 = s.len() asu64fn twice(s: text) -> u64let a = take(s)
return a + take(s)
spec/examples/change/types/yield_outside.rce
Expected: requires change at the check stage, rule W-ITER-1: line 2: W-ITER-1 yield outside an iterator function
fn f() -> u64yield1return0
Inadmissible programs (18)
Each of these type-checks but does not pass admission: an example, a check, a comptime block or a constant does not hold when evaluated, so it requires change.
Expected: requires change at the admit stage, rule W-INT-1: line 8: W-INT-1 check: trap: size limit
fn build(n: u64) -> u64var k: u64 = 0witharena a bound16let xs: List[u64] @a = [n, n, n, n, n, n, n, n, n, n]
k = xs.len() asu64return k
check build(12345) == 10
Expected: requires change at the admit stage, rule W-UI-1: line 6: W-UI-1 the example's 1 frames: WCAG 1.3.1 undecided: needs human attestation: whether every structure and relationship shown is expressed by roles and states
# W-UI-1: the button raises an action but has no tabindex, so no key reaches it (WCAG 2.1.1)module door_frames
use ui.view
intent"a door panel that emits one frame per step"exampleOpen -> opened
structFrame
view: ViewstateDoor
opened: bool = falseeventOpenstepDooronOpen
opened = trueemitFrame(view: panel())
fn panel() -> Viewvar v = view.view_new("div", "")
for kv in [["lang", "en"], ["title", "Door"], ["fg", "#000000"], ["bg", "#ffffff"], ["font-px", "16"]]
view.set_attr(&mut v, 0, copy(kv[0]), copy(kv[1]))
let b = view.add_el(&mut v, 0, "button", "toggle")
for kv in [["role", "button"], ["w", "44"], ["h", "44"], ["action", "Close"]]
view.set_attr(&mut v, b, copy(kv[0]), copy(kv[1]))
let _ = view.add_text(&mut v, b, "Close")
return v
spec/examples/change/admission/guard_trap.rce
Expected: requires change at the admit stage, rule W-INT-1: line 2: W-INT-1 example does not hold: event 1 (Go) kept: trap(division by zero)
intent"guard trap keeps the state (S1)"exampleGo(d: 0) -> 1stateS
n: i64 = 1eventGo(d: i64)
stepSonGo(d: d) if10 / d > 1 -> n + 1stepSonGo(d: _) -> n
spec/examples/change/admission/iter_unbounded.rce
Expected: requires change at the admit stage, rule W-INT-1: line 9: W-INT-1 check: trap: loop bound
constLOOP_LIMIT: u64 = 100fn naturals() -> iteru64var i: u64 = 0loopyield i
i += 1check naturals().collect().len() == 5
spec/examples/change/admission/law_fails.rce
Expected: requires change at the admit stage, rule W-LAW-1: line 5: W-LAW-1 law you_cant_win fails after 9 events (exhaustive, alphabet 4 complete, 86 states explored): the claim is false
example Up, Up, Up, Up, Right, Right, Right, Right, Right -> won
# W-LAW-1: the walls on the far edges are missing, so the flag is reached after 9 eventsintent"the board wraps, and the far-edge walls are missing"exampleLeft, Left, Up -> not won
exampleUp, Up, Up, Up -> y == 1law you_cant_win
"no sequence of moves from the start reaches the flag"alwaysnot won
constW: u8 = 12constH: u8 = 8constROOM: u8 = 3constFLAG_X: u8 = 1constFLAG_Y: u8 = 1stateGame
x: u8 = 8
y: u8 = 5
won: bool = falseeventUpeventDowneventLefteventRightfn wall(x: u8, y: u8) -> boollet east = x == ROOMand y <= ROOMlet south = x <= ROOMand y == ROOMlet north = falselet west = falsereturn east or south or north or west
fn up(y: u8) -> u8if y == 0returnH - 1return y - 1fn down(y: u8) -> u8if y + 1 == Hreturn0return y + 1fn left(x: u8) -> u8if x == 0returnW - 1return x - 1fn right(x: u8) -> u8if x + 1 == Wreturn0return x + 1fn on_flag(x: u8, y: u8) -> boolreturn x == FLAG_Xand y == FLAG_YstepGameonUpifnot wall(x, up(y))
y = up(y)
won = won or on_flag(x, y)
stepGameonDownifnot wall(x, down(y))
y = down(y)
won = won or on_flag(x, y)
stepGameonLeftifnot wall(left(x), y)
x = left(x)
won = won or on_flag(x, y)
stepGameonRightifnot wall(right(x), y)
x = right(x)
won = won or on_flag(x, y)
Expected: requires change at the admit stage, rule W-INT-1: line 2: W-INT-1 example does not hold: event 1 (Dec) kept: trap(overflow: -1 is outside u64)
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.