Commit 593a14b4
593a14b45ca0Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(codegen): proc fn body bigint tail unboxes for mrb_int return ABI
sp_proc_call's function-pointer ABI returns mrb_int regardless
of the source body's tail type. A promote-mode body whose tail
emits bigint (proc { n + 1 } with captured n bigint, or any
arith on bigint locals) needed the unbox before C-level return.
Snapshot the tail's static type, peek arith operands when the cache stays stale "int", and route through sp_bigint_to_int when the actual emit is bigint.
Promote-mode test count: 538 pass / 54 fail / 26 error -> 538 pass / 55 fail / 25 error. Default raise mode 618 / 0 / 0.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 593a14b45ca0
- Parent
- 7e132dff9f8c
spinel_codegen.rbmodifiedView file
@@ -30101,6 +30101,7 @@
3010130101
di = di + 13010230102
end3010330103
bexpr = "0"30104+
bexpr_t_proc = "int"3010430105
body_stmts = ""3010530106
if bbody >= 03010630107
bs = get_stmts(bbody)@@ -30115,10 +30116,12 @@
3011530116
body_stmts = @out_lines.join(10.chr) + 10.chr3011630117
@out_lines = "".split(",")3011730118
bexpr = fiber_var_ref(@nd_name[bs[k]])30119+
bexpr_t_proc = find_var_type(@nd_name[bs[k]])3011830120
elsif lt != "void"3011930121
body_stmts = @out_lines.join(10.chr) + 10.chr3012030122
@out_lines = "".split(",")3012130123
bexpr = compile_expr(bs[k])30124+
bexpr_t_proc = lt3012230125
extra = @out_lines.join(10.chr) + 10.chr3012330126
@out_lines = "".split(",")3012430127
body_stmts = body_stmts + extra@@ -30136,6 +30139,38 @@
3013630139
end3013730140
end3013830141
end30142+
# Proc fn ABI returns mrb_int regardless of body type. Unbox a30143+
# bigint body tail before return so the function signature30144+
# matches; analogous to the same coerce in compile_yield_call30145+
# _expr's tail. Also peek arith operands so a stale "int"30146+
# bexpr_t_proc gets upgraded.30147+
if base_type(bexpr_t_proc) != "bigint" && bbody >= 030148+
bs_chk = get_stmts(bbody)30149+
if bs_chk.length > 030150+
bt_last = bs_chk.last30151+
if @nd_type[bt_last] == "CallNode"30152+
bmn_proc = @nd_name[bt_last]30153+
if bmn_proc == "+" || bmn_proc == "-" || bmn_proc == "*" || bmn_proc == "/" || bmn_proc == "%" || bmn_proc == "**"30154+
br_proc = @nd_receiver[bt_last]30155+
if br_proc >= 0 && base_type(infer_type(br_proc)) == "bigint"30156+
bexpr_t_proc = "bigint"30157+
else30158+
ba_proc = @nd_arguments[bt_last]30159+
if ba_proc >= 030160+
aa_proc = get_args(ba_proc)30161+
if aa_proc.length > 0 && base_type(infer_type(aa_proc[0])) == "bigint"30162+
bexpr_t_proc = "bigint"30163+
end30164+
end30165+
end30166+
end30167+
end30168+
end30169+
end30170+
if base_type(bexpr_t_proc) == "bigint"30171+
@needs_bigint = 130172+
bexpr = "sp_bigint_to_int((sp_Bigint *)(" + bexpr + "))"30173+
end3013930174
pop_scope3014030175
@in_proc_body = saved_in_proc_body3014130176
@proc_captures = saved_proc_captures