build: pass direct exports to package compilers

This commit is contained in:
2026-08-12 18:42:22 +09:00
parent b373c445bd
commit edd3f4ee83
13 changed files with 678 additions and 611 deletions

View File

@@ -8,7 +8,8 @@ package wwi_test;
// 10): the `w6c -I <out.wwi>` producer IS the live import path, and
// `.wwi` is a cross-stage byte-id substrate pinned directly. POSITIVE:
// for ascii/strings/getopt (drew2-audited leak-free), drive the target
// as the PRIMARY module of a driver-combined unit, then (1) w6c -c -I and
// as the PRIMARY owner-only driver unit with separate direct exports, then
// (1) w6c -c -I and
// w6c_ww -c -I both succeed, (2) cs.wwi == ww.wwi byte-for-byte, (3) the
// emitted .wwi re-parses (wwdump -a exit 0). getopt is the recursion
// stressor. A synth fixture covers the decl-kinds + type-nodes no lib
@@ -28,10 +29,10 @@ package wwi_test;
// producer->importer flow on BOTH stages: (a) the dep `.wwi` package
// line equals the real leaf, (b) the dep `.wwi` is byte-identical
// across stages, (c) a root importing the dep RESOLVES on both stages
// and the two importer `.s` are byte-identical. The composed units are
// fed straight to w6c / w6c_ww (not `ww build`): the producer-unit
// shape `//ww:module-reset <path>` + body is exactly what the driver's
// sep_emit_body emits.
// and the two importer `.s` are byte-identical. The owner units and
// separate exports are fed straight to w6c / w6c_ww (not `ww build`):
// the producer-unit shape `//ww:module-reset <path>` + body is exactly
// what the driver's sep_emit_body emits.
import os;
import os.exec;
@@ -88,18 +89,40 @@ fn m2positive(pkg: str) void = {
let co: testenv.commandout;
testenv.runcommand(td, td, "drv", av, lifetime(), &co);
let comb: str = strings.concat(td, "/", pkg,
".sepwork/__root.unit.ww");
let work: str = strings.concat(td, "/", pkg, ".sepwork/");
let comb: str = strings.concat(work, "__root.unit.ww");
if (!testenv.exists(comb)) { fail(pkg, "no resolved unit"); };
let cs: str = strings.concat(td, "/cs.wwi");
let ws: str = strings.concat(td, "/ww.wwi");
// The driver-composed unit uses package separators and may contain the
// same compiler-owned origin fact through multiple direct interfaces;
// exact fact interning is intentionally tied to -c package mode.
let cav: []str = [testenv.driver("w6c"), "-c", "-I", cs, comb];
let deps: []str = [];
if (testenv.same(pkg, "ascii")) { append(deps, "strings"); };
if (testenv.same(pkg, "strings")) {
append(deps, "bytes"); append(deps, "encoding.utf8");
append(deps, "os"); append(deps, "types");
};
if (testenv.same(pkg, "getopt")) {
append(deps, "encoding.utf8"); append(deps, "fmt");
append(deps, "io"); append(deps, "os"); append(deps, "strings");
};
if (deps.len == 0) { abort("unknown m2 package"); };
let cav: []str = [testenv.driver("w6c"), "-c"];
let di: i32 = 0;
for (di < deps.len) {
append(cav, "--import"); append(cav, deps[di]);
append(cav, strings.concat(work, deps[di], ".wwi"));
di += 1;
};
append(cav, "-I"); append(cav, cs); append(cav, comb);
if (!runok(td, "w6c", cav)) { fail(pkg, "w6c -c -I rejected"); };
let wav: []str = [testenv.driver("w6c_ww"), "-c", "-I", ws, comb];
let wav: []str = [testenv.driver("w6c_ww"), "-c"];
di = 0;
for (di < deps.len) {
append(wav, "--import"); append(wav, deps[di]);
append(wav, strings.concat(work, deps[di], ".wwi"));
di += 1;
};
append(wav, "-I"); append(wav, ws); append(wav, comb);
if (!runok(td, "w6c_ww", wav)) { fail(pkg, "w6c_ww -c -I rejected"); };
if (!testenv.same(testenv.readfile(cs), testenv.readfile(ws))) {
@@ -318,22 +341,21 @@ fn leafrow(tag: str, path: str, leaf: str, body: str, want: str) void = {
fail(tag, "w6c vs w6c_ww .wwi differ (rule 10)");
};
// Leg c — a root importing the dep RESOLVES on both stages
// (pre-fix: "package main does not match import path" REJECT). The
// dep `.wwi` is prepended under //ww:module <path>, exactly as the
// driver composes an importer unit.
// Leg c — a root importing the dep RESOLVES from a separate export on
// both stages (pre-fix: "package main does not match import path"
// REJECT).
testenv.writefile(root, strings.concat(
"//ww:module ", path, "\n",
testenv.readfile(cswwi), "\n",
"//ww:module-reset\n",
"package main;\n",
"import ", path, ";\n",
"export fn main() i32 = { return 42; };\n"));
let rcav: []str = [testenv.driver("w6c"), "-c", "-o", rcss, root];
let rcav: []str = [testenv.driver("w6c"), "-c", "--import", path,
cswwi, "-o", rcss, root];
if (!runok(td, "csroot", rcav)) {
fail(tag, "w6c rejected the import (BUG-C)");
};
let rwav: []str = [testenv.driver("w6c_ww"), "-c", "-o", rwws, root];
let rwav: []str = [testenv.driver("w6c_ww"), "-c", "--import", path,
wwwwi, "-o", rwws, root];
if (!runok(td, "wsroot", rwav)) {
fail(tag, "w6c_ww rejected the import (BUG-C)");
};