Skip to content

Commit 384967a

Browse files
committed
Constant propagation only on recent Julia versions
1 parent 3318615 commit 384967a

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/fillalgebra.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ end
2020

2121
permutedims(a::AbstractFillMatrix) = fillsimilar(a, reverse(axes(a)))
2222

23-
Base.@constprop :aggressive function permutedims(B::AbstractFill, perm)
23+
@static if VERSION >= v"1.9"
24+
Base.@constprop :aggressive permutedims(B::AbstractFill, perm) = _permutedims(B, perm)
25+
else
26+
permutedims(B::AbstractFill, perm) = _permutedims(B, perm)
27+
end
28+
29+
@inline function _permutedims(B::AbstractFill, perm)
2430
dimsB = axes(B)
2531
ndimsB = ndims(B)
2632
(ndimsB == length(perm) && isperm(perm)) || throw(ArgumentError("no valid permutation of dimensions"))

test/runtests.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,21 @@ end
15121512
@test F' == G'
15131513
@test transpose(F) == transpose(G)
15141514
end
1515+
1516+
# test for inference only if aggressive constant propagation is available
1517+
H = if VERSION >= v"1.8"
1518+
@inferred(permutedims(Fill(2, (SOneTo(2), SOneTo(3)))))
1519+
else
1520+
permutedims(Fill(2, (SOneTo(2), SOneTo(3))))
1521+
end
1522+
@test H === Fill(2, (SOneTo(3), SOneTo(2)))
1523+
F = Fill(2, (SOneTo(2), SOneTo(3), SOneTo(1)))
1524+
H = if VERSION >= v"1.8"
1525+
@inferred((F -> permutedims(F, (3,1,2)))(F))
1526+
else
1527+
(F -> permutedims(F, (3,1,2)))(F)
1528+
end
1529+
@test H === Fill(2, (SOneTo(1), SOneTo(2), SOneTo(3)))
15151530
end
15161531

15171532
@testset "reverse" begin

0 commit comments

Comments
 (0)