Commit 592a33ad
592a33addfcbMerged
Yusuke Endoh <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(codegen): gc_scan skips ivars inherited from parent class
emit_class_struct already skips ivars whose name appears in the
parent chain — the subclass's struct uses the inherited field
typed by the parent. gc_scan was still walking those names
under the child's (potentially widened) recorded type, emitting a
mark with the wrong type cast (e.g. parent says int_array, child
has widened to poly, struct field is sp_RbVal but the emitted
mark used a different cast).
Skip ivars whose name is in the parent chain. The parent's own gc_scan walk handles them via the parent's recorded type, which matches the actual struct field.
Details
- Commit
- 592a33addfcb
- Parent
- 60f1b75ea8d0
spinel_codegen.rbmodifiedView file
@@ -13106,7 +13106,23 @@
1310613106
j = 01310713107
while j < names.length1310813108
if j < types.length13109-
if ivar_is_gc_ptr(types[j]) == 113109+
# Skip ivars inherited from parent — emit_class_struct13110+
# also skips them on the child, so the struct field type13111+
# comes from the parent's recorded type, and re-emitting13112+
# here under the child's type info can produce a wrong13113+
# mark (e.g. parent says int_array, child has widened to13114+
# poly, struct field is sp_RbVal). The parent walk below13115+
# marks them via the parent's type.13116+
skip_inherited = 013117+
if @cls_parents[i] != ""13118+
parent_idx = find_class_idx(@cls_parents[i])13119+
if parent_idx >= 013120+
if ivar_in_chain(parent_idx, names[j]) == 113121+
skip_inherited = 113122+
end13123+
end13124+
end13125+
if skip_inherited == 0 && ivar_is_gc_ptr(types[j]) == 11311013126
emit_gc_mark_ivar("self->" + sanitize_ivar(names[j]), types[j])1311113127
end1311213128
endtest/gc_scan_skip_inherited_ivar.rbaddedView file
Loading diff…
test/gc_scan_skip_inherited_ivar.rb.expectedaddedView file
Loading diff…