Commit 31a59e30
31a59e30af5eMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
docs(codegen): rewrite issue-ref comments forward-looking (2/2)
Continuation of 3ed0aa8 — strip the remaining Issue #N:
lead-ins from comments throughout spinel_codegen.rb and rewrite
incident-shaped descriptions as forward-looking statements about
what each piece of code does. Issue numbers are gone; the git
log retains the trail for anyone who needs the original
context.
After this commit no Issue #N / matz/spinel#N references
remain in spinel_codegen.rb. Tests: 290 pass. Bootstrap:
gen2.c == gen3.c.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 31a59e30af5e
- Parent
- dde7f6533576
spinel_codegen.rbmodifiedView file
@@ -15171,11 +15171,11 @@
1517115171
infer_function_body_call_types1517215172
infer_class_body_call_types1517315173
infer_ivar_types_from_writers15174-
# Issue #58: after scan_locals has populated @meth_param_empty15175-
# via the per-call-site forward propagation, promote int_array15176-
# params to concrete typed-arrays where bodies push known types.15177-
# Then the next iteration's scan_locals back-propagates those15178-
# promoted types to caller-side locals.15174+
# After scan_locals has populated @meth_param_empty via the15175+
# per-call-site forward propagation, promote int_array15176+
# params to concrete typed-arrays where bodies push known15177+
# types. The next iteration's scan_locals back-propagates15178+
# those promoted types to caller-side locals.1517915179
infer_param_array_type_from_body1518015180
narrow_param_types_from_body_method_calls1518115181
detect_poly_params@@ -15196,9 +15196,9 @@
1519615196
infer_class_body_call_types1519715197
infer_ivar_types_from_writers1519815198
infer_all_returns15199-
# Issue #303: param types are now stable, so module ivar refinement15200-
# (which infers hash / array specialization from `@h[k] = v` writes15201-
# in class-method bodies) sees the right key / value types instead15199+
# Param types are now stable, so module ivar refinement (which15200+
# infers hash / array specialization from `@h[k] = v` writes in15201+
# class-method bodies) sees the right key / value types instead1520215202
# of the placeholder "int" they'd carry at module-collect time.1520315203
# After refining, re-run return / call-type inference so methods1520415204
# that read or push the refined const see the new shape (e.g. a@@ -15255,12 +15255,12 @@
1525515255
end1525615256
gi = gi + 11525715257
end15258-
# Issue #229: compute the live set of cls methods before any15259-
# cls-method-related emit. Forward decls + bodies both consult15258+
# Compute the live set of cls methods before any cls-method-15259+
# related emit. Forward decls + bodies both consult1526015260
# @cls_cmeth_live to skip uncalled methods that may otherwise15261-
# emit non-compiling bodies (uncalled `def self.factory(attrs);15262-
# new(attrs); end` against a 0-arg or differently-typed15263-
# constructor).15261+
# emit non-compiling bodies (an uncalled15262+
# `def self.factory(attrs); new(attrs); end` against a 0-arg15263+
# or differently-typed constructor).1526415264
compute_live_cls_methods1526515265
emit_forward_decls1526615266
emit_global_constants@@ -16028,11 +16028,11 @@
1602816028
if @cvar_names.length > 01602916029
emit_raw("")1603016030
end16031-
# Issue #126 Stage 2: storage for module-level singleton accessors16032-
# whose resolved set has 2+ candidates. The slot stores the16033-
# assigned module's sentinel (mrb_int from `module_sentinel`); the16034-
# write site emits `slot = N;` and the chain dispatch reads back16035-
# via a sentinel switch.16031+
# Storage for module-level singleton accessors whose resolved16032+
# set has 2+ candidates. The slot stores the assigned module's16033+
# sentinel (mrb_int from `module_sentinel`); the write site16034+
# emits `slot = N;` and the chain dispatch reads back via a16035+
# sentinel switch.1603616036
j = 01603716037
emitted = 01603816038
while j < @module_acc_keys.length@@ -16414,20 +16414,21 @@
1641416414
end1641516415
end1641616416
16417-
# Issue #314: classes whose instances flow into a poly-typed param16418-
# slot at any call site. The boxing helper `sp_box_obj(p, ci)` takes16419-
# `void *p`; a value-type-eligible class would emit16420-
# `sp_box_obj(sp_<C>_new(...), ci)` (or `sp_box_obj(local, ci)`16421-
# where `local` is the value-type struct), feeding a struct-by-value16422-
# into a `void *` slot — a C type error. Excluding such classes16423-
# from the value-type optimization keeps `<C>` heap-allocated, so16424-
# the boxing argument is a stable pointer.16417+
# Track classes whose instances flow into a poly-typed param16418+
# slot at any call site. The boxing helper `sp_box_obj(p, ci)`16419+
# takes `void *p`; a value-type-eligible class would emit16420+
# `sp_box_obj(sp_<C>_new(...), ci)` or `sp_box_obj(local, ci)`16421+
# where `local` is the value-type struct, feeding a16422+
# struct-by-value into a `void *` slot — a C type error.16423+
# Excluding such classes from the value-type optimization keeps16424+
# `<C>` heap-allocated, so the boxing argument is always a16425+
# stable pointer.1642516426
#16426-
# Surfaces specifically when a kwargs widening pass (this issue's16427-
# main fix) collapses two or more concrete obj-typed call sites for16428-
# the same kwarg into "poly" — at which point the call site starts16429-
# boxing the instance, hitting the same struct-by-void-* mismatch16430-
# the ptr_array / poly-return passes already guard against.16427+
# Surfaces when kwargs widening collapses two or more concrete16428+
# obj-typed call sites for the same kwarg into "poly" — at that16429+
# point the call site starts boxing the instance, hitting the16430+
# same struct-by-void-* mismatch the ptr_array / poly-return16431+
# passes already guard against.1643116432
def detect_poly_arg_passed_types1643216433
@poly_arg_passed_types = "".split(",")1643316434
nid = 0@@ -16945,11 +16946,11 @@
1694516946
pri = pri + 11694616947
end1694716948
end16948-
# Issue #314: same exclusion for classes whose instances flow16949-
# into a poly-typed param at any call site. Surfaces when16950-
# kwargs widening collapses two obj types into "poly" — the16951-
# call site then boxes a value-type instance, mismatching16952-
# sp_box_obj's `void *` slot.16949+
# Same value-type exclusion for classes whose instances16950+
# flow into a poly-typed param at any call site. When16951+
# kwargs widening collapses two obj types into "poly",16952+
# the call site boxes a value-type instance and16953+
# mismatches sp_box_obj's `void *` slot.1695316954
if all_val == 11695416955
type_str314 = "obj_" + @cls_names[i]1695516956
pai = 0@@ -17399,14 +17400,14 @@
1739917400
i = 01740017401
while i < @cls_names.length1740117402
cname = @cls_names[i]17402-
# Issue #314 follow-up: pin @current_class_idx during this17403-
# forward-decl emit pass so block_params_csig_for_body's17404-
# infer_type calls (on `@ivar` reads inside yield arg17405-
# expressions) resolve against this class's ivar table.17406-
# Without this, ivars infer to int default and yields like17407-
# `yield k, @data[k]` lower to `(mrb_int, mrb_int)` while17408-
# the impl emit (which DOES set @current_class_idx) lowers17409-
# to `(string, sp_RbVal)` — declaration/definition mismatch.17403+
# Pin @current_class_idx during this forward-decl emit pass17404+
# so block_params_csig_for_body's infer_type calls (on17405+
# `@ivar` reads inside yield arg expressions) resolve17406+
# against this class's ivar table. Otherwise ivars infer17407+
# to the int default and yields like `yield k, @data[k]`17408+
# lower to `(mrb_int, mrb_int)` in the decl while the impl17409+
# emit lowers to `(string, sp_RbVal)` — and the C17410+
# declaration/definition signatures mismatch.1741017411
saved_ci_decl = @current_class_idx1741117412
@current_class_idx = i1741217413
# Constructor@@ -17452,10 +17453,10 @@
1745217453
cm_ptypes = @cls_cmeth_ptypes[i].split("|")1745317454
j = 01745417455
while j < cmnames.length17455-
# Issue #229: skip forward decls for dead cls methods so the17456-
# linker doesn't see "declared here" without a definition17457-
# (the corresponding emit_class_methods skip would still17458-
# otherwise leave the prototype dangling).17456+
# Skip forward decls for dead cls methods so the linker17457+
# doesn't see "declared here" without a definition — the17458+
# corresponding emit_class_methods skip would otherwise17459+
# leave the prototype dangling.1745917460
if cls_cmeth_is_live(i, cmnames[j]) == 01746017461
j = j + 11746117462
else@@ -17513,23 +17514,21 @@
1751317514
return ", void (*_block)(" + csig + ", void*), void *_benv"1751417515
end1751517516
17516-
# Issue #314 follow-up: build the block fn-pointer C signature17517-
# from the yield call sites' inferred arg types. Without this,17518-
# block_params_csig emitted `mrb_int, mrb_int, ...` regardless,17519-
# so a method that yields (String, sp_RbVal) had the function-17520-
# pointer declared `void(*)(mrb_int, mrb_int, void*)` while the17521-
# actual yield invocation site emitted `_block(const_char*,17522-
# sp_RbVal, _benv)` — gcc errored with `incompatible type for17523-
# argument`.17517+
# Build the block fn-pointer C signature from the yield call17518+
# sites' inferred arg types. block_params_csig alone returns17519+
# `mrb_int, mrb_int, ...` regardless of what's yielded; this17520+
# variant inspects the body so a method that yields (String,17521+
# sp_RbVal) gets `void (*)(const char *, sp_RbVal, void *)` —17522+
# matching the emitted `_block(lv_k, lv_v, _benv)` call site.1752417523
#1752517524
# Called BEFORE the function's scope has been pushed, so1752617525
# locally-declared vars referenced in yield args (`yield k, v`1752717526
# where `k`, `v` were assigned from typed expressions) are not1752817527
# in @scope_names. Run scan_locals on the body and push a1752917528
# temporary scope so body_yield_arg_types' infer_type calls17530-
# resolve those reads. (Re-runs both at forward-decl emit time17531-
# and at impl emit time; results converge once @meth_*/@cls_*17532-
# tables stabilize through the type-inference fixpoint.)17529+
# resolve those reads. Re-runs at both forward-decl emit time17530+
# and impl emit time; results converge once @meth_* / @cls_*17531+
# tables stabilize through the type-inference fixpoint.1753317532
def block_params_csig_for_body(bid, arity)1753417533
if bid < 0 || arity <= 01753517534
return block_params_csig(arity)@@ -17964,12 +17963,12 @@
1796417963
if j < cm_ptypes.length1796517964
ptypes = cm_ptypes[j].split(",")1796617965
end17967-
# Issue #229: dead-code-eliminate cls methods with no call17968-
# site. The bug is that an unused `def self.factory(attrs);17969-
# new(attrs); ...; end` emits a body whose `sp_<this>_new(args)`17970-
# may not match the defining class's actual constructor17971-
# arity/types — spinel can't infer types for an uncalled17972-
# method, so the body fails to C-compile. compute_live_cls_methods17966+
# Dead-code-eliminate cls methods with no call site. An17967+
# unused `def self.factory(attrs); new(attrs); ...; end`17968+
# would emit a body whose `sp_<this>_new(args)` may not17969+
# match the defining class's actual constructor arity /17970+
# types — spinel can't infer types for an uncalled method,17971+
# so the body fails to C-compile. compute_live_cls_methods1797317972
# ran before emit and seeded live entries from explicit1797417973
# `<Class>.<m>(...)` call sites + transitive self/bare calls1797517974
# within live cls method bodies.@@ -17984,15 +17983,15 @@
1798417983
end1798517984
end1798617985
17987-
# Issue #229: dead-code elimination for cls methods. An uncalled17986+
# Dead-code elimination for class methods. An uncalled1798817987
# `def self.factory(attrs); new(attrs); ...; end` on a parent17989-
# class whose own `initialize` has different arity emits a body17990-
# that doesn't C-compile (`sp_<class>_new(args)` against a 0-arg17991-
# constructor; or, with a default-arg `initialize`, against a17992-
# typed param when the uncalled method's own param can't be17988+
# class whose own `initialize` has different arity would emit a17989+
# body that doesn't C-compile (`sp_<class>_new(args)` against a17990+
# 0-arg constructor; or, with a default-arg `initialize`,17991+
# against a typed param the uncalled method itself can't have1799317992
# inferred). The reachability set seeds from explicit1799417993
# `<Class>.<m>(...)` call sites in the AST, then propagates17995-
# through bare/self calls inside live cls method bodies. Anything17994+
# through bare/self calls inside live cls method bodies; anything1799617995
# not reached is skipped at forward-decl + body emit time.1799717996
#1799817997
# Live entries are stored as `<ClassName>::<methodName>` joined@@ -18148,12 +18147,12 @@
1814818147
if @nd_type[recv] == "SelfNode" && ctx_ci >= 01814918148
cls_cmeth_mark_live(ctx_ci, mname)1815018149
end18151-
# Issue #126 / #229 interaction: `<Module>.<acc>.<method>`18152-
# where `<Module>.<acc>` was constant-folded by Pass 2.718153-
# (resolve_module_singleton_accessors) to a class name.18154-
# The receiver is a CallNode at AST level, so the18155-
# ConstantReadNode branch above doesn't catch it. Look up18156-
# the fold and mark the resolved class's cls method live.18150+
# `<Module>.<acc>.<method>` where `<Module>.<acc>` was18151+
# constant-folded by resolve_module_singleton_accessors to18152+
# one or more class names. The receiver is a CallNode at18153+
# AST level, so the ConstantReadNode branch above doesn't18154+
# catch it; look up the fold and mark each resolved18155+
# class's cls method live.1815718156
if @nd_type[recv] == "CallNode"1815818157
inner_recv = @nd_receiver[recv]1815918158
if inner_recv >= 0 && @nd_type[inner_recv] == "ConstantReadNode"@@ -18325,13 +18324,14 @@
1832518324
end1832618325
if bid >= 01832718326
@current_class_idx = ci18328-
# Issue #337: pin the synthesized sp_<C>_new function's return18329-
# type so a bare `return` inside the initialize body lowers to18330-
# `return self;` (the partially-initialized instance) rather18331-
# than the default `return 0;` (which silently NULLs the18332-
# pointer-returning constructor for the heap-allocated shape).18333-
# Value-type constructors return a struct, leave at "" so the18334-
# bare-return path falls through to its existing 0 default.18327+
# Pin the synthesized sp_<C>_new function's return type so18328+
# a bare `return` inside the initialize body lowers to18329+
# `return self;` (the partially-initialized instance)18330+
# rather than the default `return 0;` — the latter would18331+
# silently NULL the pointer-returning constructor for the18332+
# heap-allocated shape. Value-type constructors return a18333+
# struct; leave at "" so the bare-return path falls18334+
# through to its existing 0 default.1833518335
saved_method_return = @current_method_return1833618336
saved_has_self = @current_method_has_self1833718337
@current_method_has_self = 1@@ -18373,14 +18373,14 @@
1837318373
is_super = (@nd_type[sid] == "SuperNode" || @nd_type[sid] == "ForwardingSuperNode")1837418374
if is_super1837518375
if @cls_parents[ci] != ""18376-
# Issue #314 follow-up: when the immediate parent is18377-
# an "abstract" class (no own `initialize`, e.g.18378-
# `class ApplicationRecord < ActiveRecord::Base`),18379-
# the void `_initialize` wrapper is never emitted for18380-
# it — so a literal `sp_<parent>_initialize(...)` call18381-
# here would be an undefined reference at link time.18382-
# Walk up to find_init_class to skip over abstract18383-
# ancestors and call the nearest emitted wrapper.18376+
# When the immediate parent is an "abstract" class18377+
# (no own `initialize`, e.g. `class ApplicationRecord18378+
# < ActiveRecord::Base`), the void `_initialize`18379+
# wrapper is never emitted for it — a literal18380+
# `sp_<parent>_initialize(...)` call here would be18381+
# an undefined reference at link time. Walk via18382+
# find_init_class to skip over abstract ancestors18383+
# and call the nearest emitted wrapper.1838418384
pi_imm = find_class_idx(@cls_parents[ci])1838518385
pi = pi_imm1838618386
if pi_imm >= 0@@ -18444,13 +18444,13 @@
1844418444
ak = ak + 11844518445
end1844618446
end18447-
# Issue #314 follow-up: explicit `super(...)` with18448-
# fewer args than the parent expects (e.g. `super()`18449-
# against `def initialize(_attrs = {})`). Ruby fills18450-
# missing trailing slots from the parent's defaults;18451-
# the C signature has no defaults, so pad with18452-
# c_default_val per param type. Without this, gcc18453-
# errors `too few arguments to function`.18447+
# Explicit `super(...)` with fewer args than the18448+
# parent expects (e.g. `super()` against18449+
# `def initialize(_attrs = {})`). Ruby fills18450+
# missing trailing slots from the parent's18451+
# defaults; the C signature has no defaults, so18452+
# pad with c_default_val per param type to18453+
# satisfy gcc's argument count.1845418454
while ak < p_ptypes.length1845518455
if super_args != ""1845618456
super_args = super_args + ", "@@ -18585,9 +18585,9 @@
1858518585
end1858618586
emit_raw(" " + self_arrow + ivar + " = " + tmp_iv + ";")1858718587
else18588-
# Issue #130: same poly-slot boxing as the general18589-
# InstanceVariableWriteNode emit path (compile_expr branch).18590-
# Initialize bodies can introduce one of the disagreeing18588+
# Same poly-slot boxing as the general18589+
# InstanceVariableWriteNode emit path: initialize18590+
# bodies can introduce one of the disagreeing1859118591
# writes to a multi-typed ivar.1859218592
if ivt == "poly"1859318593
val = box_expr_to_poly(expr_id_iv)@@ -18656,24 +18656,22 @@
1865618656
bid = bodies[init_idx].to_i1865718657
end1865818658
if bid >= 018659-
# Issue #337: this wrapper has C return type `void`. Pin18660-
# @current_method_return so a bare `return` inside the body18661-
# lowers to the void shape (`return;`) instead of leaking18662-
# whatever was set during the prior _new emission.18659+
# This wrapper has C return type `void`. Pin18660+
# @current_method_return so a bare `return` inside the18661+
# body lowers to the void shape (`return;`) instead of18662+
# leaking whatever was set during the prior _new emission.1866318663
saved_method_return = @current_method_return1866418664
saved_has_self2 = @current_method_has_self1866518665
@current_method_has_self = 11866618666
@current_method_return = "void"1866718667
@current_class_idx = ci18668-
# Issue #314 follow-up: if the body contains an early `return`,18669-
# compile_return_stmt emits `SP_GC_RESTORE()` (which references18670-
# `_gc_saved`). The matching `SP_GC_SAVE()` at the top of the18671-
# function must therefore exist. emit_constructor restored18672-
# `@in_gc_scope` to its pre-constructor value just above; if18673-
# that was 1 from a stale prior emit, declare_method_locals'18674-
# `@in_gc_scope == 0` guard skips the SAVE emit and `_gc_saved`18675-
# ends up undeclared. Reset to 0 here so declare_method_locals18676-
# can decide cleanly.18668+
# Reset @in_gc_scope to 0 so declare_method_locals'18669+
# `@in_gc_scope == 0` guard fires and emits the18670+
# `SP_GC_SAVE()` that early-`return` paths' matching18671+
# `SP_GC_RESTORE()` (compile_return_stmt) refers to. The18672+
# value inherited from emit_constructor above could be 118673+
# (stale from a heap constructor's body) and would18674+
# otherwise leave `_gc_saved` undeclared.1867718675
saved_in_gc_scope2 = @in_gc_scope1867818676
@in_gc_scope = 01867918677
all_params = @cls_meth_params[ci].split("|")@@ -19072,9 +19070,9 @@
1907219070
end1907319071
set_var_type(lnames[k], ltypes[k])1907419072
elsif (ltypes2[j] == "str_poly_hash" || ltypes2[j] == "sym_poly_hash") && ltypes[k] != ltypes2[j]19075-
# Issue #133: empty-hash promotion in 2nd pass discovered the19076-
# iterated value type is poly (each-rebuild over a poly_hash19077-
# whose source type wasn't known on 1st pass). Upgrade the19073+
# The 2nd pass discovered the iterated value type is19074+
# poly (each-rebuild over a poly_hash whose source19075+
# type wasn't known on the 1st pass). Upgrade the1907819076
# 1st pass's intermediate non-poly variant.1907919077
ltypes[k] = ltypes2[j]1908019078
set_var_type(lnames[k], ltypes2[j])@@ -19508,8 +19506,8 @@
1950819506
end1950919507
end1951019508
end19511-
# Issue #58: empty-array param promotion at instance-method call19512-
# sites — `obj.method(arg)`. Same forward/backward propagation as19509+
# Empty-array param promotion at instance-method call sites19510+
# (`obj.method(arg)`). Same forward/backward propagation as1951319511
# the top-level branch below, but reads/writes the per-class1951419512
# @cls_meth_ptypes / @cls_meth_ptypes_empty storage.1951519513
if @nd_type[nid] == "CallNode"@@ -19619,15 +19617,15 @@
1961919617
end1962019618
end1962119619
end19622-
# Issue #58: empty-array param promotion at top-level function19623-
# call sites. Two directions in one place:19620+
# Empty-array param promotion at top-level function call19621+
# sites. Two directions in one place:1962419622
# (a) Forward: if `arg` is `[]` literal or a local with the19625-
# empty flag set, mark @meth_param_empty[mi][k] = "1" so a19626-
# later body-promotion pass can refine the param type.19623+
# empty flag set, mark @meth_param_empty[mi][k] = "1" so19624+
# a later body-promotion pass can refine the param type.1962719625
# (b) Backward: if @meth_param_types[mi][k] has already been19628-
# promoted to a concrete typed-array (str_array, etc.) and19629-
# `arg` is a local with the empty flag, upgrade the local's19630-
# type to match — this is what propagates the deferred19626+
# promoted to a concrete typed-array (str_array, etc.)19627+
# and `arg` is a local with the empty flag, upgrade the19628+
# local's type to match — this propagates the deferred1963119629
# resolution back to the caller's variable.1963219630
if @nd_type[nid] == "CallNode"1963319631
if @nd_receiver[nid] < 0@@ -19793,14 +19791,14 @@
1979319791
cur == "sym_int_hash" ||1979419792
cur == "sym_str_hash")1979519793
if promotable && ki < @scan_empty_hash_flags.length && @scan_empty_hash_flags[ki] == "1"19796-
# Issue #133: block params (e.g. `|k, v|` in19797-
# `each`) aren't yet `declare_var`'d when scan_locals19798-
# walks the block body, so a bare `infer_type(v)`19799-
# falls back to "int" even though scan_locals has19800-
# already collected v's actual type into `types[]`.19801-
# Prefer scan_locals's local types array when the19802-
# argument is a LocalVariableReadNode we've recorded;19803-
# fall back to infer_type for everything else.19794+
# Block params (e.g. `|k, v|` in `each`) aren't19795+
# yet `declare_var`'d when scan_locals walks19796+
# the block body, so a bare `infer_type(v)`19797+
# falls back to "int" even though scan_locals19798+
# has already collected v's actual type into19799+
# `types[]`. Prefer that local types array when19800+
# the argument is a LocalVariableReadNode we19801+
# recorded; fall back to infer_type otherwise.1980419802
key_type = scan_locals_arg_type(aargs[0], names, types, params)1980519803
val_type = scan_locals_arg_type(aargs[aargs.length - 1], names, types, params)1980619804
promoted = promote_empty_hash_for(key_type, val_type)@@ -20595,8 +20593,8 @@
2059520593
else2059620594
@current_lexical_scope = ""2059720595
end20598-
# Issue #303: when refine_module_ivar_types widened the const20599-
# type from the empty-hash default `str_int_hash` to a more20596+
# When refine_module_ivar_types widened the const type20597+
# from the empty-hash default `str_int_hash` to a more2060020598
# specific shape (sym_str_hash etc.), emit the matching2060120599
# `sp_<Hash>_new()` directly instead of falling through to2060220600
# compile_expr's default `sp_StrIntHash_new()`. Same for@@ -20977,9 +20975,9 @@
2097720975
return "(cvar_" + qname + " = " + val + ")"2097820976
end2097920977
if t == "InstanceVariableWriteNode"20980-
# Issue #130: same poly-slot boxing as the statement-form emit.20981-
# Expression form (`x = (@y = expr)`) is rarer but reaches the20982-
# same slot through a different compile path.20978+
# Same poly-slot boxing as the statement-form emit.20979+
# Expression form (`x = (@y = expr)`) is rarer but reaches20980+
# the same slot through a different compile path.2098320981
iname_w = @nd_name[nid]2098420982
ivt_w = ""2098520983
if @current_class_idx >= 0@@ -22311,10 +22309,10 @@
2231122309
end2231222310
end2231322311
22314-
# Issue #126: `Module.accessor.<method>` where the slot was22315-
# resolved by `resolve_module_singleton_accessors`. With a single22316-
# constant in the resolved set, inline the call directly. With22317-
# two or more, emit a sentinel-switch over the slot variable.22312+
# `Module.accessor.<method>` where the slot was resolved by22313+
# `resolve_module_singleton_accessors`. With a single constant22314+
# in the resolved set, inline the call directly. With two or22315+
# more, emit a sentinel-switch over the slot variable.2231822316
if recv >= 0 && @nd_type[recv] == "CallNode"2231922317
inner_recv = @nd_receiver[recv]2232022318
inner_mname = @nd_name[recv]@@ -22325,12 +22323,12 @@
2232522323
if rconsts != "" && rconsts != "?"2232622324
args_id = @nd_arguments[nid]2232722325
cands = rconsts.split(";")22328-
# Issue #314 follow-up: scan_new_calls' #304 widening22329-
# has already unified the candidates' per-arg ptypes,22330-
# so any candidate's ptypes table tells us the target22331-
# types here. Box each arg expression to match — without22332-
# this, an int arg passed to a poly-widened param emits22333-
# raw `mrb_int` to a `sp_RbVal` slot (Wint-conversion).22326+
# scan_new_calls' module-dispatch widening has already22327+
# unified the candidates' per-arg ptypes, so any22328+
# candidate's ptypes table tells us the target types22329+
# here. Box each arg expression to match — an int arg22330+
# passed to a poly-widened param would otherwise emit22331+
# raw `mrb_int` into a `sp_RbVal` slot.2233422332
target_ptypes = "".split(",")2233522333
cands.each { |cn_t|2233622334
cci_t = find_class_idx(cn_t)@@ -22974,11 +22972,11 @@
2297422972
end2297522973
2297622974
def compile_no_recv_call_expr(nid, mname)22977-
# Issue #207: bare `new` inside a `def self.<m>` body resolves22978-
# to <CurrentClass>.new. Dispatched here (rather than relying on22979-
# the later `mname == "new"` branch in compile_call_expr) because22980-
# compile_call_expr short-circuits to this function for recv < 022981-
# before reaching that branch.22975+
# Bare `new` inside a `def self.<m>` body resolves to22976+
# <CurrentClass>.new. Dispatched here rather than via the22977+
# later `mname == "new"` branch in compile_call_expr because22978+
# compile_call_expr short-circuits to this function for22979+
# recv < 0 before reaching that branch.2298222980
if mname == "new"2298322981
r = compile_constructor_expr(nid, -1)2298422982
if r != ""@@ -23331,12 +23329,12 @@
2333123329
bp = "0"2333223330
end2333323331
end23334-
# Issue #286: when the call resolves through inheritance to an23335-
# ancestor's method, the C function takes `sp_<owner> *self`.23336-
# Our `self` here is `sp_<current> *`. Cast so the `-Werror`23337-
# build doesn't trip on -Wincompatible-pointer-types. The same23338-
# cast pattern is already used by the recv >= 0 / instance_eval23339-
# branches a few lines above.23332+
# When the call resolves through inheritance to an23333+
# ancestor's method, the C function takes `sp_<owner>23334+
# *self`. Our `self` here is `sp_<current> *`. Cast so23335+
# the `-Werror` build doesn't trip on23336+
# -Wincompatible-pointer-types. Same cast pattern as the23337+
# recv >= 0 / instance_eval branches above.2334023338
recv_arg = self_expr2334123339
if owner != "" && owner != @cls_names[@current_class_idx]2334223340
recv_arg = "(sp_" + owner + " *)" + self_expr@@ -23959,9 +23957,10 @@
2395923957
if lt == "mutable_str"2396023958
@needs_mutable_str = 12396123959
rc = compile_expr_gc_rooted(recv)23962-
# Issue #313: unbox a poly-typed arg to const char * before23963-
# sp_String_append (which takes const char *). sp_poly_to_s23964-
# handles every tag — string passes through, others coerce.23960+
# Unbox a poly-typed arg to const char * before23961+
# sp_String_append (which takes const char *).23962+
# sp_poly_to_s handles every tag — string passes through,23963+
# others coerce.2396523964
args_id = @nd_arguments[nid]2396623965
if args_id >= 02396723966
arg_ids = get_args(args_id)@@ -24071,12 +24070,11 @@
2407124070
""2407224071
end2407324072
24074-
# Issue #207: implicit `new` (recv-less) inside a `def self.<m>`24075-
# body resolves to <CurrentClass>.new. Without this the recv < 024076-
# branch fell through to "0" with the warning, leaving a factory24077-
# like `def self.from_raw(p); instance = new; instance.x = ...; end`24078-
# broken. Mirrors how implicit `self` inside instance methods24079-
# already routes recv-less calls to the enclosing class.24073+
# Resolve an implicit `new` (recv-less) inside a `def self.<m>`24074+
# body to <CurrentClass>.new, so a factory like `def24075+
# self.from_raw(p); instance = new; instance.x = ...; end`24076+
# works. Mirrors the way implicit `self` inside instance methods24077+
# routes recv-less calls to the enclosing class.2408024078
def implicit_new_class_name(recv)2408124079
if recv >= 02408224080
return ""@@ -24266,11 +24264,11 @@
2426624264
return "sp_IntArray_new()"2426724265
end2426824266
if cname == "String"24269-
# Issue #203: `String.new` and `String.new("seed")` produce24270-
# the same sp_String * value that `s = ""` widens into when24271-
# followed by `<<`. Mirror sp_String_new's signature: a NUL-24272-
# terminated seed (defaulting to "") that the runtime copies24273-
# into the freshly allocated buffer.24267+
# `String.new` and `String.new("seed")` produce the same24268+
# sp_String * value that `s = ""` widens into when24269+
# followed by `<<`. Mirror sp_String_new's signature: a24270+
# NUL-terminated seed (defaulting to "") that the runtime24271+
# copies into the freshly allocated buffer.2427424272
@needs_mutable_str = 12427524273
@needs_gc = 12427624274
args_id = @nd_arguments[nid]@@ -26086,7 +26084,7 @@
2608626084
if mname == "empty?"2608726085
return "sp_PtrArray_empty(" + rc + ")"2608826086
end26089-
# Issue #156: transpose for [[Int]] (int_array_ptr_array). Other26087+
# transpose for [[Int]] (int_array_ptr_array). Other2609026088
# nested-array element shapes are not yet supported and fall2609126089
# through to the unresolved-call warning.2609226090
if mname == "transpose" && elem_type == "int_array"@@ -27084,11 +27082,12 @@
2708427082
mfn = rcname + "_cls_" + mname2708527083
mfi = find_method_idx(mfn)2708627084
if mfi >= 027087-
# Issue #239: route through compile_call_args_with_defaults27088-
# so a `def self.greet(name, msg = nil); end` inside a27085+
# Route through compile_call_args_with_defaults so a27086+
# `def self.greet(name, msg = nil); end` inside a2708927087
# module accepts shorter call sites — caller-omitted27090-
# trailing args get filled in from the method's recorded27091-
# default expressions, the same as top-level method calls.27088+
# trailing args get filled in from the method's27089+
# recorded default expressions, the same as top-level27090+
# method calls.2709227091
ca = compile_call_args_with_defaults(nid, mfi)2709327092
if ca != ""2709427093
return "sp_" + sanitize_name(mfn) + "(" + ca + ")"@@ -27140,9 +27139,9 @@
2714027139
if owner_ci >= 02714127140
owner_name = @cls_names[owner_ci]2714227141
ca = compile_call_args(nid)27143-
# Issue #239: fill in defaults for trailing params the27144-
# caller omitted. `def self.greet(name, msg = nil)` with27145-
# call site `C.greet("a")` would otherwise emit27142+
# Fill in defaults for trailing params the caller27143+
# omitted. `def self.greet(name, msg = nil)` with call27144+
# site `C.greet("a")` would otherwise emit2714627145
# `sp_C_cls_greet("a")` against the 2-arg signature and2714727146
# the C compiler rejects with `too few arguments`. Look2714827147
# up the cls method's recorded defaults (parallel to@@ -27448,15 +27447,16 @@
2744827447
# Fallback: if receiver is int (e.g. from IntArray get) but method belongs to a class,2744927448
# cast the int to the appropriate class pointer and dispatch.2745027449
#27451-
# Issue #305: but NOT when `mname` is a method that's also defined27452-
# on a primitive type (String, Array, Hash, Integer, etc.). The27453-
# int-to-class cast here would silently pick the first user class27454-
# that happens to define the same method name — exactly the27455-
# `String#index` vs `ArticlesController#index` collision the issue27456-
# reports. A param typed `mrb_int` because it wasn't pinned upstream27457-
# is NOT the IntArray-of-pointers shape this fallback was written27458-
# for; refuse to pick a user class and let compile_call_expr's27459-
# unresolved-call diagnostic fire instead.27450+
# ...but NOT when `mname` is a method also defined on a27451+
# primitive type (String, Array, Hash, Integer, etc.). The27452+
# int-to-class cast here would silently pick the first user27453+
# class defining the same method name — e.g. routing27454+
# `s.index("[")` (a String method on a still-int-typed param)27455+
# to `ArticlesController#index`. A param typed `mrb_int`27456+
# because it wasn't pinned upstream is not the IntArray-of-27457+
# pointers shape this fallback was written for; refuse to27458+
# pick a user class and let the unresolved-call diagnostic27459+
# fire instead.2746027460
if recv_type == "int" && primitive_method_shared_with_user_class(mname) == 12746127461
return ""2746227462
end@@ -27927,11 +27927,11 @@
2792727927
# instructions etc.) must compile to `(pc >> 8) & 1`, not to2792827928
# the array dispatch in the SP_TAG_OBJ block below — which2792927929
# would silently leave the result at nil and miscount cycles.27930-
# Issue #341: only emit the int-bit-extract fallback when the27931-
# index argument is itself an int (or a poly we can unbox to27932-
# int). For non-int keys (string, sym, etc.) the SP_TAG_INT27933-
# branch is unreachable at runtime and `(recv.v.i >> key)`27934-
# is invalid C — `>> const char *` won't compile.27930+
# Only emit the int-bit-extract fallback when the index27931+
# argument is itself an int (or a poly we can unbox to int).27932+
# For non-int keys (string, sym, ...) the SP_TAG_INT branch27933+
# is unreachable at runtime and `(recv.v.i >> key)` is27934+
# invalid C — `>> const char *` won't compile.2793527935
if mname == "[]" && arg_compiled.length >= 1 && (arg_types[0] == "int" || arg_types[0] == "poly")2793627936
a0_int = arg_compiled[0]2793727937
if arg_types[0] == "poly"@@ -27962,15 +27962,15 @@
2796227962
pk = 02796327963
while pk < arm_ptypes.length2796427964
if pk < arg_compiled.length27965-
# Issue #351: when this arm's param widened to `poly`27966-
# (matz/spinel#341 cross-call-site union) but the call27967-
# site supplied a concrete value (string / mrb_int /27968-
# symbol / ...), box it via the appropriate sp_box_*27969-
# helper. Without this, gcc errors `incompatible type27970-
# for argument` — `const char *` / `mrb_int` into a27971-
# `sp_RbVal` slot. Inverse direction (poly arg into a27972-
# concrete-typed param) was already covered downstream;27973-
# this only handles the boxing direction.27965+
# When this arm's param widened to `poly` (cross-27966+
# call-site union) but the call site supplied a27967+
# concrete value (string / mrb_int / symbol / ...),27968+
# box it via the appropriate sp_box_* helper so the27969+
# arg type matches the slot — otherwise gcc errors27970+
# `incompatible type for argument` on `const char *` /27971+
# `mrb_int` into a `sp_RbVal`. The inverse direction27972+
# (poly arg into a concrete-typed param) is handled27973+
# downstream; this only does the boxing direction.2797427974
arg_v = arg_compiled[pk]2797527975
arm_pt_base = base_type(arm_ptypes[pk])2797627976
if arm_pt_base == "poly" && pk < arg_types.length && arg_types[pk] != "poly" && arg_types[pk] != ""@@ -28052,9 +28052,9 @@
2805228052
# acceptable since the caller's static type analysis already2805328053
# picked a compatible result type.2805428054
#28055-
# Issue #341: every built-in [] arm here passes the key to a28056-
# function expecting `mrb_int`. Only emit the arms when the key28057-
# type is int or poly (poly is unboxed via `.v.i` above). For28055+
# Every built-in [] arm here passes the key to a function28056+
# expecting `mrb_int`. Only emit the arms when the key type28057+
# is int or poly (poly is unboxed via `.v.i` above). For2805828058
# non-int keys (string, sym), these arms are unreachable at2805928059
# runtime (a poly recv carrying a String key would be a hash,2806028060
# not an array) and emitting them produces Wint-conversion@@ -28265,10 +28265,11 @@
2826528265
if cc != ""2826628266
return cc2826728267
end28268-
# Issue #129: NULL-safe equality via sp_str_eq. Plain strcmp(NULL, ...)28269-
# is UB and segfaults on real inputs (ENV[] returns NULL for unset28270-
# vars). The helper does a NULL check, then strcmp; identical answer28271-
# for non-NULL operands so existing equality call sites are unaffected.28268+
# NULL-safe equality via sp_str_eq. Plain strcmp(NULL, ...)28269+
# is UB and segfaults on real inputs (ENV[] returns NULL for28270+
# unset vars). The helper does a NULL check then strcmp;28271+
# identical answer for non-NULL operands, so existing28272+
# equality call sites are unaffected.2827228273
if op == "=="2827328274
return "sp_str_eq(" + lc + ", " + rc + ")"2827428275
else@@ -28464,25 +28465,25 @@
2846428465
end2846528466
2846628467
def box_expr_to_poly(nid)28467-
# Issue #131: ternary / if-as-expression whose branches may have28468-
# different concrete types. Per-branch box unconditionally — same-28469-
# type branches yield a redundant box that still produces correct28470-
# sp_RbVal, and mixed-type branches need the per-branch box to28471-
# avoid C's pointer/integer ternary-type-mismatch (which lands as28472-
# an unsafe cast in the poly slot and segfaults).28473-
# Gating on infer_type's "poly" answer would not work: unify_return28474-
# _type treats int as default/unresolved (`int + T → T`), so a28475-
# genuinely mixed-int-string ternary infers as "string" and the28476-
# gate misses it. The pre-#131 emit then `sp_box_str`'d the entire28477-
# raw ternary, which is the same UB.28468+
# Ternary / if-as-expression whose branches may have different28469+
# concrete types: per-branch box unconditionally. Same-type28470+
# branches yield a redundant box that still produces correct28471+
# sp_RbVal; mixed-type branches need the per-branch box to28472+
# avoid C's pointer/integer ternary-type-mismatch (which would28473+
# otherwise land as an unsafe cast in the poly slot and28474+
# segfault). Gating on infer_type's "poly" answer would miss28475+
# mixed-type cases — unify_return_type treats int as28476+
# default/unresolved (`int + T → T`), so a genuinely28477+
# int-string ternary infers as "string" and a poly gate would28478+
# fall through to the same UB-prone wholesale `sp_box_str`.2847828479
if nid >= 0 && @nd_type[nid] == "IfNode"28479-
# Issue #207: if the predicate is a statically-decidable28480-
# is_a? / kind_of? on an already-typed expression, emit only28481-
# the live arm. The dead arm may contain a recursion call28482-
# whose argument types don't match the function's signature28483-
# (e.g. `v.is_a?(Hash) ? recurse(v) : v` where v is statically28484-
# a string) — generating it would land as a C type error28485-
# even though the branch is unreachable at runtime.28480+
# When the predicate is a statically-decidable is_a? /28481+
# kind_of? on an already-typed expression, emit only the28482+
# live arm. The dead arm may contain a recursion call whose28483+
# argument types don't match the function's signature (e.g.28484+
# `v.is_a?(Hash) ? recurse(v) : v` where v is statically a28485+
# string) — generating it would land as a C type error even28486+
# though the branch is unreachable at runtime.2848628487
sv = static_is_a_value(@nd_predicate[nid])2848728488
if sv == "TRUE"2848828489
body = @nd_body[nid]@@ -28589,16 +28590,17 @@
2858928590
end2859028591
return2859128592
end28592-
# Issue #236: empty `{}` / `[]` literal RHS — `compile_expr`28593-
# returns the default `sp_StrIntHash_new()` / `sp_IntArray_new()`,28594-
# but slots may have been promoted to a typed container by their28593+
# Empty `{}` / `[]` literal RHS — `compile_expr` returns the28594+
# default `sp_StrIntHash_new()` / `sp_IntArray_new()`, but28595+
# slots may have been promoted to a typed container by their2859528596
# subsequent writes (e.g. `@h["k"] = "v"` lifts the slot to28596-
# str_str_hash). If every chain participant agrees on the same28597-
# promoted concrete container type, emit the slot-typed28598-
# constructor as the temp so each store is type-correct AND the28599-
# Ruby semantic of one shared object is preserved across the28600-
# chain. Disagreeing-type chains fall through to the general28601-
# case below; the resulting C will still warn about pointer28597+
# str_str_hash). If every chain participant agrees on the28598+
# same promoted concrete container type, emit the slot-typed28599+
# constructor as the temp so each store is type-correct AND28600+
# the Ruby semantic of one shared object is preserved across28601+
# the chain. Disagreeing-type chains fall through to the28602+
# general case below; the resulting C will still warn about28603+
# pointer2860228604
# type mismatch but at least one slot will be correct.2860328605
if is_empty_hash_literal(rhs_id) == 1 || is_empty_array_literal(rhs_id) == 12860428606
consensus_t = ""@@ -28831,12 +28833,12 @@
2883128833
if kw_names[ki] == pnames[k]2883228834
kw_found = 12883328835
if k < ptypes.length && ptypes[k] == "poly"28834-
# Issue #314: pick the box helper from the arg's actual28835-
# source type via box_expr_to_poly. The pre-fix sp_box_str28836-
# hardcoding mistyped any non-string source (e.g. an28837-
# `obj_<C>` instance) as SP_TAG_STR — invalid C and the28838-
# boxed value disagrees with sp_RbVal's tag/cls_id contract28839-
# at runtime.28836+
# Pick the box helper from the arg's actual source28837+
# type via box_expr_to_poly. A hardcoded sp_box_str28838+
# would mistype any non-string source (e.g. an28839+
# `obj_<C>` instance) as SP_TAG_STR — invalid C and a28840+
# value that disagrees with sp_RbVal's tag/cls_id28841+
# contract at runtime.2884028842
result = result + box_expr_to_poly(kw_arg_ids[ki])2884128843
else2884228844
result = result + kw_vals[ki]@@ -29052,13 +29054,13 @@
2905229054
# Check if param is poly2905329055
if k < ptypes.length2905429056
if ptypes[k] == "poly"29055-
# Issue #314: pick the box helper from the arg's actual29056-
# source type via box_expr_to_poly. The pre-fix sp_box_str29057-
# hardcoding mistyped any non-string source — and a kwargs29058-
# call site with a poly-widened param (e.g. `model:` after29059-
# the call-site widening pass folds Article+Comment into29060-
# poly) is exactly the path that flows non-string objs29061-
# through here.29057+
# Pick the box helper from the arg's actual source29058+
# type via box_expr_to_poly. A hardcoded sp_box_str29059+
# would mistype any non-string source — and a29060+
# kwargs call site with a poly-widened param29061+
# (e.g. `model:` after call-site widening folds29062+
# Article + Comment into poly) is exactly the path29063+
# that flows non-string objs through here.2906229064
result = result + box_expr_to_poly(kw_arg_ids[ki])2906329065
else2906429066
result = result + kw_vals[ki]@@ -29142,11 +29144,12 @@
2914229144
k = k + 12914329145
next2914429146
end29145-
# Issue #58: empty `[]` literal at the call site needs to29146-
# construct the right typed-array container. The literal's29147-
# own infer_type returns int_array (compile_array_literal29148-
# emits sp_IntArray_new()), but if the param is a concrete29149-
# typed-array, emit the matching constructor instead.29147+
# An empty `[]` literal at the call site needs to29148+
# construct the right typed-array container. The29149+
# literal's own infer_type returns int_array29150+
# (compile_array_literal emits sp_IntArray_new()), but29151+
# when the param is a concrete typed-array, emit the29152+
# matching constructor instead.2915029153
if is_empty_array_literal(positional_ids[k]) == 12915129154
if ptypes[k] == "str_array"2915229155
@needs_str_array = 1@@ -30622,11 +30625,12 @@
3062230625
emit(" " + self_arrow + sanitize_ivar(iname) + " = " + tmp_arr + ";")3062330626
return3062430627
end30625-
# Issue #130: poly slot — every concrete-typed RHS must be boxed30626-
# to sp_RbVal. Without the box, C compiler sees `sp_RbVal = mrb_int`30627-
# (or const char *, etc.) and either rejects the assignment or30628-
# silently coerces. Read sites already dispatch through poly-aware30629-
# emitters (sp_poly_puts, etc.) that unbox.30628+
# Poly slot — every concrete-typed RHS must be boxed to30629+
# sp_RbVal. Without the box, the C compiler sees30630+
# `sp_RbVal = mrb_int` (or const char *, etc.) and either30631+
# rejects the assignment or silently coerces. Read sites30632+
# already dispatch through poly-aware emitters30633+
# (sp_poly_puts, etc.) that unbox.3063030634
if ivt == "poly"3063130635
val = box_expr_to_poly(expr_id)3063230636
else@@ -31341,15 +31345,16 @@
3134131345
compile_stmts_body(@nd_body[sub])3134231346
@indent = @indent - 13134331347
else31344-
# Issue #310: wrap elsif in braces. compile_cond_expr for the31345-
# nested predicate may emit prologue C (temp decls, tag checks)31346-
# before returning the cond expression — e.g. `value.is_a?(B)`31347-
# on a poly receiver expands to `sp_RbVal _t = ...; if (_t.tag31348-
# == SP_TAG_OBJ) {...}; if (_flag) ...`. Without wrapping, the31349-
# `} else <prologue> if (...)` shape is invalid C: the bare-31350-
# else's body is the first statement only (the prologue decl),31351-
# and the inner if sits in the outer scope with the decl out31352-
# of reach.31348+
# Wrap elsif in braces. compile_cond_expr for the nested31349+
# predicate may emit prologue C (temp decls, tag checks)31350+
# before returning the cond expression — e.g.31351+
# `value.is_a?(B)` on a poly receiver expands to31352+
# `sp_RbVal _t = ...; if (_t.tag == SP_TAG_OBJ) {...}; if31353+
# (_flag) ...`. Without the wrap, the `} else <prologue>31354+
# if (...)` shape is invalid C: the bare-else's body31355+
# would be the first statement only (the prologue decl),31356+
# leaving the inner if in the outer scope with the decl31357+
# out of reach.3135331358
emit(" } else {")3135431359
@indent = @indent + 13135531360
compile_if_stmt(sub)@@ -32063,12 +32068,13 @@
3206332068
# initialized instance)3206432069
# nullable pointer → return NULL;3206532070
# anything else → return 0;32066-
# Issue #337: `return if x.nil?` inside a `def initialize` was32067-
# emitted as `return 0;` regardless of the wrapping function. In32068-
# the synthesized `sp_<C>_new` (sp_<C> *-returning) it silently32069-
# NULLed the instance on the early-return branch; in the void32070-
# `sp_<C>_initialize` form it was a `void function should not32071-
# return a value` C error.32071+
# The shape per @current_method_return matters because a32072+
# `return if x.nil?` inside a `def initialize` reaches this32073+
# bare-return path: in the synthesized `sp_<C>_new` (sp_<C>32074+
# *-returning) emitting `return 0;` would silently NULL the32075+
# instance on the early-return branch, and in the void32076+
# `sp_<C>_initialize` form it would be a `void function32077+
# should not return a value` C error.3207232078
emit_setjmp_depth_unwind3207332079
emit_ensure_replays3207432080
if @in_gc_scope == 1@@ -32109,7 +32115,7 @@
3210932115
return3211032116
end3211132117
32112-
# Issue #126: `Module.accessor = X` write.32118+
# `Module.accessor = X` write.3211332119
# Stage 1 (1 candidate): no emit; reads fold to that constant.3211432120
# Stage 2 (2+ candidates): emit `slot = SP_MOD_<X>;` so the3211532121
# read site's sentinel switch picks the right branch.@@ -32400,10 +32406,11 @@
3240032406
emit(" sp_String_append(" + rc + ", " + val + "->data);")3240132407
else3240232408
if at == "poly"32403-
# Issue #313: a poly-typed source (e.g. a module32404-
# method returning sp_RbVal from a SymPolyHash32405-
# read) needs runtime unbox to const char * before32406-
# sp_String_append. sp_poly_to_s handles every tag.32409+
# A poly-typed source (e.g. a module method32410+
# returning sp_RbVal from a SymPolyHash read)32411+
# needs runtime unbox to const char * before32412+
# sp_String_append. sp_poly_to_s handles32413+
# every tag.3240732414
emit(" sp_String_append(" + rc + ", sp_poly_to_s(" + val + "));")3240832415
else3240932416
emit(" sp_String_append(" + rc + ", " + val + ");")@@ -36685,11 +36692,11 @@
3668536692
tmp_arr3668636693
end3668736694
36688-
# Issue #210 follow-up: an empty `map {}` block yields nil per36689-
# iteration in CRuby — the result array's length still matches the36690-
# receiver. Without an explicit push the typed accumulator stays36691-
# short and downstream `.length` / `[i]` on the result is wrong.36692-
# Push a type-appropriate default (0 / 0.0 / "" / sp_box_nil) so36695+
# An empty `map {}` block yields nil per iteration in CRuby —36696+
# the result array's length still matches the receiver. Without36697+
# an explicit push the typed accumulator stays short and36698+
# downstream `.length` / `[i]` on the result is wrong. Push a36699+
# type-appropriate default (0 / 0.0 / "" / sp_box_nil) so3669336700
# length is preserved across all map dispatches.3669436701
def emit_map_default_push(target, container_type)3669536702
if container_type == "str_array"@@ -38999,10 +39006,10 @@
3899939006
end3900039007
@indent = @indent - 13900139008
else39002-
# Issue #310: wrap elsif in braces. See compile_if_stmt for39003-
# the same fix; predicates that emit prologue C statements39004-
# (poly is_a? etc.) leak declarations out of a bare else39005-
# because the bare else's body is one statement.39009+
# Wrap elsif in braces. See compile_if_stmt for the same39010+
# rationale: predicates that emit prologue C statements39011+
# (poly is_a? etc.) would leak declarations out of a bare39012+
# else because the bare else's body is one statement.3900639013
emit(" } else {")3900739014
@indent = @indent + 13900839015
compile_if_return(sub, rt)