Would documenting the reason for passing Val(dims)
to to the dims
keyword of cat
lead to more purrfect documentation than what we have meow?
Currently the documentation for cat
indicates that one can pass a Val
to dims, but it does not explain why.
An experienced Julia user might know this is due to type stability. Should the documentation include a note about that or is this obvious?
julia> @code_warntype cat([5], [2], dims = 2)
MethodInstance for Core.kwcall(::NamedTuple{(:dims,), Tuple{Int64}}, ::typeof(cat), ::Vector{Int64}, ::Vector{Int64})
from kwcall(::Any, ::typeof(cat), A...) @ Base abstractarray.jl:1981
Arguments
_::Core.Const(Core.kwcall)
@_2::NamedTuple{(:dims,), Tuple{Int64}}
@_3::Core.Const(cat) A::Tuple{Vector{Int64}, Vector{Int64}}
Locals
@_5::Int64
dims::Int64
Body::Any 1 β nothing
β Core.NewvarNode(:(@_5))
β %3 = Core.isdefined(@_2, :dims)::Core.Const(true)
βββ goto #3 if not %3
2 β (@_5 = Core.getfield(@_2, :dims))
βββ goto #4
3 β Core.Const(:(Core.UndefKeywordError(:dims)))
βββ Core.Const(:(@_5 = Core.throw(%7)))
4 β %9 = @_5::Int64
β (dims = %9)
β %11 = (:dims,)::Core.Const((:dims,))
β %12 = Core.apply_type(Core.NamedTuple, %11)::Core.Const(NamedTuple{(:dims,)})
β %13 = Base.structdiff(@_2, %12)::Core.Const(NamedTuple())
β %14 = Base.pairs(%13)::Core.Const(Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}())
β %15 = Base.isempty(%14)::Core.Const(true)
βββ goto #6 if not %15
5 β goto #7
6 β Core.Const(:(Core.tuple(@_2, @_3)))
βββ Core.Const(:(Core._apply_iterate(Base.iterate, Base.kwerr, %18, A)))
7 β %20 = Base.:(var"#cat#153")::Core.Const(Base.var"#cat#153")
β %21 = Core.tuple(dims, @_3)::Tuple{Int64, typeof(cat)}
β %22 = Core._apply_iterate(Base.iterate, %20, %21, A)::Any
βββ return %22
julia> @code_warntype cat([5], [2], dims = Val(2))
MethodInstance for Core.kwcall(::NamedTuple{(:dims,), Tuple{Val{2}}}, ::typeof(cat), ::Vector{Int64}, ::Vector{Int64})
from kwcall(::Any, ::typeof(cat), A...) @ Base abstractarray.jl:1981
Arguments _::Core.Const(Core.kwcall) @_2::Core.Const((dims = Val{2}(),)) @_3::Core.Const(cat) A::Tuple{Vector{Int64}, Vector{Int64}} Locals
@_5::Val{2}
dims::Val{2}
Body::Matrix{Int64}
1 β nothing
β Core.NewvarNode(:(@_5))
β %3 = Core.isdefined(@_2, :dims)::Core.Const(true)
βββ goto #3 if not %3 2 β (@_5 = Core.getfield(@_2, :dims))
βββ goto #4 3 β Core.Const(:(Core.UndefKeywordError(:dims)))
βββ Core.Const(:(@_5 = Core.throw(%7)))
4 β %9 = @_5::Core.Const(Val{2}())
β (dims = %9)
β %11 = (:dims,)::Core.Const((:dims,))
β %12 = Core.apply_type(Core.NamedTuple, %11)::Core.Const(NamedTuple{(:dims,)})
β %13 = Base.structdiff(@_2, %12)::Core.Const(NamedTuple()) β %14 = Base.pairs(%13)::Core.Const(Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}())
β %15 = Base.isempty(%14)::Core.Const(true)
βββ goto #6 if not %15
5 β goto #7
6 β Core.Const(:(Core.tuple(@_2, @_3)))
βββ Core.Const(:(Core._apply_iterate(Base.iterate, Base.kwerr, %18, A)))
7 β %20 = Base.:(var"#cat#153")::Core.Const(Base.var"#cat#153")
β %21 = Core.tuple(dims, @_3)::Core.Const((Val{2}(), cat))
β %22 = Core._apply_iterate(Base.iterate, %20, %21, A)::Matrix{Int64}
βββ return %22