Skip to content

Support for arbitrary callables #84

@termi-official

Description

@termi-official

adapt_structure fails if there are mixed concrete types and parametric types in a function type.

Tests:

using Adapt

# This should be equivalent to what adapt_structure does
g(f::T) where T = length(T.parameters)

abstract type AbstractSuperType{t} end

abstract type AbstractSuperType2{t} <: Function end

struct A{T}
    a::T
end
a = A(1)
@assert g(a) == 1 # Works
Adapt.adapt_structure(1.0, a) # Works


struct B{T} <: AbstractSuperType2{true}
    b::T
end
b = B(1)
@assert g(b) == 1 # Works
Adapt.adapt_structure(1.0, b) # works

struct B2 <: AbstractSuperType2{true}
    b::Int
end
b2 = B2(1)
@assert g(b2) == 0 # Works
Adapt.adapt_structure(1.0, b2) # works

struct C{T} <: AbstractSuperType2{true}
    b::T
    a::Int
end
c = C(1,1)
@assert g(c) == 1 # Works
Adapt.adapt_structure(1.0, c) # fails


struct C2{T}
    b::T
    a::Int
end
c2 = C2(1,1)
@assert g(c2) == 1 # Works
Adapt.adapt_structure(1.0, c2) # works

struct C3{T} <: AbstractSuperType{true}
    b::T
    a::Int
end
c3 = C3(1,1)
@assert g(c3) == 1 # Works
Adapt.adapt_structure(1.0, c3) # works


struct D{T} <: AbstractSuperType2{true}
    a::Int
    b::T
end
d = D(1,1)
@assert g(d) == 1 # Works
Adapt.adapt_structure(1.0, d) # fails


struct D2{T}
    a::Int
    b::T
end
d2 = D2(1,1)
@assert g(d2) == 1 # Works
Adapt.adapt_structure(1.0, d2) # works


struct D3{T} <: AbstractSuperType{true}
    a::Int
    b::T
end
d3 = D3(1,1)
@assert g(d3) == 1 # Works
Adapt.adapt_structure(1.0, d3) # works

struct D4{T} <: AbstractSuperType2{true}
    a::Int
    b::T
end
d4 = D4(1,1)
@assert g(d4) == 1 # Works
Adapt.adapt_structure(1.0, d4) # fails


struct E{T} <: AbstractSuperType2{true}
    a::Int
    b::T
    c::Int
end
e = E(1,1,1)
@assert g(e) == 1 # Works
Adapt.adapt_structure(1.0, e) # fails

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions