Skip to content

len() family returns isize (pointer-width, signed): Sema sizes isize/usize per target (32 on wasm32); lib/std and rt flip the declarations #2262

Closed

Description

@ehartford

Ruling (Eric, 2026-10-07): len(), count() and position() return isize, the signed pointer-width integer; usize/isize are pointer-width, 32 bits on wasm32. D11 ruled signedness only; the width was unruled and the C-interop argument decided it: a len() meeting a size_t is a sign change on every target and nothing more. The spec lands first; the compiler is NON-COMPLIANT until this is done.

Implementation:

  1. Sema: ty_isize/ty_usize are registered at 64 bits regardless of target (src/Sema.w:3899-3901, "64-bit on arm64"); TypeLayout already sizes them by target_spec_ptr_bytes. Sema's width must follow the target (32 on wasm32) so widening and narrowing rules (§4.2.6) are right there: today let c: isize = b with b: i64 is accepted implicitly, which on wasm32 is a silent narrowing.
  2. lib/std and rt: the six fn len() -> i64 declarations and the iterator count()/position() family return isize; len64() stays an alias of len() widened.
  3. On every 64-bit target the change is a type name (isize and i64 interconvert implicitly today, probed 2026-10-07). On wasm32 the runtime's length fields narrow; std.regex and std.zlib on wasm32: build the bundles for the target, link the target's bundle, carry them in the release #2131's wasm32 suites are the proof.
  4. Separate mechanical sweep, not this issue: the 5223 .len() as i32 sites across src, build, lib/std and tools are legacy cast ceremony (a loop over 0..v.len() indexes directly).

Follow-on: #2261 (length param N facade clause for the sign change at the C boundary).

Activity

  1. ehartford commented on Oct 7, 2026

    @ehartford
    ContributorAuthor

    Spec landed: PR #2263 (D108, spec v7.28). This issue is the implementation.

  2. ehartford commented on Oct 11, 2026

    @ehartford
    ContributorAuthor

    Items 1–3 are on main through #2327 (verified 2026-10-11 by running the compiler: Sema sizes isize by target_spec_size_bytes, wasm32 refuses the i64 → isize narrowing, every std len() is -> isize, count/position too). Item 4, the mechanical sweep, is PR #2346 on stack #2347: 5339 sites stripped, 803 casts remain at genuine i32 demands, gate green. The wasm32 proof stays with #2131.

  3. added a commit that references this issue on Oct 11, 2026
  4. ehartford commented on Oct 13, 2026

    @ehartford
    ContributorAuthor

    Close-out verified 2026-10-13 on the installed compiler (main 5c31bf1): Sema registers isize/usize at the target's pointer width (src/Sema.w:4093-4094, size_bits) — the issue's own example now behaves: let c: isize = b with b: i64 under --target wasm32-wasi errors 'implicit integer narrowing or sign change from i64 to isize (§4.2.6)' instead of silently narrowing. lib/std's len() declarations return isize and no fn len() -> i64 remains in lib/ or rt/. What is left is the wasm32 width proof itself, tracked by #2131; the .len() as i32 sweep was always separate (item 4).

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