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

File diff suppressed because it is too large Load Diff

View File

@@ -16,6 +16,7 @@ package main;
import os;
import rt;
import mem;
import strings;
// All path/string scratch buffers go on the runtime page allocator.
// One page is plenty for any path we build.
@@ -528,7 +529,10 @@ fn scanuse(src: *u8, len: u64) (*u8, u64) = {
// decls).
fn expand(c: *expctx, pathcs: *u8) void = {
let plen: u64 = cstrlen(pathcs);
let pathstr: str = astrndup(c.a, pathcs, plen);
let view: str;
view.ptr = pathcs;
view.len = plen: i32;
let pathstr: str = strings.dup(view);
if (visitseen(c, pathstr)) { return; };
visitadd(c, pathstr);