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

Bad saving of interactively-defined function in tuple #36

Open
cstjean opened this issue Sep 3, 2017 · 2 comments
Open

Bad saving of interactively-defined function in tuple #36

cstjean opened this issue Sep 3, 2017 · 2 comments

Comments

@cstjean
Copy link

cstjean commented Sep 3, 2017

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,)
@simonster
Copy link
Member

simonster commented Sep 3, 2017

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.

@cstjean
Copy link
Author

cstjean commented Sep 3, 2017

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. 👍

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

No branches or pull requests

3 participants