Skip to content

The pinned seed predates D183: len() into an i32 parameter still needs as i32 in src/ (807 sites); goes with the next seed #3073

Closed

Description

@ehartford

D183 made an isize narrow into an i32 demand with a range check, so f(xs.len()) for f(n: i32) needs no cast in a program the installed compiler builds. src/ is compiled by the pinned seed (seed.lock), which predates D183, so the gate refuses the castless spelling there:

error: implicit integer narrowing or sign change from `isize` to `i32` (argument 3 of `ensure_generic_inst_type`); use an explicit `as` cast (§4.2.6)

807 .len() as i32 sites in src/ carry the cast for the seed alone (the census counts them as len-cast). Two more were added in #3069 with a comment naming this.

Done when: a post-D183 seed is pinned (tools/bump_seed_pins.w, with build :seed), then a with fix-ceremony pass (#3061, the widening-cast pass extended to the narrowing-with-range-check case) removes every .len() as i32 whose target is an i32 demand, as one PR, and the len-cast census count falls by that many.

Activity

  1. ehartford commented on Nov 8, 2026

    @ehartford
    ContributorAuthor

    The first src/ sweep (fix-ceremony-5) ran with --check-with src/main, so the pinned seed gated every rewrite. 242 stayed as written because the seed predates the rule that admits them; they are this issue's work once a post-D197 seed is pinned, together with the 807 len() as i32:

    kept as written count rule the seed lacks
    .clone() on a str 165 D111 (a str is a value; the seed's move checker still sees a move)
    (k as u32) at a shift count 69 D197
    : str annotation restating the initializer 4 D111 (the seed binds the copy as a view)
    Some(x) under an Option demand 2 the #3062 fix in the same stack
    as u64 widening 1 D183's range-checked conversion

    Recipe after the seed bump: with fix-ceremony --apply --check-with src/main src/main.w again; the tool reports whatever the new seed still refuses.

  2. ehartford commented on Nov 8, 2026

    @ehartford
    ContributorAuthor

    Progress under the new seed (nightly-20261110-local-1): the 242 kept rewrites are applied in the seed-bound sweep PR (330 rewrites in 31 files, nothing kept as written, the seed checks the result).

    The 807 len() as i32 are a different matter. The cast is not what the seed refused any more: dropping one is admitted by D183 and lowers to the range-checked conversion, but it also raises D183's lint, "isize narrows to i32 with a range check: widen the i32 declaration it flows into", at every site. That lint is deliberate (D183: it names the declaration whose width is wrong, never the use), so the right removal is the one it asks for: the i32 parameters and fields that receive a length or an index widen to isize (D108, D114), and the casts fall away with no lint. That is a declaration sweep over the compiler's own signatures, not a rewrite of the uses; it stays on this issue as the remaining work, and len-cast stays in the census at 819 until it lands.

  3. ehartford commented on Nov 8, 2026

    @ehartford
    ContributorAuthor

    The 242 seed-bound rewrites landed in #3082. What remains here is the 807 len() as i32, which is a declaration-widening sweep (the i32 parameters and fields that receive a length or index become isize), not a cast removal: see the comment above.

  4. ehartford commented on Nov 8, 2026

    @ehartford
    ContributorAuthor

    Shape of the declaration sweep, measured on a tree at the #3091 stack top with every .len() as i32 in src/ stripped (758 sites in 56 files; the census's 819 includes spaced spellings) and with check src/main.w under the installed post-D183 compiler:

    • 990 D183 lints, 26 hard errors.
    • 642 lints name a call target ((argument N of f)), across 230 distinct declarations; 348 name none (a let annotation, a field store, an index, a comparison). Top targets: comptime_value_list arg 3, add_type arg 3, pairs_list_i32 arg 1 (9 each), wl_struct_set_body arg 3 (8), add_sig arg 4, wl_function_type arg 3 (7), wl_struct_type arg 3 (6), then a long tail of 1–5.
    • The 26 errors are the uses that change type when the cast goes: HashMap.contains/Memo.contains/HashMap.get with an isize probe against an i32 key (no conversion on a probe) and if arms joining isize with i32 (§4.2.6 refuses the implicit join).

    Two floors the sweep stops at, where the cast is a real narrowing and stays:

    1. the C bridge (wl_*, clang_*): unsigned/int parameters are the ABI; D114 says a value crossing into C is fixed width;
    2. values stored into an i32 table (type_extra, sema_type_d1, extra_values, the MIR arrays): the element type is a layout choice, and widening it doubles the compiler's largest tables.

    Everything else — an i32 parameter or field that receives a length or index and is only compared, iterated or indexed with — widens to isize (D108, D114), and its casts fall away. The work is the classification of the 230 (plus the 348 no-note sites by their binding), one PR per area so a battery can bisect. Not started yet; the stripped tree is ~/.local/with-staging/i3073 (uncommitted).

  5. ehartford commented on Nov 8, 2026

    @ehartford
    ContributorAuthor

    The declaration sweep is done on branch i3073 (one commit, 39 files, 410 lines): gate running, battery next.

    Method, so it can be rerun: strip every .len() as i32 in src/ (758), let D183's lint name the declaration each narrowing flows into, and iterate three tools to a fixpoint — widen a named i32 parameter to isize unless it is the C bridge or a table store (add_node, add_extra, add_type, add_sig, comptime_value_*, pack_*, new_rvalue); put the cast back at a value's binding when the lint's target is a store into an i32 list/map/array, a table-id return, or a C call; widen a var x: i32 or a field f: i32 the lint points at. Then revert any widened parameter whose body still lints (an id, not a position) and cast at its callers. Returns were the trap: widening 77 -> i32 returns cascaded to 1204 lints, because those are table ids by construction; returns stay i32.

    Result: about a hundred parameters, six variables and seven fields widened; with check src/main.w clean (0 lints, 0 errors). The census's len-cast in src falls 784 → 617. What remains is the floor — a value stored into an AST/type/MIR/comptime table or crossing into C — where the cast is the narrowing it says it is. The issue's "done when" was "every .len() as i32 whose target is an i32 demand"; that set is exactly the floor, so the sweep closes this issue with the floor documented rather than cast-free.

  6. added a commit that references this issue on Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions