Commit ffba0284

ffba0284ac18Merged

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

Description

codegen: coerce poly int-args at array index/string-index builtins under promote

sp_str_index_from_opt's start offset and sp_IntArray_index[_poly]'s search value take a raw mrb_int; route them through emit_int_expr so a poly value (under promote) is unboxed with sp_poly_to_i, while non-poly args (and string-array searches) are unchanged. Unblocks array_index_int_opt_narrow, bundle_string_c.

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

Details

Commit
ffba0284ac18
Parent
22e605fc757b

src/codegen_call.cmodifiedView file

@@ -1055,7 +1055,9 @@
10551055 /* nil-on-miss -> poly */
10561056 const char *fn = !strcmp(name, "rindex") ? "rindex_poly" : "index_poly";
10571057 buf_printf(b, "sp_%sArray_%s(", k, fn);
1058- emit_expr(c, recv, b); buf_puts(b, ", "); emit_expr(c, argv[0], b); buf_puts(b, ")");
1058+ emit_expr(c, recv, b); buf_puts(b, ", ");
1059+ if (!strcmp(k, "Int")) emit_int_expr(c, argv[0], b); else emit_expr(c, argv[0], b);
1060+ buf_puts(b, ")");
10591061 return 1;
10601062 }
10611063 if (!strcmp(name, "include?") && argc == 1) {
@@ -1075,7 +1077,9 @@
10751077 if ((!strcmp(name, "include?") || !strcmp(name, "member?") || !strcmp(name, "index") || !strcmp(name, "find_index")) && argc == 1 && rt != TY_FLOAT_ARRAY) {
10761078 const char *fn = (!strcmp(name, "include?") || !strcmp(name, "member?")) ? "include" : "index";
10771079 buf_printf(b, "sp_%sArray_%s(", k, fn);
1078- emit_expr(c, recv, b); buf_puts(b, ", "); emit_expr(c, argv[0], b); buf_puts(b, ")");
1080+ emit_expr(c, recv, b); buf_puts(b, ", ");
1081+ if (!strcmp(k, "Int")) emit_int_expr(c, argv[0], b); else emit_expr(c, argv[0], b);
1082+ buf_puts(b, ")");
10791083 return 1;
10801084 }
10811085 if (!strcmp(name, "sort") && argc == 0 &&
@@ -2162,7 +2166,7 @@
21622166 else if (!strcmp(name, "index") && argc == 2) {
21632167 buf_printf(b, "sp_str_index_from_opt(%s, ", r);
21642168 emit_expr(c, argv[0], b); buf_puts(b, ", ");
2165- emit_expr(c, argv[1], b); buf_puts(b, ")");
2169+ emit_int_expr(c, argv[1], b); buf_puts(b, ")");
21662170 }
21672171 else if ((!strcmp(name, "partition") || !strcmp(name, "rpartition")) && argc == 1 &&
21682172 re_lit_index(c, argv[0]) < 0) {