18. CP Lang v2.1 Unification & Concept-Budget Guard (2026-11-20 — Language Architect Wave 3)
Wave 3 synthesizes all 21 scout friction backlogs across Batches 21–41
(research/archive/frictions/friction-backlog-batch-21.md through batch-41-oly-icpc.md,
covering 200+ hard ported problems) against locked v2 (§16), the max-N
prototype pass (c8e381f), and the aligned stdlib/ + examples/local-lib/
(§17). Full before/after examples and the next-sprint checklist live in
research/archive/architecture/language-architecture-v2.1.md; docs/one-page-cheat-sheet.md
is synchronized to match. Zero keywords (40), zero numeric types (4),
zero traits (7 + 2, as revised in 3.5), and zero @ decorators (7 + 2) are added.
- 18.1 Tropical Optional Rule (
?T), unparenthesized-??guard, and?T == T(1.3; Batches 27, 28, 32, 33, 34, 35, 36, 38, 39). Across nine batches, unlifted+/-on?Int/?F64forced repeatedif letguards and hand-writtenplus/shifthelpers that made?Intlonger thanINFsentinels. CP Lang v2.1 locks one algebraic rule:noneis the identity ofmin/max/min=/max=(includingmin(gen)/max(gen)over?Tandans min= opton plainT), andnoneis the absorber of+,-,+=,-=, unary-, andsum(gen)on numeric optionals?Intand?F64(never*,/,%, bitwise, or?V + k). To prevent thea[i] + max(...) ?? 0precedence trap permanently, mixing??with binary arithmetic (+ - * / %) without parentheses is a compile error. Equality==/!=auto-liftsTto?T(if dq.last != x:), while</<=/>/>=remain compile errors (?Tstill does not implementOrd). Chainedif let a = x and let b = y:andwhile letare surfaced on the cheat sheet; custom?Structmerges usematch (a, b):.
- 18.2 Lexically scoped
@memo, runtime flat-vs-hash dispatch, and uniform range narrowing (5.9; Batches 23, 28, 34, 35, 40).@memois legal on anyfn— top-level or nested inside a function or loop — capturing immutable outerlet/loop variables (mutated capturedvaris a compile error). Its cache is scoped to the enclosing block and hoisted into one reusable buffer cleared/stamped on block entry (eliminating the 185 MB 5-arg hash cliff incoci21c1p3and supporting scenario loops inioi20p4). Default@memoover all-Indexparameters chooses flat vs. salted open-addressedCpHashMapat runtime fromprod(K_i)(<= 2^24slots, or2^26for tri-stateuint8_t?Bool, fixingnoip21p3), and reports the chosen mode incpl check --verbose/ LSP hover. Range-typed parameters on@memofollow the exact same entry-check and flow-narrowing rules as ordinaryfns (cheerio1s5), and../..=bind looser than arithmetic and tighter than comparisons/in(i + 1..=nis(i + 1)..=n).
- 18.3 Complete algebraic
Indexsurface & lossless scalar casts (2.16; Batches 22, 28, 30, 33, 35, 37, 38, 39, 41). Clarifies all five existingIndexshapes:Bool(Bool.K == 2,for b in Bool,[V, Bool]T), structuralCharranges (['a'..='z']Int), guaranteed row-major.to_idx/.from_idxon tuple/record products(R, C), andSubset<D>(for s in Subset<D>in ascending integer order,.empty,.full, and O(1)s.first -> ?Dviactzfor bitmask DP peeling). Lossless scalar castsInt(ch)(0..=127),Char(i), andInt(b)(0 | 1) are locked;Int(f)onF64remains a compile error.
- 18.4 Lexical borrow & evaluation rules:
for mut,Copyrelease, RHS-before-LHS,.swap,.take(),.absorb()(5.3; Batches 24, 25, 26, 31, 34, 36, 38, 41).for mut x in xs:lends elements mutably for arrays/lists of self-adjusting structs (Block,Dsu,MonoDeque) while keeping generators pure. Reading aCopyelement releases its borrow immediately before enclosing calls (merge_heap(hrc[u], v)). Indexed assignmenta[i].f = rhsevaluates indices andrhsbefore borrowinga[i](making recursive arena updatesnodes[u].l = merge(nodes[u].l, b)both borrow-safe and reallocation-safe).a.swap(i, j)on[D]T/List<T>handlesi == jas a no-op; free-fnswap(mut a, mut b)is guaranteed O(1) on every heap container;.take()moves a heap container out in O(1) leaving an empty one behind (for x in mem[u].take(): mem[v].push(x)); and.absorb(mut other)drains small-into-large so it cannot be inverted into O(n^2).[D]T = exprclones anyTexpression independently per slot ([D]List<T> = []never aliases), andxs.laststays by-value (xs[xs.len - 1]mutates stack tops).
- 18.5 Ranges, chunks, boundaries,
SparseTable.fold -> ?T, and 2D grid flips (2.3, 7.19; Batches 24, 26, 32, 34, 37, 38, 41). EveryRange<D>exposes.land.rboundary cuts directly (even when empty, eliminatingrw.first!.lnoise inwindows(k)). AddD.chunks(k)(clamped non-overlappingRange<D>),Compressed<T>range slicingys[blk], domain prefixD[..k], range intersectionr1 & r2, andp.mirror/r.mirror. Replace ambiguous 2Dg.flippedwithg.flipped_rowsandg.flipped_cols(g.transposedyields[C, R]T).SparseTable.fold(r)returns?T(noneon empty ranges; no monoid identity needed).
- 18.6 Block-scoped
deferand bare top-levelreturn(5.7; Batches 24, 31, 37, 38, 41).deferis explicitly locked as block-scoped LIFO (runs at the exit of the immediately enclosing loop iteration, branch, orfn, never Go function-scoped), covering Rollback Mo's and backtracking DFS cleanly. Bare top-levelreturnexits the program cleanly (or ends the current case in whole-file@multitest).
- 18.7 Unified
Mod<P>,Intpromotion,T.zero/T.one-seededsum/prod, and cross-@multitestprecomputation (3.10; Batches 23, 29, 34, 37, 41). ConfirmsModRretirement (§17.5):let M = ...; type Z = Mod<M>unifies static and runtime moduli (including compositeP >= 1,.try_inv() -> ?Z,I128multiply past2^31 - 1, compile-time inverses for constant divisors, and one-wayIntops).sum(it)seeds from the element type's zero, andprod(it)joins the sequence prelude seeded from the element type's one; binary-op diagnostics always print type names. Cross-@multitestprecomputation needs nostaticor@once:Comb<P>()auto-grows lazily on demand, and top-level code above@multitest fn solve():runs once.
- 18.8 Value-owned
t.PreonRooted<V>, vertexless graph turbofish, andDsu.groups()(7.19; Batches 24, 26, 27, 34, 39, 41).PreonRooted<V>becomes a value-owned fresh domaint.Pre(likexs.Doncompress), preventing cross-tree preorder mix-ups (ioi18p3, superseding the type-levelRooted<V>.Prein §17.3). Addt.pos(v) -> t.Pre(inverse oft.preorder: [t.Pre]V),Rooted.from_parents(par), and iterativet.touryielding(v, entering); pint.lift_while(u, pred) -> ?Vto highest ancestor wherepredholds fromuup (ornoneifpred(u)is false). Documenttopo::<V>(next)for vertexless closure graphs and addDsu<V>.groups() -> List<List<V>>.
- 18.9 Stamp table
Marks<D>, generalizedRollingHash,Map4-lookup?(K, V),min_by/max_byties, and container polish (Batches 25, 29, 30, 31, 32, 33, 36, 38, 39, 40, 41). Add userlandMarks<D>()(generation-stamped visited set with.add(v) -> Bool,v in m, and O(1).clear()) alongsidea.fill(x). GeneralizeRollingHashoverStrand[D]TreturningHashValwith independent per-instance salted bases. Give orderedMap<K, V>all four lookups (.first_ge,.first_gt,.last_le,.last_lt) returning?(K, V)(Set/SortedBagreturn?K); accept optional iterables in container constructors; supportby:on sequencefirst_ge/last_leand.sorted()/.revon slices; exempt mutating.pop*()/.add()/.unite()from unused-result warnings; addrotate_right. Pinmin_by/max_by -> ?Twith first-extremum tie breaking, guaranteed stablesort/sorted,bit_len(x)(retiringbit_width), hex/binary literals, andSieve(n)/factor(x)/divisors(x)(retiringfactorize).
- 18.10
@graderconstants & shared domains, sibling-sized array params,Int-indexedStr, and judgeprint(1.6, 6.8; Batches 23, 25–27, 30, 33, 36, 37, 40, 41). Allow@grader const N: T(extern judge constant), file-scope size-lessdomain Vbound by grader parameters for shared callbacks, and sibling-sized array parameters left or right (fn Assist(needed: [0..r]Bool, n: Int, k: Int, r: Int)). ClarifyStrisInt-indexed (0..s.len, zero.raw) withs + ch,s.items, andmatch s:on string literals, alongside[expr for x in it if c]andList.filled(n, v). Lock judgeprint: domain values print their declared label, lists/1D arrays print space-separated, and[R, C]Chargrids print row-by-row (debug(...)prints structured brackets to stderr).
- 18.11 Compiler-trust & stress guardrails (7.4, 7.18; Batches 21–30, 34, 36).
Wrap all emitted C++17 user definitions in
namespace cp_user { ... }with C++/POSIX macro mangling (eliminatingtm,dup,arg,y0collisions); pinLazySegTree.setroot-to-leaf pushdown (ccc02s4hard); stream stdin incrementally for@interactor; addcpl stress --max-valsfor overflow hunting (O2); and place constructive generators (perm,surjection,bounded_product,tree,connected,dag,functional,simple_graph,str_of,rand_points,rand_disjoint_rects,rand_convex) instd.gen.
- 18.12 Concept-budget rejections (permanent; see
research/archive/architecture/language-architecture-v2.1.md§3). Explicitly rejected to protect the 40-keyword / 4-numeric-type / 1-page budget:Pool<Node>/Node.Id/SegPool,I32/U32,undo/Journaled,static let/@once,ModR,domain A | Bsum-domain syntax,min=/max=returningBool, dependent@memoparameter bounds, rolling-rowstep ... into, variable-length@tagsDSL, bitwise|/^onBool,loop:keyword,letinside generator comprehensions, keyed array literals[R: 1, G: 2],Rev<T>(useDesc<T>/desc(x)),Heap<T>(by:), user operators on structuraltypealiases, runtime-sizedSegTree.from(list)/combine_intoin corestd, and single-problem core helpers (Pos.window,g.lattice,cyc_range,dag_dp,take_except). Niche structures (Centroids,reroot,kruskal_tree,linalgdet/rank/solve,Interner,spanning,ranks,lis,count_in_rects,MinCount,RollbackArray,Functional(already landed inexamples/local-lib/), arbitrary-primePolyMTT +.interpolate,F64/recordLiChao) live inexamples/local-lib/.