Skip to content

Commit

Permalink
fix JuliaLang#40814, improve type stability of _totuple (JuliaLang#…
Browse files Browse the repository at this point in the history
…41074)

Replaces JuliaLang#40987, as suggested by JuliaLang#40814.
  • Loading branch information
aviatesk authored and Amit Shirodkar committed Jun 9, 2021
1 parent 76e6c62 commit 8a9a4fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion base/tuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,11 @@ function _totuple(T, itr, s...)
@_inline_meta
y = iterate(itr, s...)
y === nothing && _totuple_err(T)
return (convert(fieldtype(T, 1), y[1]), _totuple(tuple_type_tail(T), itr, y[2])...)
t1 = convert(fieldtype(T, 1), y[1])
# inference may give up in recursive calls, so annotate here to force accurate return type to be propagated
rT = tuple_type_tail(T)
ts = _totuple(rT, itr, y[2])::rT
return (t1, ts...)
end

# use iterative algorithm for long tuples
Expand Down
3 changes: 3 additions & 0 deletions test/tuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -631,3 +631,6 @@ f38837(xs) = map((F,x)->F(x), (Float32, Float64), xs)
@test_throws BoundsError (1, 2)[0:2]
@test_throws ArgumentError (1, 2)[OffsetArrays.IdOffsetRange(1:2, -1)]
end

# https://github.com/JuliaLang/julia/issues/40814
@test Base.return_types(NTuple{3,Int}, (Vector{Int},)) == Any[NTuple{3,Int}]

0 comments on commit 8a9a4fc

Please sign in to comment.