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

@@ -29753,6 +29753,9 @@
2975329753 end
2975429754 elsif is_tuple_type(infer_type(val_id)) == 1
2975529755 # RHS is a tuple-returning call — destructure via field access.
29756+ # Route every slot through emit_multi_write_target so ivar /
29757+ # constant / attr-writer / index targets (not just local vars)
29758+ # all get the per-component assignment.
2975629759 val_t = infer_type(val_id)
2975729760 @needs_gc = 1
2975829761 tmp = new_temp
@@ -29761,9 +29764,9 @@
2976129764 k = 0
2976229765 while k < targets.length
2976329766 tid = targets[k]
29764- if @nd_type[tid] == "LocalVariableTargetNode"
29765- emit(" " + fiber_var_ref(@nd_name[tid]) + " = " + tmp + "->_" + k.to_s + ";")
29766- end
29767+ slot_expr = tmp + "->_" + k.to_s
29768+ slot_type = tuple_elem_type_at(val_t, k)
29769+ emit_multi_write_target(tid, slot_expr, slot_type)
2976729770 k = k + 1
2976829771 end
2976929772 else