From 0caea19891820668f97e901a245c97da9b0ce3f1 Mon Sep 17 00:00:00 2001 From: Zachary P Christensen Date: Sat, 29 Oct 2022 16:43:48 -0400 Subject: [PATCH] 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. --- lib/ArrayInterfaceCore/Project.toml | 2 +- lib/ArrayInterfaceCore/src/ArrayInterfaceCore.jl | 11 ++++++++--- lib/ArrayInterfaceCore/test/runtests.jl | 6 ++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/ArrayInterfaceCore/Project.toml b/lib/ArrayInterfaceCore/Project.toml index 243f7bc1c..3bf916d97 100644 --- a/lib/ArrayInterfaceCore/Project.toml +++ b/lib/ArrayInterfaceCore/Project.toml @@ -1,6 +1,6 @@ name = "ArrayInterfaceCore" uuid = "30b0a656-2188-435a-8636-2ec0e6a096e2" -version = "0.1.23" +version = "0.1.24" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" diff --git a/lib/ArrayInterfaceCore/src/ArrayInterfaceCore.jl b/lib/ArrayInterfaceCore/src/ArrayInterfaceCore.jl index 36eec88b6..bca42da49 100644 --- a/lib/ArrayInterfaceCore/src/ArrayInterfaceCore.jl +++ b/lib/ArrayInterfaceCore/src/ArrayInterfaceCore.jl @@ -8,11 +8,16 @@ using SuiteSparse @static if isdefined(Base, Symbol("@assume_effects")) using Base: @assume_effects else - macro assume_effects(_, ex) - :(Base.@pure $(ex)) + macro assume_effects(args...) + n = nfields(args) + call = getfield(args, n) + if n === 2 && getfield(args, 1) === QuoteNode(:total) + return esc(:(Base.@pure $(call))) + else + return esc(call) + end end end - @assume_effects :total __parameterless_type(T) = Base.typename(T).wrapper parameterless_type(x) = parameterless_type(typeof(x)) parameterless_type(x::Type) = __parameterless_type(x) diff --git a/lib/ArrayInterfaceCore/test/runtests.jl b/lib/ArrayInterfaceCore/test/runtests.jl index 26574b0f4..262f0a978 100644 --- a/lib/ArrayInterfaceCore/test/runtests.jl +++ b/lib/ArrayInterfaceCore/test/runtests.jl @@ -11,6 +11,12 @@ using Test using Aqua Aqua.test_all(ArrayInterfaceCore) +# ensure we are correctly parsing these +ArrayInterfaceCore.@assume_effects :total foo(x::Bool) = x +ArrayInterfaceCore.@assume_effects bar(x::Bool) = x +@test foo(true) +@test bar(true) + @testset "zeromatrix and unsafematrix" begin for T in (Int, Float32, Float64) for (vectype, mattype) in ((Vector{T}, Matrix{T}), (SparseVector{T}, SparseMatrixCSC{T, Int}))