Commit 25e1efc9
25e1efc9339bMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(codegen): proc arg packing unboxes bigint; expr_emit detects method_ref alias
Two related promote-mode fixes for Proc/Method paths.
-
compile_proc_call_args: a bigint arg packed via the proc ABI's
mrb_int*array used(mrb_int)(uintptr_t)val-- but val is an sp_Bigint* heap pointer, not a tagged int. The proc body then read the pointer's low bits asn, producing wild output. Unbox via sp_bigint_to_int before packing. -
expr_emit_is_bigint: extend the Method.call branch to also catch the static-alias path.
m = method(:foo); m.call(x)rewrites in compile_dot_call_expr to a directsp_foo(x)-- no Method object exists at runtime, so the caller's type lookup falls to the LV's stale int slot type. Resolve via @method_ref_vars and inspect the target method's promoted return type so puts / arg-coerce paths see bigint.
Fixes: method, proc, proc_closure under promote.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 25e1efc9339b
- Parent
- e0c45fb3f979
spinel_codegen.rbmodifiedView file
if rcv_bm_eb >= 0 && base_type(infer_type(rcv_bm_eb)) == "obj_Method" return 1 end # Static alias: `m = method(:foo)` then `m.call(x)` rewrites to # a direct `sp_foo(x)` (see compile_dot_call_expr). Look up the # target method's promote-mode return. if rcv_bm_eb >= 0 && @nd_type[rcv_bm_eb] == "LocalVariableReadNode" rname_ma = @nd_name[rcv_bm_eb] ri_ma = 0 while ri_ma < @method_ref_vars.length if @method_ref_vars[ri_ma] == rname_ma ref_mname_ma = @method_ref_names[ri_ma] mi_ma = find_method_idx(ref_mname_ma) if mi_ma >= 0 && mi_ma < @meth_return_types.length if base_type(@meth_return_types[mi_ma]) == "bigint" return 1 end end ri_ma = @method_ref_vars.length end ri_ma = ri_ma + 1 end end end # CallNode dispatch to a user method whose return slot has been # promoted to bigint: infer_type can be stale (the cls_method end val = compile_expr(arg_ids[k]) at = infer_type(arg_ids[k]) if type_is_pointer(at) == 1 if base_type(at) == "bigint" # Proc ABI is `mrb_int(*)(void*, mrb_int*)`. In promote mode an # int arg arrives as sp_Bigint *; unbox to the underlying int # before packing. Wrapping the pointer via (mrb_int)(uintptr_t) # would silently pass a heap address as the proc's `n`. @needs_bigint = 1 result = result + "sp_bigint_to_int((sp_Bigint *)" + val + ")" elsif type_is_pointer(at) == 1 result = result + "(mrb_int)(uintptr_t)(" + val + ")" else result = result + val