Commit 7305f810
7305f810dc73Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
fix(codegen): exclude push-promoted ptr_array elements from value-type opt
PR #87 excluded value-type-eligible classes from the value-type
optimization when their instances appeared in an [Foo.new(...)]
literal. The same root mismatch fired through the push-promotion
path — arr = []; arr.push(Foo.new(...)) — where no array literal
exists at scan time, so the literal-walk in
detect_ptr_array_stored_types missed it. Foo got optimized into a
value type and the push call tried to feed sp_PtrArray_push's
void * parameter a struct-by-value, with sp_PtrArray_get further
on trying to cast void * back to a struct.
Extend the same scan to also walk push-style call sites (push,
<<, unshift, prepend) and add obj_<C> to the exclusion
whenever a push argument has that type. The existing
detect_value_types consumer of @ptr_array_stored_types then
applies the same exclusion logic for the push-promoted case as for
the literal-promoted case.
Mirrors the fix shape PR #91 suggested — option 1 from the issue's note.
test/ptr_array_of_value_class_push.rb covers the issue's exact
reproducer plus the << variant.
Closes #91
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 7305f810dc73
- Parent
- 2966d2d40985
spinel_codegen.rbmodifiedView file
end end end # Push-promotion path (issue #91): an empty `[]` grows into an # `obj_<C>_ptr_array` via later `push(Foo.new(...))` / `<< Foo.new(...)` # calls. The literal-walk above doesn't see this because no # `[Foo.new(...)]` literal exists. Inspect every push-style call # and, if the argument's inferred type is `obj_<C>`, add `<C>` # to the exclusion so it stays heap-allocated. if @nd_type[nid] == "CallNode" mname = @nd_name[nid] if mname == "push" || mname == "<<" || mname == "unshift" || mname == "prepend" args_id = @nd_arguments[nid] if args_id >= 0 push_args = get_args(args_id) pk = 0 while pk < push_args.length at_push = infer_type(push_args[pk]) if is_obj_type(at_push) == 1 if not_in(at_push, @ptr_array_stored_types) == 1 @ptr_array_stored_types.push(at_push) end end pk = pk + 1 end end end end nid = nid + 1 end endtest/ptr_array_of_value_class_push.rbaddedView file
Loading diff…