Skip to content
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
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
7 changes: 7 additions & 0 deletions Compiler/test/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2295,13 +2295,20 @@ 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)
@test ifelse_tfunc(MustAlias(2, AliasableField{Any}, 1, Bool), Int, Int) === Int
@test ifelse_tfunc(MustAlias(2, AliasableField{Any}, 1, Int), Int, Int) === Union{}
end

@testset "issue #56913: `BoundsError` in type inference" begin
R = UnitRange{Int}
@test Type{AbstractVector} == Base.infer_return_type(Base.promote_typeof, Tuple{R, R, Vector{Any}, Vararg{R}})
@test Type{AbstractVector} == Base.infer_return_type(Base.promote_typeof, Tuple{R, R, Vector{Any}, R, Vararg{R}})
end

maybeget_mustalias_tmerge(x::AliasableField) = x.f
maybeget_mustalias_tmerge(x) = x
@test Base.return_types((Union{Nothing,AliasableField{Any}},); interp=MustAliasInterpreter()) do x
Expand Down
Loading