Serializing Functions / Methods / Closures

Hi all,

over the last months I’ve spent quite some time to bring JLD2 back up to speed. One of the remaining pain points is that it is not possible to properly store and recover (anonymous) functions
and closures. This has been requested way too many times.

I’m aware that this is a difficult topic and that there probably will
be edge cases that can’t work for one reason or another. (And likely for good reasons).

Still, I’m mostly concerned with the simpler things e.g. storing simple closures and anonymous functions that commonly appear as fields in larger structures. The struct part of closures already gets serialized properly and only the attached method is missing.

I’ve experimented with this for myself and adapted some code from
BSON (BSON.jl/anonymous.jl at master · JuliaIO/BSON.jl · GitHub)
and got very basic things working but, honestly, I don’t understand what I’m doing.

So, here are my questions:
Is there more information beyond the julialang dev-docs that I can read?
(e.g. what do the fields mean? What is the purpose of the structure?
When are which fields of Method, TypeName, etc. initialized ?)
Would anyone be willing to help me work on this ?

Best,
Jonas

19 Likes

so sad that there’s been no reply in eight months to help with serializing functions. would be very convenient to be able to save them to JLD2 files. thanks so much for working on this important problem @JonasIsensee

2 Likes

Kind of a vague question. I’m still not clear what it means. There’s no example of what doesn’t work and it’s not clear what the request for more detail is about.

2 Likes

It was vague because I knew too little to ask precise questions.

I worked on this problem once more and got some things working on julia v1.6. (Deserializing anonymous functions and closures)
Now v1.6 is LTS and v1.7 has significant changes to the internals so I will most likely not pursue this any further.

2 Likes