Skip to content

Commit ce76e08

Browse files
committed
Widen unions less agressively during inference
Use `typejoin` for unions growing too large instead of just returning `Any`.
1 parent 9b397fa commit ce76e08

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

base/inference.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2619,9 +2619,11 @@ function tmerge(@nospecialize(typea), @nospecialize(typeb))
26192619
end
26202620
end
26212621
u = Union{typea, typeb}
2622-
if unionlen(u) > MAX_TYPEUNION_LEN || type_too_complex(u, MAX_TYPE_DEPTH)
2623-
# don't let type unions get too big
2624-
# TODO: something smarter, like a common supertype
2622+
if unionlen(u) > MAX_TYPEUNION_LEN
2623+
u = typejoin(typea, typeb)
2624+
end
2625+
if type_too_complex(u, MAX_TYPE_DEPTH)
2626+
# TODO: is this needed?
26252627
return Any
26262628
end
26272629
return u

test/inference.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,3 +1102,6 @@ let isa_tfunc = Core.Inference.t_ffunc_val[
11021102
@test isa_tfunc(c, Type{Complex{T}} where T) === Const(false)
11031103
end
11041104
end
1105+
1106+
f_ADD_PR_NUMBER(x) = (Int8(0), Int16(0), Int32(0), Int64(0))[x]
1107+
@test Base.return_types(f_ADD_PR_NUMBER, Tuple{Int})[1] <: Signed

0 commit comments

Comments
 (0)