Commit 8d52d1fd
8d52d1fd69a1Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
Merge pull request #136 from companygardener/codex/fix-empty-poly-array
fix(codegen): preserve mixed arrays after empty reassignment
Details
- Commit
- 8d52d1fd69a1
- Parent
- 9ad6108be22e
- Merge parent
- 3a44076eaaa8
spinel_codegen.rbmodifiedView file
@@ -2931,6 +2931,19 @@
29312931
end29322932
return "string"29332933
end2934+
if rt == "poly_array"2935+
args_id = @nd_arguments[nid]2936+
if args_id >= 02937+
a = get_args(args_id)2938+
if a.length >= 1 && @nd_type[a[0]] == "RangeNode"2939+
return "poly_array"2940+
end2941+
if a.length >= 22942+
return "poly_array"2943+
end2944+
end2945+
return "poly"2946+
end29342947
if is_ptr_array_type(rt) == 129352948
return ptr_array_elem_type(rt)29362949
end@@ -6155,6 +6168,20 @@
61556168
end61566169
return at61576170
end6171+
if is_array_type(old_pt) == 1 && is_array_type(at) == 16172+
if old_pt == "poly_array" || at == "poly_array"6173+
@needs_rb_value = 16174+
return "poly_array"6175+
end6176+
if old_pt == "int_array"6177+
return at6178+
end6179+
if at == "int_array"6180+
return old_pt6181+
end6182+
@needs_rb_value = 16183+
return "poly_array"6184+
end61586185
if at == "int"61596186
# Numeric compat: int + float is safe in both directions.61606187
if old_pt == "float"@@ -12436,6 +12463,15 @@
1243612463
if names[ki] == lname1243712464
if types[ki] != at1243812465
if types[ki] != "poly"12466+
if is_array_type(types[ki]) == 1 && is_array_type(at) == 112467+
types[ki] = unify_call_types(types[ki], at, @nd_expression[nid])12468+
if types[ki] == "poly_array"12469+
@needs_rb_value = 112470+
@needs_gc = 112471+
end12472+
ki = ki + 112473+
next12474+
end1243912475
# Genuine polymorphism: both the first write and this1244012476
# write were explicit literals, and their types differ.1244112477
# This catches `x = 1; x = "hello"` which the legacy@@ -17409,6 +17445,14 @@
1740917445
if mname == "[]"1741017446
return "sp_PolyArray_get(" + rc + ", " + compile_arg0(nid) + ")"1741117447
end17448+
if mname == "push"17449+
arg_id = -117450+
aargs = get_args(@nd_arguments[nid])17451+
if aargs.length > 017452+
arg_id = aargs[0]17453+
end17454+
return "(sp_PolyArray_push(" + rc + ", " + box_expr_to_poly(arg_id) + "), 0)"17455+
end1741217456
end1741317457
""1741417458
end@@ -19767,7 +19811,7 @@
1976719811
# early here also preserves the scope's already-promoted type1976819812
# (issue #58, #85) — the fall-through path below would clobber1976919813
# vt with infer_type([])'s "int_array" via set_var_type.19770-
if vt == "str_array" || vt == "float_array" || vt == "sym_array" || is_ptr_array_type(vt) == 119814+
if vt == "str_array" || vt == "float_array" || vt == "sym_array" || vt == "poly_array" || is_ptr_array_type(vt) == 11977119815
expr_id = @nd_expression[nid]1977219816
if expr_id >= 0 && @nd_type[expr_id] == "ArrayNode"1977319817
elems = parse_id_list(@nd_elements[expr_id])@@ -19785,6 +19829,10 @@
1978519829
@needs_int_array = 11978619830
@needs_gc = 11978719831
emit(" " + vref + " = sp_IntArray_new();")19832+
elsif vt == "poly_array"19833+
@needs_rb_value = 119834+
@needs_gc = 119835+
emit(" " + vref + " = sp_PolyArray_new();")1978819836
else1978919837
@needs_gc = 11979019838
emit(" " + vref + " = sp_PtrArray_new();")test/empty_poly_array_reassignment.rbaddedView file
Loading diff…