wcc/check: #103/#108 inferred untyped-int defaults to int (8B), both stages
cstage type_default(TY_UNTYPED_INT) returned ty_i32 (4B): an unannotated `let x = <v>` / `let a = [<v>,..]` silently TRUNCATED any value > 2^31 (5000000000 -> 705032704) and strode inferred arrays at 4. wwstage kept the element raw untyped_int (size 0), which sized INCONSISTENTLY across cgen — the array STORE strode the 8 sentinel but letslotsize under- allocated the frame (SEGV) and cgindex strode the READ at 1. The two stages were each wrong differently; #263 polarity: cstage was the truncating side. int = machine word = 8B (Go-style, MEMORY project_int_machine_word_derived_limits); Hare lowers a flexible iconst to `int`, never a fixed i32 (ref/harec/src/types.c:835). Fix, one root, both stages (FUSE — the cs default + the ww concrete element must land together, else the inferred array is transient cs!=ww): - cmd/wcc/type.c type_default(TY_UNTYPED_INT) ty_i32 -> ty_int. The root; stops scalar AND array truncation at source. - cmd/wcc/check.c N_ARRLIT empty-elt fallback ty_i32 -> ty_int. Symmetric pair; count-0 array emits no stores, so byte-id-neutral. - selfhost/cmd/wcc/check.ww exprtype N_ARRLIT: default the inferred element's untyped flavor to concrete (untyped_int->int, _float->f64, _str->str, _rune->rune, _bool->bool, mirror cstage type_default), empty-elt "i32"->"int", and stamp the synthesized N_TARRAY's .type_ so slotsize / elemsizeofc / letslotsize read its real [N]int size via the type table (rule-13) — no letslotsize special-case (SSoT). combined.ww regen (check.ww embed): w6c + wwdump. ken v2 corpus re-census (160 files): EXACTLY 5 rows move, ALL CONVERGE (byte-id YES + run exit 0, none both-wrong, zero regression): m2_while #108 scalar via alias-bool loop m8_range1 #104 for-range elem over alias [4]int m8_range2 #104 over 2-level alias m8_slice1 #103 inferred array + alias-slice init m8_slice2 #103 + 2-level-alias slice + re-slice Bootstrap byte-id neutral (5 combined units w6c==w6c_ww; 0 bare inferred arrays in selfhost). Annotated controls untouched ([4]i32 stride-4, [4]int stride-8, byte-id). Pinned in test/wcc/813_arrlit_infer_elem_run (the 2 direct repros incl the >2^31 truncation teeth + all 5 movers + controls; test-unit 296). Closes #103 (inferred-array SEGV + truncation), #108 (cstage scalar untyped-int truncation), #104 (for-range elem alias i32-stamp), and the m8_slice []int-init acceptance divergence.
This commit is contained in:
10
Makefile
10
Makefile
@@ -411,6 +411,7 @@ TESTS = $(BIN)/test_smoke $(BIN)/test_lex $(BIN)/test_parse $(BIN)/test_check \
|
||||
$(BIN)/test_idx_structlit_store \
|
||||
$(BIN)/test_inferred_let_struct \
|
||||
$(BIN)/test_agg_assign_width \
|
||||
$(BIN)/test_arrlit_infer_elem_run \
|
||||
$(BIN)/test_placeaddr_store \
|
||||
$(BIN)/test_tryprop_multisuccess \
|
||||
$(BIN)/test_append_place \
|
||||
@@ -1127,6 +1128,15 @@ $(BIN)/test_agg_assign_width: test/wcc/812_agg_assign_width.c \
|
||||
$(LIB)/libwwrt.a | $(BIN)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
# #103/#108 (+#104 + m8_slice acceptance): inferred untyped-int → int
|
||||
# (8B) default, both stages byte-id. Pins the 2 direct repros (>2^31
|
||||
# teeth) + ken v2's 5 named corpus movers + annotated i32/int controls.
|
||||
$(BIN)/test_arrlit_infer_elem_run: test/wcc/813_arrlit_infer_elem_run.c \
|
||||
$(BIN)/ww $(BIN)/w6c $(BIN)/w6c_ww $(BIN)/w6a $(BIN)/w6l \
|
||||
$(BIN)/ww_ww \
|
||||
$(LIB)/libwwrt.a | $(BIN)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
# F8+F9 (tasks #5/#12, regex fold-2b): `?` interim single-success gate
|
||||
# (|success| > 1 loud-rejected on BOTH stages until task #14's
|
||||
# subset-union typing) + direct `f()? is T` / `match (f()?)` reject
|
||||
|
||||
@@ -1856,7 +1856,7 @@ cexpr(Checker *c, Node *n)
|
||||
if (elt == NULL) elt = type_default(t);
|
||||
count++;
|
||||
}
|
||||
if (elt == NULL) elt = ty_i32;
|
||||
if (elt == NULL) elt = ty_int; /* empty inferred arrlit: pair of int-default (#103); symmetric w/ wwstage check.ww mktname "int" */
|
||||
return n->type = type_array(c->a, elt, count);
|
||||
}
|
||||
case N_SPREAD:
|
||||
|
||||
@@ -234,7 +234,7 @@ type_default(Type *t)
|
||||
{
|
||||
if (t == NULL) return NULL;
|
||||
switch (t->kind) {
|
||||
case TY_UNTYPED_INT: return ty_i32;
|
||||
case TY_UNTYPED_INT: return ty_int; /* int = machine word (8B); i32 truncated >2^31 (#103/#108) */
|
||||
case TY_UNTYPED_FLOAT: return ty_f64;
|
||||
case TY_UNTYPED_STR: return ty_str;
|
||||
case TY_UNTYPED_RUNE: return ty_rune;
|
||||
|
||||
@@ -13514,13 +13514,45 @@ fn exprtype(c: *checker, e: *node, hint: *node) *node = {
|
||||
};
|
||||
it = it.next;
|
||||
};
|
||||
if (elt == nil) { elt = mktname(c, "i32"); };
|
||||
// #103/#108: default the inferred element's UNTYPED flavor to its
|
||||
// concrete type, mirroring cstage cmd/wcc/check.c:1856
|
||||
// `elt = type_default(t)` (type.c:237 untyped_int→int after the
|
||||
// #108 polarity flip). Keeping the raw untyped_int (the prior
|
||||
// documented divergence) sized the synthesized [N]untyped_int
|
||||
// INCONSISTENTLY — untyped_int.size is 0, so the cgarrlitfillbp
|
||||
// STORE strode the 8 sentinel while slotsize (letslotsize slot)
|
||||
// and elemsizeofc (cgindex READ stride) read the 0-size element
|
||||
// → frame under-alloc SEGV + stride-1 index reads, cs≠ww. drew
|
||||
// Hare-fidelity: harec lower_flexible defaults a flexible iconst
|
||||
// to `int` (ref/harec/src/types.c:835). int = machine word (8B);
|
||||
// the old i32 truncated values >2^31 (#263 trap).
|
||||
if (elt != nil && elt.kind == nkind.N_TNAME) {
|
||||
if (streq(elt.str, "untyped_int")) {
|
||||
elt = mktname(c, "int");
|
||||
} else { if (streq(elt.str, "untyped_float")) {
|
||||
elt = mktname(c, "f64");
|
||||
} else { if (streq(elt.str, "untyped_str")) {
|
||||
elt = mktname(c, "str");
|
||||
} else { if (streq(elt.str, "untyped_rune")) {
|
||||
elt = mktname(c, "rune");
|
||||
} else { if (streq(elt.str, "untyped_bool")) {
|
||||
elt = mktname(c, "bool");
|
||||
}; }; }; }; };
|
||||
};
|
||||
// Empty inferred arrlit: default to int, symmetric with cstage
|
||||
// check.c:1859 empty-fallback ty_int (#103). Was "i32".
|
||||
if (elt == nil) { elt = mktname(c, "int"); };
|
||||
let arr: *node = newnode(nkind.N_TARRAY, "", 0, 0);
|
||||
arr.lhs = elt;
|
||||
let cn: *node = newnode(nkind.N_INTLIT, "", 0, 0);
|
||||
cn.uval = count;
|
||||
arr.rhs = cn;
|
||||
e.type_ = tinfofornode(c, arr): *void;
|
||||
// #103: stamp the synthesized array NODE too. checkletassign
|
||||
// plants this node on the inferred let's n.lhs; slotsize /
|
||||
// elemsizeofc / letslotsize all read n.lhs.type_, which was nil
|
||||
// here (only e.type_ was set) — falling to the 8 / 0 sentinels.
|
||||
arr.type_ = e.type_;
|
||||
return arr;
|
||||
};
|
||||
if (k == nkind.N_SLICE) {
|
||||
|
||||
@@ -3233,13 +3233,45 @@ fn exprtype(c: *checker, e: *node, hint: *node) *node = {
|
||||
};
|
||||
it = it.next;
|
||||
};
|
||||
if (elt == nil) { elt = mktname(c, "i32"); };
|
||||
// #103/#108: default the inferred element's UNTYPED flavor to its
|
||||
// concrete type, mirroring cstage cmd/wcc/check.c:1856
|
||||
// `elt = type_default(t)` (type.c:237 untyped_int→int after the
|
||||
// #108 polarity flip). Keeping the raw untyped_int (the prior
|
||||
// documented divergence) sized the synthesized [N]untyped_int
|
||||
// INCONSISTENTLY — untyped_int.size is 0, so the cgarrlitfillbp
|
||||
// STORE strode the 8 sentinel while slotsize (letslotsize slot)
|
||||
// and elemsizeofc (cgindex READ stride) read the 0-size element
|
||||
// → frame under-alloc SEGV + stride-1 index reads, cs≠ww. drew
|
||||
// Hare-fidelity: harec lower_flexible defaults a flexible iconst
|
||||
// to `int` (ref/harec/src/types.c:835). int = machine word (8B);
|
||||
// the old i32 truncated values >2^31 (#263 trap).
|
||||
if (elt != nil && elt.kind == nkind.N_TNAME) {
|
||||
if (streq(elt.str, "untyped_int")) {
|
||||
elt = mktname(c, "int");
|
||||
} else { if (streq(elt.str, "untyped_float")) {
|
||||
elt = mktname(c, "f64");
|
||||
} else { if (streq(elt.str, "untyped_str")) {
|
||||
elt = mktname(c, "str");
|
||||
} else { if (streq(elt.str, "untyped_rune")) {
|
||||
elt = mktname(c, "rune");
|
||||
} else { if (streq(elt.str, "untyped_bool")) {
|
||||
elt = mktname(c, "bool");
|
||||
}; }; }; }; };
|
||||
};
|
||||
// Empty inferred arrlit: default to int, symmetric with cstage
|
||||
// check.c:1859 empty-fallback ty_int (#103). Was "i32".
|
||||
if (elt == nil) { elt = mktname(c, "int"); };
|
||||
let arr: *node = newnode(nkind.N_TARRAY, "", 0, 0);
|
||||
arr.lhs = elt;
|
||||
let cn: *node = newnode(nkind.N_INTLIT, "", 0, 0);
|
||||
cn.uval = count;
|
||||
arr.rhs = cn;
|
||||
e.type_ = tinfofornode(c, arr): *void;
|
||||
// #103: stamp the synthesized array NODE too. checkletassign
|
||||
// plants this node on the inferred let's n.lhs; slotsize /
|
||||
// elemsizeofc / letslotsize all read n.lhs.type_, which was nil
|
||||
// here (only e.type_ was set) — falling to the 8 / 0 sentinels.
|
||||
arr.type_ = e.type_;
|
||||
return arr;
|
||||
};
|
||||
if (k == nkind.N_SLICE) {
|
||||
|
||||
@@ -13514,13 +13514,45 @@ fn exprtype(c: *checker, e: *node, hint: *node) *node = {
|
||||
};
|
||||
it = it.next;
|
||||
};
|
||||
if (elt == nil) { elt = mktname(c, "i32"); };
|
||||
// #103/#108: default the inferred element's UNTYPED flavor to its
|
||||
// concrete type, mirroring cstage cmd/wcc/check.c:1856
|
||||
// `elt = type_default(t)` (type.c:237 untyped_int→int after the
|
||||
// #108 polarity flip). Keeping the raw untyped_int (the prior
|
||||
// documented divergence) sized the synthesized [N]untyped_int
|
||||
// INCONSISTENTLY — untyped_int.size is 0, so the cgarrlitfillbp
|
||||
// STORE strode the 8 sentinel while slotsize (letslotsize slot)
|
||||
// and elemsizeofc (cgindex READ stride) read the 0-size element
|
||||
// → frame under-alloc SEGV + stride-1 index reads, cs≠ww. drew
|
||||
// Hare-fidelity: harec lower_flexible defaults a flexible iconst
|
||||
// to `int` (ref/harec/src/types.c:835). int = machine word (8B);
|
||||
// the old i32 truncated values >2^31 (#263 trap).
|
||||
if (elt != nil && elt.kind == nkind.N_TNAME) {
|
||||
if (streq(elt.str, "untyped_int")) {
|
||||
elt = mktname(c, "int");
|
||||
} else { if (streq(elt.str, "untyped_float")) {
|
||||
elt = mktname(c, "f64");
|
||||
} else { if (streq(elt.str, "untyped_str")) {
|
||||
elt = mktname(c, "str");
|
||||
} else { if (streq(elt.str, "untyped_rune")) {
|
||||
elt = mktname(c, "rune");
|
||||
} else { if (streq(elt.str, "untyped_bool")) {
|
||||
elt = mktname(c, "bool");
|
||||
}; }; }; }; };
|
||||
};
|
||||
// Empty inferred arrlit: default to int, symmetric with cstage
|
||||
// check.c:1859 empty-fallback ty_int (#103). Was "i32".
|
||||
if (elt == nil) { elt = mktname(c, "int"); };
|
||||
let arr: *node = newnode(nkind.N_TARRAY, "", 0, 0);
|
||||
arr.lhs = elt;
|
||||
let cn: *node = newnode(nkind.N_INTLIT, "", 0, 0);
|
||||
cn.uval = count;
|
||||
arr.rhs = cn;
|
||||
e.type_ = tinfofornode(c, arr): *void;
|
||||
// #103: stamp the synthesized array NODE too. checkletassign
|
||||
// plants this node on the inferred let's n.lhs; slotsize /
|
||||
// elemsizeofc / letslotsize all read n.lhs.type_, which was nil
|
||||
// here (only e.type_ was set) — falling to the 8 / 0 sentinels.
|
||||
arr.type_ = e.type_;
|
||||
return arr;
|
||||
};
|
||||
if (k == nkind.N_SLICE) {
|
||||
|
||||
362
test/wcc/813_arrlit_infer_elem_run.c
Normal file
362
test/wcc/813_arrlit_infer_elem_run.c
Normal file
@@ -0,0 +1,362 @@
|
||||
/*
|
||||
* 813_arrlit_infer_elem_run — #103 + #108 (+ #104 + the m8_slice
|
||||
* acceptance gap): an INFERRED let defaults its untyped-int to `int`
|
||||
* (8B machine word) on BOTH stages, byte-identically and at runtime.
|
||||
*
|
||||
* THE BUG (cstage was the truncating side — #263 polarity):
|
||||
* cstage type_default(TY_UNTYPED_INT) returned ty_i32 (4B). For a
|
||||
* scalar `let x = <v>` and an inferred array `let a = [<v>, ...]`
|
||||
* (no annotation) the literal defaulted to i32 — silently TRUNCATING
|
||||
* any value > 2^31 (5000000000 → 705032704) and striding arrays at 4.
|
||||
* wwstage kept the element as raw untyped_int (size 0), which sized
|
||||
* INCONSISTENTLY across cgen consumers: the array STORE strode the 8
|
||||
* sentinel (so the value width was right) but letslotsize under-
|
||||
* allocated the frame (SEGV) and cgindex strode the READ at 1 — so
|
||||
* `let a = [..]` SEGV'd on wwstage and the scalar ran correct only by
|
||||
* the 8B-store accident. The two stages were each wrong differently.
|
||||
*
|
||||
* THE FIX (one root, both stages, FUSE):
|
||||
* - cstage type.c type_default(TY_UNTYPED_INT) i32 -> int; the empty
|
||||
* arrlit fallback check.c ty_i32 -> ty_int (symmetric, count-0
|
||||
* neutral). int = machine word = 8B (Go-style; MEMORY
|
||||
* project_int_machine_word_derived_limits) — Hare lowers a flexible
|
||||
* iconst to `int`, never a fixed i32 (ref/harec/src/types.c:835).
|
||||
* - wwstage check.ww exprtype N_ARRLIT: default the inferred
|
||||
* element's UNTYPED flavor to its concrete type (untyped_int->int,
|
||||
* _float->f64, _str->str, _rune->rune, _bool->bool), the empty-elt
|
||||
* fallback "i32"->"int", and stamp the synthesized N_TARRAY's
|
||||
* .type_ — so slotsize / elemsizeofc / letslotsize all read its
|
||||
* real [N]int size (32 for [4]int), routing through the type table
|
||||
* (rule-13) instead of the nil/0/sentinel fallbacks. SSoT — no
|
||||
* letslotsize special-case.
|
||||
*
|
||||
* POLARITY TEETH: the wide rows use 5000000000 ( > 2^31). A small-value
|
||||
* row would pass both stages by luck (gate-blind); only a > 2^31 value
|
||||
* distinguishes the truncating i32 default from the correct int.
|
||||
*
|
||||
* COVERAGE — the two direct repros plus the FIVE corpus movers ken's v2
|
||||
* re-census named (each converges 0/0 byte-id + run-correct, NONE
|
||||
* both-wrong): m2_while (#108 scalar, alias-bool loop), m8_range1/2
|
||||
* (#104 for-range elem over alias / 2-level-alias array), m8_slice1/2
|
||||
* (#103 SEGV + slice-init acceptance over alias / 2-level-alias slice).
|
||||
* Plus the annotated controls [4]i32 (stride-4) and [4]int (stride-8),
|
||||
* which the fix must leave byte-identical — it touches ONLY the inferred
|
||||
* untyped default, never an explicit element type.
|
||||
*
|
||||
* row | shape | want
|
||||
* -----------------+---------------------------------------------+-----
|
||||
* arr_wide | let a=[5e9,2,3,4]; a[0]==5e9 && a[3]==4 | 0
|
||||
* scalar_wide | let x=5e9; x==5e9 (#108 teeth) | 0
|
||||
* arr_small | let a=[10,20,30,40]; a[2] | 30
|
||||
* m2_while | #108 scalar via alias-bool loop counter | 0
|
||||
* m8_range1 | #104 for-range elem over alias [4]int | 0
|
||||
* m8_range2 | #104 for-range elem over 2-level-alias | 0
|
||||
* m8_slice1 | #103 inferred a + slice s:sl=a[1:3] | 0
|
||||
* m8_slice2 | #103 + 2-level-alias slice + re-slice | 0
|
||||
* ctrl_i32 | let a:[4]i32=[1,2,3,4]; a[3] (stride-4) | 4
|
||||
* ctrl_int | let a:[4]int=[1,2,3,4]; a[3] (stride-8) | 4
|
||||
*
|
||||
* EACH ROW CARRIES THREE DIMENSIONS (684/802 model):
|
||||
* (a) cstage `ww build` + run, asserting the exit — pins the converged
|
||||
* asm is runtime-correct (real values, no truncation/SEGV).
|
||||
* (b) wwstage `ww_ww build` + run (gated on w6c_ww) — pins the ww SEGV
|
||||
* is gone and the value round-trips.
|
||||
* (c) w6c vs w6c_ww `.s` cmp — FAILS if the stages diverge (rule-10).
|
||||
*
|
||||
* GATE POLARITY: must stay GREEN. A wrong exit means the inferred
|
||||
* default regressed to a truncating/under-strided type; a byte-id FAIL
|
||||
* means the stages diverged.
|
||||
*/
|
||||
#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;
|
||||
}
|
||||
|
||||
struct row { const char *label; const char *src; int want; };
|
||||
|
||||
static const struct row rows[] = {
|
||||
/* #103 array, > 2^31 element — truncation + frame teeth. */
|
||||
{ "arr_wide",
|
||||
"package main;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
"\tlet a = [5000000000, 2, 3, 4];\n"
|
||||
"\tif (a[0] != 5000000000) { return 1; };\n"
|
||||
"\tif (a[3] != 4) { return 2; };\n"
|
||||
"\treturn 0;\n"
|
||||
"};\n",
|
||||
0 },
|
||||
|
||||
/* #108 scalar, > 2^31 — the cstage general truncation teeth. */
|
||||
{ "scalar_wide",
|
||||
"package main;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
"\tlet x = 5000000000;\n"
|
||||
"\tif (x != 5000000000) { return 1; };\n"
|
||||
"\treturn 0;\n"
|
||||
"};\n",
|
||||
0 },
|
||||
|
||||
/* basic inferred array — frame + stride sanity (mutation: a wrong
|
||||
* stride/slot reads a neighbouring word, not 30). */
|
||||
{ "arr_small",
|
||||
"package main;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
"\tlet a = [10, 20, 30, 40];\n"
|
||||
"\treturn a[2]: i32;\n"
|
||||
"};\n",
|
||||
30 },
|
||||
|
||||
/* corpus mover m2_while (#108 scalar via an alias-bool loop). */
|
||||
{ "m2_while",
|
||||
"package main;\n"
|
||||
"type myb = bool;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
"\tlet b: myb = true;\n"
|
||||
"\tlet i = 0;\n"
|
||||
"\tfor (b) {\n"
|
||||
"\t\ti = i + 1;\n"
|
||||
"\t\tif (i >= 3) { b = false; };\n"
|
||||
"\t};\n"
|
||||
"\tif (i != 3) { return 1; };\n"
|
||||
"\treturn 0;\n"
|
||||
"};\n",
|
||||
0 },
|
||||
|
||||
/* corpus mover m8_range1 (#104 for-range elem over alias array). */
|
||||
{ "m8_range1",
|
||||
"package main;\n"
|
||||
"type arr = [4]int;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
"\tlet a: arr = [1, 2, 3, 4];\n"
|
||||
"\tlet sum = 0;\n"
|
||||
"\tfor (let x .. a) {\n"
|
||||
"\t\tsum = sum + x;\n"
|
||||
"\t};\n"
|
||||
"\tif (sum != 10) { return 1; };\n"
|
||||
"\treturn 0;\n"
|
||||
"};\n",
|
||||
0 },
|
||||
|
||||
/* corpus mover m8_range2 (#104 for-range elem over 2-level alias). */
|
||||
{ "m8_range2",
|
||||
"package main;\n"
|
||||
"type arr = [4]int;\n"
|
||||
"type arr2 = arr;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
"\tlet a: arr2 = [1, 2, 3, 4];\n"
|
||||
"\tlet sum = 0;\n"
|
||||
"\tfor (let x .. a) {\n"
|
||||
"\t\tsum = sum + x;\n"
|
||||
"\t};\n"
|
||||
"\tif (sum != 10) { return 1; };\n"
|
||||
"\treturn 0;\n"
|
||||
"};\n",
|
||||
0 },
|
||||
|
||||
/* corpus mover m8_slice1 (#103 inferred array + alias-slice init). */
|
||||
{ "m8_slice1",
|
||||
"package main;\n"
|
||||
"type sl = []int;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
"\tlet a = [10, 20, 30, 40];\n"
|
||||
"\tlet s: sl = a[1:3];\n"
|
||||
"\tif (s.len != 2) { return 1; };\n"
|
||||
"\tif (s[0] != 20) { return 2; };\n"
|
||||
"\tif (s[1] != 30) { return 3; };\n"
|
||||
"\treturn 0;\n"
|
||||
"};\n",
|
||||
0 },
|
||||
|
||||
/* corpus mover m8_slice2 (#103 + 2-level-alias slice + re-slice). */
|
||||
{ "m8_slice2",
|
||||
"package main;\n"
|
||||
"type sl = []int;\n"
|
||||
"type sl2 = sl;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
"\tlet a = [10, 20, 30, 40];\n"
|
||||
"\tlet s: sl2 = a[1:3];\n"
|
||||
"\tif (s.len != 2) { return 1; };\n"
|
||||
"\tif (s[0] != 20) { return 2; };\n"
|
||||
"\tlet t = s[0:1];\n"
|
||||
"\tif (t[0] != 20) { return 3; };\n"
|
||||
"\treturn 0;\n"
|
||||
"};\n",
|
||||
0 },
|
||||
|
||||
/* CONTROL: annotated [4]i32 — must stay i32/stride-4, byte-id,
|
||||
* UNTOUCHED by the inferred-default fix. */
|
||||
{ "ctrl_i32",
|
||||
"package main;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
"\tlet a: [4]i32 = [1, 2, 3, 4];\n"
|
||||
"\treturn a[3];\n"
|
||||
"};\n",
|
||||
4 },
|
||||
|
||||
/* CONTROL: annotated [4]int — int/stride-8, byte-id. */
|
||||
{ "ctrl_int",
|
||||
"package main;\n"
|
||||
"export fn main() i32 = {\n"
|
||||
"\tlet a: [4]int = [1, 2, 3, 4];\n"
|
||||
"\treturn a[3]: i32;\n"
|
||||
"};\n",
|
||||
4 },
|
||||
};
|
||||
|
||||
static int
|
||||
run_driver(const char *driver, const struct row *r, int i)
|
||||
{
|
||||
char src[64], tmpdir[80], cmd[1024];
|
||||
snprintf(src, sizeof src, "/tmp/aie_%d_%d.ww", getpid(), i);
|
||||
snprintf(tmpdir, sizeof tmpdir, "/tmp/aie_%d_d_%d", getpid(), i);
|
||||
|
||||
FILE *f = fopen(src, "wb");
|
||||
if (!f) return -1;
|
||||
fputs(r->src, f);
|
||||
fclose(f);
|
||||
|
||||
mkdir(tmpdir, 0755);
|
||||
snprintf(cmd, sizeof cmd, "cd %s && %s build %s 2>/dev/null",
|
||||
tmpdir, driver, src);
|
||||
if (runwait(cmd) != 0) {
|
||||
fprintf(stderr, "row[%s]: build via %s failed\n",
|
||||
r->label, driver);
|
||||
unlink(src); rmdir(tmpdir);
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *base = strrchr(src, '/');
|
||||
base = base ? base + 1 : src;
|
||||
char outbin[160];
|
||||
snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base);
|
||||
char *dot = strrchr(outbin, '.');
|
||||
if (dot && strcmp(dot, ".ww") == 0) *dot = '\0';
|
||||
int got = runwait(outbin);
|
||||
|
||||
unlink(src); unlink(outbin); rmdir(tmpdir);
|
||||
return got;
|
||||
}
|
||||
|
||||
/* asm_byte_identical — w6c vs w6c_ww .s for the same source must match. */
|
||||
static int
|
||||
asm_byte_identical(const char *bin, const struct row *r, int i)
|
||||
{
|
||||
char src[64], cs[72], ws[72], cmd[1024];
|
||||
snprintf(src, sizeof src, "/tmp/aie_asm_%d_%d.ww", getpid(), i);
|
||||
snprintf(cs, sizeof cs, "/tmp/aie_asm_%d_%d_c.s", getpid(), i);
|
||||
snprintf(ws, sizeof ws, "/tmp/aie_asm_%d_%d_w.s", getpid(), i);
|
||||
|
||||
FILE *f = fopen(src, "wb");
|
||||
if (!f) return -1;
|
||||
fputs(r->src, f);
|
||||
fclose(f);
|
||||
|
||||
snprintf(cmd, sizeof cmd, "%s/w6c -o %s %s 2>/dev/null", bin, cs, src);
|
||||
if (runwait(cmd) != 0) {
|
||||
fprintf(stderr, "row[%s]: w6c errored\n", r->label);
|
||||
unlink(src);
|
||||
return -1;
|
||||
}
|
||||
snprintf(cmd, sizeof cmd, "%s/w6c_ww -o %s %s 2>/dev/null",
|
||||
bin, ws, src);
|
||||
if (runwait(cmd) != 0) {
|
||||
fprintf(stderr, "row[%s]: w6c_ww errored\n", r->label);
|
||||
unlink(src); unlink(cs);
|
||||
return -1;
|
||||
}
|
||||
|
||||
FILE *fc = fopen(cs, "rb");
|
||||
FILE *fw = fopen(ws, "rb");
|
||||
int rc = 0;
|
||||
if (!fc || !fw) {
|
||||
rc = -1;
|
||||
} else {
|
||||
for (;;) {
|
||||
int a = fgetc(fc);
|
||||
int b = fgetc(fw);
|
||||
if (a != b) { rc = -1; break; }
|
||||
if (a == EOF) break;
|
||||
}
|
||||
}
|
||||
if (fc) fclose(fc);
|
||||
if (fw) fclose(fw);
|
||||
if (rc != 0)
|
||||
fprintf(stderr, "row[%s]: cstage vs wwstage asm differs\n",
|
||||
r->label);
|
||||
unlink(src); unlink(cs); unlink(ws);
|
||||
return rc;
|
||||
}
|
||||
|
||||
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[1100], wdrv[1100];
|
||||
snprintf(cdrv, sizeof cdrv, "%s/ww", bin);
|
||||
snprintf(wdrv, sizeof wdrv, "%s/ww_ww", bin);
|
||||
|
||||
struct { const char *name; const char *path; int gated; }
|
||||
drivers[] = {
|
||||
{ "cstage", cdrv, 0 },
|
||||
{ "wwstage", wdrv, 1 },
|
||||
{ NULL, NULL, 0 },
|
||||
};
|
||||
|
||||
int n = (int)(sizeof rows / sizeof rows[0]);
|
||||
int total = 0, fail = 0;
|
||||
|
||||
for (int d = 0; drivers[d].name; d++) {
|
||||
if (drivers[d].gated && access(drivers[d].path, X_OK) != 0) {
|
||||
fprintf(stderr, "arrlit_infer_elem: skip %s (no %s)\n",
|
||||
drivers[d].name, drivers[d].path);
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < n; i++) {
|
||||
int got = run_driver(drivers[d].path, &rows[i], i);
|
||||
total++;
|
||||
if (got != rows[i].want) {
|
||||
fprintf(stderr,
|
||||
"arrlit_infer_elem[%s][%s]: exit=%d want=%d\n",
|
||||
drivers[d].name, rows[i].label,
|
||||
got, rows[i].want);
|
||||
fail++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (access(wdrv, X_OK) == 0) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
total++;
|
||||
if (asm_byte_identical(bin, &rows[i], i) != 0)
|
||||
fail++;
|
||||
}
|
||||
}
|
||||
|
||||
if (fail) {
|
||||
fprintf(stderr,
|
||||
"arrlit_infer_elem: %d/%d fixtures failed\n", fail, total);
|
||||
return 1;
|
||||
}
|
||||
printf("arrlit_infer_elem: %d/%d ok\n", total, total);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user