Commit c7f27395
c7f273955dbaMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
Merge pull request #372 from OriPekelman/fix/multi-write-typed-array-dispatch
fix(codegen): multi-write destructure dispatches by RHS array type
Details
- Commit
- c7f273955dba
- Parent
- 05dfa8119de5
- Merge parent
- 522df5242667
spinel_codegen.rbmodifiedView file
@@ -31106,10 +31106,15 @@
3110631106
end3110731107
else3110831108
# RHS is a function call returning a typed array. Dispatch by31109-
# the RHS's static type — IntArray default, but PolyArray when31110-
# the inner is heterogeneous (optcarrots `@io_addr,31109+
# the RHS's static type — IntArray default, PolyArray when the31110+
# inner is heterogeneous (optcarrots `@io_addr,3111131111
# @bg_pattern_lut_fetched, _ = @attr_lut[i]` where attr_lut31112-
# elements are 3-tuples of mixed types).31112+
# elements are 3-tuples of mixed types), and the matching typed-31113+
# array variants otherwise. Without per-type dispatch a method31114+
# returning e.g. `[Mat.new, Mat.new]` (typed obj_Mat_ptr_array)31115+
# destructured via `a, b = self.two_mats` got compiled as31116+
# `sp_IntArray *_t = sp_N_two_mats(...); sp_IntArray_get(_t, i)`,31117+
# mismatching the actual sp_PtrArray * return.3111331118
val_t_local = infer_type(val_id)3111431119
@needs_gc = 13111531120
tmp = new_temp@@ -31126,6 +31131,16 @@
3112631131
rb_tmp_mw = new_temp3112731132
emit(" sp_RbVal " + rb_tmp_mw + " = " + compile_expr(val_id) + ";")3112831133
emit(" sp_PolyArray *" + tmp + " = (" + rb_tmp_mw + ".cls_id == SP_BUILTIN_POLY_ARRAY) ? (sp_PolyArray *)" + rb_tmp_mw + ".v.p : NULL;")31134+
elsif val_t_local == "str_array"31135+
@needs_str_array = 131136+
emit(" sp_StrArray *" + tmp + " = " + compile_expr(val_id) + ";")31137+
elsif val_t_local == "float_array"31138+
@needs_float_array = 131139+
emit(" sp_FloatArray *" + tmp + " = " + compile_expr(val_id) + ";")31140+
elsif val_t_local == "sym_array"31141+
emit(" sp_IntArray *" + tmp + " = " + compile_expr(val_id) + ";")31142+
elsif is_ptr_array_type(val_t_local) == 131143+
emit(" sp_PtrArray *" + tmp + " = " + compile_expr(val_id) + ";")3112931144
else3113031145
@needs_int_array = 13113131146
emit(" sp_IntArray *" + tmp + " = " + compile_expr(val_id) + ";")@@ -31137,6 +31152,19 @@
3113731152
if val_t_local == "poly_array" || val_t_local == "poly"3113831153
rhs = "sp_PolyArray_get(" + tmp + ", " + k.to_s + ")"3113931154
val_t_for_target = "poly"31155+
elsif val_t_local == "str_array"31156+
rhs = "sp_StrArray_get(" + tmp + ", " + k.to_s + ")"31157+
val_t_for_target = "string"31158+
elsif val_t_local == "float_array"31159+
rhs = "sp_FloatArray_get(" + tmp + ", " + k.to_s + ")"31160+
val_t_for_target = "float"31161+
elsif val_t_local == "sym_array"31162+
rhs = "((sp_sym)sp_IntArray_get(" + tmp + ", " + k.to_s + "))"31163+
val_t_for_target = "symbol"31164+
elsif is_ptr_array_type(val_t_local) == 131165+
elem_t = ptr_array_elem_type(val_t_local)31166+
rhs = "((" + c_type(elem_t) + ")sp_PtrArray_get(" + tmp + ", " + k.to_s + "))"31167+
val_t_for_target = elem_t3114031168
else3114131169
rhs = "sp_IntArray_get(" + tmp + ", " + k.to_s + ")"3114231170
val_t_for_target = "int"test/multi_write_typed_array_dispatch.rbaddedView file
Loading diff…
test/multi_write_typed_array_dispatch.rb.expectedaddedView file
Loading diff…