Commit b04c9ea8

b04c9ea874d0Merged

Ori Pekelman <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified

Description

Infer typed array from Array.new(n, fill) in instance-variable init

infer_ivar_init_type returned int_array for any Array.new(...) expression, regardless of the fill argument type. Class fields initialized to Array.new(n, 0.5) ended up typed as the containing class's pointer (sp_Foo *) in the generated struct.

Mirror the fill-type check from infer_constructor_type so a Float fill yields float_array and a String fill yields str_array.

test/bm_ivar_float_array.rb covers the regression. All 103 tests pass; bootstrap closes.

Details

Commit
b04c9ea874d0
Parent
02cea8108166

spinel_codegen.rbmodifiedView file

@@ -4384,6 +4384,20 @@
43844384 rname = constructor_class_name(r)
43854385 if rname != ""
43864386 if rname == "Array"
4387+ # Check fill value type for Array.new(n, val) -- match infer_constructor_type
4388+ args_id = @nd_arguments[nid]
4389+ if args_id >= 0
4390+ aargs = get_args(args_id)
4391+ if aargs.length >= 2
4392+ vt = infer_type(aargs[1])
4393+ if vt == "float"
4394+ return "float_array"
4395+ end
4396+ if vt == "string"
4397+ return "str_array"
4398+ end
4399+ end
4400+ end
43874401 return "int_array"
43884402 end
43894403 if rname == "Hash"