Hello.
When the number of fields in a struct is less than 15, @code_warntype diagnoses that the function is ‘type-stable’. But as their number grows, the function becomes ‘type-unstable’ from @code_warntype’s point of view. Looks like a bug?
struct struct15; a1; a2; a3; a4; a5; a6; a7; a8; a9; a10; a11; a12; a13; a14; a15; end
struct struct16; a1; a2; a3; a4; a5; a6; a7; a8; a9; a10; a11; a12; a13; a14; a15; a16; end
function arrayofstruct15(args)
mystructs = map(zip(args...)) do x
struct15(x...)
end
end
function arrayofstruct16(args)
mystructs = map(zip(args...)) do x
struct16(x...)
end
end
args = ([1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2],
[1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2],
[1, 2], [1, 2], [1, 2], [1, 2],)
s15 = arrayofstruct15(args[1:end-1])
s16 = arrayofstruct16(args)
@code_warntype arrayofstruct15(args[1:end-1])
@code_warntype arrayofstruct16(args)
Results
Variables
#self#::Core.Const(arrayofstruct15)
args::NTuple{15, Vector{Int64}}
#5::var"#5#6"
mystructs::Vector{struct15}
Body::Vector{struct15}
1 ─ (#5 = %new(Main.:(var"#5#6")))
│ %2 = #5::Core.Const(var"#5#6"())
│ %3 = Core._apply_iterate(Base.iterate, Main.zip, args)::Base.Iterators.Zip{NTuple{15, Vector{Int64}}}
│ %4 = Main.map(%2, %3)::Vector{struct15}
│ (mystructs = %4)
└── return %4
Variables
#self#::Core.Const(arrayofstruct16)
args::NTuple{16, Vector{Int64}}
#7::var"#7#8"
mystructs::Any
Body::Any
1 ─ (#7 = %new(Main.:(var"#7#8")))
│ %2 = #7::Core.Const(var"#7#8"())
│ %3 = Core._apply_iterate(Base.iterate, Main.zip, args)::Base.Iterators.Zip{NTuple{16, Vector{Int64}}}
│ %4 = Main.map(%2, %3)::Any
│ (mystructs = %4)
└── return %4