Skip to content

better upper bounds in apply_type_tfunc for NamedTuple #32699

Closed
@quinnj

Description

Here's an example where the resulting NamedTuple{names, _A) where _A type is not ideal since it completely discards valid information up to that point.

8 ── %21 = Base.getfield(%14, :id)::Array{Int64,1}%22 = Base.arrayref(true, %21, %15)::Int64%23 = Base.getfield(%16, :salary)::Array{Union{Missing, Float64},1}%24 = Base.arrayref(true, %23, %17)::Union{Missing, Float64}%25 = (isa)(%24, Missing)::Bool
└───       goto #10 if not %25
9 ──       goto #13
10%28 = (isa)(%24, Float64)::Bool
└───       goto #12 if not %28
11%30 = π (%24, Float64)
│    %31 = Base.sitofp(Float64, 2)::Float64%32 = Base.mul_float(%30, %31)::Float64
└───       goto #13
12 ─       Core.throw(ErrorException("fatal error in type inference (type bound)"))::Union{}
└───       $(Expr(:unreachable))::Union{}
13%36 = φ (#9 => $(QuoteNode(missing)), #11 => %32)::Union{Missing, Float64}%37 = Core.tuple(%22, %36)::Tuple{Int64,Union{Missing, Float64}}%38 = (NamedTuple{(:id, :y),T} where T<:Tuple)(%37)::NamedTuple{(:id, :y),_A} where _A

@JeffBezanson thought it should be valid/fine to include an upper bound here, so that we end up with NamedTuple{(:id, :y), _A} where _A <: Tuple{Int64, Union{Missing, Float64}

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions