Skip to content

Commit 1a8feb3

Browse files
nsajkoKristofferC
authored andcommitted
Compiler: fix tmerge(Const(s), Const(t)) st. (s !== t) && (s == t) (#56915)
Updates #56913 (cherry picked from commit 9a20417)
1 parent d331cea commit 1a8feb3

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

base/compiler/typelimits.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ end
575575
@nospecializeinfer function tmerge_partial_struct(lattice::PartialsLattice, @nospecialize(typea), @nospecialize(typeb))
576576
aty = widenconst(typea)
577577
bty = widenconst(typeb)
578-
if aty === bty
578+
if aty === bty && !isType(aty)
579579
# must have egal here, since we do not create PartialStruct for non-concrete types
580580
typea_nfields = nfields_tfunc(lattice, typea)
581581
typeb_nfields = nfields_tfunc(lattice, typeb)
@@ -589,9 +589,6 @@ end
589589
for i = 1:type_nfields
590590
ai = getfield_tfunc(lattice, typea, Const(i))
591591
bi = getfield_tfunc(lattice, typeb, Const(i))
592-
# N.B.: We're assuming here that !isType(aty), because that case
593-
# only arises when typea === typeb, which should have been caught
594-
# before calling this.
595592
ft = fieldtype(aty, i)
596593
if is_lattice_equal(lattice, ai, bi) || is_lattice_equal(lattice, ai, ft)
597594
# Since ai===bi, the given type has no restrictions on complexity.

test/compiler/inference.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,13 +2305,20 @@ let 𝕃ᵢ = InferenceLattice(MustAliasesLattice(BaseInferenceLattice.instance)
23052305
@test tmerge(MustAlias(2, AliasableField{Any}, 1, Int), Const(nothing)) === Union{Int,Nothing}
23062306
@test tmerge(Const(nothing), MustAlias(2, AliasableField{Any}, 1, Any)) === Any
23072307
@test tmerge(Const(nothing), MustAlias(2, AliasableField{Any}, 1, Int)) === Union{Int,Nothing}
2308+
tmerge(Const(AbstractVector{<:Any}), Const(AbstractVector{T} where {T})) # issue #56913
23082309
@test isa_tfunc(MustAlias(2, AliasableField{Any}, 1, Bool), Const(Bool)) === Const(true)
23092310
@test isa_tfunc(MustAlias(2, AliasableField{Any}, 1, Bool), Type{Bool}) === Const(true)
23102311
@test isa_tfunc(MustAlias(2, AliasableField{Any}, 1, Int), Type{Bool}) === Const(false)
23112312
@test ifelse_tfunc(MustAlias(2, AliasableField{Any}, 1, Bool), Int, Int) === Int
23122313
@test ifelse_tfunc(MustAlias(2, AliasableField{Any}, 1, Int), Int, Int) === Union{}
23132314
end
23142315

2316+
@testset "issue #56913: `BoundsError` in type inference" begin
2317+
R = UnitRange{Int}
2318+
@test Type{AbstractVector} == Base.infer_return_type(Base.promote_typeof, Tuple{R, R, Vector{Any}, Vararg{R}})
2319+
@test Type{AbstractVector} == Base.infer_return_type(Base.promote_typeof, Tuple{R, R, Vector{Any}, R, Vararg{R}})
2320+
end
2321+
23152322
maybeget_mustalias_tmerge(x::AliasableField) = x.f
23162323
maybeget_mustalias_tmerge(x) = x
23172324
@test Base.return_types((Union{Nothing,AliasableField{Any}},); interp=MustAliasInterpreter()) do x

0 commit comments

Comments
 (0)