parse: enforce strict-package — reject package-less files (#24a)

Flip the soft-default to a hard "missing package clause" error symmetrically in
both stages (cmd/wcc/parse.c + lib/ww/syntax/parse.ww): the first real decl of a
primary section with empty pathmod/resetmod and no seen clause is now rejected.
Closes the documented soft-default divergence (the 63-wrapper carve-out).

The gate flip can't be split from the migration it breaks, so this is one atomic
commit: ~80 test/wcc wrappers gain `package main;` via a shared wwtestpkg.h
helper, 6 data fixtures plus 17 asm-grep assertions update for the bare->main.<leaf>
root-helper mangle shift, and rt/ declares `package rt;` with @symbol pinning the
bare rt_ensure/rt_malloc linker names.

Root mangling narrows: the executable entry `main` stays bare (existing
carve-out), but root helper symbols become main.X. The #84 cluster is rewritten
to assert main.run distinct from aa.run/test.run; its cgen fix and bare machinery
are retained — still load-bearing for package-less module-reset deps. New
table-driven test 782_strict_package.c (6 rows, both stages).

Retiring //ww:module-reset is deferred to #24b: it is load-bearing (clears the
.wwi pathmod so the body's package clause asserts), not a vestige; fusing its
removal here would be a silent mismatch.

All byte-id gates green; full make test reports "all 335 tests passed".
This commit is contained in:
2026-06-29 03:55:26 +09:00
parent d34c90d932
commit 7b9488706b
95 changed files with 579 additions and 223 deletions

View File

@@ -60,6 +60,7 @@
#include <unistd.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include "wwtestpkg.h"
static int
runwait(const char *cmd)
@@ -99,7 +100,7 @@ static const struct row rows[] = {
" return 0;\n"
"};\n",
NULL, NULL,
"LEAQ\tadd1(SB)",
"LEAQ\tmain.add1(SB)",
STAGE_CS | STAGE_WW },
{ "branched_callee",
"fn aa(x: i32) i32 = { return x; };\n"
@@ -111,7 +112,7 @@ static const struct row rows[] = {
" return 0;\n"
"};\n",
NULL, NULL,
"LEAQ\tbb(SB)",
"LEAQ\tmain.bb(SB)",
STAGE_CS | STAGE_WW },
{ "alias_chain",
"fn add1(x: i32) i32 = { return x + 1; };\n"
@@ -121,7 +122,7 @@ static const struct row rows[] = {
" return 0;\n"
"};\n",
NULL, NULL,
"LEAQ\tadd1(SB)",
"LEAQ\tmain.add1(SB)",
STAGE_CS | STAGE_WW },
{ "fn_with_args",
"fn many(a: i32, b: i64, p: *i32) i64 = { return b; };\n"
@@ -130,7 +131,7 @@ static const struct row rows[] = {
" return 0;\n"
"};\n",
NULL, NULL,
"LEAQ\tmany(SB)",
"LEAQ\tmain.many(SB)",
STAGE_CS | STAGE_WW },
{ "fn_tuple_return",
"fn pair() (i64, str) = { return (7: i64, \"x\"); };\n"
@@ -139,7 +140,7 @@ static const struct row rows[] = {
" return 0;\n"
"};\n",
NULL, NULL,
"LEAQ\tpair(SB)",
"LEAQ\tmain.pair(SB)",
STAGE_CS | STAGE_WW },
/* Cross-mod: cstage emits the LEAQ via N_DOT TK_AMP (already
* working pre-#180). Wwstage bails asserttyped on the same
@@ -156,6 +157,7 @@ static const struct row rows[] = {
" return 0;\n"
"};\n",
"wcamffn764mod",
"package wcamffn764mod;\n"
"export fn somefn(x: i32) i32 = { return x + 1; };\n",
"LEAQ\twcamffn764mod.somefn(SB)",
STAGE_CS },
@@ -181,13 +183,13 @@ write_sources(const struct row *r, char *src, size_t srcsz,
mkdir(moddir, 0755);
FILE *mf = fopen(modfile, "wb");
if (!mf) return -1;
fputs(r->modsrc, mf);
wwtest_fputs(r->modsrc, mf);
fclose(mf);
}
FILE *f = fopen(src, "wb");
if (!f) return -1;
fputs(r->src, f);
wwtest_fputs(r->src, f);
fclose(f);
return 0;
}