You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
len-cast: .len() as i32 is the census' largest ceremony pattern; D108's isize length needs index/range positions or a checked narrowing so the cast disappears #2522
blockedWaits on another open issue (named in a comment); not listed by the stop guardceremonya spelling the compiler already knows; mission: ceremony is a design defect
.len() as is the census' largest lexical ceremony pattern (len-cast), and with fmt cannot remove it (#2519, section C): under D108 len() returns isize, so most of these casts narrow to i32, and dropping one changes the program's meaning. The fix is in the language, not a formatter.
Counts today (.len() as <T>, tracked .w under src/ lib/ rt/ tools/ build/ examples/, corpora included in this rough count):
target
src
whole tree
i32
779
839
i64
55
65
u64
17
18
u32
4
5
(The census bar still records len-cast src 4487: ~/.local/with-green/ceremony-bar.tsv was last written 2026-10-08, so the bar is stale, see below.)
as i32 (839): needs a ruling. The code reads for i in 0..xs.len() as i32, let n = s.len() as i32, an i32 field set from a length. The cast exists because the surrounding code holds counts and indices in i32 (v[i] takes an i32 index) while len() is pointer-width. A person reading it sees no meaning in the cast; it's representation leaking through (Law 1).
Directions to brief (the "do the thing" procedure: references, spec text, mission fit, prediction):
(a) Index and range positions accept isize directly, so for i in 0..xs.len() and xs[i] need no cast and the code that holds positions moves to isize (D114 already says no code depends on isize's width).
(b) An i32 context accepts len() with a checked narrowing (panic on overflow, like out-of-range indexing, D71), so the cast disappears where the value is genuinely small.
(c) Both: positions become isize, and the remaining i32 storage (AST fields, serialized counts) narrows with a checked conversion spelled once at the boundary.
Option (b) on its own risks a silent-truncation reading; whichever is chosen, a narrowing must never be silent wraparound.
Done when: a ruling exists, .len() as i32 falls to the sites where the narrowing is a real boundary (a C struct field, a serialized width), .len() as i64 is 0, and the census bar for len-cast is lowered to match.
Also found: the census bar file has not been refreshed since 2026-10-08, although :install-user is documented to publish it on every reseed. The gate is measuring against counts that are 12 days old, so a rise up to the old bar passes silently. build.w:4841 makes install-user depend on ceremony-bar-publish, yet ~/.local/bin/with was installed 2026-10-20 21:31 while the bar is from 10-08: the publish step is not landing where the census reads it (or is skipped). That needs its own look.
Related: D108, D114, D71, #2519, #2261 (the facade-side analogue: a count parameter takes a non-negative isize without a cast).
Triage 2026-10-25, with v0.15.3.0 (main a261b65): reproduced, and the next step is a ruling. An index position takes isize today (for i in 0..xs.len(): s += xs[i] compiles), but passing a length to an i32 parameter still needs the cast:
$ with run main.w # let n = xs.len(); takes_i32(n)
error: implicit integer narrowing or sign change from `isize` to `i32` (argument 1 of `takes_i32`); use an explicit `as` cast (§4.2.6)
846 lines under src/ still contain .len() as.
The question: which language change removes the cast: lengths stay isize and the receiving parameters widen (a sweep), a checked narrowing that panics out of range, or something else? §4.2.6 forbids implicit narrowing today.
Ceremony audit 2026-11-02: this is the one item that needs Eric's ruling. Verified today with the pinned seed:
let xs = [1, 2, 3]
let n = xs.len()
let half: i32 = n / 2
error: implicit integer narrowing or sign change from `isize` to `i32`; use an explicit `as` cast (§4.2.6)
for i in 0..xs.len() and xs[xs.len() - 1] already work with no cast; the refusal is at an i32 demand. Current counts: .len() as i32 src 843 (census bar), whole tree 839+ as in the body above.
Brief (D98 shape): Go (int everywhere, no cast), Zig (usize, @intCast at every narrowing), Rust (usize, as/try_into), Swift (Int everywhere, no cast). The spec (§4.2.6) refuses silent narrowing; D108 made len() isize and called these casts legacy; D114 says no code assumes a width. Mission: a narrowing that can lose data is two meanings (wrap or trap), so a silent narrowing is out; a checked one (panic on overflow, as xs[i] panics out of range, D71) is one meaning and fits. Prediction (80%): option (c) — positions are isize and an i32 demand accepts an isize with a checked narrowing, so the cast disappears everywhere the value is small and the remaining as i32 sites are real boundaries (a C struct field, a serialized width). Waiting on Eric.
Conformance audit 2026-11-02: the spec's own §13.6 example fails on this: let sorted_index: BTreeMap[str, i32] = [w: i for (i, w) in vocab.enumerate()] → "implicit integer narrowing or sign change from isize to i32" (the enumerate index is isize, the map's value i32). A ruling here also makes the spec's example compile.
D183: ruled by Eric 2026-11-02 (spec v7.35, #2970): the general checked narrowing, as is the wrap, positions are isize, comptime out-of-range is an error, the lint names the narrow declaration. Implementation next.
D183's checked narrowing landed in #2989 (merged). What remains here is the .len() as i32 sweep: with positions isize (D108/D114) most casts can go; each site that stays a conversion now warns naming the narrow declaration, which is the worklist.
So what is left is not a cast-by-cast rewrite. D183 said it: each site that stays a conversion is a place where an i32 field or parameter is what is wrong. Dropping the casts without moving those declarations would turn 594 wraps into 594 range checks, many inside the compiler's hot loops, which the ruling names as a cost. The work is the position-width migration of the compiler's own tables and indexes (the same ground as #666's id spaces), file by file, with with fix-ceremony extended to report the declaration each cast leads to.
Order I would take: (1) teach fix-ceremony --report to print, for each len() cast, the i32 declaration that demands it, so the list is of declarations, not uses; (2) migrate the declarations with the most uses first; (3) the casts then fall away as redundant annotations do today.
Step one is merged (#3571): with fix-ceremony --report <entry> lists every narrowing cast of a length in two classes, from what Sema knows at the cast.
On the compiler today: 621 length casts: 260 demanded by a declaration (a parameter, field, annotated binding or return of the narrow width; the declaration is what to widen) and 361 that set a width nothing asks for (a plain binding or a range bound; without the cast it is the length's own width).
The pinned seed accepts D183's checked narrowing (verified with src/main), so the compiler's own source is no longer held back.
Step two, in this order:
The 361 undemanded casts: remove them file by file and re-check; put back any whose binding then meets a narrower demand (the compiler says so with the D183 lint). What stays removed is the set that never needed to be a conversion.
The 260 demanded ones: widen the declaration behind them, most uses first.
Labelled blocked on #666. Measured in #3574: of the 621 length casts, the 31 that fed nothing narrower are gone; the other 590 feed a declaration written i32 (a node id, a symbol, a count field, a parameter), directly or through a binding. Removing one of those means widening that declaration, and which declarations are ids with their own width is exactly #666's question (distinct NodeId / Symbol / TypeId / FileId types). Until those types exist, widening by hand would be decided twice.
blockedWaits on another open issue (named in a comment); not listed by the stop guardceremonya spelling the compiler already knows; mission: ceremony is a design defect
Activity
ehartford commentedon Oct 25, 2026
Triage 2026-10-25,
with v0.15.3.0(main a261b65): reproduced, and the next step is a ruling. An index position takesisizetoday (for i in 0..xs.len(): s += xs[i]compiles), but passing a length to ani32parameter still needs the cast:846 lines under
src/still contain.len() as.The question: which language change removes the cast: lengths stay
isizeand the receiving parameters widen (a sweep), a checked narrowing that panics out of range, or something else? §4.2.6 forbids implicit narrowing today.ehartford commentedon Nov 2, 2026
Ceremony audit 2026-11-02: this is the one item that needs Eric's ruling. Verified today with the pinned seed:
for i in 0..xs.len()andxs[xs.len() - 1]already work with no cast; the refusal is at ani32demand. Current counts:.len() as i32src 843 (census bar), whole tree 839+ as in the body above.Brief (D98 shape): Go (
inteverywhere, no cast), Zig (usize,@intCastat every narrowing), Rust (usize,as/try_into), Swift (Inteverywhere, no cast). The spec (§4.2.6) refuses silent narrowing; D108 madelen()isize and called these casts legacy; D114 says no code assumes a width. Mission: a narrowing that can lose data is two meanings (wrap or trap), so a silent narrowing is out; a checked one (panic on overflow, asxs[i]panics out of range, D71) is one meaning and fits. Prediction (80%): option (c) — positions areisizeand ani32demand accepts anisizewith a checked narrowing, so the cast disappears everywhere the value is small and the remainingas i32sites are real boundaries (a C struct field, a serialized width). Waiting on Eric.ehartford commentedon Nov 2, 2026
Conformance audit 2026-11-02: the spec's own §13.6 example fails on this:
let sorted_index: BTreeMap[str, i32] = [w: i for (i, w) in vocab.enumerate()]→ "implicit integer narrowing or sign change fromisizetoi32" (the enumerate index isisize, the map's valuei32). A ruling here also makes the spec's example compile.ehartford commentedon Nov 2, 2026
D183: ruled by Eric 2026-11-02 (spec v7.35, #2970): the general checked narrowing,
asis the wrap, positions areisize, comptime out-of-range is an error, the lint names the narrow declaration. Implementation next.D183 (#2522): an integer where a narrower or other-signed integer is …
D183 (#2522): an integer where a narrower or other-signed integer is …
ehartford commentedon Nov 2, 2026
D183's checked narrowing landed in #2989 (merged). What remains here is the
.len() as i32sweep: with positionsisize(D108/D114) most casts can go; each site that stays a conversion now warns naming the narrow declaration, which is the worklist.ehartford commentedon Nov 18, 2026
Not a ruling: D183's checked narrowing landed, so what is left is the sweep of
.len() as i32sites, which is mine. Label removed.ehartford commentedon Nov 23, 2026
Measured 2026-11-23 on main (after D183 and the
.withrename):.len() as i32insrc/is 594 sites.let n = xs.len() as i32(orvar)nis ani32from there on, so the binding and what it flows into move toisizefor i in 0..xs.len() as i32:ibecomesisize; each use ofiwhere ani32is demanded then narrows with a check inside the loop, unless that parameter or field moves tooi32parameter or field it feedsBy file: ComptimeEval 85, SemaCheck 77, Parser 59, Sema 44, MirLower 44, Codegen 40, MirCore 34, SemaDecl 32.
So what is left is not a cast-by-cast rewrite. D183 said it: each site that stays a conversion is a place where an
i32field or parameter is what is wrong. Dropping the casts without moving those declarations would turn 594 wraps into 594 range checks, many inside the compiler's hot loops, which the ruling names as a cost. The work is the position-width migration of the compiler's own tables and indexes (the same ground as #666's id spaces), file by file, withwith fix-ceremonyextended to report the declaration each cast leads to.Order I would take: (1) teach
fix-ceremony --reportto print, for eachlen()cast, thei32declaration that demands it, so the list is of declarations, not uses; (2) migrate the declarations with the most uses first; (3) the casts then fall away as redundant annotations do today.with fix-ceremony --report says which narrowing casts of a length a d…
ehartford commentedon Nov 23, 2026
Step one is merged (#3571):
with fix-ceremony --report <entry>lists every narrowing cast of a length in two classes, from what Sema knows at the cast.On the compiler today: 621 length casts: 260 demanded by a declaration (a parameter, field, annotated binding or return of the narrow width; the declaration is what to widen) and 361 that set a width nothing asks for (a plain binding or a range bound; without the cast it is the length's own width).
The pinned seed accepts D183's checked narrowing (verified with
src/main), so the compiler's own source is no longer held back.Step two, in this order:
31 length casts in the compiler stop being conversions: bindings and …
ehartford commentedon Nov 24, 2026
Labelled
blockedon #666. Measured in #3574: of the 621 length casts, the 31 that fed nothing narrower are gone; the other 590 feed a declaration writteni32(a node id, a symbol, a count field, a parameter), directly or through a binding. Removing one of those means widening that declaration, and which declarations are ids with their own width is exactly #666's question (distinctNodeId/Symbol/TypeId/FileIdtypes). Until those types exist, widening by hand would be decided twice.