w6c_ww: cgtypetest nullable is discriminates pointer-vs-null (#45 review)
The #45 non-ident arm tag-compared the word in AX against the variant index; for the nullable (*T | void) fold that word IS the pointer — `h.m is *t` on a non-null pointer answered FALSE (silent cs≠ww, cstage correct: CMPQ $0 + JE/JNE polarity per cgen.c N_TYPETEST). The ident path had the same missing nullable arm since before #45 (pre-existing at master, unexercised in the bootstrap corpus). One nullable branch at the shared compare choke-point closes both halves: want stays RAW (cstage tests tag == ptr_tag unclamped, a no-match -1 takes the void polarity). Rows nullable_dot_field + nullable_ident pin both polarities and both states in 927; whole-corpus control (5 selfhost combined.ww, master-vs-branch w6c + w6c_ww) byte-id.
This commit is contained in:
@@ -426,12 +426,14 @@ fn cgtypetest(c: *cgen, n: *node) void = {
|
||||
};
|
||||
};
|
||||
let want: i32 = 0;
|
||||
let nullcarrier: *node = scrutt;
|
||||
if (nonident) {
|
||||
// Variant index from the STAMPED scrutinee type (cstage:
|
||||
// u = n->lhs->type) — matchscrutt's node-shape walk can't
|
||||
// carry N_DOT (returns the scrut node, which the
|
||||
// cgtagvariantidx N_TTAGGED gate rejects). flatvariantidx /
|
||||
// flatslicevariantidx read .type_ off any stamped carrier.
|
||||
nullcarrier = lhs;
|
||||
if (n.rhs != nil) {
|
||||
if (n.rhs.kind == nkind.N_TSLICE) {
|
||||
want = flatslicevariantidx(c, lhs, n.rhs.lhs);
|
||||
@@ -442,7 +444,6 @@ fn cgtypetest(c: *cgen, n: *node) void = {
|
||||
} else {
|
||||
want = cgtagvariantidx(c, scrutt, n.rhs);
|
||||
};
|
||||
if (want < 0) { want = 0; };
|
||||
if (!nonident) {
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff(scrutoff: i64);
|
||||
@@ -450,10 +451,25 @@ fn cgtypetest(c: *cgen, n: *node) void = {
|
||||
};
|
||||
let nel: str = mklabel(c, "is_ne");
|
||||
let dnl: str = mklabel(c, "is_done");
|
||||
emitline("\tCMPQ\t$");
|
||||
emitint(want: i64);
|
||||
emitline(", AX\n");
|
||||
emitline("\tJNE\t");
|
||||
if (isnullabletype(nullcarrier)) {
|
||||
// Nullable `(*T | void)` fold: the word in AX IS the
|
||||
// pointer — discriminate pointer-vs-null, not tag-vs-index
|
||||
// (cstage cgen.c N_TYPETEST nullable arm). `want` stays RAW
|
||||
// here: cstage tests tag == ptr_tag unclamped, so a
|
||||
// no-match (-1) takes the void polarity.
|
||||
emitline("\tCMPQ\t$0, AX\n");
|
||||
if (want == nullableptrtag(nullcarrier)) {
|
||||
emitline("\tJE\t");
|
||||
} else {
|
||||
emitline("\tJNE\t");
|
||||
};
|
||||
} else {
|
||||
if (want < 0) { want = 0; };
|
||||
emitline("\tCMPQ\t$");
|
||||
emitint(want: i64);
|
||||
emitline(", AX\n");
|
||||
emitline("\tJNE\t");
|
||||
};
|
||||
emitline(nel);
|
||||
emitline("\n\tMOVQ\t$1, AX\n\tJMP\t");
|
||||
emitline(dnl);
|
||||
|
||||
Reference in New Issue
Block a user