Skip to content

with fix-ceremony --report says which narrowing casts of a length a declaration demands and which set a width nothing asks for (#2522) - #3571

Merged
ehartford merged 1 commit into
mainfrom
len-cast-report
Nov 23, 2026
Merged

ehartford merged 1 commit into
mainfrom
len-cast-report

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Part of #2522 (step one of the plan on the issue). Report only; no source is rewritten.

D183 ruled that most .len() as i32 sites should stop being conversions at all, and that a conversion that remains points at the declaration whose width is wrong, never at the use. To work that list the sites have to be told apart by what the compiler knows, not by their text.

Sema now records each narrowing cast of a len() call in one of two classes, at the place it already records a widening cast under a demand:

  • demanded: the context demands the cast's target (a parameter, a field, an annotated binding, a return). That declaration is what to widen.
  • undemanded: nothing demands it (a plain binding, a range bound). Without the cast the value is the length's own width.

with fix-ceremony --report prints one line per cast and a summary. It does not rewrite them: dropping one in place turns a wrap into a range check where it stands, which the ruling names as a cost.

On the compiler today: 621 length casts, 260 demanded by a declaration, 361 that set a width nothing asks for.

Also verified while here: the pinned seed accepts D183's checked narrowing (let n: i32 = xs.len() checks under src/main, with the D183 lint), so the compiler's own casts are no longer held back by the seed.

Test: a case in test/internals_compiler/ceremony_fix_test.with (five casts over the two classes, a widening cast that is neither, and no edit touching a narrowing cast).

Battery green; self-audit and :release-checks green (605 s).

…eclaration demands and which set a width nothing asks for (#2522)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant