Deallocate JIT code on FastFn drop
chc4 opened this issue · 2 comments
What is says on the tin: ususally JITs can't ever deallocate JIT bodies without explicit safepoints, since another thread could be currently executing the code and would segfault.
Since we JIT closures, and are using Rust where everything has explicit lifetimes, we can actually always deallocate the JIT code when the Fn goes out of scope, since by definition it is unreachable from any code. Also we don't have any multi-threading support yet lol.
Get rid of the mem::forget(f)
in JIT compilation and store the original function in the FastFn instead, too, so that we properly run destructors of the members of the closed environment.
Also we don't have any multi-threading support yet lol.
I imagine the FastFn
is as Send
and Sync
as the input closure?
I meant more that the fact that FastFn doesn't implement Send+Sync means that there are no cases in which a closure is being dropped while we are compiling other closures or running it. I think we'd have to worry about that in the event of e.g. #12 being implemented; it'd have to make sure to use reference-counted closures in order to make sure that everything stays alive while it is doing work on another thread, for example. That would have to add Send+Sync(?) bounds to
lineiform/lineiform/src/lib.rs
Line 103 in 4a104c9
Basically I was just being cheeky and the fact that we aren't caring about multithreading at all currently makes this easy.