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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -785,11 +785,13 @@ function typeinf_edge(interp::AbstractInterpreter, method::Method, @nospecialize
rettype = code.rettype
if isdefined(code, :rettype_const)
rettype_const = code.rettype_const
# the second subtyping conditions are necessary to distinguish usual cases
# from rare cases when `Const` wrapped those extended lattice type objects
if isa(rettype_const, Vector{Any}) && !(Vector{Any} <: rettype)
return PartialStruct(rettype, rettype_const), mi
elseif rettype <: Core.OpaqueClosure && isa(rettype_const, PartialOpaque)
elseif isa(rettype_const, PartialOpaque) && rettype <: Core.OpaqueClosure
return rettype_const, mi
elseif isa(rettype_const, InterConditional)
elseif isa(rettype_const, InterConditional) && !(InterConditional <: rettype)
return rettype_const, mi
else
return Const(rettype_const), mi
Expand Down
12 changes: 12 additions & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1819,6 +1819,18 @@ end
Meta.isexpr(x, :call) && return x # x::Expr
return nothing
end == Any[Union{Nothing,Expr}]

# handle the edge case
let ts = @eval Module() begin
edgecase(_) = $(Core.Compiler.InterConditional(2, Int, Any))
# create cache
Base.return_types(edgecase, (Any,))
Base.return_types((Any,)) do x
edgecase(x) ? x : nothing # ::Any
end
end
@test ts == Any[Any]
end
end

@testset "branching on conditional object" begin
Expand Down