Commit 95fdb533

95fdb5334a7fMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

fix(codegen): infer_type CallNode cache-miss falls back to obj-recv method return

infer_type's CallNode fallback returned "int" when:

  • the call wasn't a lambda call
  • the recv wasn't sub-arith
  • walk_and_cache hadn't annotated it (or annotated to stale int)

For a d.call where d is a user-class instance with a bigint- returning call method, the static type defaulted to "int" and the outer return wrapped the already-bigint emit with sp_bigint _new_int — double wrap.

Add a generic obj-recv fallback: when recv resolves to obj_ and the class defines <mname>, return @cls_meth_returns's slot.

Promote-mode test count: 547 pass / 47 fail / 24 error -> 548 pass / 47 fail / 23 error. Default raise mode 618 / 0 / 0; optcarrot checksum 59662.

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
95fdb5334a7f
Parent
edd1240fa8f2

spinel_codegen.rbmodifiedView file

@@ -2755,6 +2755,35 @@
27552755 end
27562756 end
27572757 end
2758+ # Generic `obj.method(...)` cache-miss path: when the recv is
2759+ # statically a user-class instance and the class defines a method
2760+ # of that name, route through cls_method_return so the now-
2761+ # promoted return type flows up. Without this, promote-mode CallNodes
2762+ # that walk_and_cache skipped (or that annotated as stale "int"
2763+ # before the promote sweep) silently default to "int" and the
2764+ # outer return / arith arms double-wrap with sp_bigint_new_int.
2765+ cmp_recv_obj = @nd_receiver[nid]
2766+ if cmp_recv_obj >= 0
2767+ cmp_recv_t_obj = base_type(infer_type(cmp_recv_obj))
2768+ if is_obj_type(cmp_recv_t_obj) == 1
2769+ cmp_cn_obj = cmp_recv_t_obj[4, cmp_recv_t_obj.length - 4]
2770+ cmp_ci_obj = find_class_idx(cmp_cn_obj)
2771+ if cmp_ci_obj >= 0
2772+ cmp_names_obj = @cls_meth_names[cmp_ci_obj].split(";")
2773+ cmp_returns_obj = @cls_meth_returns[cmp_ci_obj].split(";")
2774+ cmp_jj_obj = 0
2775+ while cmp_jj_obj < cmp_names_obj.length
2776+ if cmp_names_obj[cmp_jj_obj] == cmp_mname && cmp_jj_obj < cmp_returns_obj.length
2777+ cmp_ret_obj = cmp_returns_obj[cmp_jj_obj]
2778+ if cmp_ret_obj != ""
2779+ return cmp_ret_obj
2780+ end
2781+ end
2782+ cmp_jj_obj = cmp_jj_obj + 1
2783+ end
2784+ end
2785+ end
2786+ end
27582787 return "int"
27592788 end
27602789 if t == "IfNode"