Files
ww/test/wcc/944_alias_emit_b7_run.c
Hojun-Cho 3ee1906497 test: migrate Fam10 alias value tests to @test, carve divergences to pins (#5-C3)
fold-2 chunk C3 (drew's Fam8-13 plan): 8 alias value-row C drivers, 205 rows
re-homed with zero loss -- 177 value -> 8 test/lang/alias_*_test.ww @test
row-tables; 16 reject -> runww //ww:error carriers (both stages reject);
3 cs!=ww value rows -> 2 *_runonly_test.ww (T1, byte-id-excluded, #60/#81);
9 irreducible asymmetric rows -> slim C pins, each ticket-cited and
mutation-proven non-vacuous:
  - accept amplen1/2,ampcap2: cs runs / ww rejects 'unsupported address-of
    shape' (#96)
  - cgen_b5 g73_heapfill: cs!=ww .s + ww link-fails on self-contained alloc;
    compile-smoke pin (#24)
  - cgen_b6 fsarg2_bound: both reject, different msgs, each vs the correct
    stage (#271/#165 cs vs #272/#276/#277 ww)
  - emit_b7 slc/slcstr/slctag _2lvl + slc_plain_ctl: slice-literal static-init
    divergence (#120/#29-kin, ken-d2-oracle)
4 fully-migrated drivers deleted, 4 slimmed-in-place to hold only the
irreducible pins. LANGBYTEID floor 74->82 (8 new byte-id @test files); test
count 388->384 (4 deleted; 4 slimmed kept). do-not-auto-batch files not in
Fam10.
2026-06-24 02:45:09 +09:00

175 lines
5.4 KiB
C

/*
* 944_alias_emit_b7_run — SLIM CARRIER (#5-C3 alias fold-2). The 8 K_RUN value
* rows migrated to test/lang/alias_emit_b7_test.ww (@test, cs==ww byte-id); the
* symmetric K_BUILDERR rejects (slcstr_plain_ctl, slcslc_2lvl) to
* test/wcc/data/alias_{slcstr_plain,slcslc}/case.ww runww //ww:error.
*
* What survives here are the 4 IRREDUCIBLE per-stage rows neither in-language
* surface can host (ken's emit_slice_data observation cells — load-bearing
* codegen pins, MUST NOT move):
* • slc_2lvl / slc_plain_ctl (Group A): cstage builds+RUNS exit 0; wwstage
* LOUD-REJECTS at the let checker ("let: not assignable"). cstage emits the
* []my64b / []i64 slice-literal global DATA and runs; the ww checker
* rejects every slice-literal global (the #120/#29-kin acceptance
* divergence, ken-d2-oracle; pre-slim #66-R2/#29). @test needs ww to
* build, //ww:error needs cs to fail — neither fits.
* • slcstr_2lvl / slctag_2lvl (Group B): BOTH reject but with DIFFERENT
* diagnostics (cs at emit_slice_data 3-way "static-init unsupported"; ww at
* the let checker "not assignable") — a held cs!=ww divergence; the two
* messages ARE the pin, so each stage's own substring is asserted.
*/
#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
errlog_has(const char *path, const char *needle)
{
FILE *f = fopen(path, "rb");
if (!f) return 0;
char buf[8192];
size_t got = fread(buf, 1, sizeof buf - 1, f);
fclose(f);
buf[got] = '\0';
return strstr(buf, needle) != NULL;
}
#define M_CSRUN_WWERR 0 /* cstage build+run exit 0; wwstage w6c_ww rejects wwerr */
#define M_BOTHERR 1 /* cstage w6c rejects cserr; wwstage w6c_ww rejects wwerr */
struct row { const char *label; const char *src; int mode;
const char *cserr; const char *wwerr; };
static int
run_row(const char *bin, const struct row *r, int i)
{
char dir[96], srcf[160], outbin[160], cse[160], wwe[160], ss[160],
rm[200], cmd[2048];
snprintf(dir, sizeof dir, "/tmp/ab7_%d_%d", getpid(), i);
mkdir(dir, 0755);
snprintf(srcf, sizeof srcf, "%s/c.ww", dir);
snprintf(outbin, sizeof outbin, "%s/bin", dir);
snprintf(cse, sizeof cse, "%s/cs.err", dir);
snprintf(wwe, sizeof wwe, "%s/ww.err", dir);
snprintf(ss, sizeof ss, "%s/o.s", dir);
snprintf(rm, sizeof rm, "rm -rf %s", dir);
FILE *f = fopen(srcf, "wb");
if (!f) { runwait(rm); return -1; }
fputs(r->src, f);
fclose(f);
int ok = 1;
if (r->mode == M_CSRUN_WWERR) {
snprintf(cmd, sizeof cmd,
"timeout 20 %s/ww build -o %s %s >/dev/null 2>&1",
bin, outbin, srcf);
if (runwait(cmd) != 0) {
fprintf(stderr, "row[%s]: cstage build failed (want run)\n",
r->label);
ok = 0;
} else if (runwait(outbin) != 0) {
fprintf(stderr, "row[%s]: cstage run != 0\n", r->label);
ok = 0;
}
} else {
snprintf(cmd, sizeof cmd, "%s/w6c -o %s %s 2>%s", bin, ss, srcf, cse);
int crc = runwait(cmd);
if (!(crc != 0 && errlog_has(cse, r->cserr))) {
fprintf(stderr, "row[%s]: cstage expected reject \"%s\" (rc=%d)\n",
r->label, r->cserr, crc);
ok = 0;
}
}
snprintf(cmd, sizeof cmd, "%s/w6c_ww -o %s %s 2>%s", bin, ss, srcf, wwe);
int wrc = runwait(cmd);
if (!(wrc != 0 && errlog_has(wwe, r->wwerr))) {
fprintf(stderr, "row[%s]: wwstage expected reject \"%s\" (rc=%d)\n",
r->label, r->wwerr, wrc);
ok = 0;
}
runwait(rm);
return ok ? 0 : 1;
}
static const struct row rows[] = {
{ "slc_2lvl",
"package main;\n"
"type my64 = i64;\n"
"type my64b = my64;\n"
"let G: []my64b = [5, 6, 7];\n"
"export fn main() i32 = {\n"
" if (G[0] + G[1] + G[2] != 18) { return 1; };\n"
" if (len(G) != 3) { return 2; };\n"
" return 0;\n"
"};\n", M_CSRUN_WWERR, NULL, "let: not assignable" },
{ "slc_plain_ctl",
"package main;\n"
"let G: []i64 = [5, 6, 7];\n"
"export fn main() i32 = {\n"
" if (G[0] + G[1] + G[2] != 18) { return 1; };\n"
" if (len(G) != 3) { return 2; };\n"
" return 0;\n"
"};\n", M_CSRUN_WWERR, NULL, "let: not assignable" },
{ "slcstr_2lvl",
"package main;\n"
"type ms0 = str;\n"
"type ms = ms0;\n"
"let G: []ms = [\"aa\", \"bbb\"];\n"
"export fn main() i32 = {\n"
" if (len(G[0]) != 2) { return 1; };\n"
" return 0;\n"
"};\n", M_BOTHERR,
"slice-of-{str,slice,tagged} literal static-init unsupported",
"let: not assignable" },
{ "slctag_2lvl",
"package main;\n"
"type u0 = (void | i64);\n"
"type u1 = u0;\n"
"let G: []u1 = [1i64, 2i64];\n"
"export fn main() i32 = {\n"
" if (len(G) != 2) { return 1; };\n"
" return 0;\n"
"};\n", M_BOTHERR,
"slice-of-{str,slice,tagged} literal static-init unsupported",
"let: not assignable" },
};
int
main(void)
{
const char *bin = getenv("BIN");
if (!bin) bin = "out/bin";
char absbin[2080];
if (bin[0] != '/') {
char cwd[1024];
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
snprintf(absbin, sizeof absbin, "%s/%s", cwd, bin);
bin = absbin;
}
int n = (int)(sizeof rows / sizeof rows[0]);
int fail = 0;
for (int i = 0; i < n; i++)
if (run_row(bin, &rows[i], i) != 0) fail++;
if (fail) {
fprintf(stderr, "alias_emit_b7 (slim): %d/%d rows failed\n", fail, n);
return 1;
}
printf("alias_emit_b7 (slim): %d/%d ok\n", n, n);
return 0;
}