JLD2.jl
JLD2.jl copied to clipboard
Bad saving of interactively-defined function in tuple
The function disappears from the tuple:
julia> using JLD2, FileIO
julia> f(x) = x+1
f (generic function with 1 method)
julia> save("test.jld2", "tuple", (f, :hello))
### New session
julia> using JLD2, FileIO
julia> load("test.jld2", "tuple")
(:hello,)
JLD2 does not currently attempt to serialize functions in a way that they can be reconstructed without the source having been loaded (see #13). But this should probably print a warning if f is undefined in the workspace instead of silently dropping it from the tuple.
I expected it to be a ReconstructedType instead of dropped, as in:
using JLD2, FileIO
struct Foo
a
b
c
end
f() = 2
save("test.jld2", "val", Foo(vcat, f, Any[vcat, f]))
using JLD2, FileIO
struct Foo
a
b
c
end
load("test.jld2", "val")
> Foo(vcat, JLD2.ReconstructedTypes.###f#665(), Any[vcat, JLD2.ReconstructedTypes.###f#665()])
Another issue, perhaps unsolvable: saving Function[vcat, f] has a problem on reload, because ReconstructedTypes are not Function objects.
The ReconstructedTypes behaviour is great for saving and loading traces in TraceCalls.jl, thank you for JLD2. 👍