TheDan64 / inkwell

It's a New Kind of Wrapper for Exposing LLVM (Safely)
https://thedan64.github.io/inkwell/
Apache License 2.0
2.22k stars 217 forks source link

[DRAFT] thread safe-ish execution engine #487

Open BadBastion opened 3 months ago

BadBastion commented 3 months ago

Draft for conversation, this is currently demonstration of what isn't a safe change.

ExecutionEngine Changes

ExecutionEngine<'ctx> -> ExecutionEngine

ExecutionEngine can have more than one module, and thus I believe more than one context. The functions that will break if context is dropped are all related to function execution. In principle this means we should try to ensure safety via JitFunction and not the lifetime of the ExecutionEngine.

JitFunction Changes

JitFunction<'ctx, F> -> JitFunction<F>

The JitFunction<'ctx, F> type is quite a challenging interface for inkwell due to the limited ways to fulfill this lifetime with safe rust. The idiomatic rust would be to change to JitFunction<F> and an Arc to both Execution Engine & Context.

This seems like the most elegant solution from the perspective of thread safe JIT functions, but incurs cascading breaking changes to the rest of the repo.

BadBastion commented 3 months ago

Relevant to #242 and #28