Commit ea5c9399

ea5c9399602bMerged

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

Description

fix(codegen): poly length arms (both paths) wrap mrb_int for bigint slot

Two length / size arms still didn't wrap their runtime length call to match a bigint result slot:

  • compile_poly_method_call's SP_TAG_STR / SymPolyHash / Poly PolyHash arms — reach the result temp from a poly recv with user classes that override the method to a bigint return.
  • compile_poly_method_call's second length arm at ~22162 (covers the same cls_ids as emit_poly_builtin_dispatch's arm, but reached through a different upstream gate).

Pre-compute the wrap prefix once and apply uniformly. The SP_TAG _STR arm reads compile_poly_method_call's ret_type local; the emit_poly_builtin_dispatch arms read the result_t parameter (threaded through from compile_poly_method_call's ret_type at the dispatch call site).

Promote-mode test count: 549 pass / 49 fail / 20 error -> 550 pass / 50 fail / 18 error. Default raise mode 618 / 0 / 0; optcarrot checksum 59662.

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

Details

Commit
ea5c9399602b
Parent
771433db346e

spinel_codegen.rbmodifiedView file

@@ -21510,7 +21510,7 @@
2151021510 slen_c = "sp_str_length(" + recv_tmp + ".v.s)"
2151121511 if is_poly_ret == 1
2151221512 slen_rhs = "sp_box_int(" + slen_c + ")"
21513- elsif base_type(result_t) == "bigint"
21513+ elsif base_type(ret_type) == "bigint"
2151421514 @needs_bigint = 1
2151521515 slen_rhs = "sp_bigint_new_int(" + slen_c + ")"
2151621516 else
@@ -21891,12 +21891,10 @@
2189121891 emit(" if (" + recv_tmp + ".cls_id == SP_BUILTIN_INT_STR_HASH) " + result_tmp + " = " + isthc + ";")
2189221892 sphc = pbd_len_open + "sp_StrPolyHash_length((sp_StrPolyHash *)" + recv_tmp + ".v.p)" + pbd_len_close
2189321893 emit(" if (" + recv_tmp + ".cls_id == SP_BUILTIN_STR_POLY_HASH) " + result_tmp + " = " + sphc + ";")
21894- ypc = "sp_SymPolyHash_length((sp_SymPolyHash *)" + recv_tmp + ".v.p)"
21895- yprhs = is_poly_ret == 1 ? "sp_box_int(" + ypc + ")" : ypc
21896- emit(" if (" + recv_tmp + ".cls_id == SP_BUILTIN_SYM_POLY_HASH) " + result_tmp + " = " + yprhs + ";")
21897- pphc = "sp_PolyPolyHash_length((sp_PolyPolyHash *)" + recv_tmp + ".v.p)"
21898- pphrhs = is_poly_ret == 1 ? "sp_box_int(" + pphc + ")" : pphc
21899- emit(" if (" + recv_tmp + ".cls_id == SP_BUILTIN_POLY_POLY_HASH) " + result_tmp + " = " + pphrhs + ";")
21894+ ypc = pbd_len_open + "sp_SymPolyHash_length((sp_SymPolyHash *)" + recv_tmp + ".v.p)" + pbd_len_close
21895+ emit(" if (" + recv_tmp + ".cls_id == SP_BUILTIN_SYM_POLY_HASH) " + result_tmp + " = " + ypc + ";")
21896+ pphc = pbd_len_open + "sp_PolyPolyHash_length((sp_PolyPolyHash *)" + recv_tmp + ".v.p)" + pbd_len_close
21897+ emit(" if (" + recv_tmp + ".cls_id == SP_BUILTIN_POLY_POLY_HASH) " + result_tmp + " = " + pphc + ";")
2190021898 end
2190121899 # empty? arms -- sibling of length/size for the poly recv
2190221900 # variants. Issue #552. Always returns a bool (sp_box_bool
@@ -22160,25 +22158,31 @@
2216022158 # `_length` helper (sym_array shares IntArray's). PtrArray is
2216122159 # safe here because length doesn't need an element type.
2216222160 if mname == "length" || mname == "size"
22163- ic = "sp_IntArray_length((sp_IntArray *)" + recv_tmp + ".v.p)"
22164- irhs = is_poly_ret == 1 ? "sp_box_int(" + ic + ")" : ic
22165- emit(" if (" + recv_tmp + ".cls_id == SP_BUILTIN_INT_ARRAY) " + result_tmp + " = " + irhs + ";")
22166- fc = "sp_FloatArray_length((sp_FloatArray *)" + recv_tmp + ".v.p)"
22167- frhs = is_poly_ret == 1 ? "sp_box_int(" + fc + ")" : fc
22168- emit(" if (" + recv_tmp + ".cls_id == SP_BUILTIN_FLT_ARRAY) " + result_tmp + " = " + frhs + ";")
22169- sc = "sp_StrArray_length((sp_StrArray *)" + recv_tmp + ".v.p)"
22170- srhs = is_poly_ret == 1 ? "sp_box_int(" + sc + ")" : sc
22171- emit(" if (" + recv_tmp + ".cls_id == SP_BUILTIN_STR_ARRAY) " + result_tmp + " = " + srhs + ";")
22161+ # Pick int-result wrap once: poly-ret needs sp_box_int, bigint
22162+ # result slot needs sp_bigint_new_int, otherwise raw mrb_int.
22163+ pmc_len_open = ""
22164+ pmc_len_close = ""
22165+ if is_poly_ret == 1
22166+ pmc_len_open = "sp_box_int("
22167+ pmc_len_close = ")"
22168+ elsif base_type(result_t) == "bigint"
22169+ @needs_bigint = 1
22170+ pmc_len_open = "sp_bigint_new_int("
22171+ pmc_len_close = ")"
22172+ end
22173+ ic = pmc_len_open + "sp_IntArray_length((sp_IntArray *)" + recv_tmp + ".v.p)" + pmc_len_close
22174+ emit(" if (" + recv_tmp + ".cls_id == SP_BUILTIN_INT_ARRAY) " + result_tmp + " = " + ic + ";")
22175+ fc = pmc_len_open + "sp_FloatArray_length((sp_FloatArray *)" + recv_tmp + ".v.p)" + pmc_len_close
22176+ emit(" if (" + recv_tmp + ".cls_id == SP_BUILTIN_FLT_ARRAY) " + result_tmp + " = " + fc + ";")
22177+ sc = pmc_len_open + "sp_StrArray_length((sp_StrArray *)" + recv_tmp + ".v.p)" + pmc_len_close
22178+ emit(" if (" + recv_tmp + ".cls_id == SP_BUILTIN_STR_ARRAY) " + result_tmp + " = " + sc + ";")
2217222179 # sym_array shares the IntArray representation (same `_length`).
22173- yc = "sp_IntArray_length((sp_IntArray *)" + recv_tmp + ".v.p)"
22174- yrhs = is_poly_ret == 1 ? "sp_box_int(" + yc + ")" : yc
22175- emit(" if (" + recv_tmp + ".cls_id == SP_BUILTIN_SYM_ARRAY) " + result_tmp + " = " + yrhs + ";")
22176- pc = "sp_PtrArray_length((sp_PtrArray *)" + recv_tmp + ".v.p)"
22177- prhs = is_poly_ret == 1 ? "sp_box_int(" + pc + ")" : pc
22178- emit(" if (" + recv_tmp + ".cls_id == SP_BUILTIN_PTR_ARRAY) " + result_tmp + " = " + prhs + ";")
22179- polyc = "sp_PolyArray_length((sp_PolyArray *)" + recv_tmp + ".v.p)"
22180- polyrhs = is_poly_ret == 1 ? "sp_box_int(" + polyc + ")" : polyc
22181- emit(" if (" + recv_tmp + ".cls_id == SP_BUILTIN_POLY_ARRAY) " + result_tmp + " = " + polyrhs + ";")
22180+ yc = pmc_len_open + "sp_IntArray_length((sp_IntArray *)" + recv_tmp + ".v.p)" + pmc_len_close
22181+ emit(" if (" + recv_tmp + ".cls_id == SP_BUILTIN_SYM_ARRAY) " + result_tmp + " = " + yc + ";")
22182+ pc = pmc_len_open + "sp_PtrArray_length((sp_PtrArray *)" + recv_tmp + ".v.p)" + pmc_len_close
22183+ emit(" if (" + recv_tmp + ".cls_id == SP_BUILTIN_PTR_ARRAY) " + result_tmp + " = " + pc + ";")
22184+ polyc = pmc_len_open + "sp_PolyArray_length((sp_PolyArray *)" + recv_tmp + ".v.p)" + pmc_len_close
22185+ emit(" if (" + recv_tmp + ".cls_id == SP_BUILTIN_POLY_ARRAY) " + result_tmp + " = " + polyc + ";")
2218222186 end
2218322187 end
2218422188