julia
julia copied to clipboard
improve inference in `afoldl`
This improves the type inference of the temporary variable y
.
MWE, on master
julia> struct A end
julia> struct B end
julia> struct C end
julia> Base.:(+)(::A, ::B) = C()
julia> @code_warntype Base.afoldl(+, A(), B())
MethodInstance for Base.afoldl(::typeof(+), ::A, ::B)
from afoldl(op, a, bs...) @ Base operators.jl:531
Arguments
#self#::Core.Const(Base.afoldl)
op::Core.Const(+)
a::Core.Const(A())
bs::Core.Const((B(),))
Locals
@_5::Union{}
y::Union{A, C}
i@_7::Int64
l::Int64
i@_9::Union{}
Body::C
[...]
PR
julia> @code_warntype Base.afoldl(+, A(), B())
MethodInstance for Base.afoldl(::typeof(+), ::A, ::B)
from afoldl(op, a, bs...) @ Base operators.jl:531
Arguments
#self#::Core.Const(Base.afoldl)
op::Core.Const(+)
a::Core.Const(A())
bs::Core.Const((B(),))
Locals
@_5::Union{}
y::C
i@_7::Int64
l::Int64
i@_9::Union{}
Body::C
[...]
But @code_typed
gives the same result with/without this PR?
So I'm assuming there's no performance difference.
(Our compiler should be good enough to track this kind of local instability.)
Yeah, it's only because return type information or the Locals
information show result that is "squashed" to represent inference on a single frame, while our compiler actually sees types per-statement. So this change won't make performance difference.
I see. In that case, I'll close this. If I see some real-world difference in the future, I'll open a separate issue.