Skip to content

Commit

Permalink
fix #38837, inference regression in tuple map (#38887)
Browse files Browse the repository at this point in the history
(cherry picked from commit c28611f)
  • Loading branch information
JeffBezanson authored and staticfloat committed Dec 22, 2022
1 parent 532210f commit 0ad3a4d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 5 additions & 5 deletions base/tuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ end

# 1 argument function
map(f, t::Tuple{}) = ()
map(f, t::Tuple{Any,}) = (f(t[1]),)
map(f, t::Tuple{Any, Any}) = (f(t[1]), f(t[2]))
map(f, t::Tuple{Any, Any, Any}) = (f(t[1]), f(t[2]), f(t[3]))
map(f, t::Tuple{Any,}) = (@_inline_meta; (f(t[1]),))
map(f, t::Tuple{Any, Any}) = (@_inline_meta; (f(t[1]), f(t[2])))
map(f, t::Tuple{Any, Any, Any}) = (@_inline_meta; (f(t[1]), f(t[2]), f(t[3])))
map(f, t::Tuple) = (@_inline_meta; (f(t[1]), map(f,tail(t))...))
# stop inlining after some number of arguments to avoid code blowup
const Any16{N} = Tuple{Any,Any,Any,Any,Any,Any,Any,Any,
Expand All @@ -229,8 +229,8 @@ function map(f, t::Any16)
end
# 2 argument function
map(f, t::Tuple{}, s::Tuple{}) = ()
map(f, t::Tuple{Any,}, s::Tuple{Any,}) = (f(t[1],s[1]),)
map(f, t::Tuple{Any,Any}, s::Tuple{Any,Any}) = (f(t[1],s[1]), f(t[2],s[2]))
map(f, t::Tuple{Any,}, s::Tuple{Any,}) = (@_inline_meta; (f(t[1],s[1]),))
map(f, t::Tuple{Any,Any}, s::Tuple{Any,Any}) = (@_inline_meta; (f(t[1],s[1]), f(t[2],s[2])))
function map(f, t::Tuple, s::Tuple)
@_inline_meta
(f(t[1],s[1]), map(f, tail(t), tail(s))...)
Expand Down
4 changes: 4 additions & 0 deletions test/tuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -593,3 +593,7 @@ end
@test r isa Iterators.Rest
@test collect(r) == -[3, 2, 4]
end

# issue #38837
f38837(xs) = map((F,x)->F(x), (Float32, Float64), xs)
@test @inferred(f38837((1,2))) === (1.0f0, 2.0)

0 comments on commit 0ad3a4d

Please sign in to comment.