The wcc test drivers ran `ww build <bare-/tmp src>` with no -o, so the compiler's <stem>.sepwork scratch landed beside the source and was never cleaned: unbounded /tmp growth (2195 stale dirs observed) that fills tmpfs and fabricates phantom test failures + silent harness aborts, and for in-repo fixture builds leaked .sepwork into the tracked tree. Each leaking build now writes its source + output inside a per-invocation tmpdir, passes -o <tmpdir>/<stem> so the .sepwork lands inside it, and rm -rf's the tmpdir on every exit path -- including fopen-fail and the expected-fail reject builds (scratch is mkdir'd before the build can fail). `ww run` and explicit-`-o`/byte-id helpers are left as-is; the 990/993 byte-id comparison logic is byte-for-byte unchanged. Two items filed separately (this commit holds the no-Makefile / no-main.c rail): - #13: a stale <src>.s byte-id readback (749) silently no-ops since separate-compile emits .s to <ostem>.sepwork/__root.s; documented inline. - #14: build-system Makefile recipes build selfhost/cmd/*/main.ww with no -o and leak main.sepwork in-tree (bounded, gitignored; own commit). One concern -- sepwork leak hygiene -- across 228 drivers; uniform transform applied per-file and two-round reviewed. make test: all 402 passed, zero net-new /tmp scratch, zero test-driven in-repo .sepwork.
128 lines
4.2 KiB
C
128 lines
4.2 KiB
C
/*
|
|
* 699_use_promote_alias — SK_USE→SK_X promotion preserves use_alias.
|
|
*
|
|
* Sweep of every reachable promotion site in cmd/wcc/check.c where an
|
|
* SK_USE leaf gets in-place-promoted to a same-named decl. With driver
|
|
* concatenation, the imported module's top-level decls appear in
|
|
* file.list BEFORE the primary's `use foo;`, so pass-1 (N_USE +
|
|
* N_TYPEDECL only) installs an SK_USE("foo") that pass-1.5 later
|
|
* promotes when it walks the imported N_DEF / N_FNDECL / N_LET of the
|
|
* same name. Each promotion must set `prev->use_alias = 1` so the
|
|
* dot-prefixed lookups in resolve_typename (L77) and N_DOT (L709)
|
|
* continue to walk the leaf as a module head.
|
|
*
|
|
* The fnmatch.flag-style "unknown type" failure that surfaced this is
|
|
* the SK_FN row; the SK_TYPE row pins the random.random precedent
|
|
* against regression; SK_DEF / SK_VAR are the same structural shape
|
|
* with `def` / top-level `let` standing in for `fn`.
|
|
*
|
|
* row | imported decl shape | path | check.c line
|
|
* -----+-----------------------------+----------+-------------
|
|
* type | `type typmod = struct {...}`| L1660/77 | regression pin
|
|
* fn | `fn fnmod() i32 = ...` | L1722 | the bug
|
|
* def | `def defmod: i32 = 0` | L1709 | same shape
|
|
* var | `let varmod: i32 = 0` | L1736 | same shape
|
|
*
|
|
* Fixtures: test/wcc/data/usepromote/{type,fn,def,var}mod/<name>.ww
|
|
* primary: test/wcc/data/usepromote/pos_{type,fn,def,var}.ww
|
|
*
|
|
* Each primary returns `flag.A` (= 42) so a successful build + run +
|
|
* exit=42 proves the lookup chain end-to-end. Cstage-only: wwstage
|
|
* uses a coexistence-not-promotion model in selfhost/cmd/wcc/check.ww
|
|
* (separate sym entries differentiated by `mod`, no use_alias flag at
|
|
* all), so the bug is structurally non-reachable on that side — see
|
|
* the architectural note at installdecl in check.ww. Task #11 will
|
|
* revisit when wwstage grows a real check pass on the cgen path.
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/wait.h>
|
|
|
|
static int
|
|
runwait(const char *cmd)
|
|
{
|
|
int rc = system(cmd);
|
|
if (rc == -1) return -1;
|
|
if (WIFEXITED(rc)) return WEXITSTATUS(rc);
|
|
return -1;
|
|
}
|
|
|
|
static int
|
|
run_row(const char *driver, const char *fixdir, const char *tag)
|
|
{
|
|
/* Scratch dir OUT of the repo: the driver's sep `<stem>.sepwork/`
|
|
* follows the build output stem, so point -o into /tmp so both the
|
|
* binary and its .sepwork land there and die with rm -rf. */
|
|
char td[64];
|
|
snprintf(td, sizeof td, "/tmp/usepr_%d_%s", getpid(), tag);
|
|
mkdir(td, 0755);
|
|
char rmcmd[128];
|
|
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", td);
|
|
|
|
char src[64];
|
|
snprintf(src, sizeof src, "pos_%s.ww", tag);
|
|
char bin[2048];
|
|
snprintf(bin, sizeof bin, "%s/out", td);
|
|
char cmd[2048];
|
|
/* cd into the fixture dir so the driver's source-dir-first
|
|
* import search resolves `use <tag>mod;`; -o points OUT of the repo. */
|
|
snprintf(cmd, sizeof cmd,
|
|
"cd %s && %s build -o %s %s >/dev/null 2>&1", fixdir, driver, bin, src);
|
|
if (runwait(cmd) != 0) {
|
|
fprintf(stderr,
|
|
"use_promote_alias[%s]: build failed — SK_USE→SK_X "
|
|
"promotion likely dropped use_alias\n", tag);
|
|
runwait(rmcmd);
|
|
return 1;
|
|
}
|
|
int got = runwait(bin);
|
|
runwait(rmcmd);
|
|
if (got != 42) {
|
|
fprintf(stderr,
|
|
"use_promote_alias[%s]: exit=%d want=42\n", tag, got);
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
const char *bin = getenv("BIN");
|
|
if (!bin) bin = "out/bin";
|
|
char absbin[1024];
|
|
if (bin[0] != '/') {
|
|
char cwd[1024];
|
|
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
|
|
snprintf(absbin, sizeof absbin, "%s/%s", cwd, bin);
|
|
bin = absbin;
|
|
}
|
|
|
|
char cdrv[1024];
|
|
snprintf(cdrv, sizeof cdrv, "%s/ww", bin);
|
|
|
|
char fixdir[1024];
|
|
if (getcwd(fixdir, sizeof fixdir) == NULL) return 1;
|
|
size_t cwd_n = strlen(fixdir);
|
|
const char *rel = "/test/wcc/data/usepromote";
|
|
if (cwd_n + strlen(rel) + 1 >= sizeof fixdir) return 1;
|
|
memcpy(fixdir + cwd_n, rel, strlen(rel) + 1);
|
|
|
|
int fail = 0;
|
|
fail += run_row(cdrv, fixdir, "type");
|
|
fail += run_row(cdrv, fixdir, "fn");
|
|
fail += run_row(cdrv, fixdir, "def");
|
|
fail += run_row(cdrv, fixdir, "var");
|
|
|
|
if (fail) {
|
|
fprintf(stderr,
|
|
"use_promote_alias: %d row(s) failed\n", fail);
|
|
return 1;
|
|
}
|
|
printf("use_promote_alias: 4/4 ok\n");
|
|
return 0;
|
|
}
|