I’ve got this function which widens each of the arguments of a Tuple
type
widen_tupleargs(::Type{T}) where {T<:Tuple} = Tuple{map(widen,T.parameters)...}
e.g.
julia> widen_tupleargs(Tuple{Int16,Float16})
Tuple{Int32,Float32}
However, its not type-stable,
julia> @code_warntype widen_tupleargs(Tuple{Int16,Float16})
Variables:
#self# <optimized out>
#unused# <optimized out>
Body:
begin
return (Core._apply)(Core.apply_type, (Core.tuple)(Main.Tuple)::Tuple{DataType}, $(Expr(:invoke, MethodInstance for map(::Base.#widen, ::SimpleVector), :(Main.map), :(Main.widen), :((Core.getfield)($(Expr(:static_parameter, 1)), :parameters)::SimpleVector))))::Any
end::Any
Is there any way to write this so that it is type stable? I’d be curious on either 0.6 or 0.7 (above output was 0.6). Thanks for any help!