Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix @assume_effects compat #361

Merged
merged 3 commits into from
Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ArrayInterfaceCore/Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
11 changes: 8 additions & 3 deletions lib/ArrayInterfaceCore/src/ArrayInterfaceCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions lib/ArrayInterfaceCore/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}))
Expand Down