Skip to content

inference: need to invalidate stale Conditional wrapped in PartialStruct #42090

Closed
@aviatesk

Description

@aviatesk

MRE:

# should invalidate old constraint wrapped in PartialStruct when the subject of condition has changed
let M = Module()
    @eval M begin
        struct BePartialStruct
            val::Int
            cond
        end
    end

    rt = @eval M begin
        Base.return_types((Union{Nothing,Int},)) do a
            cond = a === nothing
            obj = $(Expr(:new, M.BePartialStruct, 42, :cond))
            r1 = getfield(obj, :cond) ? 0 : a # r1::Int
            a = $(gensym(:anyvar))::Any
            r2 = getfield(obj, :cond) ? a : nothing # r2::Any, not r2::Const(nothing)
            return r1, r2 # ::Tuple{Int,Any}
        end |> only
    end
    @test rt == Tuple{Int,Any}
end

I encountered Conditional wrapped in PartialStruct when the Conditional is captured in a closure.

Solutions:

  • (dirty, but more accurate) we can add another special case as like LimitedAccuracy:
    newtypetyp = ignorelimited(newtype.typ)
  • (simple, but less accurate) disallow PartialStruct to wrap Conditional

Which one do we want ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    compiler:inferenceType inferencegood first issueIndicates a good issue for first-time contributors to Julia

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions