Commit 842574c8

842574c8fd43Merged

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

Description

fix: root GC-returning subexpressions as transient temps, close #4

Method-call receivers (and other GC-returning subexpressions) were emitted inline like sp_str_split(sp_str_strip(lv_line), " "); The result of the inner call is held only as a C-stack argument, not on sp_gc_roots[], so when the outer call triggers sp_gc_collect (e.g. sp_str_split's internal sp_StrArray_new crossing the heap threshold), the inner allocation is swept and the outer reads freed memory. On glibc this is usually masked because the freed bytes aren't immediately reused. On Darwin's malloc the reuse is aggressive and the bug surfaces as corrupted hash keys in io_wordcount.

The same structural UAF applies to every GC-allocated type, not just strings: chained calls producing IntArrays, StrArrays, class instances, etc. all share the pattern. The fix is therefore at codegen level, uniform across types.

Introduce compile_expr_gc_rooted(nid). If the expression is a CallNode whose result type needs GC protection, bind the result to a fresh temp and SP_GC_ROOT it before use. Route the receiver of every call dispatch (the 58 rc = compile_expr(recv) sites) through this helper instead of plain compile_expr.

lv_parts = sp_str_split(sp_str_strip(lv_line), " "); becomes const char *_t1 = sp_str_strip(lv_line); SP_GC_ROOT(_t1); lv_parts = sp_str_split(_t1, " ");

Locals, ivars, and literals are skipped: they're already rooted or immortal. Non-GC types are skipped: no rooting needed.

Bootstrap still reproduces (gen2.c == gen3.c). 74 tests / 55 benchmarks pass on Linux with no measurable compile-time regression. macOS verification pending on the PR thread; the bug the OP diagnosed should be fixed by construction for all GC types, not just strings.

Diagnosis and macOS symptom reported by Stoyan Zhekov (@zh) in #4. Credit for the root-cause analysis is entirely his.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
842574c8fd43
Parent
fba2456a451b

spinel_codegen.rbmodifiedView file

@@ -11431,6 +11431,67 @@
1143111431 result
1143211432 end
1143311433
11434+ # True if `t` is a GC-allocated pointer that could be swept by
11435+ # sp_gc_collect if held only as a C-stack temp when the collector
11436+ # runs mid-expression.
11437+ def type_needs_transient_root(t)
11438+ if t == ""
11439+ return 0
11440+ end
11441+ if is_nullable_type(t) == 1
11442+ t = base_type(t)
11443+ end
11444+ if t == "string" || t == "mutable_str"
11445+ return 1
11446+ end
11447+ if t == "int_array" || t == "str_array" || t == "float_array" || t == "sym_array"
11448+ return 1
11449+ end
11450+ if t == "str_int_hash" || t == "str_str_hash" || t == "sym_int_hash" || t == "sym_str_hash"
11451+ return 1
11452+ end
11453+ if t == "str_poly_hash" || t == "sym_poly_hash"
11454+ return 1
11455+ end
11456+ if is_ptr_array_type(t) == 1
11457+ return 1
11458+ end
11459+ if is_obj_type(t) == 1
11460+ return 1
11461+ end
11462+ if is_tuple_type(t) == 1
11463+ return 1
11464+ end
11465+ if t == "stringio" || t == "fiber" || t == "bigint" || t == "lambda" || t == "poly_array"
11466+ return 1
11467+ end
11468+ 0
11469+ end
11470+
11471+ # Compile `nid`, and if it's a call expression whose result is a
11472+ # GC-allocated pointer, bind that result to a rooted temp variable
11473+ # so a subsequent mid-expression sp_gc_collect cannot sweep it.
11474+ # For non-call expressions (locals, ivars, literals) rooting is
11475+ # either already in place or unnecessary.
11476+ def compile_expr_gc_rooted(nid)
11477+ val = compile_expr(nid)
11478+ if nid < 0
11479+ return val
11480+ end
11481+ if @nd_type[nid] != "CallNode"
11482+ return val
11483+ end
11484+ t = infer_type(nid)
11485+ if type_needs_transient_root(t) == 0
11486+ return val
11487+ end
11488+ @needs_gc = 1
11489+ tmp = new_temp
11490+ emit(" " + c_type(t) + " " + tmp + " = " + val + ";")
11491+ emit(" SP_GC_ROOT(" + tmp + ");")
11492+ tmp
11493+ end
11494+
1143411495 def compile_arg0(nid)
1143511496 args_id = @nd_arguments[nid]
1143611497 if args_id >= 0
@@ -11847,7 +11908,7 @@
1184711908 if mname == "resume" && recv >= 0
1184811909 rt2 = base_type(infer_type(recv))
1184911910 if rt2 == "fiber"
11850- rc = compile_expr(recv)
11911+ rc = compile_expr_gc_rooted(recv)
1185111912 args_id = @nd_arguments[nid]
1185211913 if args_id >= 0
1185311914 arg_ids = get_args(args_id)
@@ -11877,7 +11938,7 @@
1187711938 if mname == "alive?" && recv >= 0
1187811939 rt2 = base_type(infer_type(recv))
1187911940 if rt2 == "fiber"
11880- rc = compile_expr(recv)
11941+ rc = compile_expr_gc_rooted(recv)
1188111942 return "sp_Fiber_alive((sp_Fiber *)(" + rc + "))"
1188211943 end
1188311944 end
@@ -11885,7 +11946,7 @@
1188511946 if mname == "transfer" && recv >= 0
1188611947 rt2 = base_type(infer_type(recv))
1188711948 if rt2 == "fiber"
11888- rc = compile_expr(recv)
11949+ rc = compile_expr_gc_rooted(recv)
1188911950 args_id = @nd_arguments[nid]
1189011951 if args_id >= 0
1189111952 arg_ids = get_args(args_id)
@@ -11950,7 +12011,7 @@
1195012011 end
1195112012
1195212013 recv_type = infer_type(recv)
11953- rc = compile_expr(recv)
12014+ rc = compile_expr_gc_rooted(recv)
1195412015 # Root receiver if it may be collected during argument evaluation
1195512016 if expr_may_gc(recv) == 1 && type_is_pointer(recv_type) == 1
1195612017 args_id = @nd_arguments[nid]
@@ -12425,7 +12486,7 @@
1242512486 end
1242612487
1242712488 def compile_lambda_call_expr(nid, mname, recv)
12428- rc = compile_expr(recv)
12489+ rc = compile_expr_gc_rooted(recv)
1242912490 # Determine return type unboxing
1243012491 ret_type = ""
1243112492 if @nd_type[recv] == "LocalVariableReadNode"
@@ -12458,7 +12519,7 @@
1245812519 owner = find_method_owner(ci, mname)
1245912520 if owner != ""
1246012521 ca = compile_call_args(nid)
12461- rc = compile_expr(recv)
12522+ rc = compile_expr_gc_rooted(recv)
1246212523 if owner == cname
1246312524 if ca != ""
1246412525 return "sp_" + owner + "_" + sanitize_name(mname) + "(" + rc + ", " + ca + ")"
@@ -12477,7 +12538,7 @@
1247712538 cmp_owner = find_method_owner(ci, "<=>")
1247812539 if cmp_owner != ""
1247912540 ca = compile_call_args(nid)
12480- rc = compile_expr(recv)
12541+ rc = compile_expr_gc_rooted(recv)
1248112542 cmp_call = "sp_" + cmp_owner + "__cmp(" + rc + ", " + ca + ")"
1248212543 if mname == "<"
1248312544 return "(" + cmp_call + " < 0)"
@@ -12684,7 +12745,7 @@
1268412745 return "sp_poly_add(" + compile_expr(recv) + ", " + box_expr_to_poly(@nd_arguments[nid] >= 0 ? get_args(@nd_arguments[nid])[0] : -1) + ")"
1268512746 end
1268612747 if lt == "int_array" || lt == "str_array" || lt == "float_array" || lt == "sym_array"
12687- rc = compile_expr(recv)
12748+ rc = compile_expr_gc_rooted(recv)
1268812749 arg = compile_arg0(nid)
1268912750 pfx = array_c_prefix(lt)
1269012751 tmp = new_temp
@@ -12791,7 +12852,7 @@
1279112852 end
1279212853 if mname == "=~"
1279312854 # str =~ /pattern/ → sp_re_match(pat, str)
12794- rc = compile_expr(recv)
12855+ rc = compile_expr_gc_rooted(recv)
1279512856 re_args_id = @nd_arguments[nid]
1279612857 if re_args_id >= 0
1279712858 argl = get_args(re_args_id)
@@ -12818,7 +12879,7 @@
1281812879 if args_id >= 0
1281912880 aargs = get_args(args_id)
1282012881 if aargs.length >= 2
12821- rc = compile_expr(recv)
12882+ rc = compile_expr_gc_rooted(recv)
1282212883 lo = compile_expr(aargs[0])
1282312884 hi = compile_expr(aargs[1])
1282412885 lt = infer_type(recv)
@@ -12833,7 +12894,7 @@
1283312894 lt = infer_type(recv)
1283412895 if lt == "mutable_str"
1283512896 @needs_mutable_str = 1
12836- rc = compile_expr(recv)
12897+ rc = compile_expr_gc_rooted(recv)
1283712898 val = compile_arg0(nid)
1283812899 return "(sp_String_append(" + rc + ", " + val + "), " + rc + ")"
1283912900 end
@@ -16355,7 +16416,7 @@
1635516416 return ""
1635616417 end
1635716418 tmp = new_temp
16358- rc = compile_expr(recv)
16419+ rc = compile_expr_gc_rooted(recv)
1635916420 emit(" mrb_int " + tmp + " = (mrb_int)strlen(" + rc + ");")
1636016421 @hoisted_strlen_recv = rc
1636116422 return tmp
@@ -16369,7 +16430,7 @@
1636916430 # (The pred_nid is the while predicate; body scan happens below via caller
1637016431 # passing @while_body_nid. Here we only check if type is hoistable.)
1637116432 tmp = new_temp
16372- rc = compile_expr(recv)
16433+ rc = compile_expr_gc_rooted(recv)
1637316434 emit(" mrb_int " + tmp + " = " + length_c_expr(rt, rc) + ";")
1637416435 @hoisted_strlen_recv = rc
1637516436 tmp
@@ -16868,7 +16929,7 @@
1686816929 if args_id >= 0
1686916930 aargs = get_args(args_id)
1687016931 if aargs.length >= 2
16871- rc = compile_expr(recv)
16932+ rc = compile_expr_gc_rooted(recv)
1687216933 val = compile_expr(aargs[1])
1687316934 if rt == "sym_int_hash"
1687416935 emit(" sp_SymIntHash_set(" + rc + ", " + compile_expr(aargs[0]) + ", " + val + ");")
@@ -16896,7 +16957,7 @@
1689616957 if mname == "delete"
1689716958 if recv >= 0
1689816959 rt = infer_type(recv)
16899- rc = compile_expr(recv)
16960+ rc = compile_expr_gc_rooted(recv)
1690016961 if rt == "sym_int_hash"
1690116962 emit(" sp_SymIntHash_delete(" + rc + ", " + compile_arg0(nid) + ");")
1690216963 return 1
@@ -16930,7 +16991,7 @@
1693016991 rt = infer_type(recv)
1693116992 if rt == "mutable_str"
1693216993 @needs_mutable_str = 1
16933- rc = compile_expr(recv)
16994+ rc = compile_expr_gc_rooted(recv)
1693416995 arg_id = @nd_arguments[nid]
1693516996 if arg_id >= 0
1693616997 argl = parse_id_list(@nd_args[arg_id])
@@ -16952,7 +17013,7 @@
1695217013 end
1695317014 if rt == "string"
1695417015 @needs_string_helpers = 1
16955- rc = compile_expr(recv)
17016+ rc = compile_expr_gc_rooted(recv)
1695617017 val = compile_arg0(nid)
1695717018 # If receiver is a local variable, reassign
1695817019 if @nd_type[recv] == "LocalVariableReadNode"
@@ -16972,22 +17033,22 @@
1697217033 if recv >= 0
1697317034 rt = infer_type(recv)
1697417035 if rt == "int_array"
16975- rc = compile_expr(recv)
17036+ rc = compile_expr_gc_rooted(recv)
1697617037 emit(" sp_IntArray_push(" + rc + ", " + compile_arg0(nid) + ");")
1697717038 return 1
1697817039 end
1697917040 if rt == "str_array"
16980- rc = compile_expr(recv)
17041+ rc = compile_expr_gc_rooted(recv)
1698117042 emit(" sp_StrArray_push(" + rc + ", " + compile_arg0(nid) + ");")
1698217043 return 1
1698317044 end
1698417045 if rt == "float_array"
16985- rc = compile_expr(recv)
17046+ rc = compile_expr_gc_rooted(recv)
1698617047 emit(" sp_FloatArray_push(" + rc + ", " + compile_arg0(nid) + ");")
1698717048 return 1
1698817049 end
1698917050 if is_ptr_array_type(rt) == 1
16990- rc = compile_expr(recv)
17051+ rc = compile_expr_gc_rooted(recv)
1699117052 emit(" sp_PtrArray_push(" + rc + ", " + compile_arg0(nid) + ");")
1699217053 return 1
1699317054 end
@@ -16999,12 +17060,12 @@
1699917060 if recv >= 0
1700017061 rt = infer_type(recv)
1700117062 if rt == "str_int_hash"
17002- rc = compile_expr(recv)
17063+ rc = compile_expr_gc_rooted(recv)
1700317064 emit(" sp_StrIntHash_update(" + rc + ", " + compile_arg0(nid) + ");")
1700417065 return 1
1700517066 end
1700617067 if rt == "str_str_hash"
17007- rc = compile_expr(recv)
17068+ rc = compile_expr_gc_rooted(recv)
1700817069 emit(" sp_StrStrHash_update(" + rc + ", " + compile_arg0(nid) + ");")
1700917070 return 1
1701017071 end
@@ -17016,7 +17077,7 @@
1701617077 if recv >= 0
1701717078 rt = infer_type(recv)
1701817079 if rt == "int_array" || rt == "str_array" || rt == "float_array" || rt == "sym_array"
17019- rc = compile_expr(recv)
17080+ rc = compile_expr_gc_rooted(recv)
1702017081 arg = compile_arg0(nid)
1702117082 pfx = array_c_prefix(rt)
1702217083 tmp = new_temp
@@ -17026,7 +17087,7 @@
1702617087 end
1702717088 if rt == "mutable_str"
1702817089 @needs_mutable_str = 1
17029- rc = compile_expr(recv)
17090+ rc = compile_expr_gc_rooted(recv)
1703017091 args_id = @nd_arguments[nid]
1703117092 if args_id >= 0
1703217093 aargs = get_args(args_id)
@@ -17046,7 +17107,7 @@
1704617107 if recv >= 0
1704717108 rt = infer_type(recv)
1704817109 if rt == "mutable_str"
17049- rc = compile_expr(recv)
17110+ rc = compile_expr_gc_rooted(recv)
1705017111 val = compile_arg0(nid)
1705117112 emit(" " + rc + "->len = 0; " + rc + "->data[0] = 0; sp_String_append(" + rc + ", " + val + ");")
1705217113 return 1
@@ -17071,7 +17132,7 @@
1707117132 rt = infer_type(recv)
1707217133 if rt == "mutable_str"
1707317134 @needs_mutable_str = 1
17074- rc = compile_expr(recv)
17135+ rc = compile_expr_gc_rooted(recv)
1707517136 val = compile_arg0(nid)
1707617137 emit(" sp_String_prepend(" + rc + ", " + val + ");")
1707717138 return 1
@@ -17084,7 +17145,7 @@
1708417145 if recv >= 0
1708517146 rt = infer_type(recv)
1708617147 if rt == "mutable_str"
17087- rc = compile_expr(recv)
17148+ rc = compile_expr_gc_rooted(recv)
1708817149 emit(" " + rc + "->len = 0; " + rc + "->data[0] = 0;")
1708917150 return 1
1709017151 end
@@ -17105,7 +17166,7 @@
1710517166 if mname == "push"
1710617167 if recv >= 0
1710717168 rt = infer_type(recv)
17108- rc = compile_expr(recv)
17169+ rc = compile_expr_gc_rooted(recv)
1710917170 if rt == "int_array"
1711017171 av = compile_arg0(nid)
1711117172 # If pushing a lambda value, cast to mrb_int
@@ -17136,7 +17197,7 @@
1713617197 if mname == "reverse!"
1713717198 if recv >= 0
1713817199 rt = infer_type(recv)
17139- rc = compile_expr(recv)
17200+ rc = compile_expr_gc_rooted(recv)
1714017201 if rt == "int_array"
1714117202 emit(" sp_IntArray_reverse_bang(" + rc + ");")
1714217203 return 1
@@ -17146,7 +17207,7 @@
1714617207 if mname == "sort!"
1714717208 if recv >= 0
1714817209 rt = infer_type(recv)
17149- rc = compile_expr(recv)
17210+ rc = compile_expr_gc_rooted(recv)
1715017211 if rt == "sym_array"
1715117212 emit(" sp_sym_array_sort(" + rc + ");")
1715217213 return 1
@@ -17198,7 +17259,7 @@
1719817259 if @nd_block[nid] >= 0 && recv >= 0
1719917260 rt = infer_type(recv)
1720017261 if rt == "string" || rt == "mutable_str"
17201- rc = compile_expr(recv)
17262+ rc = compile_expr_gc_rooted(recv)
1720217263 bp = get_block_param(nid, 0)
1720317264 if bp == ""
1720417265 bp = "_c"
@@ -17227,7 +17288,7 @@
1722717288 if @nd_block[nid] >= 0 && recv >= 0
1722817289 rt = infer_type(recv)
1722917290 if rt == "string" || rt == "mutable_str"
17230- rc = compile_expr(recv)
17291+ rc = compile_expr_gc_rooted(recv)
1723117292 bp = get_block_param(nid, 0)
1723217293 if bp == ""
1723317294 bp = "_b"
@@ -17255,7 +17316,7 @@
1725517316 if @nd_block[nid] >= 0 && recv >= 0
1725617317 rt = infer_type(recv)
1725717318 if rt == "string" || rt == "mutable_str"
17258- rc = compile_expr(recv)
17319+ rc = compile_expr_gc_rooted(recv)
1725917320 bp = get_block_param(nid, 0)
1726017321 if bp == ""
1726117322 bp = "_l"
@@ -17299,7 +17360,7 @@
1729917360 old = @in_loop
1730017361 @in_loop = 1
1730117362 rt = infer_type(recv)
17302- rc = compile_expr(recv)
17363+ rc = compile_expr_gc_rooted(recv)
1730317364 arg = compile_arg0(nid)
1730417365 bp1 = get_block_param(nid, 0)
1730517366 bp2 = get_block_param(nid, 1)
@@ -17327,7 +17388,7 @@
1732717388 if @nd_block[nid] >= 0 && recv >= 0
1732817389 old = @in_loop
1732917390 @in_loop = 1
17330- rc = compile_expr(recv)
17391+ rc = compile_expr_gc_rooted(recv)
1733117392 args_id = @nd_arguments[nid]
1733217393 limit_val = "0"
1733317394 step_val = "1"
@@ -17359,7 +17420,7 @@
1735917420 old = @in_loop
1736017421 @in_loop = 1
1736117422 rt = infer_type(recv)
17362- rc = compile_expr(recv)
17423+ rc = compile_expr_gc_rooted(recv)
1736317424 n = compile_arg0(nid)
1736417425 bp1 = get_block_param(nid, 0)
1736517426 if bp1 == ""
@@ -17392,7 +17453,7 @@
1739217453 ridx = find_regexp_index(argl[0])
1739317454 if ridx >= 0
1739417455 @needs_str_array = 1
17395- rc = compile_expr(recv)
17456+ rc = compile_expr_gc_rooted(recv)
1739617457 bp = get_block_param(nid, 0)
1739717458 if bp == ""
1739817459 bp = "_m"
@@ -17609,7 +17670,7 @@
1760917670 bname = mname[0, mname.length - 1]
1761017671 rt = infer_type(recv)
1761117672 if is_obj_type(rt) == 1
17612- rc = compile_expr(recv)
17673+ rc = compile_expr_gc_rooted(recv)
1761317674 arrow2 = "->"
1761417675 if is_value_type_obj(rt) == 1
1761517676 arrow2 = "."
@@ -18610,7 +18671,7 @@
1861018671 def compile_bracket_assign(nid)
1861118672 recv = @nd_receiver[nid]
1861218673 rt = infer_type(recv)
18613- rc = compile_expr(recv)
18674+ rc = compile_expr_gc_rooted(recv)
1861418675 args_id = @nd_arguments[nid]
1861518676 arg_ids = []
1861618677 if args_id >= 0
@@ -18923,7 +18984,7 @@
1892318984 old = @in_loop
1892418985 @in_loop = 1
1892518986 rt = infer_type(@nd_receiver[nid])
18926- rc = compile_expr(@nd_receiver[nid])
18987+ rc = compile_expr_gc_rooted(@nd_receiver[nid])
1892718988 n = compile_arg0(nid)
1892818989 bp1 = get_block_param(nid, 0)
1892918990 if bp1 == ""
@@ -18951,7 +19012,7 @@
1895119012 old = @in_loop
1895219013 @in_loop = 1
1895319014 rt = infer_type(@nd_receiver[nid])
18954- rc = compile_expr(@nd_receiver[nid])
19015+ rc = compile_expr_gc_rooted(@nd_receiver[nid])
1895519016 n = compile_arg0(nid)
1895619017 bp1 = get_block_param(nid, 0)
1895719018 if bp1 == ""
@@ -18979,7 +19040,7 @@
1897919040 old = @in_loop
1898019041 @in_loop = 1
1898119042 rt = infer_type(@nd_receiver[nid])
18982- rc = compile_expr(@nd_receiver[nid])
19043+ rc = compile_expr_gc_rooted(@nd_receiver[nid])
1898319044 obj_arg = compile_arg0(nid)
1898419045 bp1 = get_block_param(nid, 0)
1898519046 bp2 = get_block_param(nid, 1)
@@ -19007,7 +19068,7 @@
1900719068 old = @in_loop
1900819069 @in_loop = 1
1900919070 rt = infer_type(@nd_receiver[nid])
19010- rc = compile_expr(@nd_receiver[nid])
19071+ rc = compile_expr_gc_rooted(@nd_receiver[nid])
1901119072 bp1 = get_block_param(nid, 0)
1901219073 bp2 = get_block_param(nid, 1)
1901319074 if bp1 == ""
@@ -19032,7 +19093,7 @@
1903219093 old = @in_loop
1903319094 @in_loop = 1
1903419095 rt = infer_type(@nd_receiver[nid])
19035- rc = compile_expr(@nd_receiver[nid])
19096+ rc = compile_expr_gc_rooted(@nd_receiver[nid])
1903619097 bp1 = get_block_param(nid, 0)
1903719098 bp2 = get_block_param(nid, 1)
1903819099 has_bp = 1
@@ -19175,7 +19236,7 @@
1917519236 def compile_times_block(nid)
1917619237 old = @in_loop
1917719238 @in_loop = 1
19178- rc = compile_expr(@nd_receiver[nid])
19239+ rc = compile_expr_gc_rooted(@nd_receiver[nid])
1917919240 bp1 = get_block_param(nid, 0)
1918019241 tmp = new_temp
1918119242 emit(" for (mrb_int " + tmp + " = 0; " + tmp + " < " + rc + "; " + tmp + "++) {")
@@ -19192,7 +19253,7 @@
1919219253 def compile_upto_block(nid)
1919319254 old = @in_loop
1919419255 @in_loop = 1
19195- rc = compile_expr(@nd_receiver[nid])
19256+ rc = compile_expr_gc_rooted(@nd_receiver[nid])
1919619257 lim = compile_arg0(nid)
1919719258 bp1 = get_block_param(nid, 0)
1919819259 tmp = new_temp
@@ -19210,7 +19271,7 @@
1921019271 def compile_downto_block(nid)
1921119272 old = @in_loop
1921219273 @in_loop = 1
19213- rc = compile_expr(@nd_receiver[nid])
19274+ rc = compile_expr_gc_rooted(@nd_receiver[nid])
1921419275 lim = compile_arg0(nid)
1921519276 bp1 = get_block_param(nid, 0)
1921619277 tmp = new_temp
@@ -19228,7 +19289,7 @@
1922819289 def compile_tap_expr(nid)
1922919290 # Execute block with receiver bound to block param, return receiver
1923019291 rt = infer_type(@nd_receiver[nid])
19231- rc = compile_expr(@nd_receiver[nid])
19292+ rc = compile_expr_gc_rooted(@nd_receiver[nid])
1923219293 bp = get_block_param(nid, 0)
1923319294 if bp == ""
1923419295 bp = "_x"
@@ -19253,7 +19314,7 @@
1925319314 def compile_then_expr(nid)
1925419315 # Execute block with receiver bound to block param, return block result
1925519316 rt = infer_type(@nd_receiver[nid])
19256- rc = compile_expr(@nd_receiver[nid])
19317+ rc = compile_expr_gc_rooted(@nd_receiver[nid])
1925719318 bp = get_block_param(nid, 0)
1925819319 if bp == ""
1925919320 bp = "_x"
@@ -19715,7 +19776,7 @@
1971519776 def compile_flat_map_expr(nid)
1971619777 # flat_map: for each element, block returns an array; concat all results
1971719778 rt = infer_type(@nd_receiver[nid])
19718- rc = compile_expr(@nd_receiver[nid])
19779+ rc = compile_expr_gc_rooted(@nd_receiver[nid])
1971919780 bp1 = get_block_param(nid, 0)
1972019781 if bp1 == ""
1972119782 bp1 = "_x"
@@ -19949,7 +20010,7 @@
1994920010
1995020011 def compile_select_expr(nid)
1995120012 rt = infer_type(@nd_receiver[nid])
19952- rc = compile_expr(@nd_receiver[nid])
20013+ rc = compile_expr_gc_rooted(@nd_receiver[nid])
1995320014 bp1 = get_block_param(nid, 0)
1995420015 if bp1 == ""
1995520016 bp1 = "_x"
@@ -19993,7 +20054,7 @@
1999320054 end
1999420055
1999520056 def compile_reduce_block(nid)
19996- rc = compile_expr(@nd_receiver[nid])
20057+ rc = compile_expr_gc_rooted(@nd_receiver[nid])
1999720058 init_val = compile_arg0(nid)
1999820059 bp1 = get_block_param(nid, 0)
1999920060 bp2 = get_block_param(nid, 1)
@@ -20027,7 +20088,7 @@
2002720088 end
2002820089
2002920090 def compile_reject_expr(nid)
20030- rc = compile_expr(@nd_receiver[nid])
20091+ rc = compile_expr_gc_rooted(@nd_receiver[nid])
2003120092 bp1 = get_block_param(nid, 0)
2003220093 if bp1 == ""
2003320094 bp1 = "_x"
@@ -20061,7 +20122,7 @@
2006120122 end
2006220123
2006320124 def compile_reject_block(nid)
20064- rc = compile_expr(@nd_receiver[nid])
20125+ rc = compile_expr_gc_rooted(@nd_receiver[nid])
2006520126 bp1 = get_block_param(nid, 0)
2006620127 if bp1 == ""
2006720128 bp1 = "_x"
@@ -20698,7 +20759,7 @@
2069820759 end
2069920760
2070020761 recv = @nd_receiver[nid]
20701- rc = compile_expr(recv)
20762+ rc = compile_expr_gc_rooted(recv)
2070220763
2070320764 bodies = @cls_meth_bodies[cci].split(";")
2070420765 bid = -1
@@ -20921,7 +20982,7 @@
2092120982 return
2092220983 end
2092320984 rt = infer_type(@nd_receiver[nid])
20924- rc = compile_expr(@nd_receiver[nid])
20985+ rc = compile_expr_gc_rooted(@nd_receiver[nid])
2092520986 bp1 = get_block_param(nid, 0)
2092620987 if bp1 == ""
2092720988 bp1 = "_x"
@@ -20978,7 +21039,7 @@
2097821039 old = @in_loop
2097921040 @in_loop = 1
2098021041 rt = infer_type(@nd_receiver[nid])
20981- rc = compile_expr(@nd_receiver[nid])
21042+ rc = compile_expr_gc_rooted(@nd_receiver[nid])
2098221043 bp1 = get_block_param(nid, 0)
2098321044 if bp1 == ""
2098421045 bp1 = "_x"