Commit 427c8286
427c82862e58Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · ~3 modified
Description
codegen(promote): invoke bound methods through the poly ABI
Under promote every method is poly-signatured (sp_RbVal (*)(self*, sp_RbVal) -> sp_RbVal), but a bound Method (obj.method(:m)) was always
called through the legacy mrb_int ABI (void*, mrb_int) -> mrb_int. The
cast truncated the boxed args and return to garbage, so bm.call(x)
yielded 0.
When the target is unresolved, use the poly ABI in promote at all three invocation sites:
- codegen object-bound
.callfallback: cast through sp_RbVal self/args/ return, box each arg. - codegen poly-receiver
.callternary (Method | Proc): call the Method arm via the poly ABI and unbox with sp_poly_to_i so both ternary arms share the mrb_int type the Proc arm yields. - runtime sp_poly_index_int Method arm (
n[i]where n holds a Method): guarded by SP_INT_OVERFLOW_MODE_PROMOTE. A bound-method.callwith an unresolved target also now infers TY_POLY (not TY_INT) under promote so the surrounding context types it correctly.
Fixes promote-mode bound_method_gc, bound_method_obj_recv, method_dispatch_poly_array.
Default test 992/0/0 and optcarrot checksum 59662 unchanged.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 427c82862e58
- Parent
- 71029dd5129d
lib/sp_runtime.hmodifiedView file
@@ -4483,7 +4483,13 @@
44834483
if (a.tag == SP_TAG_OBJ) {44844484
if (a.cls_id == SP_BUILTIN_METHOD) {44854485
sp_BoundMethod *m = (sp_BoundMethod *)a.v.p;4486+
#ifdef SP_INT_OVERFLOW_MODE_PROMOTE4487+
/* promote: methods are poly-signatured, so invoke through the poly ABI4488+
and unbox the result rather than the legacy mrb_int ABI. */4489+
return sp_poly_to_i(((sp_RbVal (*)(void *, sp_RbVal))(uintptr_t)m->fn)((void *)m->self, sp_box_int(i)));4490+
#else44864491
return ((mrb_int (*)(void *, mrb_int))(uintptr_t)m->fn)((void *)m->self, i);4492+
#endif44874493
}44884494
if (a.cls_id == SP_BUILTIN_INT_ARRAY) return sp_IntArray_get((sp_IntArray *)a.v.p, i);44894495
}src/analyze_infer.cmodifiedView file
Loading diff…
src/codegen_call.cmodifiedView file
Loading diff…