21. Batch 7 calls: graph vertices, getters, randomness, the prelude budget and always-on traps (0.2.2, 2026-11-20)
These came out of the cold-writer benchmark and Friction Hunter waves 5 to 10, where the same few fights kept
recurring. Each one is implemented in the Rust compiler and covered by a program under
crates/cpl-cli/tests/programs/.
-
21.1 A tuple of domains is a domain for graph search.
[V]TwhereVstands for(R, C)is the same flat table as[R, C]T, sobfsanddijkstratake grid cells as vertices directly instead of a cell number packed by hand:use std.grid.{adj4} domain R = 0..3 domain C = 0..3 let wall: [R, C]Bool = [R, C] (r, c) => r.ord == 1 and c.ord < 2 let d = bfs(p => [q for q in p.adj4 if not wall[q]], [(R(0), C(0))]) print(d[(R(2), C(0))])
- 21.2 The vertex domain comes from the neighbour function. When
peel,topoorsccis given a lambda, the vertex domain is the domain the lambda indexes with its parameter, sopeel(v => adj[v])needs no::<V>. A namedGraphworks the same way:peel(g)andtopo(g)take the domain fromg.
- 21.3 A getter reads the same with or without parentheses. A
@getmethod such asMod.invcan be writtenx.invorx.inv(). Writers coming from other languages reach for the parentheses first, and there is no second meaning they could have, so both spellings are accepted rather than one being an error.
- 21.4 Seeded randomness is a library type.
std.randholdsRng(Rng.new(seed),.int(lo, hi),.next()), imported explicitly withuse std.rand.{Rng}. The prelude keeps onlyrand(lo, hi)andshuffle(mut xs), which cover generators and most randomized solutions.
- 21.5 The prelude has a budget of 80 names.
stdlib/prelude.cpimports exactly 80 names. Batch 7 brought inDir8,step,find_all,windows,zipanddigit, which the benchmarks showed people write without ause, and movedNeighbours,Hashable,Prefix1andHashValout, since they are named only by library authors. A name joins the prelude only when another one leaves.
- 21.6 Arithmetic traps run in every build, not only locally. Division or modulo by zero, a shift
outside
0..64, a negative power andU64division by zero stop the program with exit status 3 in the submitted release binary too. A modulus above3_037_000_499multiplies in 128 bits, soMod<4_000_000_007>no longer overflows. The release binary is what the judge runs, and a silent wrong answer there is worse than a crash; the perf tail profile (research/perf/perf-tail-profile-2.md) measured no cost from the always-on division checks. UnprovenIntoverflow stays a local-only trap (7.x).
- 21.7 Two silent-empty cases are errors. A domain named inside a tuple
read(), such aslet (s, k): ([domain Pos]Char, Int) = read(), used to read no values; it is now a compile error. Amatchon an enum without fields needs an arm for every variant.