Should passing Val(dims) to cat be better documented?

Do we need to document it at all now that Julia v1.10+ does the constant propagation as one would prefur?

julia> f(x, y) = cat(x, y; dims = 2)
f (generic function with 1 method)

julia> @code_warntype f([5],[2])
MethodInstance for f(::Vector{Int64}, ::Vector{Int64})
  from f(x, y) @ Main REPL[1]:1
Arguments
  #self#::Core.Const(f)
  x::Vector{Int64}
  y::Vector{Int64}
Body::Matrix{Int64}
1 ─ %1 = (:dims,)::Core.Const((:dims,))
│   %2 = Core.apply_type(Core.NamedTuple, %1)::Core.Const(NamedTuple{(:dims,)})
│   %3 = Core.tuple(2)::Core.Const((2,))
│   %4 = (%2)(%3)::Core.Const((dims = 2,))
│   %5 = Core.kwcall(%4, Main.cat, x, y)::Matrix{Int64}
└──      return %5

I see Val as an ugly band-aid of Julia’s past. Now that the compiler is much better about constant propagation it’s largely not needed.

3 Likes