You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It occurs to me that, in the heterogeneous key/value type case, #12327/#12261 causes us to lose type information. Consider basically any code that uses the for (k, v) in dict idiom, e.g.:
functionf(a)
x =0for (k, v) in a
x += v
end
x
end
Now consider what happens if the key and value types aren't the same. Previously, because we do fancy things for tuple destructuring, we could infer that k is of the key type K and v is of the value type V. But we don't do these fancy things for Pair destructuring. code_warntype(f, (Dict{Float64,Int},)) shows that now we can only determine that k and v are both of type Union{K,V}. For the benchmark:
d =Dict([rand() =>rand(Int) for i =1:10000000]);
@timef(d)
As a short term solution you could add an indexed_next thing for pairs, as well as the corresponding hack in inference.jl.
I have some ideas on how to solve this more generally (this is the same problem as the getindex(::Fact,::Symbol) non leaf return types for matrix factorizations) but it's not gonna happen soon :-)
It occurs to me that, in the heterogeneous key/value type case, #12327/#12261 causes us to lose type information. Consider basically any code that uses the
for (k, v) in dict
idiom, e.g.:Now consider what happens if the key and value types aren't the same. Previously, because we do fancy things for tuple destructuring, we could infer that
k
is of the key type K andv
is of the value type V. But we don't do these fancy things for Pair destructuring.code_warntype(f, (Dict{Float64,Int},))
shows that now we can only determine thatk
andv
are both of typeUnion{K,V}
. For the benchmark:On 6c34bc7 I get:
On the 0.3 branch I get:
The text was updated successfully, but these errors were encountered: