Commit 42c29318
42c29318732aMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
Re-pin RBS module-method ptypes post-fixpoint, fixing env-dependent hash over-specialization
A method declared in RBS under a module (e.g. the Hash[untyped, untyped]
params of a RequestDispatch helper mixed into a test class) could be emitted
with a concrete hash C type (sp_SymPolyHash *) on some build hosts while
correctly boxed to sp_RbVal on others -- identical source, arch, gcc and
LTO, differing only by host. The {}-default str_int_hash callers then
passed sp_StrIntHash * into the sp_SymPolyHash * param, the reported
incompatible-pointer mismatch.
Root cause: the RBS seed for a module method reaches the including class via
apply_rbs_seeds' module-include path, which depends on module_name_exists /
find_class_idx classifying the module header. When that classification is
dropped, the @cls_meth_rbs_ptypes entry is never created, so
arbitrate_rbs_vs_inferred_methods has nothing to restore and the
call-site-inferred concrete hash type sticks. Confirmed locally by forcing
the module header to misclassify (is_module=0): with --rbs the param
deterministically flips to sp_SymPolyHash *. valgrind on the analyze pass
is clean, consistent with a logic/ordering drop rather than an uninitialised
read; the exact host-specific trigger on the GH runner is not reproduced
locally.
Fix: record every seed meth line's declared ptypes/returns in a
module-keyed shadow table unconditionally (gated only on the header name, so
it survives module/class misclassification), and in
arbitrate_rbs_vs_inferred_methods re-pin them onto every including class
post-fixpoint -- when reconcile_class_includes has attached the include-copy
and cls_find_method_direct is reliable. This makes the RBS pin independent of
the fragile seed-time classification. No-op without --rbs (shadow stays
empty); the apply_rbs_seeds branch-merge is behavior-preserving for working
seeds (get/post/patch/delete still emit sp_RbVal).
Verified on the roundhouse repro: with the module header forced to
misclassify, dispatch_request's params flips sp_SymPolyHash * -> sp_RbVal
once the backstop is active, and a plain-gcc compile no longer reports the
SymPolyHash/StrIntHash mismatch. gate green (843 tests, optcarrot 59662,
self-host fixpoint OK). Note: the gate does not exercise the --rbs inference
path (rbs-test covers only the extractor), so this has no automated guard.
The deterministic over-specialization spinel still emits for this shape without --rbs is a separate inference-layer issue (cross-key-family hash param unification), left open as a sibling.
Refs #1303
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 42c29318732a
- Parent
- 058b8f2a4450
spinel_analyze.rbmodifiedView file
@cls_cmeth_rbs_returns = {} @meth_rbs_ptypes = {} @meth_rbs_returns = {} # Module-method RBS shadow, keyed "<ModuleName>\t<method>". Filled # for every seed `meth` line regardless of whether the header # resolved as a class/module at seed time, so # arbitrate_rbs_vs_inferred_methods can re-pin the declared ptypes # onto every including class post-fixpoint -- a backstop for the # non-deterministic seed-time drop where module_name_exists / # find_class_idx misclassifies the module header (the env-dependent # `Hash[untyped,untyped]` param over-specialization). A header that # is a real class (not included anywhere) simply never matches an # include list, so the extra entries are harmless. @module_meth_rbs_ptypes = {} @module_meth_rbs_returns = {} # Per-(class, cmeth) local scope tables. @nd_scope_names is # keyed by AST body id only; an inherited class method's body # is shared across subclasses, so the per-bid table gets elsif parts[0] == "ivar" && parts.length >= 3 && current_ci >= 0 seed_class_ivar(current_ci, parts[1], parts[2]) i = i + 1 elsif parts[0] == "meth" && parts.length >= 3 && current_ci >= 0 elsif parts[0] == "meth" && parts.length >= 3 && current_cls_name != "" mname = parts[1] ret = parts[2] ptypes_token = "-" if parts.length >= 4 ptypes_token = parts[3] end seed_class_method(current_ci, mname, ret, ptypes_token) i = i + 1 elsif parts[0] == "meth" && parts.length >= 3 && current_is_module == 1 # Record the declared signature under the header name # unconditionally, before the class-vs-module dispatch below. # arbitrate_rbs_vs_inferred_methods re-pins from this shadow # post-fixpoint, so the RBS pin survives even when the seed-time # classification here is wrong on this host (module_name_exists / # find_class_idx non-determinism). Class headers never match an # include list, so their entries stay inert. mkey = current_cls_name + "\t" + mname if ptypes_token != "-" && ptypes_token != "" @module_meth_rbs_ptypes[mkey] = ptypes_token end if ret != "-" && ret != "" @module_meth_rbs_returns[mkey] = ret end if current_ci >= 0 seed_class_method(current_ci, mname, ret, ptypes_token) elsif current_is_module == 1 # Module method seed: a class that includes this module ends # up with the method in its @cls_meth_* after # reconcile_class_includes. Seed each such class so the same # would only seed `class Dispatch` (which has no methods in # spinel's table) and the include-attached copy stayed at # collect_all's int defaults. Issue #613. mname_m = parts[1] ret_m = parts[2] ptypes_token_m = "-" if parts.length >= 4 ptypes_token_m = parts[3] end ck = 0 while ck < @cls_includes.length incs = @cls_includes[ck].split(";", -1) ik = 0 while ik < incs.length if incs[ik] == current_cls_name seed_class_method(ck, mname_m, ret_m, ptypes_token_m) ik = incs.length else ik = ik + 1 ck = 0 while ck < @cls_includes.length incs = @cls_includes[ck].split(";", -1) ik = 0 while ik < incs.length if incs[ik] == current_cls_name seed_class_method(ck, mname, ret, ptypes_token) ik = incs.length else ik = ik + 1 end end ck = ck + 1 end ck = ck + 1 end i = i + 1 elsif parts[0] == "cmeth" && parts.length >= 3 && current_cls_name != "" @cls_meth_return_cache = {} end } # Module-method backstop. Re-pin each RBS-declared module method # onto every class that includes the module, looking the method up # now (post-fixpoint) when reconcile_class_includes has attached the # include-copy and cls_find_method_direct's cache is stable. This # makes the RBS pin independent of the seed-time include-seed, which # is dropped non-deterministically on some hosts when # module_name_exists / find_class_idx misclassify the module header # -- the cause of the env-dependent `Hash[untyped,untyped]` param # over-specialization (sp_SymPolyHash* vs the str_int_hash callers). @module_meth_rbs_ptypes.each_pair { |mk, rbs_pt| mparts = mk.split("\t", -1) if mparts.length >= 2 modname = mparts[0] methname = mparts[1] ck = 0 while ck < @cls_includes.length incs = @cls_includes[ck].split(";", -1) if not_in(modname, incs) == 0 && ck < @cls_meth_ptypes.length midx = cls_find_method_direct(ck, methname) if midx >= 0 all_pt = @cls_meth_ptypes[ck].split("|", -1) if midx < all_pt.length && all_pt[midx] != rbs_pt all_pt[midx] = rbs_pt @cls_meth_ptypes[ck] = all_pt.join("|") @cls_meth_ptypes_version = @cls_meth_ptypes_version + 1 end @cls_meth_rbs_ptypes[ck.to_s + "|" + midx.to_s] = rbs_pt end end ck = ck + 1 end end } @module_meth_rbs_returns.each_pair { |mk, rbs_ret| mparts = mk.split("\t", -1) if mparts.length >= 2 modname = mparts[0] methname = mparts[1] ck = 0 while ck < @cls_includes.length incs = @cls_includes[ck].split(";", -1) if not_in(modname, incs) == 0 && ck < @cls_meth_returns.length midx = cls_find_method_direct(ck, methname) if midx >= 0 rets = @cls_meth_returns[ck].split(";", -1) if midx < rets.length && rets[midx] != rbs_ret rets[midx] = rbs_ret @cls_meth_returns[ck] = rets.join(";") @cls_meth_return_cache = {} end end end ck = ck + 1 end end } # Class methods (cmeth). @cls_cmeth_rbs_ptypes.each_pair { |k, rbs_pt| parts = k.split("|", -1)