Commit 1c351765

1c351765afb5Merged

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

Description

fix(codegen): expr_emit_is_bigint gates arith widening on numeric recv + module-singleton chain

The arith/bitop fallback in expr_emit_is_bigint returned 1 whenever either operand walked to bigint, without checking that the recv was itself numeric. In promote mode a dead-code included-module body ("hello, " + name + "!" where the per-class param copy got promoted to bigint) made the inner + report bigint and the outer + route through sp_bigint_add on string args -- compile error.

Gate on base_type(infer_type(recv)) in {int, float, bigint, numeric} so non-numeric recvs (string concat) fall back to their own dispatch.

Also extend the walker to the Module.accessor.<method> chain that resolve_module_singleton_accessors resolves at codegen: if the resolved accessor candidate's class method return is bigint, propagate the type up. Fixes puts Holder.counter.count printing pointer bits.

Details

Commit
1c351765afb5
Parent
234e29dfa690

spinel_codegen.rbmodifiedView file

@@ -15779,14 +15779,55 @@
1577915779 end
1578015780 end
1578115781 end
15782+ # `Module.accessor.<method>`: recv is a CallNode whose inner
15783+ # recv is a ConstantReadNode for a module name with a resolved
15784+ # accessor (resolve_module_singleton_accessors). Walk to the
15785+ # candidate class(es) and check the cls method return type.
15786+ if @nd_type[rcv_eb_user] == "CallNode"
15787+ inner_recv_eb = @nd_receiver[rcv_eb_user]
15788+ inner_mname_eb = @nd_name[rcv_eb_user]
15789+ if inner_recv_eb >= 0 && @nd_type[inner_recv_eb] == "ConstantReadNode"
15790+ mod_name_eb = @nd_name[inner_recv_eb]
15791+ if module_name_exists(mod_name_eb) == 1
15792+ rconsts_eb = module_acc_resolved(mod_name_eb, inner_mname_eb)
15793+ if rconsts_eb != "" && rconsts_eb != "?"
15794+ cands_eb = rconsts_eb.split(";")
15795+ ki_eb = 0
15796+ while ki_eb < cands_eb.length
15797+ cn_eb_ms = cands_eb[ki_eb]
15798+ rt_eb_ms = lookup_cls_meth_return(cn_eb_ms, mn_eb)
15799+ if base_type(rt_eb_ms) == "bigint"
15800+ return 1
15801+ end
15802+ ki_eb = ki_eb + 1
15803+ end
15804+ end
15805+ end
15806+ end
15807+ end
1578215808 end
1578315809 if mn_eb != "+" && mn_eb != "-" && mn_eb != "*" && mn_eb != "/" && mn_eb != "%" && mn_eb != "**" &&
1578415810 mn_eb != "&" && mn_eb != "|" && mn_eb != "^" && mn_eb != "<<" && mn_eb != ">>" &&
1578515811 mn_eb != "~" && mn_eb != "-@"
1578615812 return 0
1578715813 end
15814+ # Arith/bitop result is bigint only when at least one side is
15815+ # bigint AND the recv is itself a numeric type (int/float/bigint
15816+ # or nullable). `string + bigint_var` (legal-shape Ruby
15817+ # dead-code in promote mode -- e.g. an included module body
15818+ # that's never reached with int args) has the recv side decide
15819+ # the dispatch: the string concat code path handles it. Treating
15820+ # the inner `+` as bigint cascades through compile_operator_expr
15821+ # and emits sp_bigint_add on string args.
1578815822 rcv_eb = @nd_receiver[nid]
15789- if rcv_eb >= 0 && expr_emit_is_bigint(rcv_eb) == 1
15823+ if rcv_eb < 0
15824+ return 0
15825+ end
15826+ rcv_t_arith = base_type(infer_type(rcv_eb))
15827+ if rcv_t_arith != "int" && rcv_t_arith != "float" && rcv_t_arith != "bigint" && rcv_t_arith != "numeric"
15828+ return 0
15829+ end
15830+ if expr_emit_is_bigint(rcv_eb) == 1
1579015831 return 1
1579115832 end
1579215833 args_eb = @nd_arguments[nid]