Commit 359b9a8d
359b9a8d6074Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
docs(codegen): document infer_call_type / compile_call_expr symmetry
Refactor item 3: the two functions walk identical branch structure 12K lines apart, but nothing in the file calls that out — the failure mode in #127 was exactly forgetting to mirror a new case in the inference half (dispatch was right, LHS local mis-typed). Add a docstring on infer_call_type listing the paired helpers (infer_operator_type ↔ compile_operator_expr, infer_constructor_type ↔ compile_constructor_expr, infer_constant_recv_type ↔ compile_constant_recv_expr) and the maintenance rule. Compile_call_expr gets a short cross-reference back so a reader landing there finds the rule too.
Pure documentation. Bootstrap (gen2 == gen3) clean; 199 tests + 56 benches pass.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 359b9a8d6074
- Parent
- 1af0d84d0da3
spinel_codegen.rbmodifiedView file
end # Returns the inferred C type ("int", "string", "poly", "obj_<Cname>", # ...) for the value a CallNode evaluates to. # # Symmetric with `compile_call_expr` (which returns the C expression # for the same node). The two walk identical branch structure: # # infer_call_type compile_call_expr # infer_operator_type ↔ compile_operator_expr # infer_constructor_ ↔ compile_constructor_expr # type # infer_constant_recv_ ↔ compile_constant_recv_expr # type # # The non-paired helpers (infer_comparison_type, infer_method_name_ # type, infer_recv_method_type, infer_open_class_type) recognise call # shapes whose codegen is inlined into compile_call_expr directly # rather than factored out, but the dispatch order matches. # # Maintenance rule: when you add a new call shape, you almost always # need both. Forgetting the inference half is the failure mode in # #127 — the dispatch emitted the right C function call, but the LHS # local was typed `mrb_int` because no inference branch claimed the # shape, so `lv_s = sp_M_cls_greet()` mis-typed an `const char *` # return. Mirror new cases in both functions, in the same order, with # the same recogniser logic. def infer_call_type(nid) mname = @nd_name[nid] recv = @nd_receiver[nid] tmp_fb end # Returns the C expression for a CallNode. Symmetric with # `infer_call_type` (which returns the call's C type) — see the # docstring there for the maintenance rule on adding new shapes. # Branch order in this function mirrors infer_call_type's order so # the two stay diff-able. def compile_call_expr(nid) mname = @nd_name[nid] recv = @nd_receiver[nid]