Skip to content

std: the unchecked helpers are unsafe fn; std acknowledges the risk at each call (D100, #2208) - #2237

Merged
ehartford merged 1 commit into
regex-stmtfrom
std-unsafe-helpers
Oct 7, 2026
Merged

ehartford merged 1 commit into
regex-stmtfrom
std-unsafe-helpers

Conversation

@ehartford

@ehartford ehartford commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Spec v7.27 (D100): an unchecked helper is also an unsafe fn. sorted_vec.slot_at, hash_index.find, trie's lookup/prefix_node/trie_key_bytes, json_skip, sys's _read_pass/_write_pass, Aes128.new, AesGcm.new, HmacSha256.new, hmac_sha256 and regex.w's raw-code helpers are unsafe fn; every std caller not already in an unsafe context wraps the call. Found on the way: with check of a module says ok over a bare unsafe call inside an uninstantiated generic body (#2235).

Fixes #2208. Draft until the stack's battery is green.

…sk at each call (D100, #2208)

Spec v7.27 (D100): "an unchecked helper should also be an unsafe fn, so
even code inside std has to acknowledge the risk when calling it". The
helpers whose safety rests on what the caller passes — a raw pointer, a
length, an unchecked index — are now `unsafe fn`: sorted_vec.slot_at,
hash_index.find, trie's lookup/prefix_node/trie_key_bytes, json_skip,
sys's _read_pass/_write_pass, Aes128.new, AesGcm.new, HmacSha256.new,
hmac_sha256, and regex.w's helpers over a raw pcre2 code pointer. Every
std caller that was not already inside an unsafe context wraps the call in
`unsafe { }` (json, sys, gcm, the Regex methods, which vouch for the code
pointer they own). Drop/deref impls that encapsulate their unsafe are
untouched.
@ehartford
ehartford added this pull request to stack #2238 October 7, 2026 02:43
@ehartford ehartford changed the title std unsafe helpers std: the unchecked helpers are unsafe fn; std acknowledges the risk at each call (D100, #2208) Oct 7, 2026
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery GREEN on stack top dd1c22f (seed-driven): gate rc=0 555s, uat rc=0 26s, battery-checks rc=0 823s.

@ehartford
ehartford marked this pull request as ready for review October 7, 2026 03:12
@ehartford
ehartford merged commit 0ede1d0 into main Oct 7, 2026
@ehartford
ehartford deleted the std-unsafe-helpers branch October 7, 2026 03:12
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.

D100: std's unchecked helpers become unsafe fn

1 participant