Commit fd76e665

fd76e6658c1dMerged

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

Description

fix(analyze,codegen): cls method adapter coerces bigint, skip Method ivar promote

Two follow-ups to the cls_method_return cache invalidate fix.

  1. emit_cls_method_adapter hardcoded mrb_int _aN for every adapter parameter and a raw pass-through call. When the wrapped class method's params (or return) got widened to bigint by promote mode, the adapter's call into the bigint signature broke (makes pointer from integer). The Method dispatch ABI is fixed at (void *, mrb_int...), so the adapter is the right place to bridge: wrap each bigint-typed arg through sp_bigint_new_int and unwrap a bigint return via sp_bigint_to_int before handing back through the ABI.

  2. Skip the built-in Method class in promote_int_to_bigint_globally. Method's @fn_ptr ivar holds a function pointer cast to mrb_int, and Method#initialize takes that mrb_int as its second arg. Promoting either to bigint produced an sp_Method_new(sp_Method *, sp_Bigint *) signature that no call site matches — sp_Method_new((sp_Method *)0, (mrb_int)(uintptr_t)&adapter_fn) then fails -Werror=int-conversion.

Also bump @cls_meth_ptypes_version / @cls_cmeth_ptypes_version inside promote_int_to_bigint_globally so the cls_*_ptypes_get per- class memoized splits re-read the now-promoted strings instead of returning the stale pre-promotion split.

Promote-mode test count: 446 pass / 39 fail / 133 error -> 450 pass / 43 fail / 125 error. Default raise mode unchanged at 618 / 0 / 0.

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

Details

Commit
fd76e6658c1d
Parent
9af973420183

spinel_analyze.rbmodifiedView file

@@ -20429,6 +20429,14 @@
2042920429 # bigint). The cache has no version stamp, so wipe it whole —
2043020430 # next caller refills lazily off the now-promoted tables.
2043120431 @cls_meth_return_cache = {}
20432+ # cls_meth_ptypes_get / cls_cmeth_ptypes_get use a per-class
20433+ # memoized split keyed off @cls_meth_ptypes_version /
20434+ # @cls_cmeth_ptypes_version. promote_meth_ptypes_table below
20435+ # mutates the underlying join'd string in place, so bump both
20436+ # version counters now to invalidate any cached split that
20437+ # downstream readers might pick up.
20438+ @cls_meth_ptypes_version = @cls_meth_ptypes_version + 1
20439+ @cls_cmeth_ptypes_version = @cls_cmeth_ptypes_version + 1
2043220440 # Top-level methods.
2043320441 mi = 0
2043420442 while mi < @meth_param_types.length
@@ -20459,6 +20467,16 @@
2045920467 # Class instance + class methods.
2046020468 ci = 0
2046120469 while ci < @cls_names.length
20470+ # The built-in Method class carries a raw function pointer in
20471+ # @fn_ptr (cast to mrb_int) and `Method#initialize(self_obj,
20472+ # fn_ptr)` takes that mrb_int. Promoting either to bigint
20473+ # breaks dispatch (sp_Method_new expects a function-pointer-
20474+ # shaped mrb_int, and the .call lowering reads @fn_ptr back as
20475+ # mrb_int). Skip the whole class.
20476+ if @cls_names[ci] == "Method"
20477+ ci = ci + 1
20478+ next
20479+ end
2046220480 promote_meth_ptypes_table(ci, @cls_meth_ptypes)
2046320481 promote_meth_returns_table(ci, @cls_meth_returns)
2046420482 if ci < @cls_cmeth_ptypes.length