Skip to content

Commit 27eee41

Browse files
authored
Revert "Let tmerge form a Union more often (#27843)" (#39406)
This reverts commit 6c1824d. Fixes #39349. The extra inference precision is nice, but seems to carry too much risk of blowup.
1 parent dd1fcf3 commit 27eee41

File tree

2 files changed

+3
-14
lines changed

2 files changed

+3
-14
lines changed

base/compiler/typelimits.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,9 @@ function tmerge(@nospecialize(typea), @nospecialize(typeb))
375375
return Any
376376
end
377377
typea == typeb && return typea
378-
# it's always ok to form a Union of two Union-free types
379-
u = Union{typea, typeb}
380-
if unioncomplexity(u) <= 1
381-
return u
378+
# it's always ok to form a Union of two concrete types
379+
if (isconcretetype(typea) || isType(typea)) && (isconcretetype(typeb) || isType(typeb))
380+
return Union{typea, typeb}
382381
end
383382
# collect the list of types from past tmerge calls returning Union
384383
# and then reduce over that list

test/compiler/inference.jl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,16 +2041,6 @@ let rt = Base.return_types(splat27434, (NamedTuple{(:x,), Tuple{T}} where T,))
20412041
@test !Base.has_free_typevars(rt[1])
20422042
end
20432043

2044-
# PR #27843
2045-
bar27843(x, y::Bool) = fill(x, 0)
2046-
bar27843(x, y) = fill(x, ntuple(_ -> 0, y))::Array{typeof(x)}
2047-
foo27843(x, y) = bar27843(x, y)
2048-
@test Core.Compiler.return_type(foo27843, Tuple{Union{Float64,Int}, Any}) == Union{Array{Float64}, Array{Int}}
2049-
let atypes1 = Tuple{Union{IndexCartesian, IndexLinear}, Any, Union{Tuple{}, Tuple{Any,Vararg{Any,N}} where N}, Tuple},
2050-
atypes2 = Tuple{Union{IndexCartesian, IndexLinear}, Any, Tuple, Tuple}
2051-
@test Core.Compiler.return_type(SubArray, atypes1) <: Core.Compiler.return_type(SubArray, atypes2)
2052-
end
2053-
20542044
# issue #27078
20552045
f27078(T::Type{S}) where {S} = isa(T, UnionAll) ? f27078(T.body) : T
20562046
T27078 = Vector{Vector{T}} where T

0 commit comments

Comments
 (0)