wcc,ww: flip driver to separate-compilation only; delete build_one amalgamator (M4 E3-C1, #22)
build_one_sep (per-package compile + .wwi interfaces + link) becomes the sole build path. do_build/do_run/do_test and the ww twins all route through it; --sep is now an accepted no-op and the run-rejects-sep guard is removed. Deleted the single-file amalgamator, both stages: build_one, expand, expand_dir, peek_package (+ the wwstage twins + strictpkgmismatch). unit_has_package is retained -- the sep scan loop's inline-package check needs it. The sep-shared helpers (enumerate_dir_ww, locate_import*, import_path_form, ImportSet, and ww counterparts) stay; they back the surviving sep path. Restores missing-package enforcement under sep by construction: the sep scan loop loudly rejects an unresolvable import (cannot find package <name>) unless the package is defined inline in the same unit -- matching the deleted amalgamator and closing the silent-accept the flip would otherwise introduce. All 5 wwstage tools relink (each is built via the now-sep `ww build`); emitted asm is byte-identical to the combined build per bootstrap input, so the binary md5 delta is pure link layout, not codegen. selfhost/cmd/ww/main.combined.ww is now stale and unregenerable (its writer build_one is deleted); #90 deletes it next. Test retargets folded in (rule-11 carve-out, #61/#133 precedent): each asserts post-flip-only behavior, is un-pre-migratable unlike #93/#94/#103, and splitting reddens one side. Closes #97. - 989_slttypepref -> dir-package layout (xb imports xa so both same-leaf `invalid` types are in scope at xb.f); inline-multipackage was the amalgamator shape, deleted with the flip. - 989_sepbuild_run -> run --sep now genuinely runs (exit 7), not the old loud-reject (exit 2); + a private per-pid WW_PKGCACHE so the cs/ww per-package byte-id compare on the shared real lib pkgs (rt/time/os) no longer races concurrent siblings on the global out/.pkgcache (the flip made sep the sole path, so every test now contends that cache). - 737_direnum -> the deleted strictpkgmismatch "differs from" wording -> sep's "does not match import path" (shared substring, wwstage terser #68). - 989_lib_byteid -> corpus-completeness scan excludes generated .sepwork scratch (the old `! -name '*.combined.ww'` exclude didn't cover the new sep artifact).
This commit is contained in:
@@ -88,8 +88,12 @@ main(void)
|
||||
(void)tmp;
|
||||
}
|
||||
|
||||
/* bad: mismatched package decls in same dir → strict-same-package
|
||||
* error. Both stages must surface "differs from" in stderr. */
|
||||
/* bad: mismatched package decls in same dir → import-path mismatch
|
||||
* error. E3-C1: the amalgamator's strict-same-package "differs from"
|
||||
* check is deleted; under sep w6c rejects the composed unit with
|
||||
* "package <p> does not match import path <i>" (wwstage is terser per
|
||||
* #68, so match the shared "does not match import path" substring).
|
||||
* Both stages must surface it in stderr. */
|
||||
{
|
||||
const char *src = "test/wcc/data/direnum/bad_entry.ww";
|
||||
snprintf(errp, sizeof errp, "/tmp/direnum_%d_bad.err", getpid());
|
||||
@@ -102,8 +106,8 @@ main(void)
|
||||
if (rc == 0) {
|
||||
fprintf(stderr, "737[bad-cstage]: expected build failure, succeeded\n");
|
||||
fail++;
|
||||
} else if (!stderr_contains(errp, "differs from")) {
|
||||
fprintf(stderr, "737[bad-cstage]: stderr missing 'differs from'\n");
|
||||
} else if (!stderr_contains(errp, "does not match import path")) {
|
||||
fprintf(stderr, "737[bad-cstage]: stderr missing 'does not match import path'\n");
|
||||
fail++;
|
||||
}
|
||||
unlink(errp);
|
||||
@@ -116,8 +120,8 @@ main(void)
|
||||
if (rc == 0) {
|
||||
fprintf(stderr, "737[bad-wwstage]: expected build failure, succeeded\n");
|
||||
fail++;
|
||||
} else if (!stderr_contains(errp, "differs from")) {
|
||||
fprintf(stderr, "737[bad-wwstage]: stderr missing 'differs from'\n");
|
||||
} else if (!stderr_contains(errp, "does not match import path")) {
|
||||
fprintf(stderr, "737[bad-wwstage]: stderr missing 'does not match import path'\n");
|
||||
fail++;
|
||||
}
|
||||
unlink(errp);
|
||||
@@ -129,7 +133,7 @@ main(void)
|
||||
* (#16): the old 2048-capped peek missed that decl, so the strict-
|
||||
* same-package check skipped the file and the mismatch went
|
||||
* undetected (build wrongly succeeded); the whole-file peek finds it
|
||||
* → "differs from". Both stages. (reviewer-batcha pin.) */
|
||||
* → "does not match import path". Both stages. (reviewer-batcha pin.) */
|
||||
{
|
||||
const char *src = "test/wcc/data/direnum/bad_deep_entry.ww";
|
||||
snprintf(errp, sizeof errp, "/tmp/direnum_%d_baddeep.err", getpid());
|
||||
@@ -142,8 +146,8 @@ main(void)
|
||||
if (rc == 0) {
|
||||
fprintf(stderr, "737[bad-deep-cstage]: expected build failure, succeeded\n");
|
||||
fail++;
|
||||
} else if (!stderr_contains(errp, "differs from")) {
|
||||
fprintf(stderr, "737[bad-deep-cstage]: stderr missing 'differs from'\n");
|
||||
} else if (!stderr_contains(errp, "does not match import path")) {
|
||||
fprintf(stderr, "737[bad-deep-cstage]: stderr missing 'does not match import path'\n");
|
||||
fail++;
|
||||
}
|
||||
unlink(errp);
|
||||
@@ -156,8 +160,8 @@ main(void)
|
||||
if (rc == 0) {
|
||||
fprintf(stderr, "737[bad-deep-wwstage]: expected build failure, succeeded\n");
|
||||
fail++;
|
||||
} else if (!stderr_contains(errp, "differs from")) {
|
||||
fprintf(stderr, "737[bad-deep-wwstage]: stderr missing 'differs from'\n");
|
||||
} else if (!stderr_contains(errp, "does not match import path")) {
|
||||
fprintf(stderr, "737[bad-deep-wwstage]: stderr missing 'does not match import path'\n");
|
||||
fail++;
|
||||
}
|
||||
unlink(errp);
|
||||
|
||||
@@ -421,8 +421,12 @@ static int
|
||||
corpus_complete(const char *cwd)
|
||||
{
|
||||
char cmd[2048];
|
||||
/* E3-C1: the flip routes lib @test builds through sep, which drops
|
||||
* <stem>.sepwork/<pkg>.unit.ww scratch next to source; exclude it so
|
||||
* the scan enrols real source dirs only, not generated work dirs. */
|
||||
snprintf(cmd, sizeof cmd, "cd %s && find lib -name '*.ww' "
|
||||
"! -name '*.combined.ww' | sed 's|/[^/]*$||' | sort -u", cwd);
|
||||
"! -name '*.combined.ww' ! -path '*.sepwork/*' "
|
||||
"| sed 's|/[^/]*$||' | sort -u", cwd);
|
||||
FILE *p = popen(cmd, "r");
|
||||
if (!p) return -1;
|
||||
char dir[512];
|
||||
|
||||
@@ -236,6 +236,18 @@ main(void)
|
||||
runwait(cmd);
|
||||
mkdir(td, 0755);
|
||||
|
||||
/* E3-C1: with the flip making sep the sole build path, every concurrent
|
||||
* test now writes the global out/.pkgcache; this test's cs/ww per-package
|
||||
* byte-id compare on the heavily-shared real lib pkgs (rt/time/os) then
|
||||
* races a sibling building the same pkg. Pin a private per-pid cache so
|
||||
* the cs and ww legs are isolated (system() builds inherit this env).
|
||||
* pkgcache writes are non-atomic (cp -f), the real torn-read bug; this
|
||||
* hermetic isolation is correct standalone, pending #104 (atomic
|
||||
* temp+rename, both stages). */
|
||||
char cachedir[80];
|
||||
snprintf(cachedir, sizeof cachedir, "%s/pkgcache", td);
|
||||
setenv("WW_PKGCACHE", cachedir, 1);
|
||||
|
||||
char rootww[1024];
|
||||
snprintf(rootww, sizeof rootww, "%s/root.ww", td);
|
||||
if (write_file(rootww, root_src)) { fail++; goto out; }
|
||||
@@ -339,13 +351,11 @@ main(void)
|
||||
}
|
||||
}
|
||||
|
||||
/* run --sep symmetry (#46 c3): `run` has no sep-compile-then-run
|
||||
* path (out of commit-3 scope), so BOTH stages must LOUD-REJECT
|
||||
* `run --sep` identically (rule 10) — not one silently ignore it.
|
||||
* The reject exits 2 (the driver's usage/flag-error code); assert
|
||||
* cs and ww agree AND actually rejected (exit 2, not a build+run
|
||||
* that happened to exit nonzero). This row is the gate-visible
|
||||
* guard whose absence let the divergence hide. */
|
||||
/* run --sep symmetry: E3-C1 makes sep the sole compile path, so
|
||||
* `run` now genuinely sep-compiles-then-runs (the old "no sep run
|
||||
* path → loud-reject exit 2" is gone with the amalgamator). BOTH
|
||||
* stages must build+run the cross-boundary fixture identically
|
||||
* (rule 10) and exit EXPECT_EXIT — `--sep` is an accepted no-op. */
|
||||
{
|
||||
int rc_cs, rc_ww;
|
||||
snprintf(cmd, sizeof cmd,
|
||||
@@ -354,9 +364,10 @@ main(void)
|
||||
snprintf(cmd, sizeof cmd,
|
||||
"%s/ww_ww run --sep %s >/dev/null 2>&1", bin, rootww);
|
||||
rc_ww = runwait(cmd);
|
||||
if (rc_cs != rc_ww || rc_cs != 2) {
|
||||
if (rc_cs != rc_ww || rc_cs != EXPECT_EXIT) {
|
||||
fprintf(stderr, "sepbuild FAIL: run --sep cs=%d ww=%d "
|
||||
"(both must loud-reject, exit 2)\n", rc_cs, rc_ww);
|
||||
"(both must run via sep, exit %d)\n", rc_cs, rc_ww,
|
||||
EXPECT_EXIT);
|
||||
fail++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,14 +26,19 @@
|
||||
* The shadow row was RED pre-c1 (ww resolved xa's !i8 -> exit 1, the wrong
|
||||
* module's type under rc=0). The noshadow control pins the non-shadow path
|
||||
* (scopelookupprefer lands on the SK_TYPE directly) so the fix can't
|
||||
* perturb it. Single-file multi-package source is the sanctioned shape
|
||||
* (cmd/ww/main.c).
|
||||
* perturb it.
|
||||
*
|
||||
* E3-C1 retarget: the single-file multi-package source the original used
|
||||
* is the amalgamator shape, deleted with the flip (ww is now strictly
|
||||
* dir=module). Re-expressed as a dir-package tree: xb/ and xa/ both export
|
||||
* `type invalid`, and xb IMPORTS xa so both `invalid` leaves are in scope
|
||||
* during xb's sep-compile — the exact two-module same-leaf collision the
|
||||
* scopelookuptype mod-preference fix governs. A regression flips to xa's
|
||||
* !i8 -> exit 1.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
static int
|
||||
@@ -45,62 +50,70 @@ runwait(const char *cmd)
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct row { const char *label; const char *src; int want_exit; };
|
||||
/* Only xb's param name varies between rows; xa and the root are shared.
|
||||
* `xb_param` is the parameter spelling: "invalid" shadows the type leaf,
|
||||
* "x" does not. */
|
||||
struct row { const char *label; const char *xb_param; int want_exit; };
|
||||
|
||||
static const struct row rows[] = {
|
||||
{ "shadow",
|
||||
"package xb;\n"
|
||||
"export type invalid = !i64;\n"
|
||||
"export fn f(invalid: i32) i64 = { return size(invalid): i64; };\n"
|
||||
"package xa;\n"
|
||||
"export type invalid = !i8;\n"
|
||||
"package main;\n"
|
||||
"import xb;\n"
|
||||
"import xa;\n"
|
||||
"fn main() int = { return xb.f(0): int; };\n",
|
||||
8 },
|
||||
|
||||
{ "noshadow",
|
||||
"package xb;\n"
|
||||
"export type invalid = !i64;\n"
|
||||
"export fn f(x: i32) i64 = { return size(invalid): i64; };\n"
|
||||
"package xa;\n"
|
||||
"export type invalid = !i8;\n"
|
||||
"package main;\n"
|
||||
"import xb;\n"
|
||||
"import xa;\n"
|
||||
"fn main() int = { return xb.f(0): int; };\n",
|
||||
8 },
|
||||
{ "shadow", "invalid", 8 },
|
||||
{ "noshadow", "x", 8 },
|
||||
};
|
||||
|
||||
static int
|
||||
write_file(const char *path, const char *content)
|
||||
{
|
||||
FILE *f = fopen(path, "wb");
|
||||
if (!f) return -1;
|
||||
fputs(content, f);
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
run_build(const char *driver, const struct row *r, int i)
|
||||
{
|
||||
char src[64], tmpdir[64], cmd[1024];
|
||||
snprintf(src, sizeof src, "/tmp/sltp_%d_%d.ww", getpid(), i);
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/sltp_%d_d_%d", getpid(), i);
|
||||
char dir[64], sub[128], path[256], xbsrc[512], cmd[1024];
|
||||
snprintf(dir, sizeof dir, "/tmp/sltp_%d_d_%d", getpid(), i);
|
||||
|
||||
FILE *f = fopen(src, "wb");
|
||||
if (!f) return -2;
|
||||
fputs(r->src, f);
|
||||
fclose(f);
|
||||
snprintf(cmd, sizeof cmd, "rm -rf %s && mkdir -p %s/xa %s/xb",
|
||||
dir, dir, dir);
|
||||
if (runwait(cmd) != 0) return -2;
|
||||
|
||||
mkdir(tmpdir, 0755);
|
||||
snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null",
|
||||
tmpdir, driver, src);
|
||||
snprintf(path, sizeof path, "%s/xa/xa.ww", dir);
|
||||
if (write_file(path, "package xa;\nexport type invalid = !i8;\n"))
|
||||
return -2;
|
||||
|
||||
snprintf(sub, sizeof sub, "%s/xb/xb.ww", dir);
|
||||
snprintf(xbsrc, sizeof xbsrc,
|
||||
"package xb;\n"
|
||||
"import xa;\n"
|
||||
"export type invalid = !i64;\n"
|
||||
"export fn f(%s: i32) i64 = { return size(invalid): i64; };\n",
|
||||
r->xb_param);
|
||||
if (write_file(sub, xbsrc)) return -2;
|
||||
|
||||
snprintf(path, sizeof path, "%s/root.ww", dir);
|
||||
if (write_file(path,
|
||||
"package main;\n"
|
||||
"import xb;\n"
|
||||
"import xa;\n"
|
||||
"fn main() int = { return xb.f(0): int; };\n"))
|
||||
return -2;
|
||||
|
||||
/* canonical dir-package build: cd into the package root, build the
|
||||
* root unit; the binary lands in cwd (#22 dir=module). */
|
||||
snprintf(cmd, sizeof cmd, "cd %s && %s build root.ww 2>/dev/null",
|
||||
dir, driver);
|
||||
int brc = runwait(cmd);
|
||||
|
||||
const char *base = strrchr(src, '/');
|
||||
base = base ? base + 1 : src;
|
||||
char outbin[128];
|
||||
snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base);
|
||||
char *dot = strrchr(outbin, '.');
|
||||
if (dot && strcmp(dot, ".ww") == 0) *dot = '\0';
|
||||
|
||||
snprintf(outbin, sizeof outbin, "%s/root", dir);
|
||||
int got = -1;
|
||||
if (brc == 0) got = runwait(outbin);
|
||||
|
||||
unlink(src); unlink(outbin); rmdir(tmpdir);
|
||||
snprintf(cmd, sizeof cmd, "rm -rf %s", dir);
|
||||
runwait(cmd);
|
||||
return brc == 0 ? got : -1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user