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

@@ -1732,6 +1732,31 @@
17321732 end
17331733
17341734
1735+ # Returns the inferred C type ("int", "string", "poly", "obj_<Cname>",
1736+ # ...) for the value a CallNode evaluates to.
1737+ #
1738+ # Symmetric with `compile_call_expr` (which returns the C expression
1739+ # for the same node). The two walk identical branch structure:
1740+ #
1741+ # infer_call_type compile_call_expr
1742+ # infer_operator_type ↔ compile_operator_expr
1743+ # infer_constructor_ ↔ compile_constructor_expr
1744+ # type
1745+ # infer_constant_recv_ ↔ compile_constant_recv_expr
1746+ # type
1747+ #
1748+ # The non-paired helpers (infer_comparison_type, infer_method_name_
1749+ # type, infer_recv_method_type, infer_open_class_type) recognise call
1750+ # shapes whose codegen is inlined into compile_call_expr directly
1751+ # rather than factored out, but the dispatch order matches.
1752+ #
1753+ # Maintenance rule: when you add a new call shape, you almost always
1754+ # need both. Forgetting the inference half is the failure mode in
1755+ # #127 — the dispatch emitted the right C function call, but the LHS
1756+ # local was typed `mrb_int` because no inference branch claimed the
1757+ # shape, so `lv_s = sp_M_cls_greet()` mis-typed an `const char *`
1758+ # return. Mirror new cases in both functions, in the same order, with
1759+ # the same recogniser logic.
17351760 def infer_call_type(nid)
17361761 mname = @nd_name[nid]
17371762 recv = @nd_receiver[nid]
@@ -14385,6 +14410,11 @@
1438514410 tmp_fb
1438614411 end
1438714412
14413+ # Returns the C expression for a CallNode. Symmetric with
14414+ # `infer_call_type` (which returns the call's C type) — see the
14415+ # docstring there for the maintenance rule on adding new shapes.
14416+ # Branch order in this function mirrors infer_call_type's order so
14417+ # the two stay diff-able.
1438814418 def compile_call_expr(nid)
1438914419 mname = @nd_name[nid]
1439014420 recv = @nd_receiver[nid]