Design decisions

26. The stdlib surface (plan/STDLIB.md, 2026-11-21)

26.1. Sorted lookup keeps first_ge/first_gt/last_le/last_lt. The 0.3 spec spells them first(from:), first(after:), last(upto:), last(before:). The four names read the same in lists, [D]T, Map, SortedBag and Compressed, are greppable, and need no overloading on argument labels, which the core does not have. Reverse: add label overloading to the core, then a codemod renames the family.

26.2. Mod<P> and Comb<P> keep their names over the spec's Mint(mod: p) and Z.factorials: 135 and 37 port files use them and the ideas are the same. Reverse: add aliases, codemod the ports, drop the old names.

26.3. Bitset<D> stays Bitset. The spec's candidate Bits<D> collides with the Bits trait for integer widths. Reverse: rename the trait first, then the type.

26.4. Monoid and Action stay values, not traits, until user traits can carry associated constants; values also let one type have several monoids (min and max over Int) without newtypes. Reverse: make them traits with instance values as a bridge.

26.5. Promotion order: the local library is a staging area, and a module moves into the stdlib when it meets the stdlib bar and ports reach for it (two ports outside its own batch, a friction report, or an import such as the nine lib.math.poly ones). The north star is everything ever asked at the hardest contests, so nothing is excluded; this only orders the work. NTT products, matrices, primes, Hopcroft-Karp, min-cost flow, Manacher, Aho-Corasick and convex hull come first. Reverse: move a module back and leave a re-export.

26.6. The design names every public name, by test (the_stdlib_design_names_every_public_name), so the doc cannot drift silently. Reverse: delete the test.

26.7. One number-theory home: std.math owns pow_mod, is_prime, factor_big, phi, primitive_root and floor_sum, promoted from examples/local-lib/math/primes.cp and floor_sum.cp, which keep only what builds on them. is_prime and factor_big are exact for every Int, not only below 4e18, because mul_mod now goes through I128 in O(1) instead of doubling in O(log b); factor (trial division) stays because it is simpler and fast enough to 1e12. Reverse: move the functions back into the local library and import them from there.

26.8. Rollback marks are a Mark; values and parities roll back with the sets. Dsu.mark() returned an Int, so cf2222f kept a second Int for its own payload history and the two could be swapped. Mark is one nominal type shared by Dsu, DsuOf<V, T> (a value per set, join(value of a's set, value of b's set) on merge, whichever root is kept) and ParityDsu<V> (promoted from the local library's BipartiteDsu, renamed after what it stores, with unite/diff spelled like the local PotentialDsu so a later group-valued potential DSU can absorb it). DsuOf is a separate type, not a payload parameter on Dsu, because a plain Dsu should not pay for a value array, and the core has no default type parameters. A closure rollback(body) helper is left out: its body must change the lent structure, which lexical borrowing rejects; scoped rollback waits for the core's defer/undo block. Reverse: make mark() return Int again and inline DsuOf's log into callers. Dsu.size and DsuOf.get bind find(v) before indexing: the C++ backend copies the whole field when an index changes self (sz[self.find(v)]), which made cf2237h 10x slower (1608 ms against 167 ms); the copy is the codegen lane's to remove.

26.9. A test after the sequence is the walk's body. count(xs, p), all(xs, p), any(xs, p), first(xs, p) and the methods xs.count(p), xs.all(p), xs.any(p) lower to count(p(x) for x in xs) and first(x for x in xs if p(x)), with an inline lambda's body substituted, so they cost what the walk costs, stop where it stops, and run on every sequence a for takes (Str, ranges, sets, alive.each()). Four ports asked for it (cf2207e2, cf2069e, cf2147h, cf2066e). Only the folds of a test take one: sum(xs, f) would be a second spelling of sum(f(x) for x in xs), which spec 22.2 forbids; prod joins sum as the product fold (a struct's one and *, else 1). xs.count(v) with a value still counts equal elements; a function argument is a test. find stays the position search on lists and the substring search on Str; the first element matching is first. Reverse: drop tested_walk from the count/all/any/first arms and the method hook; ports go back to the walk form.

26.10. Stdlib areas own section 4; a cross-area item goes to the area of the type it returns. Ten owners each take a slice of plan/STDLIB.md section 4 (table "Who owns what"); the coordinator keeps sections 1 to 3, the prelude, std.spec and section 5. Items no area named are placed by what they are: RNG and hashing with number theory, bitsets and List methods with containers, std.grid with graphs, offline time divide and conquer with containers (its owner designed offline_over beside the rollback DSU), link-cut trees with trees, the searches on answers with DP/search, the walk folds' compiler side in section 3 and their library side with sequences. Reason: one owner per name keeps one vocabulary reviewable. Reverse: edit the table; the routing rule in spec/lib/rationale/README.md follows it.