Suboptimal inference for incompletely specified named tuples #29970
Closed
Description
opened on Nov 9, 2018
jullia> f(x) = NamedTuple{(:x,)}((x,))
julia> code_typed(f, Tuple{Any})
1-element Array{Any,1}:
CodeInfo(
1 1 ─ %1 = (Core.tuple)(x)::Tuple{Any} │
│ %2 = (NamedTuple{(:x,),T} where T<:Tuple)(%1)::Any │
└── return %2 │
) => Any
julia> code_typed(f, Tuple{Union{Int64, Float64}})
1-element Array{Any,1}:
CodeInfo(
1 1 ─ %1 = (Core.tuple)(x)::Tuple{Union{Float64, Int64}} │
│ %2 = (NamedTuple{(:x,),T} where T<:Tuple)(%1)::Any │
└── return %2 │
) => Any
It would be nice if these could at least figure out that it's gonna be a NamedTuple{(:x,), <:Any}
, or even if the second one distributed over the union.
Activity