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

Functors.children fails on Type in Functors v0.5 #94

Closed
mtfishman opened this issue Nov 6, 2024 · 1 comment · Fixed by #95
Closed

Functors.children fails on Type in Functors v0.5 #94

mtfishman opened this issue Nov 6, 2024 · 1 comment · Fixed by #95

Comments

@mtfishman
Copy link

mtfishman commented Nov 6, 2024

For example:

julia> using Functors

julia> pkgversion(Functors)
v"0.5.0"

julia> Functors.children(Matrix{Float64})
ERROR: UndefRefError: access to undefined reference
Stacktrace:
 [1] #2
   @ ~/.julia/packages/Functors/1RvWk/src/functor.jl:21 [inlined]
 [2] ntuple(f::Functors.var"#2#5"{DataType, NTuple{8, Symbol}}, n::Int64)
   @ Base ./ntuple.jl:19
 [3] functor(T::Type, x::Type)
   @ Functors ~/.julia/packages/Functors/1RvWk/src/functor.jl:21
 [4] functor(x::Type)
   @ Functors ~/.julia/packages/Functors/1RvWk/src/functor.jl:25
 [5] children(x::Type)
   @ Functors ~/.julia/packages/Functors/1RvWk/src/functor.jl:58
 [6] top-level scope
   @ REPL[11]:1

julia> versioninfo()
Julia Version 1.11.1
Commit 8f5b7ca12ad (2024-10-16 10:53 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 10 × Apple M1 Max
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, apple-m1)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)

while:

julia> using Functors

julia> pkgversion(Functors)
v"0.4.12"

julia> Functors.children(Matrix{Float64})
()

The cause seems to be that Functors v0.5 has generic code for walking through structs, which fails for types.

Probably it just requires a definition like:

Functors.functor(x::Type) = NoChildren(), _ -> x
@mcabbott
Copy link
Member

mcabbott commented Nov 7, 2024

Oh that's not good. @leaf Type seems to be one fix.

Are there other objects which are also going to go wrong?

julia> using Functors  # master branch

julia> fmap(x -> @show(x), (; a=1, b=Int, c=3))
x = 1
ERROR: UndefRefError: access to undefined reference
Stacktrace:
  [1] #functor##2
    @ ~/.julia/packages/Functors/1RvWk/src/functor.jl:21 [inlined]
  [2] ntuple(f::Functors.var"#functor##2#functor##3"{Type{Int64}, NTuple{8, Symbol}}, n::Int64)
    @ Base ./ntuple.jl:19
  [3] functor(T::Type, x::Type)
    @ Functors ~/.julia/packages/Functors/1RvWk/src/functor.jl:21
  [4] functor(x::Type)
    @ Functors ~/.julia/packages/Functors/1RvWk/src/functor.jl:25
  [5] children(x::Type)
    @ Functors ~/.julia/packages/Functors/1RvWk/src/functor.jl:58

julia> fmap(x -> @show(x), (; a=1, b=Array, c=3))  # gives awful errors on 1.12 with Functors@0.5
x = 1
x = :T
x = Union{}
ERROR: UndefRefError: access to undefined reference
Stacktrace:
  [1] #functor##2
    @ ~/.julia/packages/Functors/be90D/src/functor.jl:21 [inlined]
  [2] ntuple(f::Functors.var"#functor##2#functor##3"{Type{Any}, NTuple{8, Symbol}}, n::Int64)
    @ Base ./ntuple.jl:19
  [3] functor(T::Type, x::Type)
    @ Functors ~/.julia/packages/Functors/be90D/src/functor.jl:21
  [4] functor(x::Type)
    @ Functors ~/.julia/packages/Functors/be90D/src/functor.jl:25
  [5] children(x::Type)
julia> Functors.@leaf DataType  # this is not enough

julia> fmap(x -> @show(x), (; a=1, b=Int, c=3))
x = 1
x = Int64
x = 3
(a = 1, b = Int64, c = 3)

julia> fmap(x -> @show(x), (; a=1, b=Array, c=3))
x = 1
x = :T
x = Union{}
x = Any
x = :N
x = Union{}
x = Array{T, N}
x = 3
(a = 1, b = Array{T, N}, c = 3)

julia> Functors.@leaf Type  # but perhaps this is?

julia> fmap(x -> @show(x), (; a=1, b=Array, c=3))
x = 1
x = Array
x = 3
(a = 1, b = Array, c = 3)

julia> isstructtype(Int)
false

julia> isstructtype(Array)
true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants