Skip to content

Instantly share code, notes, and snippets.

@jrevels
Created July 1, 2018 11:15
Show Gist options
  • Save jrevels/4e56e78d91d53ca29af73b5b36d506d0 to your computer and use it in GitHub Desktop.
Save jrevels/4e56e78d91d53ca29af73b5b36d506d0 to your computer and use it in GitHub Desktop.
using Test
using Cassette: @overdub, @context, @pass
f27078(T::Type{S}) where {S} = isa(T, UnionAll) ? f27078(T.body) : T
T27078 = Vector{Vector{T}} where T
@test f27078(T27078) === T27078.body
@context Ctx
@overdub(Ctx(), convert(Tuple{Vararg{Float64}}, (1,2)))
bar(T) = isa(T, UnionAll) ? bar(T.body) : T
@overdub(Ctx(), bar(Vector{T} where T))
@overdub(Ctx(), bar(Vector{Vector{T}} where T))
sig_collection = DataType[]
mypass = @pass (ctx, sig, cinfo) -> (push!(sig_collection, sig); cinfo)
@overdub(Ctx(pass=mypass), sum(rand(3)))
@test !isempty(sig_collection) && all(T -> T <: Tuple, sig_collection)
@noinline function g(f, a::T, ::Type{S} = Any) where {T, S}
cf = @cfunction $f Ref{T} (Ref{T},)
GC.gc()
@assert cf === Base.cconvert(Ptr{Cvoid}, cf)
GC.@preserve cf begin
fptr = Base.unsafe_convert(Ptr{Cvoid}, cf)
b = ccall(fptr, Ref{T}, (Ref{T},), a)
end
end
@test g(identity, 1) === 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment