Skip to content

Commit c28611f

Browse files
authored
fix #38837, inference regression in tuple map (#38887)
1 parent bd0ddf3 commit c28611f

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

base/tuple.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ end
210210

211211
# 1 argument function
212212
map(f, t::Tuple{}) = ()
213-
map(f, t::Tuple{Any,}) = (f(t[1]),)
214-
map(f, t::Tuple{Any, Any}) = (f(t[1]), f(t[2]))
215-
map(f, t::Tuple{Any, Any, Any}) = (f(t[1]), f(t[2]), f(t[3]))
213+
map(f, t::Tuple{Any,}) = (@_inline_meta; (f(t[1]),))
214+
map(f, t::Tuple{Any, Any}) = (@_inline_meta; (f(t[1]), f(t[2])))
215+
map(f, t::Tuple{Any, Any, Any}) = (@_inline_meta; (f(t[1]), f(t[2]), f(t[3])))
216216
map(f, t::Tuple) = (@_inline_meta; (f(t[1]), map(f,tail(t))...))
217217
# stop inlining after some number of arguments to avoid code blowup
218218
const Any16{N} = Tuple{Any,Any,Any,Any,Any,Any,Any,Any,
@@ -229,8 +229,8 @@ function map(f, t::Any16)
229229
end
230230
# 2 argument function
231231
map(f, t::Tuple{}, s::Tuple{}) = ()
232-
map(f, t::Tuple{Any,}, s::Tuple{Any,}) = (f(t[1],s[1]),)
233-
map(f, t::Tuple{Any,Any}, s::Tuple{Any,Any}) = (f(t[1],s[1]), f(t[2],s[2]))
232+
map(f, t::Tuple{Any,}, s::Tuple{Any,}) = (@_inline_meta; (f(t[1],s[1]),))
233+
map(f, t::Tuple{Any,Any}, s::Tuple{Any,Any}) = (@_inline_meta; (f(t[1],s[1]), f(t[2],s[2])))
234234
function map(f, t::Tuple, s::Tuple)
235235
@_inline_meta
236236
(f(t[1],s[1]), map(f, tail(t), tail(s))...)

test/tuple.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,3 +594,7 @@ end
594594
@test r isa Iterators.Rest
595595
@test collect(r) == -[3, 2, 4]
596596
end
597+
598+
# issue #38837
599+
f38837(xs) = map((F,x)->F(x), (Float32, Float64), xs)
600+
@test @inferred(f38837((1,2))) === (1.0f0, 2.0)

0 commit comments

Comments
 (0)