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
const PairUnion = Union{Pair{Int,Int8},Pair{Int,UInt8}}
array = PairUnion[1=>0x2]
functionpair1(a)
x, y = a[1]
x => y
endfunctionpair2(a)
xy = a[1]
x = xy.first
y = xy.second
x => y
endfunctionpair3(a)
xy = a[1]
x =first(xy)
y =last(xy)
x => y
end
When looking at @code_warntype, it looks like x and y are inferred to be Union{Int,Int8,UInt8} for pair1 and pair2, while in pair3 they are inferred as Int and Union{Int8,UInt8} as expected.
The text was updated successfully, but these errors were encountered:
Seems to be something with getproperty, rewriting as
I had suspected as well, and had tried the exact same pair4 function, but without checking the @code_warntype output, which indeed seems to solve the problem. I had only benchmarked it, which gives:
vtjnash
changed the title
pair.first leads to worse inferred code than first(pair)
[feature] inference constant propagation even for union-split methods
Jul 13, 2020
Consider the following example:
Then:
When looking at
@code_warntype
, it looks likex
andy
are inferred to beUnion{Int,Int8,UInt8}
forpair1
andpair2
, while inpair3
they are inferred asInt
andUnion{Int8,UInt8}
as expected.The text was updated successfully, but these errors were encountered: