Commit bc14d977
bc14d9772da5Merged
Yusuke Endoh <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
fix(codegen): truncate extra args in poly-dispatch arms
The arity-padding logic (which pads missing trailing slots so each
arm matches its target's fixed C arity) didn't handle the opposite
case: when the call site supplies more args than a candidate
class's method accepts. With several classes sharing a method name
but disagreeing on parameter count, those over-arity arms emitted
sp_<Class>_<m>(... too_many_args) and the C compile failed even
though the runtime cls_id check would skip the wrong arm.
Rebuild arm_arg_strs from arg_compiled per arm, taking the call
site's arg at slot k when present and padding/truncating around the
target's arm_ptypes.length. Each arm now compiles with exactly
the shape its target signature demands.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- bc14d9772da5
- Parent
- a8c8ac8156dc
spinel_codegen.rbmodifiedView file
cname = @cls_names[i] midx = cls_find_method_direct(i, mname) if midx >= 0 # Pad with default-typed zeros when target method has more # params than the call site supplied — same shape that C # demands at every fixed-arity call. Per-arm padding lets us # poly-dispatch `recv.m()` even when one of the candidate # classes has a method that takes positional defaults. arm_arg_strs = arg_strs # Match each arm to the target method's *fixed* C arity: # pad missing trailing slots with default-typed zeros, and # truncate extras (when the call site supplies more args than # this candidate accepts — happens when several classes share # the method name but disagree on parameter count). arm_arg_strs = "" all_ptypes = @cls_meth_ptypes[i].split("|") arm_ptypes = "".split(",") if midx < all_ptypes.length arm_ptypes = all_ptypes[midx].split(",") pk = arg_compiled.length while pk < arm_ptypes.length end pk = 0 while pk < arm_ptypes.length if pk < arg_compiled.length arm_arg_strs = arm_arg_strs + ", " + arg_compiled[pk] else pad = "0" pt_base = base_type(arm_ptypes[pk]) if pt_base == "poly" pad = "sp_box_nil()" end arm_arg_strs = arm_arg_strs + ", " + pad pk = pk + 1 end pk = pk + 1 end call_expr = "sp_" + cname + "_" + sanitize_name(mname) + "((sp_" + cname + " *)" + recv_tmp + ".v.p" + arm_arg_strs + ")" rhs = call_exprtest/poly_dispatch_arity_truncate.rbaddedView file
Loading diff…