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_types
1517215172 infer_class_body_call_types
1517315173 infer_ivar_types_from_writers
15174- # Issue #58: after scan_locals has populated @meth_param_empty
15175- # via the per-call-site forward propagation, promote int_array
15176- # params to concrete typed-arrays where bodies push known types.
15177- # Then the next iteration's scan_locals back-propagates those
15178- # promoted types to caller-side locals.
15174+ # After scan_locals has populated @meth_param_empty via the
15175+ # per-call-site forward propagation, promote int_array
15176+ # params to concrete typed-arrays where bodies push known
15177+ # types. The next iteration's scan_locals back-propagates
15178+ # those promoted types to caller-side locals.
1517915179 infer_param_array_type_from_body
1518015180 narrow_param_types_from_body_method_calls
1518115181 detect_poly_params
@@ -15196,9 +15196,9 @@
1519615196 infer_class_body_call_types
1519715197 infer_ivar_types_from_writers
1519815198 infer_all_returns
15199- # Issue #303: param types are now stable, so module ivar refinement
15200- # (which infers hash / array specialization from `@h[k] = v` writes
15201- # in class-method bodies) sees the right key / value types instead
15199+ # Param types are now stable, so module ivar refinement (which
15200+ # infers hash / array specialization from `@h[k] = v` writes in
15201+ # class-method bodies) sees the right key / value types instead
1520215202 # of the placeholder "int" they'd carry at module-collect time.
1520315203 # After refining, re-run return / call-type inference so methods
1520415204 # that read or push the refined const see the new shape (e.g. a
@@ -15255,12 +15255,12 @@
1525515255 end
1525615256 gi = gi + 1
1525715257 end
15258- # Issue #229: compute the live set of cls methods before any
15259- # cls-method-related emit. Forward decls + bodies both consult
15258+ # Compute the live set of cls methods before any cls-method-
15259+ # related emit. Forward decls + bodies both consult
1526015260 # @cls_cmeth_live to skip uncalled methods that may otherwise
15261- # emit non-compiling bodies (uncalled `def self.factory(attrs);
15262- # new(attrs); end` against a 0-arg or differently-typed
15263- # constructor).
15261+ # emit non-compiling bodies (an uncalled
15262+ # `def self.factory(attrs); new(attrs); end` against a 0-arg
15263+ # or differently-typed constructor).
1526415264 compute_live_cls_methods
1526515265 emit_forward_decls
1526615266 emit_global_constants
@@ -16028,11 +16028,11 @@
1602816028 if @cvar_names.length > 0
1602916029 emit_raw("")
1603016030 end
16031- # Issue #126 Stage 2: storage for module-level singleton accessors
16032- # whose resolved set has 2+ candidates. The slot stores the
16033- # assigned module's sentinel (mrb_int from `module_sentinel`); the
16034- # write site emits `slot = N;` and the chain dispatch reads back
16035- # via a sentinel switch.
16031+ # Storage for module-level singleton accessors whose resolved
16032+ # set has 2+ candidates. The slot stores the assigned module's
16033+ # sentinel (mrb_int from `module_sentinel`); the write site
16034+ # emits `slot = N;` and the chain dispatch reads back via a
16035+ # sentinel switch.
1603616036 j = 0
1603716037 emitted = 0
1603816038 while j < @module_acc_keys.length
@@ -16414,20 +16414,21 @@
1641416414 end
1641516415 end
1641616416
16417- # Issue #314: classes whose instances flow into a poly-typed param
16418- # slot at any call site. The boxing helper `sp_box_obj(p, ci)` takes
16419- # `void *p`; a value-type-eligible class would emit
16420- # `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-value
16422- # into a `void *` slot — a C type error. Excluding such classes
16423- # from the value-type optimization keeps `<C>` heap-allocated, so
16424- # the boxing argument is a stable pointer.
16417+ # Track classes whose instances flow into a poly-typed param
16418+ # slot at any call site. The boxing helper `sp_box_obj(p, ci)`
16419+ # takes `void *p`; a value-type-eligible class would emit
16420+ # `sp_box_obj(sp_<C>_new(...), ci)` or `sp_box_obj(local, ci)`
16421+ # where `local` is the value-type struct, feeding a
16422+ # struct-by-value into a `void *` slot — a C type error.
16423+ # Excluding such classes from the value-type optimization keeps
16424+ # `<C>` heap-allocated, so the boxing argument is always a
16425+ # stable pointer.
1642516426 #
16426- # Surfaces specifically when a kwargs widening pass (this issue's
16427- # main fix) collapses two or more concrete obj-typed call sites for
16428- # the same kwarg into "poly" — at which point the call site starts
16429- # boxing the instance, hitting the same struct-by-void-* mismatch
16430- # the ptr_array / poly-return passes already guard against.
16427+ # Surfaces when kwargs widening collapses two or more concrete
16428+ # obj-typed call sites for the same kwarg into "poly" — at that
16429+ # point the call site starts boxing the instance, hitting the
16430+ # same struct-by-void-* mismatch the ptr_array / poly-return
16431+ # passes already guard against.
1643116432 def detect_poly_arg_passed_types
1643216433 @poly_arg_passed_types = "".split(",")
1643316434 nid = 0
@@ -16945,11 +16946,11 @@
1694516946 pri = pri + 1
1694616947 end
1694716948 end
16948- # Issue #314: same exclusion for classes whose instances flow
16949- # into a poly-typed param at any call site. Surfaces when
16950- # kwargs widening collapses two obj types into "poly" — the
16951- # call site then boxes a value-type instance, mismatching
16952- # sp_box_obj's `void *` slot.
16949+ # Same value-type exclusion for classes whose instances
16950+ # flow into a poly-typed param at any call site. When
16951+ # kwargs widening collapses two obj types into "poly",
16952+ # the call site boxes a value-type instance and
16953+ # mismatches sp_box_obj's `void *` slot.
1695316954 if all_val == 1
1695416955 type_str314 = "obj_" + @cls_names[i]
1695516956 pai = 0
@@ -17399,14 +17400,14 @@
1739917400 i = 0
1740017401 while i < @cls_names.length
1740117402 cname = @cls_names[i]
17402- # Issue #314 follow-up: pin @current_class_idx during this
17403- # forward-decl emit pass so block_params_csig_for_body's
17404- # infer_type calls (on `@ivar` reads inside yield arg
17405- # expressions) resolve against this class's ivar table.
17406- # Without this, ivars infer to int default and yields like
17407- # `yield k, @data[k]` lower to `(mrb_int, mrb_int)` while
17408- # the impl emit (which DOES set @current_class_idx) lowers
17409- # to `(string, sp_RbVal)` — declaration/definition mismatch.
17403+ # Pin @current_class_idx during this forward-decl emit pass
17404+ # so block_params_csig_for_body's infer_type calls (on
17405+ # `@ivar` reads inside yield arg expressions) resolve
17406+ # against this class's ivar table. Otherwise ivars infer
17407+ # to the int default and yields like `yield k, @data[k]`
17408+ # lower to `(mrb_int, mrb_int)` in the decl while the impl
17409+ # emit lowers to `(string, sp_RbVal)` — and the C
17410+ # declaration/definition signatures mismatch.
1741017411 saved_ci_decl = @current_class_idx
1741117412 @current_class_idx = i
1741217413 # Constructor
@@ -17452,10 +17453,10 @@
1745217453 cm_ptypes = @cls_cmeth_ptypes[i].split("|")
1745317454 j = 0
1745417455 while j < cmnames.length
17455- # Issue #229: skip forward decls for dead cls methods so the
17456- # linker doesn't see "declared here" without a definition
17457- # (the corresponding emit_class_methods skip would still
17458- # otherwise leave the prototype dangling).
17456+ # Skip forward decls for dead cls methods so the linker
17457+ # doesn't see "declared here" without a definition — the
17458+ # corresponding emit_class_methods skip would otherwise
17459+ # leave the prototype dangling.
1745917460 if cls_cmeth_is_live(i, cmnames[j]) == 0
1746017461 j = j + 1
1746117462 else
@@ -17513,23 +17514,21 @@
1751317514 return ", void (*_block)(" + csig + ", void*), void *_benv"
1751417515 end
1751517516
17516- # Issue #314 follow-up: build the block fn-pointer C signature
17517- # 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 the
17521- # actual yield invocation site emitted `_block(const_char*,
17522- # sp_RbVal, _benv)` — gcc errored with `incompatible type for
17523- # argument`.
17517+ # Build the block fn-pointer C signature from the yield call
17518+ # sites' inferred arg types. block_params_csig alone returns
17519+ # `mrb_int, mrb_int, ...` regardless of what's yielded; this
17520+ # 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, so
1752617525 # locally-declared vars referenced in yield args (`yield k, v`
1752717526 # where `k`, `v` were assigned from typed expressions) are not
1752817527 # in @scope_names. Run scan_locals on the body and push a
1752917528 # temporary scope so body_yield_arg_types' infer_type calls
17530- # resolve those reads. (Re-runs both at forward-decl emit time
17531- # 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 time
17530+ # 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 <= 0
1753517534 return block_params_csig(arity)
@@ -17964,12 +17963,12 @@
1796417963 if j < cm_ptypes.length
1796517964 ptypes = cm_ptypes[j].split(",")
1796617965 end
17967- # Issue #229: dead-code-eliminate cls methods with no call
17968- # 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 constructor
17971- # arity/types — spinel can't infer types for an uncalled
17972- # method, so the body fails to C-compile. compute_live_cls_methods
17966+ # Dead-code-eliminate cls methods with no call site. An
17967+ # unused `def self.factory(attrs); new(attrs); ...; end`
17968+ # would emit a body whose `sp_<this>_new(args)` may not
17969+ # 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_methods
1797317972 # ran before emit and seeded live entries from explicit
1797417973 # `<Class>.<m>(...)` call sites + transitive self/bare calls
1797517974 # within live cls method bodies.
@@ -17984,15 +17983,15 @@
1798417983 end
1798517984 end
1798617985
17987- # Issue #229: dead-code elimination for cls methods. An uncalled
17986+ # Dead-code elimination for class methods. An uncalled
1798817987 # `def self.factory(attrs); new(attrs); ...; end` on a parent
17989- # class whose own `initialize` has different arity emits a body
17990- # that doesn't C-compile (`sp_<class>_new(args)` against a 0-arg
17991- # constructor; or, with a default-arg `initialize`, against a
17992- # typed param when the uncalled method's own param can't be
17988+ # class whose own `initialize` has different arity would emit a
17989+ # body that doesn't C-compile (`sp_<class>_new(args)` against a
17990+ # 0-arg constructor; or, with a default-arg `initialize`,
17991+ # against a typed param the uncalled method itself can't have
1799317992 # inferred). The reachability set seeds from explicit
1799417993 # `<Class>.<m>(...)` call sites in the AST, then propagates
17995- # through bare/self calls inside live cls method bodies. Anything
17994+ # through bare/self calls inside live cls method bodies; anything
1799617995 # 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 >= 0
1814918148 cls_cmeth_mark_live(ctx_ci, mname)
1815018149 end
18151- # Issue #126 / #229 interaction: `<Module>.<acc>.<method>`
18152- # where `<Module>.<acc>` was constant-folded by Pass 2.7
18153- # (resolve_module_singleton_accessors) to a class name.
18154- # The receiver is a CallNode at AST level, so the
18155- # ConstantReadNode branch above doesn't catch it. Look up
18156- # the fold and mark the resolved class's cls method live.
18150+ # `<Module>.<acc>.<method>` where `<Module>.<acc>` was
18151+ # constant-folded by resolve_module_singleton_accessors to
18152+ # one or more class names. The receiver is a CallNode at
18153+ # AST level, so the ConstantReadNode branch above doesn't
18154+ # catch it; look up the fold and mark each resolved
18155+ # 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 end
1832618325 if bid >= 0
1832718326 @current_class_idx = ci
18328- # Issue #337: pin the synthesized sp_<C>_new function's return
18329- # type so a bare `return` inside the initialize body lowers to
18330- # `return self;` (the partially-initialized instance) rather
18331- # than the default `return 0;` (which silently NULLs the
18332- # pointer-returning constructor for the heap-allocated shape).
18333- # Value-type constructors return a struct, leave at "" so the
18334- # bare-return path falls through to its existing 0 default.
18327+ # Pin the synthesized sp_<C>_new function's return type so
18328+ # a bare `return` inside the initialize body lowers to
18329+ # `return self;` (the partially-initialized instance)
18330+ # rather than the default `return 0;` — the latter would
18331+ # silently NULL the pointer-returning constructor for the
18332+ # heap-allocated shape. Value-type constructors return a
18333+ # struct; leave at "" so the bare-return path falls
18334+ # through to its existing 0 default.
1833518335 saved_method_return = @current_method_return
1833618336 saved_has_self = @current_method_has_self
1833718337 @current_method_has_self = 1
@@ -18373,14 +18373,14 @@
1837318373 is_super = (@nd_type[sid] == "SuperNode" || @nd_type[sid] == "ForwardingSuperNode")
1837418374 if is_super
1837518375 if @cls_parents[ci] != ""
18376- # Issue #314 follow-up: when the immediate parent is
18377- # an "abstract" class (no own `initialize`, e.g.
18378- # `class ApplicationRecord < ActiveRecord::Base`),
18379- # the void `_initialize` wrapper is never emitted for
18380- # it — so a literal `sp_<parent>_initialize(...)` call
18381- # here would be an undefined reference at link time.
18382- # Walk up to find_init_class to skip over abstract
18383- # ancestors and call the nearest emitted wrapper.
18376+ # When the immediate parent is an "abstract" class
18377+ # (no own `initialize`, e.g. `class ApplicationRecord
18378+ # < ActiveRecord::Base`), the void `_initialize`
18379+ # wrapper is never emitted for it — a literal
18380+ # `sp_<parent>_initialize(...)` call here would be
18381+ # an undefined reference at link time. Walk via
18382+ # find_init_class to skip over abstract ancestors
18383+ # and call the nearest emitted wrapper.
1838418384 pi_imm = find_class_idx(@cls_parents[ci])
1838518385 pi = pi_imm
1838618386 if pi_imm >= 0
@@ -18444,13 +18444,13 @@
1844418444 ak = ak + 1
1844518445 end
1844618446 end
18447- # Issue #314 follow-up: explicit `super(...)` with
18448- # fewer args than the parent expects (e.g. `super()`
18449- # against `def initialize(_attrs = {})`). Ruby fills
18450- # missing trailing slots from the parent's defaults;
18451- # the C signature has no defaults, so pad with
18452- # c_default_val per param type. Without this, gcc
18453- # errors `too few arguments to function`.
18447+ # Explicit `super(...)` with fewer args than the
18448+ # parent expects (e.g. `super()` against
18449+ # `def initialize(_attrs = {})`). Ruby fills
18450+ # missing trailing slots from the parent's
18451+ # defaults; the C signature has no defaults, so
18452+ # pad with c_default_val per param type to
18453+ # satisfy gcc's argument count.
1845418454 while ak < p_ptypes.length
1845518455 if super_args != ""
1845618456 super_args = super_args + ", "
@@ -18585,9 +18585,9 @@
1858518585 end
1858618586 emit_raw(" " + self_arrow + ivar + " = " + tmp_iv + ";")
1858718587 else
18588- # Issue #130: same poly-slot boxing as the general
18589- # InstanceVariableWriteNode emit path (compile_expr branch).
18590- # Initialize bodies can introduce one of the disagreeing
18588+ # Same poly-slot boxing as the general
18589+ # InstanceVariableWriteNode emit path: initialize
18590+ # bodies can introduce one of the disagreeing
1859118591 # 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_i
1865718657 end
1865818658 if bid >= 0
18659- # Issue #337: this wrapper has C return type `void`. Pin
18660- # @current_method_return so a bare `return` inside the body
18661- # lowers to the void shape (`return;`) instead of leaking
18662- # whatever was set during the prior _new emission.
18659+ # This wrapper has C return type `void`. Pin
18660+ # @current_method_return so a bare `return` inside the
18661+ # body lowers to the void shape (`return;`) instead of
18662+ # leaking whatever was set during the prior _new emission.
1866318663 saved_method_return = @current_method_return
1866418664 saved_has_self2 = @current_method_has_self
1866518665 @current_method_has_self = 1
1866618666 @current_method_return = "void"
1866718667 @current_class_idx = ci
18668- # Issue #314 follow-up: if the body contains an early `return`,
18669- # compile_return_stmt emits `SP_GC_RESTORE()` (which references
18670- # `_gc_saved`). The matching `SP_GC_SAVE()` at the top of the
18671- # function must therefore exist. emit_constructor restored
18672- # `@in_gc_scope` to its pre-constructor value just above; if
18673- # 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_locals
18676- # can decide cleanly.
18668+ # Reset @in_gc_scope to 0 so declare_method_locals'
18669+ # `@in_gc_scope == 0` guard fires and emits the
18670+ # `SP_GC_SAVE()` that early-`return` paths' matching
18671+ # `SP_GC_RESTORE()` (compile_return_stmt) refers to. The
18672+ # value inherited from emit_constructor above could be 1
18673+ # (stale from a heap constructor's body) and would
18674+ # otherwise leave `_gc_saved` undeclared.
1867718675 saved_in_gc_scope2 = @in_gc_scope
1867818676 @in_gc_scope = 0
1867918677 all_params = @cls_meth_params[ci].split("|")
@@ -19072,9 +19070,9 @@
1907219070 end
1907319071 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 the
19076- # iterated value type is poly (each-rebuild over a poly_hash
19077- # whose source type wasn't known on 1st pass). Upgrade the
19073+ # The 2nd pass discovered the iterated value type is
19074+ # poly (each-rebuild over a poly_hash whose source
19075+ # type wasn't known on the 1st pass). Upgrade the
1907819076 # 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 end
1950919507 end
1951019508 end
19511- # Issue #58: empty-array param promotion at instance-method call
19512- # sites — `obj.method(arg)`. Same forward/backward propagation as
19509+ # Empty-array param promotion at instance-method call sites
19510+ # (`obj.method(arg)`). Same forward/backward propagation as
1951319511 # the top-level branch below, but reads/writes the per-class
1951419512 # @cls_meth_ptypes / @cls_meth_ptypes_empty storage.
1951519513 if @nd_type[nid] == "CallNode"
@@ -19619,15 +19617,15 @@
1961919617 end
1962019618 end
1962119619 end
19622- # Issue #58: empty-array param promotion at top-level function
19623- # call sites. Two directions in one place:
19620+ # Empty-array param promotion at top-level function call
19621+ # sites. Two directions in one place:
1962419622 # (a) Forward: if `arg` is `[]` literal or a local with the
19625- # empty flag set, mark @meth_param_empty[mi][k] = "1" so a
19626- # later body-promotion pass can refine the param type.
19623+ # empty flag set, mark @meth_param_empty[mi][k] = "1" so
19624+ # a later body-promotion pass can refine the param type.
1962719625 # (b) Backward: if @meth_param_types[mi][k] has already been
19628- # promoted to a concrete typed-array (str_array, etc.) and
19629- # `arg` is a local with the empty flag, upgrade the local's
19630- # type to match — this is what propagates the deferred
19626+ # promoted to a concrete typed-array (str_array, etc.)
19627+ # and `arg` is a local with the empty flag, upgrade the
19628+ # local's type to match — this propagates the deferred
1963119629 # 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|` in
19797- # `each`) aren't yet `declare_var`'d when scan_locals
19798- # walks the block body, so a bare `infer_type(v)`
19799- # falls back to "int" even though scan_locals has
19800- # already collected v's actual type into `types[]`.
19801- # Prefer scan_locals's local types array when the
19802- # 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't
19795+ # yet `declare_var`'d when scan_locals walks
19796+ # the block body, so a bare `infer_type(v)`
19797+ # falls back to "int" even though scan_locals
19798+ # has already collected v's actual type into
19799+ # `types[]`. Prefer that local types array when
19800+ # the argument is a LocalVariableReadNode we
19801+ # 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 else
2059620594 @current_lexical_scope = ""
2059720595 end
20598- # Issue #303: when refine_module_ivar_types widened the const
20599- # type from the empty-hash default `str_int_hash` to a more
20596+ # When refine_module_ivar_types widened the const type
20597+ # from the empty-hash default `str_int_hash` to a more
2060020598 # specific shape (sym_str_hash etc.), emit the matching
2060120599 # `sp_<Hash>_new()` directly instead of falling through to
2060220600 # compile_expr's default `sp_StrIntHash_new()`. Same for
@@ -20977,9 +20975,9 @@
2097720975 return "(cvar_" + qname + " = " + val + ")"
2097820976 end
2097920977 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 the
20982- # 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 reaches
20980+ # 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 end
2231222310 end
2231322311
22314- # Issue #126: `Module.accessor.<method>` where the slot was
22315- # resolved by `resolve_module_singleton_accessors`. With a single
22316- # constant in the resolved set, inline the call directly. With
22317- # two or more, emit a sentinel-switch over the slot variable.
22312+ # `Module.accessor.<method>` where the slot was resolved by
22313+ # `resolve_module_singleton_accessors`. With a single constant
22314+ # in the resolved set, inline the call directly. With two or
22315+ # 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 widening
22329- # has already unified the candidates' per-arg ptypes,
22330- # so any candidate's ptypes table tells us the target
22331- # types here. Box each arg expression to match — without
22332- # this, an int arg passed to a poly-widened param emits
22333- # raw `mrb_int` to a `sp_RbVal` slot (Wint-conversion).
22326+ # scan_new_calls' module-dispatch widening has already
22327+ # unified the candidates' per-arg ptypes, so any
22328+ # candidate's ptypes table tells us the target types
22329+ # here. Box each arg expression to match — an int arg
22330+ # passed to a poly-widened param would otherwise emit
22331+ # 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 end
2297522973
2297622974 def compile_no_recv_call_expr(nid, mname)
22977- # Issue #207: bare `new` inside a `def self.<m>` body resolves
22978- # to <CurrentClass>.new. Dispatched here (rather than relying on
22979- # the later `mname == "new"` branch in compile_call_expr) because
22980- # compile_call_expr short-circuits to this function for recv < 0
22981- # before reaching that branch.
22975+ # Bare `new` inside a `def self.<m>` body resolves to
22976+ # <CurrentClass>.new. Dispatched here rather than via the
22977+ # later `mname == "new"` branch in compile_call_expr because
22978+ # compile_call_expr short-circuits to this function for
22979+ # 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 end
2333323331 end
23334- # Issue #286: when the call resolves through inheritance to an
23335- # 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 same
23338- # cast pattern is already used by the recv >= 0 / instance_eval
23339- # branches a few lines above.
23332+ # When the call resolves through inheritance to an
23333+ # ancestor's method, the C function takes `sp_<owner>
23334+ # *self`. Our `self` here is `sp_<current> *`. Cast so
23335+ # the `-Werror` build doesn't trip on
23336+ # -Wincompatible-pointer-types. Same cast pattern as the
23337+ # recv >= 0 / instance_eval branches above.
2334023338 recv_arg = self_expr
2334123339 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 = 1
2396123959 rc = compile_expr_gc_rooted(recv)
23962- # Issue #313: unbox a poly-typed arg to const char * before
23963- # sp_String_append (which takes const char *). sp_poly_to_s
23964- # handles every tag — string passes through, others coerce.
23960+ # Unbox a poly-typed arg to const char * before
23961+ # 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 >= 0
2396723966 arg_ids = get_args(args_id)
@@ -24071,12 +24070,11 @@
2407124070 ""
2407224071 end
2407324072
24074- # Issue #207: implicit `new` (recv-less) inside a `def self.<m>`
24075- # body resolves to <CurrentClass>.new. Without this the recv < 0
24076- # branch fell through to "0" with the warning, leaving a factory
24077- # like `def self.from_raw(p); instance = new; instance.x = ...; end`
24078- # broken. Mirrors how implicit `self` inside instance methods
24079- # 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 `def
24075+ # self.from_raw(p); instance = new; instance.x = ...; end`
24076+ # works. Mirrors the way implicit `self` inside instance methods
24077+ # routes recv-less calls to the enclosing class.
2408024078 def implicit_new_class_name(recv)
2408124079 if recv >= 0
2408224080 return ""
@@ -24266,11 +24264,11 @@
2426624264 return "sp_IntArray_new()"
2426724265 end
2426824266 if cname == "String"
24269- # Issue #203: `String.new` and `String.new("seed")` produce
24270- # the same sp_String * value that `s = ""` widens into when
24271- # followed by `<<`. Mirror sp_String_new's signature: a NUL-
24272- # terminated seed (defaulting to "") that the runtime copies
24273- # into the freshly allocated buffer.
24267+ # `String.new` and `String.new("seed")` produce the same
24268+ # sp_String * value that `s = ""` widens into when
24269+ # followed by `<<`. Mirror sp_String_new's signature: a
24270+ # NUL-terminated seed (defaulting to "") that the runtime
24271+ # copies into the freshly allocated buffer.
2427424272 @needs_mutable_str = 1
2427524273 @needs_gc = 1
2427624274 args_id = @nd_arguments[nid]
@@ -26086,7 +26084,7 @@
2608626084 if mname == "empty?"
2608726085 return "sp_PtrArray_empty(" + rc + ")"
2608826086 end
26089- # Issue #156: transpose for [[Int]] (int_array_ptr_array). Other
26087+ # transpose for [[Int]] (int_array_ptr_array). Other
2609026088 # nested-array element shapes are not yet supported and fall
2609126089 # through to the unresolved-call warning.
2609226090 if mname == "transpose" && elem_type == "int_array"
@@ -27084,11 +27082,12 @@
2708427082 mfn = rcname + "_cls_" + mname
2708527083 mfi = find_method_idx(mfn)
2708627084 if mfi >= 0
27087- # Issue #239: route through compile_call_args_with_defaults
27088- # so a `def self.greet(name, msg = nil); end` inside a
27085+ # Route through compile_call_args_with_defaults so a
27086+ # `def self.greet(name, msg = nil); end` inside a
2708927087 # module accepts shorter call sites — caller-omitted
27090- # trailing args get filled in from the method's recorded
27091- # default expressions, the same as top-level method calls.
27088+ # trailing args get filled in from the method's
27089+ # recorded default expressions, the same as top-level
27090+ # 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 >= 0
2714127140 owner_name = @cls_names[owner_ci]
2714227141 ca = compile_call_args(nid)
27143- # Issue #239: fill in defaults for trailing params the
27144- # caller omitted. `def self.greet(name, msg = nil)` with
27145- # call site `C.greet("a")` would otherwise emit
27142+ # Fill in defaults for trailing params the caller
27143+ # omitted. `def self.greet(name, msg = nil)` with call
27144+ # site `C.greet("a")` would otherwise emit
2714627145 # `sp_C_cls_greet("a")` against the 2-arg signature and
2714727146 # the C compiler rejects with `too few arguments`. Look
2714827147 # 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 defined
27452- # on a primitive type (String, Array, Hash, Integer, etc.). The
27453- # int-to-class cast here would silently pick the first user class
27454- # that happens to define the same method name — exactly the
27455- # `String#index` vs `ArticlesController#index` collision the issue
27456- # reports. A param typed `mrb_int` because it wasn't pinned upstream
27457- # is NOT the IntArray-of-pointers shape this fallback was written
27458- # for; refuse to pick a user class and let compile_call_expr's
27459- # unresolved-call diagnostic fire instead.
27450+ # ...but NOT when `mname` is a method also defined on a
27451+ # primitive type (String, Array, Hash, Integer, etc.). The
27452+ # int-to-class cast here would silently pick the first user
27453+ # class defining the same method name — e.g. routing
27454+ # `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 to
27458+ # pick a user class and let the unresolved-call diagnostic
27459+ # fire instead.
2746027460 if recv_type == "int" && primitive_method_shared_with_user_class(mname) == 1
2746127461 return ""
2746227462 end
@@ -27927,11 +27927,11 @@
2792727927 # instructions etc.) must compile to `(pc >> 8) & 1`, not to
2792827928 # the array dispatch in the SP_TAG_OBJ block below — which
2792927929 # would silently leave the result at nil and miscount cycles.
27930- # Issue #341: only emit the int-bit-extract fallback when the
27931- # index argument is itself an int (or a poly we can unbox to
27932- # int). For non-int keys (string, sym, etc.) the SP_TAG_INT
27933- # 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 index
27931+ # argument is itself an int (or a poly we can unbox to int).
27932+ # For non-int keys (string, sym, ...) the SP_TAG_INT branch
27933+ # is unreachable at runtime and `(recv.v.i >> key)` is
27934+ # 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 = 0
2796327963 while pk < arm_ptypes.length
2796427964 if pk < arg_compiled.length
27965- # Issue #351: when this arm's param widened to `poly`
27966- # (matz/spinel#341 cross-call-site union) but the call
27967- # site supplied a concrete value (string / mrb_int /
27968- # symbol / ...), box it via the appropriate sp_box_*
27969- # helper. Without this, gcc errors `incompatible type
27970- # for argument` — `const char *` / `mrb_int` into a
27971- # `sp_RbVal` slot. Inverse direction (poly arg into a
27972- # 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 a
27967+ # concrete value (string / mrb_int / symbol / ...),
27968+ # box it via the appropriate sp_box_* helper so the
27969+ # arg type matches the slot — otherwise gcc errors
27970+ # `incompatible type for argument` on `const char *` /
27971+ # `mrb_int` into a `sp_RbVal`. The inverse direction
27972+ # (poly arg into a concrete-typed param) is handled
27973+ # 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 already
2805328053 # picked a compatible result type.
2805428054 #
28055- # Issue #341: every built-in [] arm here passes the key to a
28056- # function expecting `mrb_int`. Only emit the arms when the key
28057- # type is int or poly (poly is unboxed via `.v.i` above). For
28055+ # Every built-in [] arm here passes the key to a function
28056+ # expecting `mrb_int`. Only emit the arms when the key type
28057+ # is int or poly (poly is unboxed via `.v.i` above). For
2805828058 # non-int keys (string, sym), these arms are unreachable at
2805928059 # 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 cc
2826728267 end
28268- # Issue #129: NULL-safe equality via sp_str_eq. Plain strcmp(NULL, ...)
28269- # is UB and segfaults on real inputs (ENV[] returns NULL for unset
28270- # vars). The helper does a NULL check, then strcmp; identical answer
28271- # 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 for
28270+ # unset vars). The helper does a NULL check then strcmp;
28271+ # identical answer for non-NULL operands, so existing
28272+ # equality call sites are unaffected.
2827228273 if op == "=="
2827328274 return "sp_str_eq(" + lc + ", " + rc + ")"
2827428275 else
@@ -28464,25 +28465,25 @@
2846428465 end
2846528466
2846628467 def box_expr_to_poly(nid)
28467- # Issue #131: ternary / if-as-expression whose branches may have
28468- # different concrete types. Per-branch box unconditionally — same-
28469- # type branches yield a redundant box that still produces correct
28470- # sp_RbVal, and mixed-type branches need the per-branch box to
28471- # avoid C's pointer/integer ternary-type-mismatch (which lands as
28472- # an unsafe cast in the poly slot and segfaults).
28473- # Gating on infer_type's "poly" answer would not work: unify_return
28474- # _type treats int as default/unresolved (`int + T → T`), so a
28475- # genuinely mixed-int-string ternary infers as "string" and the
28476- # gate misses it. The pre-#131 emit then `sp_box_str`'d the entire
28477- # raw ternary, which is the same UB.
28468+ # Ternary / if-as-expression whose branches may have different
28469+ # concrete types: per-branch box unconditionally. Same-type
28470+ # branches yield a redundant box that still produces correct
28471+ # sp_RbVal; mixed-type branches need the per-branch box to
28472+ # avoid C's pointer/integer ternary-type-mismatch (which would
28473+ # otherwise land as an unsafe cast in the poly slot and
28474+ # segfault). Gating on infer_type's "poly" answer would miss
28475+ # mixed-type cases — unify_return_type treats int as
28476+ # default/unresolved (`int + T → T`), so a genuinely
28477+ # int-string ternary infers as "string" and a poly gate would
28478+ # 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-decidable
28480- # is_a? / kind_of? on an already-typed expression, emit only
28481- # the live arm. The dead arm may contain a recursion call
28482- # whose argument types don't match the function's signature
28483- # (e.g. `v.is_a?(Hash) ? recurse(v) : v` where v is statically
28484- # a string) — generating it would land as a C type error
28485- # 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 the
28482+ # live arm. The dead arm may contain a recursion call whose
28483+ # argument types don't match the function's signature (e.g.
28484+ # `v.is_a?(Hash) ? recurse(v) : v` where v is statically a
28485+ # string) — generating it would land as a C type error even
28486+ # 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 end
2859028591 return
2859128592 end
28592- # 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 their
28593+ # Empty `{}` / `[]` literal RHS — `compile_expr` returns the
28594+ # default `sp_StrIntHash_new()` / `sp_IntArray_new()`, but
28595+ # slots may have been promoted to a typed container by their
2859528596 # subsequent writes (e.g. `@h["k"] = "v"` lifts the slot to
28596- # str_str_hash). If every chain participant agrees on the same
28597- # promoted concrete container type, emit the slot-typed
28598- # constructor as the temp so each store is type-correct AND the
28599- # Ruby semantic of one shared object is preserved across the
28600- # chain. Disagreeing-type chains fall through to the general
28601- # case below; the resulting C will still warn about pointer
28597+ # str_str_hash). If every chain participant agrees on the
28598+ # same promoted concrete container type, emit the slot-typed
28599+ # constructor as the temp so each store is type-correct AND
28600+ # the Ruby semantic of one shared object is preserved across
28601+ # the chain. Disagreeing-type chains fall through to the
28602+ # general case below; the resulting C will still warn about
28603+ # pointer
2860228604 # 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) == 1
2860428606 consensus_t = ""
@@ -28831,12 +28833,12 @@
2883128833 if kw_names[ki] == pnames[k]
2883228834 kw_found = 1
2883328835 if k < ptypes.length && ptypes[k] == "poly"
28834- # Issue #314: pick the box helper from the arg's actual
28835- # source type via box_expr_to_poly. The pre-fix sp_box_str
28836- # hardcoding mistyped any non-string source (e.g. an
28837- # `obj_<C>` instance) as SP_TAG_STR — invalid C and the
28838- # boxed value disagrees with sp_RbVal's tag/cls_id contract
28839- # at runtime.
28836+ # Pick the box helper from the arg's actual source
28837+ # type via box_expr_to_poly. A hardcoded sp_box_str
28838+ # would mistype any non-string source (e.g. an
28839+ # `obj_<C>` instance) as SP_TAG_STR — invalid C and a
28840+ # value that disagrees with sp_RbVal's tag/cls_id
28841+ # contract at runtime.
2884028842 result = result + box_expr_to_poly(kw_arg_ids[ki])
2884128843 else
2884228844 result = result + kw_vals[ki]
@@ -29052,13 +29054,13 @@
2905229054 # Check if param is poly
2905329055 if k < ptypes.length
2905429056 if ptypes[k] == "poly"
29055- # Issue #314: pick the box helper from the arg's actual
29056- # source type via box_expr_to_poly. The pre-fix sp_box_str
29057- # hardcoding mistyped any non-string source — and a kwargs
29058- # call site with a poly-widened param (e.g. `model:` after
29059- # the call-site widening pass folds Article+Comment into
29060- # poly) is exactly the path that flows non-string objs
29061- # through here.
29057+ # Pick the box helper from the arg's actual source
29058+ # type via box_expr_to_poly. A hardcoded sp_box_str
29059+ # would mistype any non-string source — and a
29060+ # kwargs call site with a poly-widened param
29061+ # (e.g. `model:` after call-site widening folds
29062+ # Article + Comment into poly) is exactly the path
29063+ # that flows non-string objs through here.
2906229064 result = result + box_expr_to_poly(kw_arg_ids[ki])
2906329065 else
2906429066 result = result + kw_vals[ki]
@@ -29142,11 +29144,12 @@
2914229144 k = k + 1
2914329145 next
2914429146 end
29145- # Issue #58: empty `[]` literal at the call site needs to
29146- # construct the right typed-array container. The literal's
29147- # own infer_type returns int_array (compile_array_literal
29148- # emits sp_IntArray_new()), but if the param is a concrete
29149- # typed-array, emit the matching constructor instead.
29147+ # An empty `[]` literal at the call site needs to
29148+ # construct the right typed-array container. The
29149+ # literal's own infer_type returns int_array
29150+ # (compile_array_literal emits sp_IntArray_new()), but
29151+ # when the param is a concrete typed-array, emit the
29152+ # matching constructor instead.
2915029153 if is_empty_array_literal(positional_ids[k]) == 1
2915129154 if ptypes[k] == "str_array"
2915229155 @needs_str_array = 1
@@ -30622,11 +30625,12 @@
3062230625 emit(" " + self_arrow + sanitize_ivar(iname) + " = " + tmp_arr + ";")
3062330626 return
3062430627 end
30625- # Issue #130: poly slot — every concrete-typed RHS must be boxed
30626- # to sp_RbVal. Without the box, C compiler sees `sp_RbVal = mrb_int`
30627- # (or const char *, etc.) and either rejects the assignment or
30628- # silently coerces. Read sites already dispatch through poly-aware
30629- # emitters (sp_poly_puts, etc.) that unbox.
30628+ # Poly slot — every concrete-typed RHS must be boxed to
30629+ # sp_RbVal. Without the box, the C compiler sees
30630+ # `sp_RbVal = mrb_int` (or const char *, etc.) and either
30631+ # rejects the assignment or silently coerces. Read sites
30632+ # already dispatch through poly-aware emitters
30633+ # (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 - 1
3134331347 else
31344- # Issue #310: wrap elsif in braces. compile_cond_expr for the
31345- # 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.tag
31348- # == SP_TAG_OBJ) {...}; if (_flag) ...`. Without wrapping, the
31349- # `} 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 out
31352- # of reach.
31348+ # Wrap elsif in braces. compile_cond_expr for the nested
31349+ # 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 to
31352+ # `sp_RbVal _t = ...; if (_t.tag == SP_TAG_OBJ) {...}; if
31353+ # (_flag) ...`. Without the wrap, the `} else <prologue>
31354+ # if (...)` shape is invalid C: the bare-else's body
31355+ # would be the first statement only (the prologue decl),
31356+ # leaving the inner if in the outer scope with the decl
31357+ # out of reach.
3135331358 emit(" } else {")
3135431359 @indent = @indent + 1
3135531360 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` was
32067- # emitted as `return 0;` regardless of the wrapping function. In
32068- # the synthesized `sp_<C>_new` (sp_<C> *-returning) it silently
32069- # NULLed the instance on the early-return branch; in the void
32070- # `sp_<C>_initialize` form it was a `void function should not
32071- # return a value` C error.
32071+ # The shape per @current_method_return matters because a
32072+ # `return if x.nil?` inside a `def initialize` reaches this
32073+ # bare-return path: in the synthesized `sp_<C>_new` (sp_<C>
32074+ # *-returning) emitting `return 0;` would silently NULL the
32075+ # instance on the early-return branch, and in the void
32076+ # `sp_<C>_initialize` form it would be a `void function
32077+ # should not return a value` C error.
3207232078 emit_setjmp_depth_unwind
3207332079 emit_ensure_replays
3207432080 if @in_gc_scope == 1
@@ -32109,7 +32115,7 @@
3210932115 return
3211032116 end
3211132117
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 the
3211532121 # read site's sentinel switch picks the right branch.
@@ -32400,10 +32406,11 @@
3240032406 emit(" sp_String_append(" + rc + ", " + val + "->data);")
3240132407 else
3240232408 if at == "poly"
32403- # Issue #313: a poly-typed source (e.g. a module
32404- # method returning sp_RbVal from a SymPolyHash
32405- # read) needs runtime unbox to const char * before
32406- # sp_String_append. sp_poly_to_s handles every tag.
32409+ # A poly-typed source (e.g. a module method
32410+ # returning sp_RbVal from a SymPolyHash read)
32411+ # needs runtime unbox to const char * before
32412+ # sp_String_append. sp_poly_to_s handles
32413+ # every tag.
3240732414 emit(" sp_String_append(" + rc + ", sp_poly_to_s(" + val + "));")
3240832415 else
3240932416 emit(" sp_String_append(" + rc + ", " + val + ");")
@@ -36685,11 +36692,11 @@
3668536692 tmp_arr
3668636693 end
3668736694
36688- # Issue #210 follow-up: an empty `map {}` block yields nil per
36689- # iteration in CRuby — the result array's length still matches the
36690- # receiver. Without an explicit push the typed accumulator stays
36691- # short and downstream `.length` / `[i]` on the result is wrong.
36692- # Push a type-appropriate default (0 / 0.0 / "" / sp_box_nil) so
36695+ # An empty `map {}` block yields nil per iteration in CRuby —
36696+ # the result array's length still matches the receiver. Without
36697+ # an explicit push the typed accumulator stays short and
36698+ # downstream `.length` / `[i]` on the result is wrong. Push a
36699+ # type-appropriate default (0 / 0.0 / "" / sp_box_nil) so
3669336700 # 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 end
3900039007 @indent = @indent - 1
3900139008 else
39002- # Issue #310: wrap elsif in braces. See compile_if_stmt for
39003- # the same fix; predicates that emit prologue C statements
39004- # (poly is_a? etc.) leak declarations out of a bare else
39005- # because the bare else's body is one statement.
39009+ # Wrap elsif in braces. See compile_if_stmt for the same
39010+ # rationale: predicates that emit prologue C statements
39011+ # (poly is_a? etc.) would leak declarations out of a bare
39012+ # else because the bare else's body is one statement.
3900639013 emit(" } else {")
3900739014 @indent = @indent + 1
3900839015 compile_if_return(sub, rt)