diff --git a/base/inference.jl b/base/inference.jl index b70485c24339f..713c7b1b810c8 100644 --- a/base/inference.jl +++ b/base/inference.jl @@ -2798,21 +2798,13 @@ function tmerge(@nospecialize(typea), @nospecialize(typeb)) if !(isa(typea,Type) || isa(typea,TypeVar)) || !(isa(typeb,Type) || isa(typeb,TypeVar)) return Any end - if (typea <: Tuple) && (typeb <: Tuple) - if isa(typea, DataType) && isa(typeb, DataType) && length(typea.parameters) == length(typeb.parameters) && !isvatuple(typea) && !isvatuple(typeb) - return typejoin(typea, typeb) - end - if isa(typea, Union) || isa(typeb, Union) || (isa(typea,DataType) && length(typea.parameters)>3) || - (isa(typeb,DataType) && length(typeb.parameters)>3) - # widen tuples faster (see #6704), but not too much, to make sure we can infer - # e.g. (t::Union{Tuple{Bool},Tuple{Bool,Int}})[1] - return Tuple - end - end u = Union{typea, typeb} - if unionlen(u) > MAX_TYPEUNION_LEN || type_too_complex(u, MAX_TYPE_DEPTH) - # don't let type unions get too big - # TODO: something smarter, like a common supertype + if unionlen(u) > MAX_TYPEUNION_LEN + u = typejoin(typea, typeb) + end + if type_too_complex(u, MAX_TYPE_DEPTH) + # helps convergence speed (large types that are changing value become very slow to + # work with very quickly) return Any end return u diff --git a/test/inference.jl b/test/inference.jl index c04c6b8c6dcda..aa43d03da8e2f 100644 --- a/test/inference.jl +++ b/test/inference.jl @@ -1291,3 +1291,8 @@ let T1 = Array{Float64}, T2 = Array{_1,2} where _1 rt = Base.return_types(g, (Union{Ref{Array{Float64}}, Ref{Array{Float32}}},))[1] @test rt >: Union{Type{Array{Float64}}, Type{Array{Float32}}} end + +f_23077(x) = (Int8(0), Int16(0), Int32(0), Int64(0))[x] +@test Base.return_types(f_23077, Tuple{Int})[1] <: Signed +g_23077(x,y,z) = x ? y ? z ? (1,) : (1,1.0) : (1,1) : (1,1.0,1) +@test Base.return_types(g_23077, Tuple{Bool,Bool,Bool})[1] <: Tuple{Int,Vararg{Real}}