Skip to content

31 length casts in the compiler stop being conversions: bindings and range bounds that never meet a narrower demand keep the length's own width (#2522) - #3574

Merged
ehartford merged 1 commit into
mainfrom
len-casts-undemanded
Nov 23, 2026
Merged

ehartford merged 1 commit into
mainfrom
len-casts-undemanded

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Part of #2522 (step two, first half).

#3571's report found 361 narrowing casts of a length in src/ that nothing demands: a plain binding or a range bound made i32 by the cast alone. D183 says such a site should stop being a conversion.

This removes the ones that can go with no other change. How they were chosen: every undemanded cast was removed, the compiler's source was checked, and each cast was put back wherever the compiler then objected (its binding or loop variable meets an i32 later, as an error or as the D183 lint) until the source checked clean again, with no warning at all, under both the installed compiler and the pinned seed. 31 remain removed, in 16 files: mostly for i in 0..xs.len(): loops and a few bindings.

No semantics change: each of these values is now the length's own width from start to finish, and no range check was added anywhere (the lint would have said so).

What this measured about the rest. Of the 621 length casts, 590 exist because something downstream is declared i32: 260 demanded directly by a declaration and 330 whose binding or loop variable meets one later. Nearly all trace to node, symbol and type ids being i32. The remaining work on #2522 is that width decision (#666's ground), not a cast sweep.

The lexical census agrees (len-cast in src 466 -> 435 in the changed files); the typed census is unchanged. Battery green (488 s); self-audit and :release-checks, fixpoint included, green (582 s).

…range bounds that never meet a narrower demand keep the length's own width (#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