wcc: typeeqast TY_FN compares result/params/variadic at AST layer (#94 fold-b)
Pre-fix master left N_TFN under typeeqast's conservative
"anything else fails" tail (selfhost/cmd/wcc/check.ww:748-751).
case-patterns spelled with a raw `*fn(...)` head — the io vtable
use case — tripped casevariantin / casecovers on every variant
compare, so a well-typed `match (v: tagged-of-fn-ptr) { case
*fn(...) => ... }` would not compile under wwstage.
Adds a TY_FN arm that mirrors harec STORAGE_FUNCTION
(ref/harec/src/types.c:589-615): recurse on the result type
(.lhs), iterate the param chain (.list of N_PARAM, descend each
.lhs), require the variadic flag (.op == TK_ELLIPSIS) to match
position-by-position, and require both chains to terminate
together. Param NAMES do not participate (harec analog), and the
C-variadic terminal sentinel (N_PARAM with .str == "...") is
handled defensively even though wwstage's parseparams doesn't
currently produce it. Attributes + default-param values are NOT
checked (drew-pre-approved, harec doesn't either).
cstage type.c:239's type_eq walks the same shape on the resolved
Type. typeeqast lives one layer below — a documented divergence
filed as project #178 for the harmonization fold; the in-source
comment cites #178.
Probe 763_typeeq_fn_ast.c locks 7 rows covering identical /
diff-return / diff-arity / diff-param-type / variadic / param-
name-only / io-vtable shapes across cstage + wwstage (14
fixtures). Pre-fix wwstage red-errors every row at the checker
("case: not a variant of scrutinee" + "match: variant not
handled"); post-fix all 14 compile and the tag-0 arm fires
(exit 7). Per-row .s byte-id is intentionally NOT gated — see
the probe header for the cgmatch N_TPTR-not-routed-to-
flatvariantidx sibling bug that drives the divergence on rows
b/c/d/e/g; orthogonal to this AST-layer typeeqast fold and not
swept per the brief's "do not sweep" instruction.
This commit is contained in:
@@ -10775,9 +10775,31 @@ fn typeeqast(a: *node, b: *node) bool = {
|
||||
if (k == nkind.N_TPTR) { return typeeqast(aa.lhs, bb.lhs); };
|
||||
if (k == nkind.N_TSLICE){ return typeeqast(aa.lhs, bb.lhs); };
|
||||
if (k == nkind.N_TCHAN) { return typeeqast(aa.lhs, bb.lhs); };
|
||||
// Conservative: anything else (struct/fn/tagged/tuple/array)
|
||||
// fails the cheap check. Selfhost code doesn't currently rely
|
||||
// on equality at these shapes for the targeted checks.
|
||||
if (k == nkind.N_TFN) {
|
||||
// Divergence: cstage type.c:239 compares resolved Type; we
|
||||
// compare AST. See #178.
|
||||
if (!typeeqast(aa.lhs, bb.lhs)) { return false; };
|
||||
let pa: *node = aa.list;
|
||||
let pb: *node = bb.list;
|
||||
for (pa != nil) {
|
||||
if (pb == nil) { return false; };
|
||||
let ac: bool = streq(pa.str, "...");
|
||||
let bc: bool = streq(pb.str, "...");
|
||||
if (ac != bc) { return false; };
|
||||
if (!ac) {
|
||||
let va: bool = pa.op == tkind.TK_ELLIPSIS;
|
||||
let vb: bool = pb.op == tkind.TK_ELLIPSIS;
|
||||
if (va != vb) { return false; };
|
||||
if (!typeeqast(pa.lhs, pb.lhs)) { return false; };
|
||||
};
|
||||
pa = pa.next;
|
||||
pb = pb.next;
|
||||
};
|
||||
return pb == nil;
|
||||
};
|
||||
// Conservative: anything else (struct/tagged/tuple/array) fails
|
||||
// the cheap check. Selfhost code doesn't currently rely on
|
||||
// equality at these shapes for the targeted checks.
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
@@ -745,9 +745,31 @@ fn typeeqast(a: *node, b: *node) bool = {
|
||||
if (k == nkind.N_TPTR) { return typeeqast(aa.lhs, bb.lhs); };
|
||||
if (k == nkind.N_TSLICE){ return typeeqast(aa.lhs, bb.lhs); };
|
||||
if (k == nkind.N_TCHAN) { return typeeqast(aa.lhs, bb.lhs); };
|
||||
// Conservative: anything else (struct/fn/tagged/tuple/array)
|
||||
// fails the cheap check. Selfhost code doesn't currently rely
|
||||
// on equality at these shapes for the targeted checks.
|
||||
if (k == nkind.N_TFN) {
|
||||
// Divergence: cstage type.c:239 compares resolved Type; we
|
||||
// compare AST. See #178.
|
||||
if (!typeeqast(aa.lhs, bb.lhs)) { return false; };
|
||||
let pa: *node = aa.list;
|
||||
let pb: *node = bb.list;
|
||||
for (pa != nil) {
|
||||
if (pb == nil) { return false; };
|
||||
let ac: bool = streq(pa.str, "...");
|
||||
let bc: bool = streq(pb.str, "...");
|
||||
if (ac != bc) { return false; };
|
||||
if (!ac) {
|
||||
let va: bool = pa.op == tkind.TK_ELLIPSIS;
|
||||
let vb: bool = pb.op == tkind.TK_ELLIPSIS;
|
||||
if (va != vb) { return false; };
|
||||
if (!typeeqast(pa.lhs, pb.lhs)) { return false; };
|
||||
};
|
||||
pa = pa.next;
|
||||
pb = pb.next;
|
||||
};
|
||||
return pb == nil;
|
||||
};
|
||||
// Conservative: anything else (struct/tagged/tuple/array) fails
|
||||
// the cheap check. Selfhost code doesn't currently rely on
|
||||
// equality at these shapes for the targeted checks.
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
@@ -10775,9 +10775,31 @@ fn typeeqast(a: *node, b: *node) bool = {
|
||||
if (k == nkind.N_TPTR) { return typeeqast(aa.lhs, bb.lhs); };
|
||||
if (k == nkind.N_TSLICE){ return typeeqast(aa.lhs, bb.lhs); };
|
||||
if (k == nkind.N_TCHAN) { return typeeqast(aa.lhs, bb.lhs); };
|
||||
// Conservative: anything else (struct/fn/tagged/tuple/array)
|
||||
// fails the cheap check. Selfhost code doesn't currently rely
|
||||
// on equality at these shapes for the targeted checks.
|
||||
if (k == nkind.N_TFN) {
|
||||
// Divergence: cstage type.c:239 compares resolved Type; we
|
||||
// compare AST. See #178.
|
||||
if (!typeeqast(aa.lhs, bb.lhs)) { return false; };
|
||||
let pa: *node = aa.list;
|
||||
let pb: *node = bb.list;
|
||||
for (pa != nil) {
|
||||
if (pb == nil) { return false; };
|
||||
let ac: bool = streq(pa.str, "...");
|
||||
let bc: bool = streq(pb.str, "...");
|
||||
if (ac != bc) { return false; };
|
||||
if (!ac) {
|
||||
let va: bool = pa.op == tkind.TK_ELLIPSIS;
|
||||
let vb: bool = pb.op == tkind.TK_ELLIPSIS;
|
||||
if (va != vb) { return false; };
|
||||
if (!typeeqast(pa.lhs, pb.lhs)) { return false; };
|
||||
};
|
||||
pa = pa.next;
|
||||
pb = pb.next;
|
||||
};
|
||||
return pb == nil;
|
||||
};
|
||||
// Conservative: anything else (struct/tagged/tuple/array) fails
|
||||
// the cheap check. Selfhost code doesn't currently rely on
|
||||
// equality at these shapes for the targeted checks.
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user