-
Notifications
You must be signed in to change notification settings - Fork 64
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
Question: Serialization of entire Lua state #35
Comments
Good question! You're not the first person to ask it, and I've thought about this before! So... there's not really any deal breakers, but there are things that range from somewhat difficult to impossible to do, and it will never be possible in EVERY case to serialize everything. Let me outline what I've thought about so far... When talking about serializing "state", I'm basically focusing on serializing arbitrary The first, obvious problem is that a network of There's also the complexity of threads, closures, upvalues, function prototypes... but I think these are all basically tractable, they're "just" complex, cyclic data structures that can be serialized with value tables and indirection. The biggest problem is probably dyn trait objects, which is probably why you mentioned callbacks first. So you mentioned callbacks and that's a good one, those are obviously not serializable as is. Userdata is also not (directly) serializable, as well as Sequence impls, both for the same reasons. Wherever we have a dyn trait object, obviously this presents a serialization problem. The three main objects of this type held by AnyCallback
Supposing that every callback is always statically defined and none of them are mutable, a way to serialize all callbacks is to keep a dictionary of known callbacks and serialize some other marker in their place. It would be potentially a lot of boilerplate, but one could imagine keeping every callback function (any exposed stdlib functions and all user made functions) in a lookup table that maps to a marker, and whenever we encounter an AnyValue
AnySequenceThe juggernaut of the three... IF we added downcasting to Whatever the user's serialization system is, they'd probably have to re-implement the parts of the stdlib that use
Another possible solution for Anyway, in summary I think it's actually.. surprisingly feasible, but there are several different "levels" of serialization support and each level brings with it new challenges. The trick is figuring out how to experiment with it I think without explicit piccolo support, I actually think that might even be a good "inside out" test to see just how much you can use piccolo in a non-standard way. Maybe it just requires making a lot more of the details of Edit: Oh also I should mention, there ARE indeed many different levels of serialization support below this too, such as not serializing Threads or arbitrary Values at all! Currently I'm sitting at the lowest level with simplistic serde support, I have piccolo serde integration and some other goodies I super duper mega promise to release in a |
Just reading old issues, and I wanted to clarify some changes that have occurred since I wrote the last response for anyone reading. First, there have been a bunch of renames, so the objects prefixed with Second, the "quasi-CPS idea" has been implemented, so the whole thing with Another change that has been made is that we can now finally implement I think the only sensible way forward would be to make sequences potentially downcast-able, but not require it on everything because it makes the API obnoxious to use, and then only support downcasting for whatever the few subset of "serializable" I still think about this issue, it's just ofc lower priority than "completing" piccolo (making it fully implement a respectable version of Lua, getting rid of the really bad pain points, finishing the stdlib, making it "fast enough", etc). |
Not proposing this as a feature but just wondering if it would be possible in theory to save and reload the entire Lua state? Given the "stackless vm" design and the "reified stack", it seems like it may be more possible than in other designs so I thought I would ask. I expect that if nothing else, the Rust callbacks that are stored in the state would be unserializable, but curious what other deal breakers there might be?
The text was updated successfully, but these errors were encountered: