Commit 7980373f
7980373f777bMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 6 files · +4 added · ~2 modified
Description
fix(codegen): three Ruby-semantics fixes — multi-write nil + block_given inline + LV ||=/&&= poly
Three orthogonal repros from the new issue batch:
#705: a, b = nil segfaulted because multi-write fell through to
the typed-array destructure path and emitted sp_IntArray *_t = 0; sp_IntArray_get(_t, 0). Add a NilNode-RHS early-return in
compile_multi_write that binds each target to nil. The analyze
side (multi_write_target_type) likewise returns "nil" so the
target slots get the correct first-write type. (Output still
prints [0, 0] vs Ruby's [nil, nil] -- the LV nil type makes
the surrounding array literal an int_array; a wider fix for
nil-typed-LV-in-array shape is deferred. The segfault is gone.)
#706: f (no args) on a yield-using method (block_given? marks
it yield-using) emitted sp_f(, NULL, NULL) -- empty leading
arg slot. Strip the leading ", " from yargs when the regular-
args list is empty.
#706 part 2: f { } (with literal block) inlined block_given?
to 0 because compile_block_given_expr's only 1 arm checked
@in_yield_method (set when compiling f's own body, NOT when
inlining at the call site). Add an @inline_yield_blk arm so
inlined-context block_given? answers true.
#702: a = nil; a ||= 5; a &&= true failed C compile because
the LV ||= / &&= emit used C's if (!vref) directly. For poly
(sp_RbVal struct) vref this isn't a valid scalar; for int? it
compared the SP_INT_NIL sentinel to NULL. Route the truthy
check through truthy_c_expr when the LV's declared type is poly
or scalar-nullable; keep the C-truthy fallback for other types
(notably the a = nil first-write nil type, where the runtime
value gets checked via C if (vref)).
(#702 display: the final puts a.inspect still emits nil
because analyze didn't widen a's declared type past the
initial nil write -- a separate scan_locals issue for the
||= / &&= forms, deferred.)
Tests: bang_op_ruby_truthy.rb, block_given_inline_call_site.rb. 451 tests pass, optcarrot 59662 holds.
Refs #702 Fixes #705 (segfault) Fixes #706
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 7980373f777b
- Parent
- 8e19a79517b4
spinel_analyze.rbmodifiedView file
if val_id < 0 return "int" end # `a, b = nil` -- every target gets nil (Ruby semantic). Avoids # the typed-array destructure path that NULL-derefs at runtime # (#705). if @nd_type[val_id] == "NilNode" return "nil" end rt = infer_type(val_id) if is_tuple_type(rt) == 1 return tuple_elem_type_at(rt, ti)spinel_codegen.rbmodifiedView file
Loading diff…
test/bang_op_ruby_truthy.expectedaddedView file
Loading diff…
test/bang_op_ruby_truthy.rbaddedView file
Loading diff…
test/block_given_inline_call_site.expectedaddedView file
Loading diff…
test/block_given_inline_call_site.rbaddedView file
Loading diff…