wcc+ww: //ww:module-reset boundary directive; package-less files keep module "" (#16 PREP-main)

Driver twins emit the line-comment directive only before package-less
files (peekpackage==nil); both lexers tokenize it (TK_MODRESET, appended
=87 so existing token values hold) and both parsers reset curmod — a
package-less file's decls get module "" instead of inheriting the last
bundled package (the sticky-curmod leak, task #11). Withdrawn
alternative: injecting 'package main' flips non-entry symbols
bare->main-prefixed (FFI-visible, broke 764). Codegen-neutral by proof:
bare symbols preserved, both stages emit byte-identical asm for a
directive-bearing combined. Transitional until strict-package rejects
package-less files outright. Includes 737 bad-deep pin for the
PREP-peek >2048 edge + 904/toktest rows for the new token.
This commit is contained in:
2026-06-10 14:07:35 +09:00
parent 2227d698c6
commit 49a5173f3f
17 changed files with 358 additions and 22 deletions

View File

@@ -3315,6 +3315,19 @@ fn expand(c: *expctx, pathcs: *u8) void = {
i = j + 1u64;
};
// #16 option-B: a package-less file's decls would otherwise inherit
// the preceding bundled module's sticky curmod (parser parse.ww). Emit
// a curmod-reset boundary directive so the lexer/parser attribute the
// file to the primary module ("") — fixes the self-import false-fire
// and the leaked-prefix bug, codegen-neutral (bare symbols kept; not
// `package main`, which would main-prefix them). A packaged file's own
// `package` decl already sets curmod, so it needs nothing — keeping
// the directive out of every tracked combined.ww. (Task #11.)
if (peekpackage(pathcs) == nil) {
let d: str = "//ww:module-reset\n";
os.writeall(c.out, d.ptr, d.len: u64);
};
os.writeall(c.out, bufp, blen);
os.writeall(c.out, "\n".ptr, 1u64);
};

View File

@@ -529,6 +529,19 @@ fn expand(c: *expctx, pathcs: *u8) void = {
i = j + 1u64;
};
// #16 option-B: a package-less file's decls would otherwise inherit
// the preceding bundled module's sticky curmod (parser parse.ww). Emit
// a curmod-reset boundary directive so the lexer/parser attribute the
// file to the primary module ("") — fixes the self-import false-fire
// and the leaked-prefix bug, codegen-neutral (bare symbols kept; not
// `package main`, which would main-prefix them). A packaged file's own
// `package` decl already sets curmod, so it needs nothing — keeping
// the directive out of every tracked combined.ww. (Task #11.)
if (peekpackage(pathcs) == nil) {
let d: str = "//ww:module-reset\n";
os.writeall(c.out, d.ptr, d.len: u64);
};
os.writeall(c.out, bufp, blen);
os.writeall(c.out, "\n".ptr, 1u64);
};