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: correctly handle rare cases when Const wraps extended lattice objects #42434

Merged
merged 1 commit into from
Oct 1, 2021

Conversation

aviatesk
Copy link
Member

Otherwise, in rare cases, we may see this sort of weird behavior:

julia> @eval edgecase(_) = $(Core.Compiler.InterConditional(2, Int, Any))
edgecase (generic function with 1 method)

julia> code_typed((Any,)) do x
           edgecase(x) ? x : nothing
       end
1-element Vector{Any}:
 CodeInfo(
1 ─     goto #3 if not $(QuoteNode(Core.InterConditional(2, Int64, Any)))
2return x
3return Main.nothing
) => Any

julia> code_typed((Any,)) do x
           edgecase(x) ? x : nothing
       end
1-element Vector{Any}:
 CodeInfo(
1 ─      goto #3 if not $(QuoteNode(Core.InterConditional(2, Int64, Any)))
2%2 = π (x, Int64)
└──      return %2
3return Main.nothing
) => Union{Nothing, Int64}

…ttice objects

Otherwise, in rare cases, we may see this sort of weird behavior:
```julia
julia> @eval edgecase(_) = $(Core.Compiler.InterConditional(2, Int, Any))
edgecase (generic function with 1 method)

julia> code_typed((Any,)) do x
           edgecase(x) ? x : nothing
       end
1-element Vector{Any}:
 CodeInfo(
1 ─     goto #3 if not $(QuoteNode(Core.InterConditional(2, Int64, Any)))
2 ─     return x
3 ─     return Main.nothing
) => Any

julia> code_typed((Any,)) do x
           edgecase(x) ? x : nothing
       end
1-element Vector{Any}:
 CodeInfo(
1 ─      goto #3 if not $(QuoteNode(Core.InterConditional(2, Int64, Any)))
2 ─ %2 = π (x, Int64)
└──      return %2
3 ─      return Main.nothing
) => Union{Nothing, Int64}
```
@aviatesk
Copy link
Member Author

@vtjnash I also found we actually never pass Const into the global cache:

if isa(result_type, Const)
rettype_const = result_type.val
const_flags = 0x2

So I wonder there is actually no external consumer of those extended lattice objects, and we can just move them to Core.Compiler (except PartialOpaque, which is observed in C) ?

@aviatesk aviatesk added the compiler:inference Type inference label Sep 30, 2021
@aviatesk aviatesk requested a review from vtjnash September 30, 2021 12:42
@vtjnash
Copy link
Member

vtjnash commented Sep 30, 2021

Const (and other extended lattice types) get passed in as the sub-lattice fields of other lattice types

@vtjnash
Copy link
Member

vtjnash commented Sep 30, 2021

Though I would note that the commit/issue title is misleading, as only InterConditional had this issue, whereas we already previously handled it for the other extended lattice types

@aviatesk
Copy link
Member Author

Const (and other extended lattice types) get passed in as the sub-lattice fields of other lattice types

Do you mean cases like PartialStruct(T, Any[Const(42), ...]) and InterConditional(n, Const(42), PartialStruct(...)) ?
I'm still not sure if there is any external consumer that wants to use jl_const_type etc. for such cases.

@aviatesk aviatesk merged commit d2289e6 into master Oct 1, 2021
@aviatesk aviatesk deleted the avi/infedgecase branch October 1, 2021 04:57
aviatesk added a commit to JuliaDebug/Cthulhu.jl that referenced this pull request Oct 6, 2021
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Feb 22, 2022
…tional` (JuliaLang#42434)

Otherwise, in rare cases, we may see this sort of weird behavior:
```julia
julia> @eval edgecase(_) = $(Core.Compiler.InterConditional(2, Int, Any))
edgecase (generic function with 1 method)

julia> code_typed((Any,)) do x
           edgecase(x) ? x : nothing
       end
1-element Vector{Any}:
 CodeInfo(
1 ─     goto #3 if not $(QuoteNode(Core.InterConditional(2, Int64, Any)))
2 ─     return x
3 ─     return Main.nothing
) => Any

julia> code_typed((Any,)) do x
           edgecase(x) ? x : nothing
       end
1-element Vector{Any}:
 CodeInfo(
1 ─      goto #3 if not $(QuoteNode(Core.InterConditional(2, Int64, Any)))
2 ─ %2 = π (x, Int64)
└──      return %2
3 ─      return Main.nothing
) => Union{Nothing, Int64}
```
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Mar 8, 2022
…tional` (JuliaLang#42434)

Otherwise, in rare cases, we may see this sort of weird behavior:
```julia
julia> @eval edgecase(_) = $(Core.Compiler.InterConditional(2, Int, Any))
edgecase (generic function with 1 method)

julia> code_typed((Any,)) do x
           edgecase(x) ? x : nothing
       end
1-element Vector{Any}:
 CodeInfo(
1 ─     goto #3 if not $(QuoteNode(Core.InterConditional(2, Int64, Any)))
2 ─     return x
3 ─     return Main.nothing
) => Any

julia> code_typed((Any,)) do x
           edgecase(x) ? x : nothing
       end
1-element Vector{Any}:
 CodeInfo(
1 ─      goto #3 if not $(QuoteNode(Core.InterConditional(2, Int64, Any)))
2 ─ %2 = π (x, Int64)
└──      return %2
3 ─      return Main.nothing
) => Union{Nothing, Int64}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:inference Type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants