100. Validate stores into range-typed places via ExprKind::RangeCheck (2026-11-21)
- Decision. Every store into a range-typed place (scalar
var/let, struct field and constructor arg, array element including compound assignment /max=/min=/ fill / comprehension, andList.push/.resize/.fill) lowers throughLowerer::check_range, which wraps unproved values inExprKind::RangeCheck { value, lo, hi, text }. Bothcpl-interpandcpl-codegen(cpl::check_rangeunder#ifdef LOCAL) trap with exit code 3 and{v} is outside \{text}`. Release builds (-DLOCALunset) compilecpl::check_range` to a zero-cost passthrough, including for narrowed 32-bit struct fields (and future narrowed arrays). - Why. Narrowed
0..=1_000_000struct fields previously truncated silently in C++ whilecpl runprinted the raw 64-bit value, breaking interpreter/C++ parity, and scalar/array ranges were unenforced on assignment. Checking incpl runand--checked(-DLOCAL) catches every contract violation locally with identical diagnostics, while eliding proven-in-range stores (literals, narrower range-typed sources,x % Pinto0..P,Mod<P>branch-refined+/-/neg) keeps hot loops andMod<P>codegen completely free of checks. Keeping release zero-cost matchesfsqrt,shl128, andsortcomparator validation (#ifdef LOCAL) so valid programs pay zero runtime overhead on judges. - Reverse. Remove
ExprKind::RangeCheckandcrates/cpl-ir/src/lower/range.rsto revert validation; or remove the#ifdef LOCALguard incpl::check_rangeincrates/cpl-codegen/src/runtime.rsif release builds should also trap before narrowing truncation.