-
Notifications
You must be signed in to change notification settings - Fork 235
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
Types derived from ContextRef are always shortlived #165
Comments
You're correct. This is because context methods derive I wonder if we should just get rid of TLDR: Return types from |
I think there are two options here, both of which require getting ride of the deref impl because it causes this problem. Either A) We add our own "deref" method which lies about returning a Obviously, A) is more ergonomic. But it boils down to safety. |
I suspect A) is safe because:
That last part is the crux of whether or not this approach is safe. 1) is certainly true. 2) is iffy |
I think this is related. I've been looking into using this library for a small pet project that would effectively be a JIT usable from a CFFI. In trying to create an abstraction over the types in this crate (i.e. some |
If you're asking if it's possible for inkwell to do that, it's certainly technically possible. But I don't consider it to be the right approach since we'd lose many guarantees provided by the lifetimes. If you're asking if it's possible to wrap types like |
You maybe want something like the |
It is not possible to write a function which takes something with a
get_context
as a parameter, use that context to create something else, and return that something else.get_context
calls returnContextRef
s rather than regular references, and Rust considers theContextRef
a temporary, so (I'm pretty sure) the lifetime on whatever you create is inferred to be the lifetime of theContextRef
.LLVM Version:
Desktop:
The text was updated successfully, but these errors were encountered: