selfhost/cmd/ww/main.ww: 3× ".\0" amalloc → stack [2]u8

dobuild/dorun/dotest each allocated a 2-byte heap "." prefix buffer via
amalloc, set dot[0]='.'; dot[1]=0; passed dot as *u8 to a callee, then
let the arena chunk live forever. The dot pointer never escapes the
function — every callee chain (resolvemodule, cstrendswithlit,
rundirtests/runsingletest) byte-copies its input into a fresh arena
allocation before returning, never storing the original pointer.

Replace with `let dot: [2]u8 = ['.': u8, 0u8]; ... &dot[0]`. Both
stages allocate a fresh frame slot per let at function-frame entry
(localoff cstage / localadd wwstage), so the slot lives across the
synchronous callee.

Verified 132/132 + 995_self_rebuild byte-identity.
This commit is contained in:
2026-05-20 19:28:59 +09:00
parent b060822bd8
commit a1ee817906
2 changed files with 12 additions and 18 deletions

View File

@@ -2038,9 +2038,8 @@ fn dobuild(selfdir: *u8, argv: **u8, argc: i32, start: i32) i32 = {
if (src == nil) {
// default to cwd module
let dot: *u8 = amalloc(a, 2u64): *u8;
dot[0] = 46u8; dot[1] = 0u8;
src = dot;
let dot: [2]u8 = ['.': u8, 0u8];
src = &dot[0];
};
let isdir: i32 = 0;
let resolved: *u8 = resolvemodule(a, selfdir, src, incs, &isdir);
@@ -2193,9 +2192,8 @@ fn dorun(selfdir: *u8, argv: **u8, argc: i32, start: i32) i32 = {
};
if (src == nil) {
let dot: *u8 = amalloc(a, 2u64): *u8;
dot[0] = 46u8; dot[1] = 0u8;
src = dot;
let dot: [2]u8 = ['.': u8, 0u8];
src = &dot[0];
};
let isdir: i32 = 0;
let resolved: *u8 = resolvemodule(a, selfdir, src, incs, &isdir);
@@ -2331,9 +2329,8 @@ fn dotest(selfdir: *u8, argv: **u8, argc: i32, start: i32) i32 = {
let a: *arena = newarena();
let target: *u8;
if (start >= argc) {
let dot: *u8 = amalloc(a, 2u64): *u8;
dot[0] = 46u8; dot[1] = 0u8;
target = dot;
let dot: [2]u8 = ['.': u8, 0u8];
target = &dot[0];
} else {
target = argv[start];
};

View File

@@ -1178,9 +1178,8 @@ fn dobuild(selfdir: *u8, argv: **u8, argc: i32, start: i32) i32 = {
if (src == nil) {
// default to cwd module
let dot: *u8 = amalloc(a, 2u64): *u8;
dot[0] = 46u8; dot[1] = 0u8;
src = dot;
let dot: [2]u8 = ['.': u8, 0u8];
src = &dot[0];
};
let isdir: i32 = 0;
let resolved: *u8 = resolvemodule(a, selfdir, src, incs, &isdir);
@@ -1333,9 +1332,8 @@ fn dorun(selfdir: *u8, argv: **u8, argc: i32, start: i32) i32 = {
};
if (src == nil) {
let dot: *u8 = amalloc(a, 2u64): *u8;
dot[0] = 46u8; dot[1] = 0u8;
src = dot;
let dot: [2]u8 = ['.': u8, 0u8];
src = &dot[0];
};
let isdir: i32 = 0;
let resolved: *u8 = resolvemodule(a, selfdir, src, incs, &isdir);
@@ -1471,9 +1469,8 @@ fn dotest(selfdir: *u8, argv: **u8, argc: i32, start: i32) i32 = {
let a: *arena = newarena();
let target: *u8;
if (start >= argc) {
let dot: *u8 = amalloc(a, 2u64): *u8;
dot[0] = 46u8; dot[1] = 0u8;
target = dot;
let dot: [2]u8 = ['.': u8, 0u8];
target = &dot[0];
} else {
target = argv[start];
};