Skip to content

Commit 15b7c6b

Browse files
authored
Allow effect inference of eltype(::Tuple) (#48322)
By bumping max_methods for `eltype` slightly to cover all four Tuple methods.
1 parent 688f5cf commit 15b7c6b

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

base/tuple.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,21 @@ function _compute_eltype(@nospecialize t)
234234
end
235235
end
236236

237+
# We'd like to be able to infer eltype(::Tuple), which needs to be able to
238+
# look at these four methods:
239+
#
240+
# julia> methods(Base.eltype, Tuple{Type{<:Tuple}})
241+
# 4 methods for generic function "eltype" from Base:
242+
# [1] eltype(::Type{Union{}})
243+
# @ abstractarray.jl:234
244+
# [2] eltype(::Type{Tuple{}})
245+
# @ tuple.jl:199
246+
# [3] eltype(t::Type{<:Tuple{Vararg{E}}}) where E
247+
# @ tuple.jl:200
248+
# [4] eltype(t::Type{<:Tuple})
249+
# @ tuple.jl:209
250+
typeof(function eltype end).name.max_methods = UInt8(4)
251+
237252
# version of tail that doesn't throw on empty tuples (used in array indexing)
238253
safe_tail(t::Tuple) = tail(t)
239254
safe_tail(t::Tuple{}) = ()

test/tuple.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,3 +782,4 @@ namedtup = (;a=1, b=2, c=3)
782782

783783
# Make sure that tuple iteration is foldable
784784
@test Core.Compiler.is_foldable(Base.infer_effects(iterate, Tuple{NTuple{4, Float64}, Int}))
785+
@test Core.Compiler.is_foldable(Base.infer_effects(eltype, Tuple{Tuple}))

0 commit comments

Comments
 (0)