Files
ww/test/wcc/944_alias_emit_b7_run.c
Hojun-Cho e60297085d wwstage: accept module-level const/let slice-from-arrlit (#28)
wwstage rejected a module-level `const/let []T = [arrlit]` global with "let: not assignable"; cstage accepts (textbook Hare, ref/hare/path/stack.ha:30). The arrlit->slice admission in checkletassign was gated local-only; lift it to module scope too, aligning wwstage UP to cstage's arrlit_init_fits (check.c:3406-3409, slice arm 519-520). cstage unchanged.

Two guards the un-gating requires: the n.rhs.lhs=arr stash stays local-only (a module decl keeps its raw N_ARRLIT for DATA emit, so stashing would leave an untyped count node for the pass-3 asserttyped walker); and tuple-element slice globals are excluded at module scope, because the synthesis delegates element checks to isassignable which lacks a strict tuple arm (#38) -- a [](str,*fn) table would over-accept a sig-mismatched &fn that cstage's strict type_assignable rejects (#124) -- so they stay on the existing typeeqast path.

Closes two divergences 944_alias_emit_b7 pinned: Group A (cstage-runs/ww-rejects) migrates to test/lang/slice_global_arg_test.ww (promoted from _runonly, now cs==ww byte-id); Group B converges to a shared emit_slice_data reject with the identical diagnostic.
2026-06-26 23:16:19 +09:00

162 lines
5.2 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 2 IRREDUCIBLE both-stage emit-reject rows neither
* in-language surface can host (ken's emit_slice_data observation cells —
* load-bearing codegen pins, MUST NOT move):
* • slcstr_2lvl / slctag_2lvl: a slice-of-{str,tagged} literal GLOBAL is
* admitted by BOTH checkers and then LOUD-REJECTED at emit_slice_data
* ("slice-of-{str,slice,tagged} literal static-init unsupported", a rule-7
* deferred #10 follow-up) in BOTH stages with the IDENTICAL message. @test
* needs a build, runww //ww:error drives one path — a dual-stage emit
* reject fits neither, so each stage's reject is asserted directly here.
*
* HISTORY (#28): Group A (slc_2lvl []my64b / slc_plain_ctl []i64, cstage-runs /
* wwstage-checker-rejects) and Group B's old wwstage HALF (the ww checker
* rejected EVERY slice-literal global at "let: not assignable") were both that
* pre-#28 divergence. Once the module-scope slice-from-arrlit admission landed
* (selfhost check.ww checkletassign), wwstage admits these globals at the
* checker exactly as cstage does: Group A converged to cs==ww build+run and
* migrated to test/lang/slice_global_arg_test.ww; Group B converged to the
* shared emit_slice_data reject below.
*/
#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[] = {
{ "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",
"slice-of-{str,slice,tagged} literal static-init unsupported" },
{ "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",
"slice-of-{str,slice,tagged} literal static-init unsupported" },
};
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;
}