Commit 29edbb8a

29edbb8a7aa4Merged

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

Description

fix(codegen): array literal / map block IntArray push unbox bigint element

Three IntArray-push sites pushed the raw block-tail / array-literal element regardless of its actual type. With promote mode widening arithmetic to bigint, the pushed value became sp_Bigint *:

  • compile_array_literal_from_ids fallback ([a/b, a%b] where a/b are bigint) -- mirror the existing poly unbox arm.
  • compile_map_expr plain recv.map { ... } IntArray path.
  • compile_map_expr each_cons fusion path's IntArray push.

Each now infer_types the block tail / element and routes through sp_bigint_to_int when bigint.

Promote-mode test count: 501 pass / 43 fail / 74 error -> 502 pass / 43 fail / 73 error. Default raise mode unchanged at 618 / 0 / 0.

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

Details

Commit
29edbb8a7aa4
Parent
41a4dd16e4a3

spinel_codegen.rbmodifiedView file

@@ -24462,6 +24462,10 @@
2446224462 # compiler rejects the push with "incompatible type".
2446324463 if et == "poly"
2446424464 ev = "(" + ev + ").v.i"
24465+ elsif et == "bigint"
24466+ # promote-mode element: unbox to mrb_int.
24467+ @needs_bigint = 1
24468+ ev = "sp_bigint_to_int((sp_Bigint *)" + ev + ")"
2446524469 end
2446624470 emit(" sp_IntArray_push(" + tmp + ", " + ev + ");")
2446724471 k = k + 1
@@ -32797,6 +32801,12 @@
3279732801 elsif nested_arr_outer == 1
3279832802 emit(" sp_PtrArray_push(" + tmp_arrn + ", " + lastv + ");")
3279932803 else
32804+ # promote-mode block tail returning bigint into IntArray;
32805+ # unbox before pushing.
32806+ if infer_type(stmts_n2.last) == "bigint"
32807+ @needs_bigint = 1
32808+ lastv = "sp_bigint_to_int((sp_Bigint *)" + lastv + ")"
32809+ end
3280032810 emit(" sp_IntArray_push(" + tmp_arrn + ", " + lastv + ");")
3280132811 end
3280232812 else
@@ -32957,6 +32967,10 @@
3295732967 elsif ec_nested == 1
3295832968 emit(" sp_PtrArray_push(" + ec_tmp_arr + ", " + ec_lastv + ");")
3295932969 else
32970+ if infer_type(ec_stmts_n2.last) == "bigint"
32971+ @needs_bigint = 1
32972+ ec_lastv = "sp_bigint_to_int((sp_Bigint *)" + ec_lastv + ")"
32973+ end
3296032974 emit(" sp_IntArray_push(" + ec_tmp_arr + ", " + ec_lastv + ");")
3296132975 end
3296232976 end