lib/ww/lex + selfhost/cmd: astrndup → strings.dup view (γ-1)

#7 Phase A first cut. 13 of 15 astrndup callers converted to the
explicit (*u8, n) → str view + strings.dup shape (ref/hare/strings/
dup.ha:7). astrndup export stays in selfhost/cmd/wcc/mem.ww — 2 w6a
sites blocked by the selfhost/cmd/w6a/types.ww shadow (filed as #11)
and carry an inline WHY pointer until the rename ships.

NUL-dependence audit: no consumer reads token text past `.len`. tok.text
flows through fputq (length-bounded) and parse.curtext → n.str (streq-
based dispatch across check/cgenutil); p.file is written via os.write
(ptr,len); selfhost/cmd/ww/main.ww's astrndup'd pathstr only flows into
visitseen/visitadd's manual byte-loop, while all OS calls in that file
use the unrelated `pathstr(*u8) str` view helper on the raw pointer.

Empty-str sites (lex.ww:579, 624, 640) collapse to strings.dup of an
empty view; strings.dup short-circuits len==0 (lib/strings/strings.ww:72)
and returns {nil, 0} — observationally identical to astrndup's prior
{arena_1byte, 0}.

Sites:
 - lib/ww/lex/lex.ww (8: 450, 529, 554, 564, 579, 624, 640, 794)
 - selfhost/cmd/w6c/main.ww:139
 - selfhost/cmd/w6l/dyn.ww:111 (inside dcstrtostr)
 - selfhost/cmd/w6l/obj.ww:185 (inside cstrtostr)
 - selfhost/cmd/ww/main.ww:531

Wrappers (dupstr/cstrtostr/dcstrtostr) keep their bodies; deletion
deferred to #10.
This commit is contained in:
2026-05-21 10:41:54 +09:00
parent fd7dee985e
commit 917d6250fc
12 changed files with 4005 additions and 32 deletions

View File

@@ -1331,6 +1331,7 @@ fn perr(a: *asm_, msg: str) void = {
};
// dupstr — copy n bytes from p into a fresh heap str.
// astrndup until #11 (w6a types shadow) is fixed.
fn dupstr(a: *arena, p: *u8, n: u64) str = {
return astrndup(a, p, n);
};
@@ -3120,6 +3121,7 @@ export fn main(argc: i32, argv: **u8) i32 = {
let ar: *arena = newarena();
let s: asm_;
let nlen: u64 = cstrlen(src);
// astrndup until #11 (w6a types shadow) is fixed.
let fname: str = astrndup(ar, src, nlen);
init(&s, ar, fname, buf, blen);