-
Notifications
You must be signed in to change notification settings - Fork 544
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
Safe and convenient resource destruction #288
Comments
Actually, screw RAII. We really just need linear types for the resources. Edit: that was a silly idea! Linear types are great, but not for our case. |
Does Rust support linear types? |
AFAIK, not yet, unfortunately. I hope someone will post the status of linear types support here. |
Could we cc the linear type RFC? Would be good to show them a real use case. |
Ohh, I rembered it, but forgot it wasn't up on Github yet. |
@bjz I find it weird that linear types are still in pre-RFC stage. For our purpose, it would suffice to just be able to disable going out-of-scope for some type: generate a compile error whenever a variable of this type goes out of scope. The only way to destruct it would be to deconstruct it, and since the type is provided by our library, we can prevent user from deconstructing it by adding any private fields. |
Here is a use-case shared by @XMPPwocky:
Unfortunately, linear types will not allow this case. Time to brainstorm it again? |
Notes by @amaranth:
By @tomaka :
|
I gave it a little think time, and came up with the following plan (extending @csherratt's proposal): PlanEvery device-associated resource is stored by #[derive(Copy, Clone, PartialEq, Debug)]
pub struct Shader<R: Resources>(Arc<<R as Resources>::Shader>, shade::Stage);
AnalysisIt's not clear how much of this code we'll be able to store in the device-independent part. Hopefully - all of it, but that leaves the question open about user-facing One obvious drawback is performance. I don't know how much Speaking of the costs, it would be great to allow ProblemsHow do we check that an |
There is another option that I have thought about. It has a different set of trade-offs from what is described above.
Like @kvark's suggestion this would probably have to use There are some advantages:
Some disadvantages:
Some differences:
|
Would be nice to have our resources self-destructed, though I'm not sure we can really do that with our architecture and potential other device back-ends.
The path seems to be mostly cleared now (at last!). Here are the steps we will take:
Arc<>
Factory
to store the references to all created resourcessweep()
pass for the device/factory. The device may be able to enumerate all the factories and callsweep()
on them.Rc
andArc
. Examples.Graphics
enforcesRc
, while the general way goes withArc
PR #633 covers the basics.
Issue #636 will cover
Rc
usage.The text was updated successfully, but these errors were encountered: