From 1cf277d9590d6a341e5f3b3e833e78c591c3e6ad Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Sat, 28 Dec 2024 17:39:17 +0100 Subject: [PATCH 1/2] Compiler: fix `tmerge(Const(s), Const(t))` st. `(s !== t) && (s == t)` Updates #56913 --- Compiler/src/typelimits.jl | 5 +---- Compiler/test/inference.jl | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Compiler/src/typelimits.jl b/Compiler/src/typelimits.jl index e420db030715b..11245fbaee9b0 100644 --- a/Compiler/src/typelimits.jl +++ b/Compiler/src/typelimits.jl @@ -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)) @@ -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. diff --git a/Compiler/test/inference.jl b/Compiler/test/inference.jl index 9301a2809daf3..7774de54e03d0 100644 --- a/Compiler/test/inference.jl +++ b/Compiler/test/inference.jl @@ -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) From f27a56b4df78ec74fdb37be3da6a18110cd70452 Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Sun, 5 Jan 2025 01:00:32 +0100 Subject: [PATCH 2/2] add higher-level test --- Compiler/test/inference.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Compiler/test/inference.jl b/Compiler/test/inference.jl index 7774de54e03d0..21d29c376bb27 100644 --- a/Compiler/test/inference.jl +++ b/Compiler/test/inference.jl @@ -2303,6 +2303,12 @@ let ๐•ƒแตข = InferenceLattice(MustAliasesLattice(BaseInferenceLattice.instance) @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