selfhost+lib+test: route cgcall + nodeis{slice,str} N_DOT through fnretlookupmod (#34)
Class A silent miscompile, surfaced by landing strings.slice in Hare's natural delegation form `fromutf8_unsafe(utf8.slice(begin, end))` (ref/hare/strings/iter.ha:75). strings.slice itself returns str, so the inner utf8.slice (cross-module N_DOT) call's cgcall return-ABI fixup hit post-#4e fnretlookup's same-module-first walk and grabbed strings.slice's own str return — emitted a spurious `MOVQ DX, BX` after the cross-module CALL even though utf8.slice returns []u8 (selfhost/cmd/wcc/cgenexpr.ww cgcall return-ABI fixup, line 3249-3261 pre-fix). Every other consumer of cgcall:3249's str-shuffle decision sat on the same bare-leaf table and was silently miscompiling on the same collision shape pre-#34. Sibling: nodeisslice + nodeisstr N_CALL arms in selfhost/cmd/wcc/cgenutil.ww were N_IDENT-only — for a cross- module N_DOT call returning a slice or str, pushargsrev fell through to the natural 1-word PUSHQ AX, dropping the `.len` (and `.cap` for slices) of the return value when consumed as a call arg. strings.slice's body passes utf8.slice's []u8 result to fromutf8_unsafe; pre-fix wwstage pushed 1 word vs cstage's 3, breaking the receiver's slice-3-pop drain. Cstage carries no sister bug: cmd/w6c/cgen.c reads return shape from the typed `n->lhs->type` (TY_FN sig) for both str-shuffle and slice-/str-arg push counts — module-aware via the typed AST, sidestepping any bare-leaf table. Mirror of #4e's cstage-no- sister-bug note. Fix: route cgcall return-ABI fixup + nodeisslice/nodeisstr N_CALL arms through fnretlookupmod with `callee.lhs.str` (N_DOT qualifier) or `c.curmod` (N_IDENT). Mirror of #28 fnparamslookupmod / #31 fnretlookupmod N_DOT re-routing. Remaining bare-leaf fnretlookup consumer sites (~8 sites across cgenexpr/cgenutil/cgenstmt/cgendecl listed in task #34a) stay on the graduated bare-leaf path — none of the present-corpus N_DOT leaf collisions have return-shape divergence at those sites. A future stdlib port introducing a return-shape-divergent same-leaf N_DOT collision will need the *mod re-routing — filed as #34a sibling-latents. Bundled three concerns per rule 11: cgcall fix, nodeisslice/ nodeisstr fix, and strings.slice retire + sentinel. (a) alone leaves strings.slice byte-id breaking on slice-arg push count. (b) alone leaves a phantom MOVQ DX, BX on the inner cross- module CALL. (c) alone fails 995_self_rebuild without (a)+(b). The three cannot land separately bisect-cleanly; the 745 sentinel pins the primary repro (cgcall str-shuffle) which sentinel-flips on a cgcall:3257 revert. 745_fnret34_modshadow pins the fix with 1 row: caller.slice returns str (same leaf as the cross-module callee, divergent return shape); caller.run calls myutf8.slice returning []u8. Asserts CALL myutf8.slice present inside caller.run TEXT + `MOVQ DX, BX` anti-check on each stage plus cs-vs-ws byte-id. strings.slice retired in lib/strings/strings.ww: the deferral block becomes the natural Hare delegation form with two local utf8.decoder reconstructions for the iterator endpoints — ww has no anonymous-embed (parallel to the existing `move` helper). iter_slice_cases mirrors ref/hare/strings/iter.ha:110-127; sidesteps the Hare `let t = s;` iterator-copy via fresh strings.iter() to stay clear of #35's sibling latents. 119/119 ok. ww2 == ww3 == ww4 byte-id holds.
This commit is contained in:
@@ -513,6 +513,50 @@ fn streq(a: str, b: str) bool = {
|
||||
if (strings.position(&it) != 5) { fail(); };
|
||||
};
|
||||
|
||||
// ref/hare/strings/iter.ha:110 @test fn slice. Hare uses `let t = s;`
|
||||
// to copy the iterator; ww re-initialises t from the same source to
|
||||
// stay in scope of #32 (local struct ident rhs already fixed) without
|
||||
// reaching for #35's sibling latents.
|
||||
@test fn iter_slice_cases() void = {
|
||||
let s: strings.iterator = strings.iter("こんにちは");
|
||||
let t: strings.iterator = strings.iter("こんにちは");
|
||||
if (strings.slice(&s, &t).len != 0) { fail(); };
|
||||
if (strings.slice(&t, &s).len != 0) { fail(); };
|
||||
let i: i32 = 0;
|
||||
for (i < 2) {
|
||||
match (strings.next(&s)) {
|
||||
case let r: rune => void;
|
||||
case utf8.done => { fail(); };
|
||||
};
|
||||
match (strings.next(&t)) {
|
||||
case let r: rune => void;
|
||||
case utf8.done => { fail(); };
|
||||
};
|
||||
i += 1;
|
||||
};
|
||||
if (strings.slice(&s, &t).len != 0) { fail(); };
|
||||
if (strings.slice(&t, &s).len != 0) { fail(); };
|
||||
i = 0;
|
||||
for (i < 3) {
|
||||
match (strings.next(&t)) {
|
||||
case let r: rune => void;
|
||||
case utf8.done => { fail(); };
|
||||
};
|
||||
i += 1;
|
||||
};
|
||||
if (!streq(strings.slice(&s, &t), "にちは")) { fail(); };
|
||||
i = 0;
|
||||
for (i < 3) {
|
||||
match (strings.next(&s)) {
|
||||
case let r: rune => void;
|
||||
case utf8.done => { fail(); };
|
||||
};
|
||||
i += 1;
|
||||
};
|
||||
if (strings.slice(&s, &t).len != 0) { fail(); };
|
||||
if (strings.slice(&t, &s).len != 0) { fail(); };
|
||||
};
|
||||
|
||||
@test fn iter_iterstr_reverse_cases() void = {
|
||||
// Reverse iter: iterstr is `src[0:offs]` — bytes BEFORE the cursor
|
||||
// (the still-to-be-walked region in reverse direction).
|
||||
@@ -552,5 +596,6 @@ export fn main() i32 = {
|
||||
signalled = 24; iter_full_cases();
|
||||
signalled = 25; iter_position_cases();
|
||||
signalled = 26; iter_iterstr_reverse_cases();
|
||||
signalled = 27; iter_slice_cases();
|
||||
return 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user