Commit 4fc5db6f
4fc5db6f5a25Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified
Description
fix(analyze,codegen): default-typed param + inlined-yield self/local cascade
Five cooperating fixes peeling back the C-compile error layers in Sam Ruby's roundhouse controller-test pipeline (issue #572's "test binary doesn't build" surface, distinct from the kwarg-bundle fix in 4019767).
-
Analyzer
infer_cls_meth_param_from_body+infer_param_type_from_body: when widening a param's type because the body invokes methods on it, re-infer the param's default expression FIRST (with the method's owning class scope set) and trust anobj_<C>answer over the "first class that has every called method" walk. The walk's first-match rule silently pickedActionController_Base(defined earlier in the file) whenassert_response(expected, response = @__response)'s default was actuallyActionResponse, so callers passingself->iv___response(sp_ActionResponse) tripped -Wincompatible-pointer-types on the third arg. -
Analyzer
widen_param_types_from_body_writes: set up the method's scope (push_scope+ per-paramdeclare_var) around the per-param scan so the body-write widening'sis_reliable_literal_for_widenLV-read arm (below) sees sibling-param types. Without this, an inter-param assignmentopts = content_or_optscouldn't see the rhs's poly type. -
Analyzer
is_reliable_literal_for_widen: acceptLocalVariableReadNodewhen the local has a known non-nil non-int type. With (2),opts = content_or_optsbetween two params correctly widensoptsto poly, matching the C-side writelv_opts = lv_content_or_opts. -
Codegen
compile_yield_method_call_stmt: when inlining the yield-using method's body, wrap@self_overridein a cast to the callee's class pointer. The enclosing function'sselfis the subclass type; calls inside the inlined body to inherited methods that go throughself_exprpreviously emitted bareself, mismatching the callee's param type. Also declare each inlined param/local under its ORIGINAL name (in addition to the renamed_yNform) soinfer_typecalls during emit -- which look up by original name -- see the correct type and don't fall through to the int default. -
Codegen
compile_stmt_with_blockLocalVariableWriteNode arm: mirror the maincompile_stmtLV-write boxing so ac = nilagainst a poly-typed slot lowers tolv_c = sp_box_nil(), notlv_c = 0(which gcc rejects). Also switch the inlined default-arg initializer toc_default_val(pt)so the slot's C type and initializer agree (sp_RbVal x = 0is invalid C).
After the cascade: roundhouse articles_controller_test.rb and
comments_controller_test.rb both compile and run. They surface
runtime test failures from unrelated logic (e.g.
STATUS_SYMBOLS[:success].include?(actual) not matching), but
the original C-compile blocker -- self / param / boxing type
mismatches -- is cleared.
make test: 564/564 pass (one new fixture).
make optcarrot: checksum 59662 stable.
Stage-2 bootstrap fixpoint clean.
Refs #572
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 4fc5db6f5a25
- Parent
- 4c62268e2452
spinel_analyze.rbmodifiedView file
called = "".split(",") collect_param_methods(bid, pnames[pk], called) if called.length > 0 && called_methods_only_on_container_builtins(called) == 0 ci2 = 0 best = -1 while ci2 < @cls_names.length if best < 0 && class_has_all_methods(ci2, called) == 1 best = ci2 # Check the param's default expression first: if it's an # ivar/local/call that NOW (after ivars are known) infers # to a concrete `obj_<C>`, trust that over the # "first class that has all called methods" heuristic -- # which silently picks the wrong sibling class when two # classes define the same surface (e.g. `response.status` # exists on both ActionController_Base and ActionResponse). default_obj_t = "" defs_str_cm = "" if j < @cls_meth_defaults[oci].split("|").length defs_str_cm = @cls_meth_defaults[oci].split("|")[j] end defs_arr_cm = defs_str_cm.split(",") if pk < defs_arr_cm.length def_id_cm = defs_arr_cm[pk].to_i if def_id_cm > 0 saved_ci_pd = @current_class_idx @current_class_idx = oci push_scope dt_inferred = infer_type(def_id_cm) pop_scope @current_class_idx = saved_ci_pd if is_obj_type(dt_inferred) == 1 default_obj_t = dt_inferred end end ci2 = ci2 + 1 end if best >= 0 ptypes[pk] = "obj_" + @cls_names[best] if default_obj_t != "" ptypes[pk] = default_obj_t cls_meth_ptypes_put(oci, j, ptypes) else ci2 = 0 best = -1 while ci2 < @cls_names.length if best < 0 && class_has_all_methods(ci2, called) == 1 best = ci2 end ci2 = ci2 + 1 end if best >= 0 ptypes[pk] = "obj_" + @cls_names[best] cls_meth_ptypes_put(oci, j, ptypes) end end end end called = "".split(",") collect_param_methods(bid, pnames[pk], called) if called.length > 0 && called_methods_only_on_container_builtins(called) == 0 ci2 = 0 best = -1 while ci2 < @cls_names.length if best < 0 && class_has_all_methods(ci2, called) == 1 best = ci2 # Same precedence rule as the cls_meth side above: if the # param's default expression infers to a concrete obj_<C> # under the current scope, prefer that over the # "first class with all called methods" walk. default_obj_t = "" defs_str_mp = "" if mi < @meth_has_defaults.length defs_str_mp = @meth_has_defaults[mi] end defs_arr_mp = defs_str_mp.split(",") if pk < defs_arr_mp.length def_id_mp = defs_arr_mp[pk].to_i if def_id_mp > 0 push_scope dt_inferred_mp = infer_type(def_id_mp) pop_scope if is_obj_type(dt_inferred_mp) == 1 default_obj_t = dt_inferred_mp end end ci2 = ci2 + 1 end if best >= 0 ptypes[pk] = "obj_" + @cls_names[best] if default_obj_t != "" ptypes[pk] = default_obj_t @meth_param_types[mi] = ptypes.join(",") else ci2 = 0 best = -1 while ci2 < @cls_names.length if best < 0 && class_has_all_methods(ci2, called) == 1 best = ci2 end ci2 = ci2 + 1 end if best >= 0 ptypes[pk] = "obj_" + @cls_names[best] @meth_param_types[mi] = ptypes.join(",") end end end end pnames = @meth_param_names[mi].split(",") ptypes = @meth_param_types[mi].split(",") ptypes_changed = 0 # Set up the method's scope so scan_param_body_write_unify's # LV-read arm (used by is_reliable_literal_for_widen) can look # up sibling params via find_var_type. Without this, an # `opts = content_or_opts` assignment between two params # never widened `opts` because the rhs's type was unknown. push_scope dpi = 0 while dpi < pnames.length pt_dp = "int" if dpi < ptypes.length pt_dp = ptypes[dpi] end declare_var(pnames[dpi], pt_dp) dpi = dpi + 1 end pk = 0 while pk < pnames.length if pk < ptypes.length end pk = pk + 1 end pop_scope if ptypes_changed == 1 @meth_param_types[mi] = ptypes.join(",") end pnames_j = all_params[mj].split(",") ptypes_j = all_ptypes[mj].split(",") inner_changed = 0 # Same scope setup as the top-level branch so the LV-read # widening picks up sibling-param types. push_scope dpcj = 0 while dpcj < pnames_j.length pt_cj = "int" if dpcj < ptypes_j.length pt_cj = ptypes_j[dpcj] end declare_var(pnames_j[dpcj], pt_cj) dpcj = dpcj + 1 end pk = 0 while pk < pnames_j.length if pk < ptypes_j.length end pk = pk + 1 end pop_scope if inner_changed == 1 all_ptypes[mj] = ptypes_j.join(",") cls_changed = 1 if nt == "StringNode" || nt == "IntegerNode" || nt == "FloatNode" || nt == "SymbolNode" || nt == "NilNode" || nt == "TrueNode" || nt == "FalseNode" return 1 end # Reading another local that's already typed (typically a # sibling param) is reliable enough -- the analyzer's scope # holds the declared type for that name. Without this, # `opts = content_or_opts` inside a method body (where both # are params, one nil-defaulted int, the other poly-defaulted) # left `opts` typed nil/int even though the body write # delivered poly, and the C emit type-mismatched the # assignment. if nt == "LocalVariableReadNode" vt = find_var_type(@nd_name[nid]) if vt != "" && vt != "int" && vt != "nil" return 1 end end 0 endspinel_codegen.rbmodifiedView file
Loading diff…
test/inherited_method_kwarg_block_self.rbaddedView file
Loading diff…
test/inherited_method_kwarg_block_self.rb.expectedaddedView file
Loading diff…