Commit 3a44076e
3a44076eaaa8Merged
Erik Peterson <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
fix(codegen): preserve mixed arrays after empty reassignment
Fixes #134
Co-Authored-By: OpenAI Codex [email protected]
Details
- Commit
- 3a44076eaaa8
- Parent
- 84715d7bed78
spinel_codegen.rbmodifiedView file
@@ -2905,6 +2905,19 @@
29052905
end29062906
return "string"29072907
end2908+
if rt == "poly_array"2909+
args_id = @nd_arguments[nid]2910+
if args_id >= 02911+
a = get_args(args_id)2912+
if a.length >= 1 && @nd_type[a[0]] == "RangeNode"2913+
return "poly_array"2914+
end2915+
if a.length >= 22916+
return "poly_array"2917+
end2918+
end2919+
return "poly"2920+
end29082921
if is_ptr_array_type(rt) == 129092922
return ptr_array_elem_type(rt)29102923
end@@ -6050,6 +6063,20 @@
60506063
end60516064
return at60526065
end6066+
if is_array_type(old_pt) == 1 && is_array_type(at) == 16067+
if old_pt == "poly_array" || at == "poly_array"6068+
@needs_rb_value = 16069+
return "poly_array"6070+
end6071+
if old_pt == "int_array"6072+
return at6073+
end6074+
if at == "int_array"6075+
return old_pt6076+
end6077+
@needs_rb_value = 16078+
return "poly_array"6079+
end60536080
if at == "int"60546081
# Numeric compat: int + float is safe in both directions.60556082
if old_pt == "float"@@ -12301,6 +12328,15 @@
1230112328
if names[ki] == lname1230212329
if types[ki] != at1230312330
if types[ki] != "poly"12331+
if is_array_type(types[ki]) == 1 && is_array_type(at) == 112332+
types[ki] = unify_call_types(types[ki], at, @nd_expression[nid])12333+
if types[ki] == "poly_array"12334+
@needs_rb_value = 112335+
@needs_gc = 112336+
end12337+
ki = ki + 112338+
next12339+
end1230412340
# Genuine polymorphism: both the first write and this1230512341
# write were explicit literals, and their types differ.1230612342
# This catches `x = 1; x = "hello"` which the legacy@@ -17244,6 +17280,14 @@
1724417280
if mname == "[]"1724517281
return "sp_PolyArray_get(" + rc + ", " + compile_arg0(nid) + ")"1724617282
end17283+
if mname == "push"17284+
arg_id = -117285+
aargs = get_args(@nd_arguments[nid])17286+
if aargs.length > 017287+
arg_id = aargs[0]17288+
end17289+
return "(sp_PolyArray_push(" + rc + ", " + box_expr_to_poly(arg_id) + "), 0)"17290+
end1724717291
end1724817292
""1724917293
end@@ -19602,7 +19646,7 @@
1960219646
# early here also preserves the scope's already-promoted type1960319647
# (issue #58, #85) — the fall-through path below would clobber1960419648
# vt with infer_type([])'s "int_array" via set_var_type.19605-
if vt == "str_array" || vt == "float_array" || vt == "sym_array" || is_ptr_array_type(vt) == 119649+
if vt == "str_array" || vt == "float_array" || vt == "sym_array" || vt == "poly_array" || is_ptr_array_type(vt) == 11960619650
expr_id = @nd_expression[nid]1960719651
if expr_id >= 0 && @nd_type[expr_id] == "ArrayNode"1960819652
elems = parse_id_list(@nd_elements[expr_id])@@ -19620,6 +19664,10 @@
1962019664
@needs_int_array = 11962119665
@needs_gc = 11962219666
emit(" " + vref + " = sp_IntArray_new();")19667+
elsif vt == "poly_array"19668+
@needs_rb_value = 119669+
@needs_gc = 119670+
emit(" " + vref + " = sp_PolyArray_new();")1962319671
else1962419672
@needs_gc = 11962519673
emit(" " + vref + " = sp_PtrArray_new();")test/empty_poly_array_reassignment.rbaddedView file
Loading diff…