Every surviving carrier now owns its artifacts: checked mkdir/mkdtemp/ fopen acquisition, one all-exit cleanup funnel per carrier, ENOENT- tolerant checked unlinks, exact-path deletion (rm -rf only for an owned pid-keyed dir or a .sepwork beneath one), and cleanup failure fails a passing carrier without overwriting its diagnostic. In the same pass the carriers adapt to the driver contract this branch lands: --sep and WW_PKGCACHE are gone, -S and the /tmp/ww_run_<pid> scratch contract are asserted, and rows whose runtime or reject coverage moved to test/wcc/data fixtures or test/lang @test owners are trimmed to the byte/artifact/diagnostic observations only they can make. Repair and adaptation ride together because most files interleave both in the same hunks; splitting would manufacture intermediate carrier states that never existed and cannot run against either driver.
120 lines
3.4 KiB
C
120 lines
3.4 KiB
C
/*
|
|
* 697_samemod_prefer — same-module preference for bare-leaf lookup.
|
|
*
|
|
* Two modules each export `read` with intentionally distinct
|
|
* signatures (mod1: i32 → i32, mod2: str → i32). Each module's
|
|
* `caller()` invokes bare `read(...)` with its own arg type. The
|
|
* bare-leaf lookup must resolve to the SAME-MODULE `read`; otherwise
|
|
* the call is a check-time signature mismatch.
|
|
*
|
|
* Pre-fix (flat scope, first-wins by hash order): one of the bare
|
|
* lookups picked the wrong module's `read` and the build failed with
|
|
* "argument type not assignable". Post-fix (scope_lookup_prefer): each
|
|
* bare-leaf inside its own module binds to the same-module entry, both
|
|
* calls type-check, and the build succeeds.
|
|
*
|
|
* Runtime exit codes aren't asserted here because cgen still emits
|
|
* unmangled `TEXT read` labels for both modules and the linker
|
|
* collapses them. Mangling fn labels by module is a separate codegen
|
|
* sweep; this test pins the resolver fix alone.
|
|
*
|
|
* Fixtures live in test/wcc/data/samemodprefer/. Same shape as
|
|
* 696_modtype_leaf_collision.c.
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <errno.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_pos(const char *driver, const char *fixdir, const char *tag)
|
|
{
|
|
/* -o puts the binary and caller-owned `<stem>.sepwork/` under the
|
|
* acquired directory; the cd keeps source-dir-first import search
|
|
* resolving `use mod1; use mod2;`. */
|
|
char td[1024], outbin[1024], sepwork[1100];
|
|
snprintf(td, sizeof td, "/tmp/smprefer_%d_%s", getpid(), tag);
|
|
if (mkdir(td, 0755) != 0) {
|
|
fprintf(stderr, "samemod_prefer[%s]: mkdir %s failed\n", tag, td);
|
|
return 1;
|
|
}
|
|
snprintf(outbin, sizeof outbin, "%s/pos", td);
|
|
snprintf(sepwork, sizeof sepwork, "%s/pos.sepwork", td);
|
|
|
|
char cmd[2048];
|
|
snprintf(cmd, sizeof cmd,
|
|
"cd %s && %s build -o %s/pos pos.ww >/dev/null 2>&1",
|
|
fixdir, driver, td);
|
|
int fail = 0;
|
|
if (runwait(cmd) != 0) {
|
|
fprintf(stderr,
|
|
"samemod_prefer[%s]: pos.ww build failed — bare-leaf "
|
|
"`read` lookup likely cross-bound\n", tag);
|
|
fail = 1;
|
|
}
|
|
|
|
snprintf(cmd, sizeof cmd, "rm -rf %s", sepwork);
|
|
if (runwait(cmd) != 0) {
|
|
fprintf(stderr, "samemod_prefer[%s]: cleanup %s failed\n",
|
|
tag, sepwork);
|
|
fail = 1;
|
|
}
|
|
if (unlink(outbin) != 0 && errno != ENOENT) {
|
|
fprintf(stderr, "samemod_prefer[%s]: cleanup %s failed\n",
|
|
tag, outbin);
|
|
fail = 1;
|
|
}
|
|
if (rmdir(td) != 0) {
|
|
fprintf(stderr, "samemod_prefer[%s]: cleanup %s failed\n", tag, td);
|
|
fail = 1;
|
|
}
|
|
return fail;
|
|
}
|
|
|
|
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/samemodprefer";
|
|
if (cwd_n + strlen(rel) + 1 >= sizeof fixdir) return 1;
|
|
memcpy(fixdir + cwd_n, rel, strlen(rel) + 1);
|
|
|
|
int fail = 0;
|
|
fail += run_pos(cdrv, fixdir, "cstage");
|
|
|
|
if (fail) {
|
|
fprintf(stderr,
|
|
"samemod_prefer: %d case(s) failed\n", fail);
|
|
return 1;
|
|
}
|
|
printf("samemod_prefer: 1/1 ok\n");
|
|
return 0;
|
|
}
|