Commit 5cceb14
prevent some unnecessary uses of
There's no reason for a `Base.@pure` annotation in cases where Julia
successfully infers `:consistent`, `:effect_free` and
`:terminates_globally` without the annotation.
Effect inference tested with Julia v1.9.2, the latest release.
While the effect inference is not favorable for `_Length(::Int...)`, as
the consistency is not inferred, `_Length` actually seems to be an
internal function meant as merely an implementation detail for
`Length`, whose effect inference is perfect for the relevant method.
The script for testing the effect inference is appended. `:consistent`
(`+c`), `:effect_free` (`+e`) and `:terminates_globally` (`+t`) are
successfully inferred in each case:
```julia
using StaticArrays
const d = StaticArraysCore.Dynamic()
const test_sizes = (
(1,2,3,4,5,6,7,8,9,1,2,3),
(7,8,9,1,2,3,1,2,3,4,5,6),
(2,3,4,2,3,4,2,3,4,2,3,4),
(1,2,3,4,5,6,7,8,9,1,2,d),
(7,8,9,1,2,3,1,2,3,4,5,d),
(2,3,4,2,3,4,2,3,4,2,3,d),
(d,2,3,4,5,6,7,8,9,1,2,3),
(d,8,9,1,2,3,1,2,3,4,5,6),
(d,3,4,2,3,4,2,3,4,2,3,4),
(1,2,3,4,d,6,7,8,d,1,2,3),
(7,8,9,1,d,3,1,2,d,4,5,6),
(2,3,4,2,d,4,2,3,d,2,3,4),
)
const test_lengths = (0, 1, 2, 3, d)
const test_size_types = map((s -> Size{s}), test_sizes)
const test_length_types = map((l -> Length{l}), test_lengths)
const test_tuple_int_types = (
Tuple{},
Tuple{Int},
Tuple{Int,Int},
Tuple{Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int},
Tuple{Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int},
Tuple{Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int},
)
println("Length(::Size)")
for S ∈ test_size_types
display(Base.infer_effects(Length, (S,)))
end
println()
println("(::Type{Tuple})(::Size)")
for S ∈ test_size_types
display(Base.infer_effects(Tuple, (S,)))
end
println()
println("length(::Size)")
for S ∈ test_size_types
display(Base.infer_effects(length, (S,)))
end
println()
println("length_val(::Size)")
for S ∈ test_size_types
display(Base.infer_effects(StaticArrays.length_val, (S,)))
end
println()
println("==(::Size, ::Tuple{Vararg{Int}})")
for S ∈ test_size_types, T ∈ test_tuple_int_types
display(Base.infer_effects(==, (S, T)))
end
println()
println("==(::Tuple{Vararg{Int}}, ::Size)")
for S ∈ test_size_types, T ∈ test_tuple_int_types
display(Base.infer_effects(==, (T, S)))
end
println()
println("prod(::Size)")
for S ∈ test_size_types
display(Base.infer_effects(prod, (S,)))
end
println()
println("size_tuple(::Size)")
for S ∈ test_size_types
display(Base.infer_effects(StaticArrays.size_tuple, (S,)))
end
println()
println("==(::Length, ::Int)")
for L ∈ test_length_types
display(Base.infer_effects(==, (L, Int)))
end
println()
println("==(::Int, ::Length)")
for L ∈ test_length_types
display(Base.infer_effects(==, (Int, L)))
end
println()
println("sizematch(::Size, ::Size)")
for S1 ∈ test_size_types, S2 ∈ test_size_types
display(Base.infer_effects(StaticArrays.sizematch, (S1, S2)))
end
println()
println("diagsize(::Size)")
for S ∈ test_size_types
display(Base.infer_effects(StaticArrays.diagsize, (S,)))
end
println()
```
Co-authored-by: Mateusz Baran <mateuszbaran89@gmail.com>@pure in traits.jl (#1177)1 parent 0d16e67 commit 5cceb14
2 files changed
+14
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
45 | | - | |
| 44 | + | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
50 | | - | |
| 49 | + | |
| 50 | + | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | | - | |
| 53 | + | |
| 54 | + | |
55 | 55 | | |
56 | | - | |
| 56 | + | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
| 60 | + | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
66 | | - | |
| 65 | + | |
| 66 | + | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
| 118 | + | |
0 commit comments