25. Stress testing and shrinking (0.2.2, 2026-11-21)
- 25.1
Perm<V>andTree<V>are stdlib types.std.seq.Perm<V> = [V]Vandstd.graph.Tree<V> = [0..V.len - 1](u: V, v: V). Before, onlycpl stressknew the names: the compiler rejectedlet t: Tree<V> = read()with E0204, so a port had to declare a local alias (andproto/ports/nccc10s2.cp, which usesPerm<L>bare, does not compile). As plain generic aliases they read, print and index the same incpl runand the C++, and stress still makes and shrinks them as a permutation and a tree. They stay out of the prelude (21.5's budget), so a file names them with ause. Stress still recognises the alias by its name; keying it to the stdlib declaration instead is open. Reverse: delete the two aliases.
- 25.2 The seeded-bug benchmark compares exact minimal inputs. Each
bench/stress/<bug>.cpis a port with one classic bug planted and the correct fn as its@brute;<bug>.minis the smallest input that shows it, andtests/seeded_bugs.rsfails unlesscpl stressprints exactly that input, with a median under 10 s (GOALS4). Byte equality makes a shrinker regression (a case that is still failing but larger) fail the gate, not just a missed bug; the cost is that a legitimate improvement that finds a different minimum of equal size updates the.min. Reverse: compare weights (Case::weight) instead of bytes.
- 25.3 Letter domains are made as code points.
domain L = 'A'..'A' + kis read bycpl runand the C++ as numbers (66, notB) today, thoughplan/19says its values are chars; stress makes what the reader accepts. When the reader takes letters, makeShape::Intwith a char bound produceValue::Char. Reverse: that same change.
- 25.4 Simple, connected and acyclic graphs are three stdlib aliases.
std.graphgainsSimpleGraph<V, E>,ConnectedGraph<V, E>andDag<V, E>, each[E](u: V, v: V): one edge per value ofE, read and printed like any edge list bycpl runand the C++. Stress makes them with no loop and no repeated pair (an unordered pair for the first two, an arc forDag), the second connected (a random spanning tree first) and the third acyclic (arcs follow a random vertex order), and shrinks them by deleting a vertex with its edges, deleting edges, and renaming vertices in the order the edges name them, keeping each property. A deleted or renamed vertex is renamed in every other value read over the same vertex range (let (s, t): (V, V)), so the case keeps its meaning. The spec'sgen<Graph<V>>(simple: true)needs named arguments on a type the core does not have; three names over one shape need nothing new, and a weighted graph is a local alias with more fields (type SimpleGraph = [E](u: V, v: V, w: W)), as forTree. The names are recognised by name, like 25.1. Reverse: delete the three aliases andShape::Graph.
- 25.5 Equal values are lowered together, sizes apart. After lowering each number alone, the
shrinker lowers every number holding one value as one (in one input, and across the test cases
of a multitest), so a failure that needs two values equal (a count left over from an earlier
test, a repeated element) shrinks to
1 1, not to wherever the first value stood. Sizes stay out of the group: they are halved and stepped on their own, and a size that equals a value by chance (n = 2,a = [2, 2]) would otherwise drag the array shorter and stop the group. The cost is one more bisection per distinct value per round. Reverse: drop step 3b and the joint step inshrink_tests.
- 25.6 Trees are made in four shapes; graphs are renamed toward their plainest form. Hanging
each vertex under a uniformly earlier one alone made 27 paths and 2 stars in 400 seven-vertex
trees (
random_trees_include_paths_and_stars); deep and wide trees are what break recursion and adjacency loops.Pick::treenow chooses random, long (under one of the three before), path or star, for aTreeand the tree aConnectedGraphstarts from (68 paths, 100 stars), andcpl benchoverrides it, so its path and star cases now exist forTree<V>(they were skipped). Shrinking a graph also tries swapping two vertex names (among the first 16) and writing every undirected edge low end first, so a star shrinks to1 2, 1 3, 1 4from any centre. The seedednoip14p5-unsafe-stepnow reaches a lighter minimum (weight 15 for 16), so its.minchanged (25.2). Reverse: makePick::treereturnRandomand drop the swap and flip steps.
- 25.7
std.graph.Digraphis a directed simple graph.SimpleGraphis undirected, so the seedednoip14p5-unsafe-step, which reads arcs, was made with every pair at most once (neveru vandv u) and shrunk by flipping arcs, which changes a directed graph.Digraph<V, E>joins the other three aliases (25.4): no loop, no arc twice,u vandv udistinct, roomn(n-1), arcs never flipped while shrinking (shrinking_a_digraph_keeps_each_arc_the_way_it_points). The port now reads aDigraph; its.minis the same graph with its arcs in order. Reverse: drop the alias andGraphKind::Digraphand point the port back atSimpleGraph.
- 25.8 Reads in a loop are a field; reads stress can't make are errors. 342 of 1,332 ports
read inside
for _ in 0..q:, and stress refused all of them. A loop over a range or a domain whose passes read only typedlet x: T = read()lines (or loops like it), with types that use nothing bound inside the loop, is now an array field of what one pass reads: the same input, so no new concept, and every shrink step already works on it. Abreakorreturn, acontinuebefore a read, or a type that uses a value read in the pass is refused, since a fixed row cannot describe it. Reads inside a plain (or@memo) fn andread(gen:)/read(none:)were silently left out of every case (a too-short input, not a bug found); they are errors now. Shrinking gains one step, run only once the others stall: lower a value by one while dropping one element. Reverse: dropBuilder::passand theForarm (loops are refused again), and theFnandreads_with_optionsarms (those reads are left out again).
- 25.9 A tuple's parts can bind names for the parts after them. A loop pass that reads
s, then[0..s]City, has a row whose later bounds use an earlier value, which no fixed shape says.Shape::Tuplegainsbinds(the names each part binds, as a field'snamesdo); make, fit and the list of numbers bind them in a local scope, and a bound size inside a row is a size for shrinking (lowered, or lowered with one element dropped). One mechanism serves rows at any depth, so noRowshape besideTuple. Names worked out in the pass (let m = k + 1) are still refused. Reverse: dropbindsand refuse a pass type that uses a name read in the pass.
- 25.10
domain V = read(lo..=hi)is a size read where it is declared. The design declares an index space read from the input this way (design/spec/21-index-spaces.md); the generator read its bounds as a fixed domain and left the count out. The count is now a field (or a part of a loop row) at the place of the declaration, arrays overVtake that many values, andVis0..count. Reverse: dropread_sizeand the generator refuses such domains again.
- 25.11 A row whose reads depend on a tag read first is a
Choice.if op == 1: read A elif op == 2: read B else: ...andmatch kind: 'B' => ... _ => ...read different values per tag; refusing them left out most query problems.Shape::Choice { tag, name, arms }holds one arm per branch with the literal tags that take it (Nonetakes the rest). Generation picks an arm evenly, then a tag that takes it; fitting rebuilds an arm's values at their low ends when shrinking moves the tag to another arm; shrinking tries each arm's tag before lowering values, so a query that reads nothing wins. AnInttag read with no range is narrowed to the tags the arms test (and one more for anelse), since a far-off tag is noise, not a query. Branches with guards, non-literal tests or a test of anything but the tag are still refused. Reverse: removeShape::ChoiceandBuilder::choice; such loops are refused with their old message.
- 25.12 A struct or an
@tagsenum read from the input is generated field by field.read()reads a struct's fields in order and an@tags("R", "C")enum as its variant's tag, then that variant's fields, so the generator does the same: a struct is aTupleof its field types, and a tagged enum is aChoiceon a letter whose arms are its variants. Generic records and tags longer than one letter are still refused with the old message. Reverse: dropBuilder::recordsandRecord.
- 25.13
read(none: x)makes?Teitherxor a value ofT, and the shrinker tries a number's low end first.read(none: 0)writes an absent value as0, so the generator writes the sentinel about a quarter of the time and an integer ofTotherwise; a present value shrinks toward the lower ofT's low end and the sentinel. Only integerTwith a number (or numeric string) sentinel is accepted; anything else keeps the old refusal. Lowering a number now tries its low end before the binary search, because a fit that clamps?(1..=n)up to1hidesnone: 0below the gap. Reverse: dropShape::Maybe,read_noneand the low-end attempt inshrink'slower.
- 25.14
read(gen: f)is drawn by runningfon the input above it, and shrinks by seed. The type next to aread(gen: f)holds less thanfdoes (a tree written as[E](u: V, v: V), a strictly rising[I]1..=1e6), so the field's value is whateverf()makes:cpl-ir'slower_gen_readkeeps the program's top-level statements above that line, then printsf()asread()reads it, and the interpreter runs it withrandseeded (Io::seeded). The value is kept as its seed and its text (Value::Drawn). Shrinking never edits inside it: every time the values above it change it is drawn again from its seed, a rejected smaller case is retried with up to 16 other seeds, and a pass tries those seeds alone. Only top-level reads outside a test case are drawn; the rest keep their refusal. The generator runs in the interpreter only: it makes inputs, and the solution under test still runs on both sides. Reverse: dropShape::Gen,Value::Drawn,lower_gen_read,Io::seededand the reseeding inshrink.
- 25.15 A jump counts against a loop pass only when it leaves that pass. A
breakorcontinueinside a nestedfor/whileends only that loop, and areturninside a nestedfnor closure ends only that call, so the pass still makes every read of its row. A labelledbreak/continueis taken as leaving, since telling which loop its label names is not worth it for the few ports that use one. Reverse: makeJumpscount every jump in the pass again.
- 25.16 A typed read inside an expression is a field, where it runs a known number of
times.
read<T>()andread::<T>()give their type, soGraph.undirected(read<[m](V, V)>()),[0..n] _ => read::<Int>() - 1,for a in read<[n]T>():andmatch read::<Op>():make fields in the order the reads run: operands left to right, a table or a range comprehension as one array. A read in a branch, a closure, a filtered comprehension or a short-circuit operand, an untypedread()in an expression, anda[read()] = read()(no sure order) are refused. Before this, generic reads were not seen at all, so their input was silently left out. Reverse: dropBuilder::inlineand refuse every read that is not a wholelet.
- 25.17 The ecnerwala interactors also talk over their own stdio. With no
-- cmd,interactors/_lib.pydrives the solution on its stdin and stdout, the waycpl stress --interactorandcpl judgeconnect one, so the 16 interactorsgate.shalready trusts are the ones stress runs under, not copies.stress_judgesstresses all 16 and the 5 checker ports on theirgen/cases, and checks that a solution printing1is caught under each judge. Reverse: delete the stdio branch and the test.
- 25.18
cpl stress --explainnames the first value the two runs give a variable differently. On a failure against the file's own@brute(main), both run on the shrunk case in the tree-walking interpreter withTraceConfig::assignments, which logs every value alet, an assignment, a mutation or a loop gives a named variable, in fns too. For each name both runs use, the values it takes (repeats collapsed) are compared, and the one whose first difference comes earliest in the solution's run is reported with its ordinal and the line on each side. Comparing histories by name, not steps, lines up two programs that share names but not shape; a history that is only a reordering ending on the same value is a loop in another order and is not a divergence. Variables only one side names are skipped, so when no shared name differs it says so and thedebug(...)stages remain the guide. Off by default: logging every assignment slows a run. Reverse: drop the flag,assignmentsandfirst_divergence.
- 25.19 A fn that reads is read where it is called, when every call always runs. A fn with
no parameters, called only as a whole top-level statement or a
let's whole value (read_moves(),let a = read_sym()), reads its body's input at each call, in order, so its body is walked there as if written inline, nested calls included. A parameterless fn whose only reads are fixedlet name: T = read()lines reads the same values in any expression, so such a call is a field wherever it is. Areturnafter the body's last read ends the fn as its end would and is allowed; one inside a nested fn or lambda is not the reader's. Any other call (in a branch, a loop, an argument), a parameter its reads could depend on, or areturnbefore a read reads only some of the time, and the fn stays refused. Reverse: dropreaders,valuesandexpandinspec.rs.
- 25.20 Types with a fixed text form are generated from that form.
U64is0..=2^64-1,Mod<P>is0..P,F64andI128are whole numbers in theIntdefault range (any whole number is a validF64token, and the shrinker lowers them like integers), and a stdlib struct (Pt,Pt3) is read field by field like a user struct, looked up in its stdlib module, unless the file declares its own type of that name. Fractions and values pasti64are left to--gen. Reverse: drop those arms ofBuilder::shape.
- 25.21 A tag read first in a tuple or above the reads it chooses still chooses.
let (kind, l): (0..=2, Cell) = read()thenmatch kindis aChoicewhose shared parts are the tuple's other parts and any reads between the tag and the branch; a tag rebound before the branch is refused, not trusted. Reverse: drop the tuple case ofBuilder::choice.
- 25.22 A loop read's type may use the loop's own name.
for r in 1..=n: let row: [0..r]Int = read()is an array whose elementatis made, fitted and shrunk withrbound tolo + at, so a triangle stays a triangle asnshrinks. Only a plain name pattern is bound; a value worked out in the pass is still refused. Reverse: dropindexfromShape::Arrayand refuse the loop name again.
- 25.23 A
Strtag compared with words is one of those words.let op: Str = read()thenif op == "ADD" ... elif op == "SHOW" ...is aChoiceoverShape::Words, the literals in the order the branches name them, plus one word none of them is when an arm takes the rest. A word is drawn and shrunk as its position, so the shrinker moves to the first-named arm. Words with spaces, or an interpolated string, are refused. Reverse: dropShape::WordsandValue::Word.
- 25.24 The seeded-bug median bar is 1 s, over at least 21 bugs. With ten more bugs
across multitest leakage, overflow at bounds and off-by-one at a range end, the gate's
median time to a minimal counterexample is 0.77 s, so the bar drops from 10 s to 1 s and
the benchmark refuses fewer than 21 bugs. The time is wall clock in the debug build the
gate runs, so a loaded machine is part of what it measures. Reverse: restore
MEDIAN_LIMITto 10 s and the bug floor to 4 intests/seeded_bugs.rs.
- 25.25 The seeded-bug test decides by input, not by clock. Every bug runs with
--seed 1 --cases 1000and a 60 s run limit, four at a time, so whether a bug is found and shrunk to its.minis the same on any machine; the median is printed against the 1 s bar and never asserted. A wall-clock assertion failed a full gate under load (40 s) that passed alone, blocking every lane. Reverse: assertmedian <= 1 sagain.
- 25.26
a[i] = read()reads the element typeais declared with. The type is taken from the onelet/varin the file that namesawith an array type (orList<T>, whose element isT); a name declared twice is refused, since which declaration a write means depends on scope. This is the read the program makes, so the generated row matches it without asking the port to read into a typedletfirst. Reverse: dropelemsand theAssignarm inrows.
- 25.27 A bare
read()takes the type of the call it is passed to. When every argument is a bareread(),Graph<V, E>.undirected/.directedreads[E](V, V)and a struct constructor reads the struct field by field, as the interpreter does. The edges are any[E](V, V): a port that needs a DAG or a connected map should sayDagorConnectedGraph, as a typedletwould have to. Reverse: dropBuilder::read_as.
- 25.28 A pass that skips its first or last index reads from the rest. A loop
whose body starts
if v == V.first: continue(or== lo,== V.last,== hi) is read as a loop over the other indices, sofor v in Vreading each vertex's parent but the root's is a row per non-root vertex. A skip in the middle stays refused. Adomaina pass computes from its own values is unknown like those values: only a read whose type names it is refused. The parents read this way are anyVs, not a tree; a port that needs a tree should readTree. Reverse: dropskipped_endand return to refusing such domains.
- 25.29 A table that skips its first or last cell reads the rest.
[D] i => if i == D.first: x else: y, withxreading nothing, readsyonce per cell but one, the same rule 25.28 gives a loop. A skip of any other cell stays refused. Reverse: dropskipped_cell.
- 25.30
let a: List<T> = [read() for _ in lo..hi]reads[lo..hi]T. The bare read takes the element type theletdeclares, aslet a: [D]T = [D] _ => read()already does; a comprehension with a filter or a named loop variable stays refused. Reverse: drop theComprehensionarm oftyped_read.
- 25.31 A top-level
if/matchon a value read above it is a choice. The fields from the tag on become one choice field, as a loop pass's row already does, solet k: 1..=2 = read()thenif k == 2:reading in each arm generates each arm. Only when the branch is the last top-level line that reads, no reader fn is inlined and no name is bound twice: a later read could need a name the arms now hold. Reverse: dropBuilder::top_choiceand its call.