Skip to content

Commit

Permalink
For singleton types make Const(T.instance) and T equivalent as lattic…
Browse files Browse the repository at this point in the history
…e elements (#27296)

Both inference and the optimizer will readily change the latter to the former
in a number of places and it is important for the type lattice to consider
them equivalent in order for that operation to be not cause potential assertion
errors.
  • Loading branch information
Keno authored and JeffBezanson committed May 29, 2018
1 parent 71b5e83 commit 993c551
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions base/compiler/typelattice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ function ⊑(@nospecialize(a), @nospecialize(b))
end
return isa(a.val, widenconst(b))
elseif isa(b, Const)
if isa(a, DataType) && isdefined(a, :instance)
return a.instance === b.val
end
return a === Bottom
elseif !(isa(a, Type) || isa(a, TypeVar)) ||
!(isa(b, Type) || isa(b, TypeVar))
Expand Down
3 changes: 3 additions & 0 deletions test/compiler/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1580,3 +1580,6 @@ function _g_ifelse_isa_()
ifelse(isa(x, Nothing), 1, x)
end
@test Base.return_types(_g_ifelse_isa_, ()) == [Int]

# Equivalence of Const(T.instance) and T for singleton types
@test Const(nothing) Nothing && Nothing Const(nothing)

0 comments on commit 993c551

Please sign in to comment.