|
998 | 998 | @test (@inferred Base.IteratorSize(zip(1:5, (1,2,3)) )) == Base.HasLength() # for zip of ::HasShape and ::HasLength
|
999 | 999 | end
|
1000 | 1000 |
|
| 1001 | +@testset "foldability inference" begin |
| 1002 | + functions = (eltype, Base.IteratorSize, Base.IteratorEltype) |
| 1003 | + helper(type::UnionAll) = (type{n} for n ∈ 1:10) # helper for trying with multiple iterator counts |
| 1004 | + iterator_types = ( # each element here takes an iterator type as first parameter |
| 1005 | + Base.Generator, |
| 1006 | + Iterators.Reverse, |
| 1007 | + Iterators.Enumerate, |
| 1008 | + Iterators.Filter{F, I} where {I, F}, |
| 1009 | + Iterators.Accumulate{F, I} where {I, F}, |
| 1010 | + Iterators.Rest, |
| 1011 | + Iterators.Count, |
| 1012 | + Iterators.Take, |
| 1013 | + Iterators.Drop, |
| 1014 | + Iterators.TakeWhile, |
| 1015 | + Iterators.DropWhile, |
| 1016 | + Iterators.Cycle, |
| 1017 | + Iterators.Repeated, |
| 1018 | + Iterators.PartitionIterator, |
| 1019 | + Iterators.Stateful, |
| 1020 | + helper(Iterators.ProductIterator{Tuple{Vararg{I, N}}} where {N, I})..., |
| 1021 | + ) |
| 1022 | + iterator_types_extra = ( |
| 1023 | + iterator_types..., |
| 1024 | + helper(Iterators.Zip{Tuple{Vararg{I, N}}} where {N, I})..., |
| 1025 | + helper(Iterators.Flatten{Tuple{Vararg{I, N}}} where {N, I})..., |
| 1026 | + ) |
| 1027 | + simple_types = (Vector, NTuple, NamedTuple{X, Y} where {X, Y <: NTuple}) |
| 1028 | + example_type = Tuple{Bool, Int8, Vararg{Int16, 20}} |
| 1029 | + function test_foldability_inference(f, S::Type) |
| 1030 | + @test Core.Compiler.is_foldable(Base.infer_effects(f, Tuple{S})) |
| 1031 | + @test Core.Compiler.is_foldable(Base.infer_effects(f, Tuple{Type{<:S}})) |
| 1032 | + end |
| 1033 | + @testset "concrete" begin # weaker test, only checks foldability for certain concrete types |
| 1034 | + @testset "f: $f" for f ∈ functions |
| 1035 | + for U ∈ iterator_types_extra |
| 1036 | + test_foldability_inference(f, U{example_type}) |
| 1037 | + end |
| 1038 | + end |
| 1039 | + end |
| 1040 | + @testset "nonconcrete" begin # stronger test, checks foldability for large families of types |
| 1041 | + @testset "f: $f" for f ∈ functions |
| 1042 | + for V ∈ simple_types |
| 1043 | + test_foldability_inference(f, V) # sanity check |
| 1044 | + for U ∈ iterator_types |
| 1045 | + test_foldability_inference(f, U{<:V}) |
| 1046 | + end |
| 1047 | + end |
| 1048 | + end |
| 1049 | + end |
| 1050 | +end |
| 1051 | + |
1001 | 1052 | @testset "proper partition for non-1-indexed vector" begin
|
1002 | 1053 | @test partition(IdentityUnitRange(11:19), 5) |> collect == [11:15,16:19] # IdentityUnitRange
|
1003 | 1054 | end
|
|
0 commit comments