Skip to content

Commit

Permalink
Compiler: fix tmerge(Const(s), Const(t)) st. (s !== t) && (s == t)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsajko committed Jan 5, 2025
1 parent 638dacc commit 1cf277d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
5 changes: 1 addition & 4 deletions Compiler/src/typelimits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ end
@nospecializeinfer function tmerge_partial_struct(𝕃::PartialsLattice, @nospecialize(typea), @nospecialize(typeb))
aty = widenconst(typea)
bty = widenconst(typeb)
if aty === bty
if aty === bty && !isType(aty)
if typea isa PartialStruct
if typeb isa PartialStruct
nflds = min(length(typea.fields), length(typeb.fields))
Expand All @@ -605,9 +605,6 @@ end
for i = 1:nflds
ai = getfield_tfunc(𝕃, typea, Const(i))
bi = getfield_tfunc(𝕃, typeb, Const(i))
# N.B.: We're assuming here that !isType(aty), because that case
# only arises when typea === typeb, which should have been caught
# before calling this.
ft = fieldtype(aty, i)
if is_lattice_equal(𝕃, ai, bi) || is_lattice_equal(𝕃, ai, ft)
# Since ai===bi, the given type has no restrictions on complexity.
Expand Down
1 change: 1 addition & 0 deletions Compiler/test/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2295,6 +2295,7 @@ let 𝕃ᡒ = InferenceLattice(MustAliasesLattice(BaseInferenceLattice.instance)
@test tmerge(MustAlias(2, AliasableField{Any}, 1, Int), Const(nothing)) === Union{Int,Nothing}
@test tmerge(Const(nothing), MustAlias(2, AliasableField{Any}, 1, Any)) === Any
@test tmerge(Const(nothing), MustAlias(2, AliasableField{Any}, 1, Int)) === Union{Int,Nothing}
tmerge(Const(AbstractVector{<:Any}), Const(AbstractVector{T} where {T})) # issue #56913
@test isa_tfunc(MustAlias(2, AliasableField{Any}, 1, Bool), Const(Bool)) === Const(true)
@test isa_tfunc(MustAlias(2, AliasableField{Any}, 1, Bool), Type{Bool}) === Const(true)
@test isa_tfunc(MustAlias(2, AliasableField{Any}, 1, Int), Type{Bool}) === Const(false)
Expand Down

0 comments on commit 1cf277d

Please sign in to comment.