compiler: make package exports self-contained

This commit is contained in:
2026-08-12 01:12:42 +09:00
parent 52f6d6f0d4
commit 9b970eb16a
10 changed files with 965 additions and 82 deletions

View File

@@ -8,8 +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 -I and
// w6c_ww -I both succeed, (2) cs.wwi == ww.wwi byte-for-byte, (3) the
// as the PRIMARY module of a driver-combined unit, 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
// package reaches (def const-expr fold, let global, [N]T, fn-ptr, !T,
@@ -94,10 +94,13 @@ fn m2positive(pkg: str) void = {
let cs: str = strings.concat(td, "/cs.wwi");
let ws: str = strings.concat(td, "/ww.wwi");
let cav: []str = [testenv.driver("w6c"), "-I", cs, comb];
if (!runok(td, "w6c", cav)) { fail(pkg, "w6c -I rejected"); };
let wav: []str = [testenv.driver("w6c_ww"), "-I", ws, comb];
if (!runok(td, "w6c_ww", wav)) { fail(pkg, "w6c_ww -I rejected"); };
// 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];
if (!runok(td, "w6c", cav)) { fail(pkg, "w6c -c -I rejected"); };
let wav: []str = [testenv.driver("w6c_ww"), "-c", "-I", ws, comb];
if (!runok(td, "w6c_ww", wav)) { fail(pkg, "w6c_ww -c -I rejected"); };
if (!testenv.same(testenv.readfile(cs), testenv.readfile(ws))) {
fail(pkg, "cs.wwi != ww.wwi (byte-id broken on the .wwi substrate)");
@@ -125,7 +128,8 @@ fn m2positive(pkg: str) void = {
let td: str = testenv.fresh();
let src: str = strings.concat(
"package synth;\n",
"export type color = enum { RED, GREEN = 5, BLUE };\n",
"def GREEN: i32 = 99;\n",
"export type color = enum { RED, GREEN = 5, BLUE = GREEN + 1 };\n",
"export def LIMIT: i32 = 10 + 2 * 3;\n",
"export def NAME: str = \"hi\\n\";\n",
"export def FLAG: bool = true;\n",
@@ -154,8 +158,15 @@ fn m2positive(pkg: str) void = {
"cs.wwi != ww.wwi (const-expr / decl-kind unparse diverges)");
};
if (!testenv.has(testenv.readfile(cs),
"export let grouped: [((1 + 2) * 3)]u8;")) {
fail("synth", ".wwi changed grouped array-dimension semantics");
"export let grouped: [9]u8;")
|| !testenv.has(testenv.readfile(cs),
"export fn matrix() [16]u8;")) {
fail("synth", ".wwi did not canonicalize checked array dimensions");
};
if (!testenv.has(testenv.readfile(cs),
"export type color = enum { RED, GREEN = 5, BLUE = (GREEN + 1) };")
|| testenv.has(testenv.readfile(cs), "def GREEN: i32 = 99")) {
fail("synth", ".wwi confused an enum sibling with a package def");
};
// #47: the @symbol attribute must survive the round-trip verbatim.
if (!testenv.has(testenv.readfile(cs),
@@ -195,10 +206,14 @@ fn m2positive(pkg: str) void = {
if (!testenv.same(testenv.readfile(cs), testenv.readfile(ws))) {
fail("qualified", "cs.wwi != ww.wwi");
};
if (!testenv.has(testenv.readfile(cs),
"export fn use(x: dep.Clash) i32;")) {
let body: str = testenv.readfile(cs);
if (!testenv.has(body, "export fn use(x: dep.Clash) i32;")) {
fail("qualified", ".wwi dropped the qualified signature");
};
if (!testenv.has(body, "//ww:module a.dep\n")
|| !testenv.has(body, "export type Clash = struct { x: i32 };")) {
fail("qualified", ".wwi omitted the signature's origin-owned type fact");
};
let dav: []str = [testenv.driver("wwdump"), "-a", cs];
if (!runok(td, "wwdump", dav)) {
fail("qualified", "emitted .wwi does not re-parse");