-
Notifications
You must be signed in to change notification settings - Fork 228
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
Look into ways get_function_address could safely return a function #5
Comments
I'm starting to think that this might not be possible, and possible as a safe wrapper:
So, this may just be an area where unsafety is required on the user's part 😢. One slightly safer approach (that doesn't solve this problem but is a related idea) might be to return a non-copy address wrapper reference |
I would just have a separate |
Oh, neat, thanks! I didn't know something like this existed. I'll have to look into it more. What's the name for this feature? I could probably just have an experimental crate feature for stuff like this, so that the whole crate doesn't have to move to nightly. |
Also, does this let you specify that the generated Fn is unsafe somehow? |
I think
I don't think so, because the |
Yeah, ideally the function generator would be safe, and the actual function would be unsafe. Nonetheless, thanks for the idea! Worth exploring for sure.
…On Aug 7, 2017, 9:45 AM, at 9:45 AM, Nathaniel Ringo ***@***.***> wrote:
> What's the name for this feature?
I *think* `unboxed_closures`; at least, that's the feature name for it.
> Also, does this let you specify that the generated Fn is unsafe
somehow?
I don't think so, because the `Fn` trait doesn't have the function
marked as `unsafe`. Maybe make the `get_function_handle` method
`unsafe`? (Although I agree, that's not 100% satisfying.)
--
You are receiving this because you were assigned.
Reply to this email directly or view it on GitHub:
#5 (comment)
|
In the tutorial I'm working on I noticed how awkward it is to use the execution engine's The In general, I feel like this crate can benefit a lot from using lifetimes more. I've already encountered a couple segfaults because I didn't fully understand |
Good point, it maybe should be a The method itself should not be unsafe to call, but the result should be unsafe to manipulate, I think (but could be wrong). I've also thought about using the typesystem and lifetimes here to tie it to the EE somehow and my most recent idea was to return a I do want to get more issues solved via the type system, but I'm holding that off until the second iteration/version(v0.2.0) of inkwell(I've jotted down ideas here: #8) because it's a lot of additional work and I just want to focus on core functionality being complete first across multiple LLVM versions so that we can get an initial version out the door. And yeah, LLVM's ownership model is very confusing, and I've just been piecing it together myself as I go |
(I saw this a while back when looking around at LLVM in Rust, so this has been sitting in my mind for a while. Then I had an idea, so) Just to spitball the idea: Maybe you could use Frunk's My first idea was that you could expose an interface that gave back a Then I remembered seeing the blog posts about Frunk's HList. Above I've linked the actual blog post, but an HList is basically a type-level cons list, so you can have types like So, using Maybe if in the future the |
@CAD97 I like the idea of using something like a cons list for passing in arguments, but there may be issues trying to shoehorn a LLVM function signature (an instance of The big problem I see is you can't guarantee a function signature at compile time, because LLVM doesn't even generate the function until runtime. So about the best you can do is either provide some sort of builder type which will do runtime checks to validate the signature ( Either way, I don't think it's sound to try and remove the |
I also think it should stay unsafe. Using a wrapper type or |
@6a I've made a PR which replaces the old Under the hood it's essentially just the old I don't know if you can constrain |
Looks like a good compromise to me, but it essentially depends on @TheDan64's opinion. To my knowledge, there aren't any |
I tried using the It seems like
|
I wonder if we could use the nightly |
Update inkwell llvm12
Currently it returns an address value pointer, which is in itself safe - but to actually use it, the user needs to unsafely transmute it into a rust extern "C" function. I'm wondering if this could be accomplished under the hood by "deserializing" the function's FunctionType (which has all of the needed type info) into rust types. Maybe writing a Serde plugin could help when it comes to complex types like StructType & PointerType.
Will probably need to account for edge cases - is VoidType deserializable? If so, would that just be
()
and is that ever useful? Is*()
/&()
valid in rust? EtcThe text was updated successfully, but these errors were encountered: