Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
aviatesk opened this issue Sep 2, 2021 · 1 comment
Closed
Labels
compiler:inference Type inference good first issue Indicates a good issue for first-time contributors to Julia

Comments

@aviatesk
Copy link
Member

aviatesk commented Sep 2, 2021

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 ?

@aviatesk aviatesk added good first issue Indicates a good issue for first-time contributors to Julia compiler:inference Type inference labels Sep 2, 2021
@vtjnash
Copy link
Member

vtjnash commented Sep 2, 2021

I would prefer the simpler solution. There is typically no value in forwarding Conditional too far (widenreturn often strips it too).

aviatesk added a commit that referenced this issue Sep 2, 2021
KristofferC pushed a commit that referenced this issue Sep 3, 2021
KristofferC pushed a commit that referenced this issue Sep 3, 2021
KristofferC pushed a commit that referenced this issue Sep 6, 2021
KristofferC pushed a commit that referenced this issue Sep 8, 2021
LilithHafner pushed a commit to LilithHafner/julia that referenced this issue Feb 22, 2022
LilithHafner pushed a commit to LilithHafner/julia that referenced this issue Mar 8, 2022
staticfloat pushed a commit that referenced this issue Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:inference Type inference good first issue Indicates a good issue for first-time contributors to Julia
Projects
None yet
Development

No branches or pull requests

2 participants