Commit 34efb775

34efb77573f0Merged

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

Description

fix(codegen): emit_poly_builtin_dispatch unboxes bigint index arg

Promote-mode poly recv [] with bigint index (a typical block param widened to bigint) had two issues:

  • The a0 unbox path only handled poly arg, not bigint.
  • a0_is_int gate filtered out the bigint case so no arm fired.

Both addressed: extend the unbox to bigint via sp_bigint_to_int, and add bigint to the a0_is_int membership.

Promote-mode test: +10 pass. Default 633/0/0.

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

Details

Commit
34efb77573f0
Parent
26c725060f9e

spinel_codegen.rbmodifiedView file

@@ -22362,14 +22362,17 @@
2236222362 a0 = ""
2236322363 if arg_compiled.length > 0
2236422364 a0 = arg_compiled[0]
22365- # Unbox if poly — every built-in `[]` arm here passes a0 to a
22366- # function expecting `mrb_int` (sp_IntArray_get etc., or the
22367- # Method fn_ptr's int parameter). When the caller's arg is
22368- # poly (e.g. `def fetch(addr); @fetch[addr][addr]; end` with
22369- # addr widened), we must unbox before the C call.
22365+ # Unbox if poly / bigint — every built-in `[]` arm here passes
22366+ # a0 to a function expecting `mrb_int` (sp_IntArray_get etc.,
22367+ # or the Method fn_ptr's int parameter). When the caller's arg
22368+ # is poly or promote-mode bigint, unbox before the C call.
2237022369 if arg_types.length > 0 && arg_types[0] == "poly"
2237122370 a0 = "(" + a0 + ").v.i"
2237222371 end
22372+ if arg_types.length > 0 && arg_types[0] == "bigint"
22373+ @needs_bigint = 1
22374+ a0 = "sp_bigint_to_int((sp_Bigint *)" + a0 + ")"
22375+ end
2237322376 end
2237422377 # `[]` — element types differ per built-in. When the result temp
2237522378 # is sp_RbVal (poly return), every branch can box into it. When
@@ -22387,7 +22390,7 @@
2238722390 # runtime (a poly recv carrying a String key would be a hash,
2238822391 # not an array) and emitting them produces Wint-conversion
2238922392 # warnings — or hard errors under -Werror.
22390- a0_is_int = arg_compiled.length >= 1 && (arg_types.length == 0 || arg_types[0] == "int" || arg_types[0] == "poly")
22393+ a0_is_int = arg_compiled.length >= 1 && (arg_types.length == 0 || arg_types[0] == "int" || arg_types[0] == "poly" || arg_types[0] == "bigint")
2239122394 # Hash dispatch arms for `[]` on a poly recv whose runtime
2239222395 # storage is a *-Hash variant. The chained `outer[k1][k2]`
2239322396 # shape where outer is StrPolyHash lands here — the inner []