Skip to content

Commit 0caea19

Browse files
authored
Fix @assume_effects compat (#361)
Fix `@assume_effects` compat Julia v1.6 doesn't have assumed effects so we have a fallback defined. However, the previous implementation doesn't have proper macro hygeine and assumes only `@assume_effects :total call` is every done. This only provides the `@pure` def when applicable.
1 parent c2e3867 commit 0caea19

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

lib/ArrayInterfaceCore/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ArrayInterfaceCore"
22
uuid = "30b0a656-2188-435a-8636-2ec0e6a096e2"
3-
version = "0.1.23"
3+
version = "0.1.24"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

lib/ArrayInterfaceCore/src/ArrayInterfaceCore.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@ using SuiteSparse
88
@static if isdefined(Base, Symbol("@assume_effects"))
99
using Base: @assume_effects
1010
else
11-
macro assume_effects(_, ex)
12-
:(Base.@pure $(ex))
11+
macro assume_effects(args...)
12+
n = nfields(args)
13+
call = getfield(args, n)
14+
if n === 2 && getfield(args, 1) === QuoteNode(:total)
15+
return esc(:(Base.@pure $(call)))
16+
else
17+
return esc(call)
18+
end
1319
end
1420
end
15-
1621
@assume_effects :total __parameterless_type(T) = Base.typename(T).wrapper
1722
parameterless_type(x) = parameterless_type(typeof(x))
1823
parameterless_type(x::Type) = __parameterless_type(x)

lib/ArrayInterfaceCore/test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ using Test
1111
using Aqua
1212
Aqua.test_all(ArrayInterfaceCore)
1313

14+
# ensure we are correctly parsing these
15+
ArrayInterfaceCore.@assume_effects :total foo(x::Bool) = x
16+
ArrayInterfaceCore.@assume_effects bar(x::Bool) = x
17+
@test foo(true)
18+
@test bar(true)
19+
1420
@testset "zeromatrix and unsafematrix" begin
1521
for T in (Int, Float32, Float64)
1622
for (vectype, mattype) in ((Vector{T}, Matrix{T}), (SparseVector{T}, SparseMatrixCSC{T, Int}))

0 commit comments

Comments
 (0)