Commit b5df9125
b5df912517ebMerged
Yusuke Endoh <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(codegen): multi-return into ivar / const / attr destructure
compile_multi_write's tuple-RHS branch only emitted the per-slot
assignment when the LHS target was a LocalVariableTargetNode.
InstanceVariableTargetNode, ConstantTargetNode, CallTargetNode,
and IndexTargetNode were silently skipped, so
@a, @b, @c = method_returning_a_three_class_tuple
allocated and rooted the temp tuple but never decomposed it back into the three ivar slots — leaving them NULL / zero, with the next read either returning the wrong value or segfaulting.
Route every slot through the existing emit_multi_write_target
helper (already used by the IntArray / PolyArray branches just below
in the same function); it handles all four target kinds in one place
and inherits the box-when-slot-is-poly logic for free. scan_ivars
already registers ivars from a tuple-typed RHS via
scan_ivars_multi_target_type, so no scan-side changes are needed.
Fixes the optcarrot pattern
@video, @audio, @input = Driver.load(@conf)
which had to be rewritten as a 4-step local-then-ivar dance to compile.
Details
- Commit
- b5df912517eb
- Parent
- 2ff7ba46856e
spinel_codegen.rbmodifiedView file
end elsif is_tuple_type(infer_type(val_id)) == 1 # RHS is a tuple-returning call — destructure via field access. # Route every slot through emit_multi_write_target so ivar / # constant / attr-writer / index targets (not just local vars) # all get the per-component assignment. val_t = infer_type(val_id) @needs_gc = 1 tmp = new_temp k = 0 while k < targets.length tid = targets[k] if @nd_type[tid] == "LocalVariableTargetNode" emit(" " + fiber_var_ref(@nd_name[tid]) + " = " + tmp + "->_" + k.to_s + ";") end slot_expr = tmp + "->_" + k.to_s slot_type = tuple_elem_type_at(val_t, k) emit_multi_write_target(tid, slot_expr, slot_type) k = k + 1 end elsetest/multi_assign_ivar.rbaddedView file
Loading diff…
test/multi_assign_ivar.rb.expectedaddedView file
Loading diff…