Commit 4d4bf30f

4d4bf30fe841Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified

Description

Skip dispatch arms whose target method body was never emitted

A class specialized into per-.new-site _implicit_NNNN variants is a "template": its own instance-method bodies are pruned (emit_class_methods gates them on implicit_specialization_template_class?) because the live variants carry their own. But the cls_id dispatch switch still enumerated the template base as a case, calling sp_ -- a function never declared or defined. C defaults the undeclared call to int, so the dispatch result slot (sp_RbVal / sp_StrArray * / ...) fails to compile. This was the dominant failure on roundhouse's compare-spinel / toolchain-spinel CI.

Filter those arms at the single chokepoint every dispatch builder shares, cls_method_override_descendants: drop a candidate whose body owner has no emitted body. The new cls_method_body_emitted? mirrors the emission gates exactly -- cls_emit_skipped for any class, plus the template prune for instance methods only (class-method bodies are not template-pruned, so their arms stay). The pruned template base's cls_id never labels a live object, so removing its dead arm changes no behavior.

Verified on the roundhouse real-blog reproducer: the emitted C no longer calls the pruned sp_Article_before_destroy / sp_Article_validate, the 12 live _implicit* variant arms are kept, and the one surviving template case is a class method whose body is emitted. Gate green (test/bench/optcarrot/self-host fixpoint).

Fixes #1344.

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
4d4bf30fe841
Parent
b6cb8ddcea88

spinel_codegen.rbmodifiedView file

@@ -2889,13 +2889,36 @@
28892889 # encoded `<descendant_ci>,<owner_ci>` separated by `;`. Empty
28902890 # string when no overrides exist (caller stays on the
28912891 # static-dispatch path). `kind` is "cmeth" or "imeth".
2892+ # Whether the body the dispatch arm would call (`sp_<class>_<mname>`,
2893+ # or `_cls_<mname>` for class methods) is actually emitted, mirroring
2894+ # the gates in emit_class_methods: a class skipped wholesale
2895+ # (cls_emit_skipped) emits no bodies, and an *instance* method on a
2896+ # class specialized into `__implicit_*` variants
2897+ # (implicit_specialization_template_class?) is pruned -- the live
2898+ # variants carry their own bodies and the template base's own bodies
2899+ # are never emitted. Class-method bodies are not pruned that way.
2900+ # Used to drop dispatch cases whose target body was never emitted,
2901+ # which would otherwise call an undeclared function. Issue #1344.
2902+ def cls_method_body_emitted?(ci, kind)
2903+ if ci < 0 || ci >= @cls_names.length
2904+ return 0
2905+ end
2906+ if cls_emit_skipped(ci) == 1
2907+ return 0
2908+ end
2909+ if kind != "cmeth" && implicit_specialization_template_class?(ci) == 1
2910+ return 0
2911+ end
2912+ 1
2913+ end
2914+
28922915 def cls_method_override_descendants(inner_ci, base_owner, mname, kind)
28932916 out = ""
28942917 ck = 0
28952918 while ck < @cls_names.length
28962919 if ck == inner_ci || cls_is_descendant(ck, inner_ci) == 1
28972920 ow = cls_method_owner_for(ck, mname, kind)
2898- if ow >= 0 && ow != base_owner
2921+ if ow >= 0 && ow != base_owner && cls_method_body_emitted?(ow, kind) == 1
28992922 if out != ""
29002923 out = out + ";"
29012924 end