Commit 13f741ed
13f741ed400bMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(codegen): poly-recv user-class dispatch consults ivar narrow set
compile_poly_method_call's SP_TAG_OBJ user-class dispatch loop
iterated every class in @cls_names and emitted an arm for any class
that defined the method by name. The companion helper
poly_dispatch_narrow_class_set already exists in compiler_helpers
(and is consulted by poly_dispatch_return_type for the result-type
union) but the emit loop missed the matching skip.
Effect: when the receiver is an ivar read whose observed types are entirely concrete obj_ entries, dispatch arms for unrelated classes that happen to share the method name are now dropped. The result-type union shrinks correspondingly, so a non-overlapping return type on one of those arms no longer widens the result temp to sp_RbVal and trips downstream type-strict consumers.
Standalone this patch fixes the dispatch when ivar observations are sharp; the canonical #575 repro still needs a follow-up because @worker's observations widen to "poly" before reaching here (the ivar's writer is a method param whose type is the unified union of callsite arg types — that union loses the concrete obj_X classes). The analyzer-side forward-propagation pass that recovers the concrete set is the next commit.
Refs #575. 586 tests pass / bootstrap fixpoint clean.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 13f741ed400b
- Parent
- aa800fe35c0b
spinel_codegen.rbmodifiedView file
emit(" if (" + recv_tmp + ".tag == SP_TAG_STR) " + tmp + " = " + sinc_rhs + ";") end emit(" if (" + recv_tmp + ".tag == SP_TAG_OBJ) {") # User-class dispatch # User-class dispatch. Narrow the candidate set when the recv # is an ivar whose observed types are entirely concrete obj_<C> # entries — the runtime value can only be an instance of one # of those classes, so dispatch arms for unrelated classes # that happen to share the method name are unreachable. # Without this filter, Issue #575 surfaces: a same-named method # on a class never assigned to the ivar (e.g. an Unrelated#run # with zero args returning int when the ivar only ever sees # Worker#run(item) returning string) widens the dispatch # result temp to sp_RbVal and trips downstream type-strict # consumers (sp_file_write etc.). The return-type union in # poly_dispatch_return_type already consults this set; the # emit loop just needed the matching skip. dispatch_narrow_set = poly_dispatch_narrow_class_set(nid) i = 0 while i < @cls_names.length if dispatch_narrow_set != "" && poly_dispatch_class_in_set(dispatch_narrow_set, i) == 0 i = i + 1 next end cname = @cls_names[i] midx = cls_find_method_direct(i, mname) owner_idx = i