Repository navigation
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
Conversation
…range bounds that never meet a narrower demand keep the length's own width (#2522)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 madei32by 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
i32later, 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: mostlyfor 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 beingi32. The remaining work on #2522 is that width decision (#666's ground), not a cast sweep.The lexical census agrees (
len-castin 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).