wwi: derive decl-less module's .wwi package leaf from parse-stamped path (#11)

wwi_emit took the .wwi `package` leaf from the first primary decl's module tag;
a fully empty primary module body (zero decls) had none, so the leaf stayed the
literal default "main" and the importer rejected it ("package main does not
match import path <leaf>"). The module identity is only available at parse time
(curmod is overwritten by imported //ww:module sections before emit), so stamp
the primary path onto the N_FILE node (TK_MODULE and TK_MODRESET rp!=NULL sites,
only-if-empty so a bare-reset `package main` root stays "main") and, when the
decl-scan finds no leaf, fall back to that stamped path. Symmetric cstage+
selfhost; both detect scan-miss via the same found-flag so the emitted .wwi
stays byte-identical.

Regression: test/wcc/989_wwileaf_run.c, table-driven over {empty body,
comment-only, nested a.b.c} decl-less shapes, non-vacuity proven.
This commit is contained in:
2026-06-22 21:17:30 +09:00
parent a1484aef28
commit 6525e137ae
6 changed files with 352 additions and 4 deletions

View File

@@ -502,6 +502,7 @@ TESTS = $(BIN)/test_smoke $(BIN)/test_lex $(BIN)/test_parse $(BIN)/test_check \
$(BIN)/test_dyn_ww $(BIN)/test_selfcheck \
$(BIN)/test_attest_record $(BIN)/test_attest_drop \
$(BIN)/test_declns_sep $(BIN)/test_modresetadj_run \
$(BIN)/test_wwileaf_run \
$(BIN)/test_wwispread_sep \
$(BIN)/test_fmt_run $(BIN)/test_log_run $(BIN)/test_fnmatch_run \
$(BIN)/test_shlex_run $(BIN)/test_getenv_run $(BIN)/test_dirs_run \
@@ -2668,6 +2669,15 @@ $(BIN)/test_modresetadj_run: test/wcc/989_modresetadj_run.c \
$(LIB)/libwwrt.a | $(BIN)
$(CC) $(CFLAGS) -o $@ $<
# #11 (BUG-C) — a decl-less primary module's `.wwi` `package` line must carry
# the real leaf, not the default "main", else its importer rejects the dep.
# Table-driven over empty/comment-only/nested-path shapes; feeds the composed
# producer + importer units straight to w6c/w6c_ww (.wwi leaf + byte-id +
# import resolves cs==ww). Frontends only — no asm/link/run leg.
$(BIN)/test_wwileaf_run: test/wcc/989_wwileaf_run.c \
$(BIN)/w6c $(BIN)/w6c_ww | $(BIN)
$(CC) $(CFLAGS) -o $@ $<
# #95 — .wwi producer must preserve the `...` union-spread marker; dir-package
# `ww build --sep` + run, both driver stages, 2-arm + 3-arm shapes + cs==ww.
$(BIN)/test_wwispread_sep: test/wcc/989_wwispread_sep.c $(BIN)/ww $(BIN)/ww_ww \