Commit 41a4dd16
41a4dd16e4a3Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(codegen): index op-assign / multi-write target unbox bigint index
compile_index_op_assign, compile_index_and_assign,
compile_index_or_assign, and the IndexTargetNode arm in
emit_multi_write_target all declared mrb_int <ti> = <idx>;
as part of their typed-array set/get fast paths. With promote
mode widening the source index expression to bigint, the init
needed an sp_bigint_to_int unbox.
Snapshot the unboxed index into a local idx_int_* variable at
the top of each function so the typed-array arms (float_array,
int_array) use the unboxed value, while the poly-recv arm
further down (which needs the boxed sp_RbVal for tag dispatch)
keeps using the raw idx. Also extend compile_expr_as_int
itself so other call sites get the same bigint unbox when the
arg expression is bigint-typed.
Promote-mode test count: 499 pass / 43 fail / 76 error -> 501 pass / 43 fail / 74 error. Default raise mode unchanged at 618 / 0 / 0.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 41a4dd16e4a3
- Parent
- 2d46808b2d42
spinel_codegen.rbmodifiedView file
if infer_type(nid) == "poly" return "(" + ce + ").v.i" end # `--int-overflow=promote` widens int slots to bigint; many # int-expecting C call sites (array indices, hash keys, range # endpoints, ...) still need a raw mrb_int. Mirror compile_arg0 # _as_int's bigint arm so promote mode flows the unbox through # the broader expr path. if infer_type(nid) == "bigint" @needs_bigint = 1 return "sp_bigint_to_int((sp_Bigint *)" + ce + ")" end ce end rt = infer_type(tgt_recv) rc = compile_expr_gc_rooted(tgt_recv) idx = compile_expr(tgt_arg_ids[0]) # promote-mode-widened index: unbox to mrb_int for typed-array / # int-keyed-hash recv sites that expect an int key. idx_int_mt = idx if infer_type(tgt_arg_ids[0]) == "bigint" @needs_bigint = 1 idx_int_mt = "sp_bigint_to_int((sp_Bigint *)" + idx + ")" end if rt == "float_array" || rt == "int_array" pfx = array_c_prefix(rt) tt = new_temp ti = new_temp emit(" { sp_" + pfx + " *" + tt + " = " + rc + "; mrb_int " + ti + " = " + idx + emit(" { sp_" + pfx + " *" + tt + " = " + rc + "; mrb_int " + ti + " = " + idx_int_mt + "; sp_" + pfx + "_set(" + tt + ", " + ti + ", (" + value_expr + ")); }") end if rt == "str_int_hash" rc = compile_expr_gc_rooted(recv) idx = compile_expr(arg_ids[0]) val = compile_expr(@nd_expression[nid]) idx_int_io = idx if infer_type(arg_ids[0]) == "bigint" @needs_bigint = 1 idx_int_io = "sp_bigint_to_int((sp_Bigint *)" + idx + ")" end if rt == "float_array" || rt == "int_array" pfx = array_c_prefix(rt) tt = new_temp ti = new_temp emit(" { sp_" + pfx + " *" + tt + " = " + rc + "; mrb_int " + ti + " = " + idx + emit(" { sp_" + pfx + " *" + tt + " = " + rc + "; mrb_int " + ti + " = " + idx_int_io + "; sp_" + pfx + "_set(" + tt + ", " + ti + ", sp_" + pfx + "_get(" + tt + ", " + ti + ") " + op + " (" + val + ")); }") return rt = infer_type(recv) rc = compile_expr_gc_rooted(recv) idx = compile_expr(arg_ids[0]) idx_int_ia = idx if infer_type(arg_ids[0]) == "bigint" @needs_bigint = 1 idx_int_ia = "sp_bigint_to_int((sp_Bigint *)" + idx + ")" end # Note: defer compile_expr(@nd_expression[nid]) to inside each # if-branch so RHS side effects only fire when the get is truthy # (Ruby `&&=` short-circuit semantics). pfx = array_c_prefix(rt) tt = new_temp ti = new_temp emit(" { sp_" + pfx + " *" + tt + " = " + rc + "; mrb_int " + ti + " = " + idx + ";") emit(" { sp_" + pfx + " *" + tt + " = " + rc + "; mrb_int " + ti + " = " + idx_int_ia + ";") emit(" if (sp_" + pfx + "_get(" + tt + ", " + ti + ")) {") val = compile_expr(@nd_expression[nid]) emit(" sp_" + pfx + "_set(" + tt + ", " + ti + ", (" + val + "));") rt = infer_type(recv) rc = compile_expr_gc_rooted(recv) idx = compile_expr(arg_ids[0]) idx_int_or = idx if infer_type(arg_ids[0]) == "bigint" @needs_bigint = 1 idx_int_or = "sp_bigint_to_int((sp_Bigint *)" + idx + ")" end # Note: defer compile_expr(@nd_expression[nid]) to inside each # if-branch so RHS side effects only fire when the get is falsy # (Ruby `||=` short-circuit semantics). pfx = array_c_prefix(rt) tt = new_temp ti = new_temp emit(" { sp_" + pfx + " *" + tt + " = " + rc + "; mrb_int " + ti + " = " + idx + ";") emit(" { sp_" + pfx + " *" + tt + " = " + rc + "; mrb_int " + ti + " = " + idx_int_or + ";") emit(" if (!sp_" + pfx + "_get(" + tt + ", " + ti + ")) {") val = compile_expr(@nd_expression[nid]) emit(" sp_" + pfx + "_set(" + tt + ", " + ti + ", (" + val + "));")