Commit 54309411

5430941173f9Merged

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

Description

fix(codegen): hash literal / bracket-assign coerce bigint values to int slots

Three int-valued hash set sites pushed promote-widened bigint values into sp_StrIntHash_set / sp_SymIntHash_set whose 3rd arg is mrb_int:

  • compile_hash_literal's str_int_hash / sym_int_hash arms ({key: bigint_lv}).
  • compile_bracket_assign's sym_int_hash store (h[k] = bigint_v).
  • compile_bracket_assign's idx unbox for int-keyed receivers when the index is bigint.

Each now infer_types the rhs / idx and routes through sp_bigint_to_int when bigint.

Promote-mode test count: 505 pass / 44 fail / 69 error -> 508 pass / 44 fail / 66 error. Default raise mode unchanged at 618 / 0 / 0.

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

Details

Commit
5430941173f9
Parent
98168c493cb9

spinel_codegen.rbmodifiedView file

@@ -24547,7 +24547,12 @@
2454724547 emit(" sp_SymIntHash *" + tmp + " = sp_SymIntHash_new();")
2454824548 elems.each { |el|
2454924549 if @nd_type[el] == "AssocNode"
24550- emit(" sp_SymIntHash_set(" + tmp + ", " + compile_expr(@nd_key[el]) + ", " + compile_expr(@nd_expression[el]) + ");")
24550+ v_syh = compile_expr(@nd_expression[el])
24551+ if infer_type(@nd_expression[el]) == "bigint"
24552+ @needs_bigint = 1
24553+ v_syh = "sp_bigint_to_int((sp_Bigint *)" + v_syh + ")"
24554+ end
24555+ emit(" sp_SymIntHash_set(" + tmp + ", " + compile_expr(@nd_key[el]) + ", " + v_syh + ");")
2455124556 end
2455224557 }
2455324558 return tmp
@@ -24605,7 +24610,12 @@
2460524610 emit(" sp_StrIntHash *" + tmp + " = sp_StrIntHash_new();")
2460624611 elems.each { |el|
2460724612 if @nd_type[el] == "AssocNode"
24608- emit(" sp_StrIntHash_set(" + tmp + ", " + compile_expr_as_string(@nd_key[el]) + ", " + compile_expr(@nd_expression[el]) + ");")
24613+ v_sih = compile_expr(@nd_expression[el])
24614+ if infer_type(@nd_expression[el]) == "bigint"
24615+ @needs_bigint = 1
24616+ v_sih = "sp_bigint_to_int((sp_Bigint *)" + v_sih + ")"
24617+ end
24618+ emit(" sp_StrIntHash_set(" + tmp + ", " + compile_expr_as_string(@nd_key[el]) + ", " + v_sih + ");")
2460924619 end
2461024620 }
2461124621 tmp
@@ -29894,6 +29904,11 @@
2989429904 if idx_t == "poly" && rt == "int_str_hash"
2989529905 idx = "(" + idx + ").v.i"
2989629906 end
29907+ # promote-mode-widened idx for int-keyed receivers.
29908+ if idx_t == "bigint" && (rt == "int_array" || rt == "float_array" || rt == "str_array" || rt == "sym_array" || is_ptr_array_type(rt) == 1 || rt == "poly_array" || rt == "int_str_hash")
29909+ @needs_bigint = 1
29910+ idx = "sp_bigint_to_int((sp_Bigint *)" + idx + ")"
29911+ end
2989729912 end
2989829913 end
2989929914 if arg_ids.length >= 2
@@ -29922,7 +29937,12 @@
2992229937 return
2992329938 end
2992429939 if rt == "sym_int_hash"
29925- emit(" sp_SymIntHash_set(" + rc + ", " + idx + ", " + val + ");")
29940+ val_sih = val
29941+ if arg_ids.length >= 2 && infer_type(arg_ids[1]) == "bigint"
29942+ @needs_bigint = 1
29943+ val_sih = "sp_bigint_to_int((sp_Bigint *)" + val + ")"
29944+ end
29945+ emit(" sp_SymIntHash_set(" + rc + ", " + idx + ", " + val_sih + ");")
2992629946 return
2992729947 end
2992829948 if rt == "sym_str_hash"