Hi everyone!
I have a very technical question about closures in Rust. Or rather, how they are implemented.
I have no experience with writing compilers, so reading the source code myself is out of the question. But what I do understand from what I've read about Rust so far is that memory in Rust is handled in some way that is pretty close to slicing. Also, when looking at the Dining Philosophers example, and reading up on it a bit more, it becomes clear, that closures perform some pretty fancy magic to retain their stack/heap across function- and calling-context borders. This leads me to assume, that closures in Rust have a very well defined stack frame (so to speak).
Now, my question is: If my assumption is correct, then (given some very carefully laid out constraints) would it technically be possible to, sooner or later, make closures byte-code-serializeable so they could (in principle) be transferred across a machine/network border?
Please note: I am very aware of potential technical issues (like architecture and endianess) as well as posing a HUGE security risk when doing so (I mean, 'executing' a serialized closure from a foreign source is essentially equivalent to running a normal binary from an unknown source). This question is strictly about the technicalities and how close to possible it would be, given the current implementation. So, you could compress it to the question:
Are closures well structured enough in the current incarnation of Rust, so that they could be, in principle, exported as their own executable code? Like a shared object, for example?
The reason for my question is rooted in an idea for doing remote procedure execution. If you could 'extrude' executable code from a closure "at runtime", this would be a very, very handy feature for distributed systems. It would be close to what CORBA always wanted to be, but failed due to implementation complexity and take-away the platform independence.
So, is anyone involved enough into the current implementation of the Rust compiler to answer my question?
Thanks!
-Timo