Commit fa08c47c

fa08c47c15e5Merged

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

Description

fix(codegen): bigint_arg peeks user-method + attr_reader returns

compile_bigint_arg's peek already handled arith CallNodes whose arg was bigint. Extend it to also catch:

  • user-method CallNodes whose recv class's cls_method_return resolves to bigint (post-promote);
  • attr_reader CallNodes — auto-generated, return type follows the ivar slot — by consulting cls_ivar_type when the recv class has an attr_reader for the method name.

Without this, total + vv.sum (Vec#sum attr_reader, @sum slot bigint) wrapped the already-bigint emit (lv_vv->iv_sum) with sp_bigint_new_int again.

Promote-mode test count: 537 pass / 53 fail / 28 error -> 537 pass / 54 fail / 27 error. Default raise mode 618 / 0 / 0.

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

Details

Commit
fa08c47c15e5
Parent
07f393361b34

spinel_codegen.rbmodifiedView file

@@ -15036,9 +15036,10 @@
1503615036 if arg_ids.length > 0
1503715037 at = infer_type(arg_ids[0])
1503815038 # The cache may say "int" even though the arg emits bigint
15039- # (arith CallNode with bigint operand). Peek operands so we
15040- # don't wrap an already-bigint expression with sp_bigint_new
15041- # _int.
15039+ # (arith CallNode with bigint operand, or an attr-reader / user-
15040+ # method call whose return slot is now promoted). Peek operands
15041+ # / consult the post-promote method-return tables so we don't
15042+ # wrap an already-bigint expression with sp_bigint_new_int.
1504215043 if at != "bigint" && @nd_type[arg_ids[0]] == "CallNode"
1504315044 ar_mn_bg = @nd_name[arg_ids[0]]
1504415045 if ar_mn_bg == "+" || ar_mn_bg == "-" || ar_mn_bg == "*" || ar_mn_bg == "/" || ar_mn_bg == "%" || ar_mn_bg == "**"
@@ -15055,6 +15056,31 @@
1505515056 end
1505615057 end
1505715058 end
15059+ # `obj.method` call: re-resolve through cls_method_return on the
15060+ # now-promoted table. Stale cache may say "int". Also check
15061+ # attr_reader directly (auto-generated, ivar-slot-typed).
15062+ if at != "bigint"
15063+ recv_bgp = @nd_receiver[arg_ids[0]]
15064+ if recv_bgp >= 0
15065+ recv_t_bgp = base_type(infer_type(recv_bgp))
15066+ if is_obj_type(recv_t_bgp) == 1
15067+ cn_bgp = recv_t_bgp[4, recv_t_bgp.length - 4]
15068+ ci_bgp = find_class_idx(cn_bgp)
15069+ if ci_bgp >= 0
15070+ mr_bgp = cls_method_return(ci_bgp, ar_mn_bg)
15071+ if base_type(mr_bgp) == "bigint"
15072+ at = "bigint"
15073+ end
15074+ if at != "bigint" && cls_has_attr_reader(ci_bgp, ar_mn_bg) == 1
15075+ slot_bgp = cls_ivar_type(ci_bgp, "@" + ar_mn_bg)
15076+ if base_type(slot_bgp) == "bigint"
15077+ at = "bigint"
15078+ end
15079+ end
15080+ end
15081+ end
15082+ end
15083+ end
1505815084 end
1505915085 val = compile_expr(arg_ids[0])
1506015086 if at == "bigint"