You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Facade clause length param N: a count parameter takes a non-negative isize without a spelled cast (D51-shaped) #2261
Follow-on to the len() width ruling (2026-10-07: len() and the length family return isize, the signed pointer-width integer). The remaining friction at the modeled-C boundary is the sign change: a len() into a size_t parameter needs a spelled cast under §4.2.6 on every target. Proposal, same tier and shape as nullable param N (D102): a facade fn item may state length param N, asserting the parameter is a count; a non-negative isize then passes without a cast and a negative one is refused (a panic at the call, the compiler finishing its own sentence at run time, as the dynamic-size ruling in docs/proposals/vx.md Part IX does). Inference never grants it (Law 4: wrong would create unsafety at the C boundary); it comes from the clause or an adopted convention profile. Not ruled; this files it.
Triage 2026-10-25, with v0.15.3.0 (main a261b65): reproduced, and the next step is a ruling (C interop, D51).
$ cat main.w
use c_import("string.h")
fn main:
let s = "hello"
let n = strnlen(c"hello".ptr, s.len())
print(n)
$ with run main.w
error: implicit integer narrowing or sign change from `isize` to `u64` (argument 2 of `strnlen`); use an explicit `as` cast (§4.2.6)
What the rulings say. D108 names this follow-on: "a length param N facade clause for the sign change at the C boundary, the shape of D102's nullable param N". The spec has no such clause. D51's test applies: "what happens if this inference is wrong?"
The question. Should a facade fn item be able to state length param N, so that a non-negative isize passes to that size_t parameter without a cast and a negative one panics at the call? The alternatives are to keep the as cast at every such call, or to derive the count from a paired buffer the way D64 buffer pairing already does for slices.
Ruled, 2026-11-18: rule A, widened. The D183 warning is not issued when the declaration on the other side of the conversion was imported from C (a parameter, a return value, a record field, a global); the range check stays in every case. D108's length param N follow-on is not needed: D183 made the conversion checked everywhere, so a per-parameter clause would restate what the type already says. Closes with the change that implements it.
Activity
D108: length is pointer-width — len(), count() and position() return …
ehartford commentedon Oct 25, 2026
Triage 2026-10-25,
with v0.15.3.0(main a261b65): reproduced, and the next step is a ruling (C interop, D51).What the rulings say. D108 names this follow-on: "a
length param Nfacade clause for the sign change at the C boundary, the shape of D102'snullable param N". The spec has no such clause. D51's test applies: "what happens if this inference is wrong?"The question. Should a facade fn item be able to state
length param N, so that a non-negativeisizepasses to thatsize_tparameter without a cast and a negative one panics at the call? The alternatives are to keep theascast at every such call, or to derive the count from a paired buffer the way D64 buffer pairing already does for slices.ehartford commentedon Nov 18, 2026
Ruled, 2026-11-18: rule A, widened. The D183 warning is not issued when the declaration on the other side of the conversion was imported from C (a parameter, a return value, a record field, a global); the range check stays in every case. D108's
length param Nfollow-on is not needed: D183 made the conversion checked everywhere, so a per-parameter clause would restate what the type already says. Closes with the change that implements it.No narrowing warning where the other side of the conversion is a C de…