Skip to content

Commit

Permalink
make _zip_isdone type-stable
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholters committed Sep 20, 2018
1 parent 111f7a8 commit 8375946
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions base/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ using .Base:
@inline, Pair, AbstractDict, IndexLinear, IndexCartesian, IndexStyle, AbstractVector, Vector,
tail, tuple_type_head, tuple_type_tail, tuple_type_cons, SizeUnknown, HasLength, HasShape,
IsInfinite, EltypeUnknown, HasEltype, OneTo, @propagate_inbounds, Generator, AbstractRange,
LinearIndices, (:), |, +, -, !==, !, <=, <, missing, map
LinearIndices, (:), |, +, -, !==, !, <=, <, missing, map, any

import .Base:
first, last,
Expand Down Expand Up @@ -335,7 +335,7 @@ end

@propagate_inbounds function _zip_iterate_all(is, ss)
ds = _zip_isdone(is, ss)
ds === true && return nothing
any(map(d -> d === true, ds)) === true && return nothing
xs1 = _zip_iterate_some(is, ss, ds, missing)
xs1 === nothing && return nothing
xs2 = _zip_iterate_some(is, ss, ds, false)
Expand Down Expand Up @@ -366,10 +366,8 @@ _zip_iterate_interleave(::Tuple{}, ::Tuple{}, ::Tuple{}) = ((), ())

function _zip_isdone(is, ss)
d = isdone(is[1], ss[1]...)
d === true && return true
ds = _zip_isdone(tail(is), tail(ss))
ds === true && return true
return (d, ds...)
d === true && map(_ -> true, is)
return (d, _zip_isdone(tail(is), tail(ss))...)
end
_zip_isdone(::Tuple{}, ::Tuple{}) = ()

Expand Down
2 changes: 1 addition & 1 deletion test/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ end

@testset "inference for large zip #26765" begin
x = zip(1:1, ["a"], (1.0,), Base.OneTo(1), Iterators.repeated("a"), 1.0:0.2:2.0,
(1 for i in 1:1), ["a"], (1.0 for i in 1:2, j in 1:3), 1)
(1 for i in 1:1), Iterators.Stateful(["a"]), (1.0 for i in 1:2, j in 1:3), 1)
z = Iterators.filter(x -> x[1] == 1, x)
@test @inferred(first(z)) == (1, "a", 1.0, 1, "a", 1.0, 1, "a", 1.0, 1)
end

0 comments on commit 8375946

Please sign in to comment.