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
# encoded `<descendant_ci>,<owner_ci>` separated by `;`. Empty # string when no overrides exist (caller stays on the # static-dispatch path). `kind` is "cmeth" or "imeth". # Whether the body the dispatch arm would call (`sp_<class>_<mname>`, # or `_cls_<mname>` for class methods) is actually emitted, mirroring # the gates in emit_class_methods: a class skipped wholesale # (cls_emit_skipped) emits no bodies, and an *instance* method on a # class specialized into `__implicit_*` variants # (implicit_specialization_template_class?) is pruned -- the live # variants carry their own bodies and the template base's own bodies # are never emitted. Class-method bodies are not pruned that way. # Used to drop dispatch cases whose target body was never emitted, # which would otherwise call an undeclared function. Issue #1344. def cls_method_body_emitted?(ci, kind) if ci < 0 || ci >= @cls_names.length return 0 end if cls_emit_skipped(ci) == 1 return 0 end if kind != "cmeth" && implicit_specialization_template_class?(ci) == 1 return 0 end 1 end def cls_method_override_descendants(inner_ci, base_owner, mname, kind) out = "" ck = 0 while ck < @cls_names.length if ck == inner_ci || cls_is_descendant(ck, inner_ci) == 1 ow = cls_method_owner_for(ck, mname, kind) if ow >= 0 && ow != base_owner if ow >= 0 && ow != base_owner && cls_method_body_emitted?(ow, kind) == 1 if out != "" out = out + ";" end