Commit 177d70f1

177d70f1452fMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 1 file · ~1 modified

Description

fix: ao_render value-type detection for classes with attr_writers

Classes with attr_writer declarations are mutable by definition, so they should not be promoted to value types (stack-allocated structs). Previously, attr_writers were skipped in the mutation check, causing Isect to be incorrectly treated as a value type in self-compiled output.

Also extend detect_param_mutated_types to check toplevel functions (not just class methods) for parameter mutation.

67 tests pass, bootstrap clean.

Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]

Details

Commit
177d70f1452f
Parent
dfb930ffa39f

spinel_codegen.rbmodifiedView file

@@ -7652,6 +7652,42 @@
76527652 end
76537653 i = i + 1
76547654 end
7655+ # Also check toplevel functions
7656+ mi = 0
7657+ while mi < @meth_names.length
7658+ bid = @meth_body_ids[mi]
7659+ pnames = @meth_param_names[mi].split(",")
7660+ ptypes = @meth_param_types[mi].split(",")
7661+ obj_param_names = "".split(",")
7662+ obj_param_types = "".split(",")
7663+ pj = 0
7664+ while pj < pnames.length
7665+ pt = "int"
7666+ if pj < ptypes.length
7667+ pt = ptypes[pj]
7668+ end
7669+ if is_obj_type(pt) == 1
7670+ obj_param_names.push(pnames[pj])
7671+ obj_param_types.push(pt)
7672+ end
7673+ pj = pj + 1
7674+ end
7675+ if obj_param_names.length > 0 && bid >= 0
7676+ mutated_name = subtree_has_setter_on_params(bid, obj_param_names)
7677+ if mutated_name != ""
7678+ pj = 0
7679+ while pj < obj_param_names.length
7680+ if obj_param_names[pj] == mutated_name
7681+ if not_in(obj_param_types[pj], @param_mutated_types) == 1
7682+ @param_mutated_types.push(obj_param_types[pj])
7683+ end
7684+ end
7685+ pj = pj + 1
7686+ end
7687+ end
7688+ end
7689+ mi = mi + 1
7690+ end
76557691 end
76567692
76577693 def recalc_needs_gc
@@ -7703,11 +7739,15 @@
77037739 end
77047740 j = j + 1
77057741 end
7706- # Exclude classes with self-mutating methods
7742+ # Exclude classes with self-mutating methods or attr_writers
77077743 if all_val == 1
77087744 if cls_has_self_mutating_methods(i) == 1
77097745 all_val = 0
77107746 end
7747+ writers = @cls_attr_writers[i].split(";")
7748+ if writers.length > 0 && writers[0] != ""
7749+ all_val = 0
7750+ end
77117751 end
77127752 # Exclude classes involved in inheritance
77137753 if all_val == 1