Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upSafe and convenient resource destruction #288
Comments
kvark
added
D-hard
labels
Aug 26, 2014
kvark
referenced this issue
Aug 26, 2014
Closed
Things that I think could be improved in gfx-rs #216
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
Does Rust support linear types? |
This comment has been minimized.
This comment has been minimized.
|
AFAIK, not yet, unfortunately. I hope someone will post the status of linear types support here. |
This comment has been minimized.
This comment has been minimized.
|
Could we cc the linear type RFC? Would be good to show them a real use case. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Ohh, I rembered it, but forgot it wasn't up on Github yet. |
This comment has been minimized.
This comment has been minimized.
|
@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. |
kvark
added
the
status: blocked
label
Jan 30, 2015
kvark
changed the title
RAII for single-threaded resources
Safe and convenient resource destruction
Feb 3, 2015
kvark
added
value: high
value: strategic
and removed
value: high
labels
Feb 14, 2015
This comment has been minimized.
This comment has been minimized.
|
Here is a use-case shared by @XMPPwocky:
Unfortunately, linear types will not allow this case. Time to brainstorm it again? |
kvark
added
module: other
and removed
module: render
status: blocked
labels
Feb 18, 2015
This comment has been minimized.
This comment has been minimized.
|
Notes by @amaranth:
By @tomaka :
|
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
ghost
commented
Mar 5, 2015
|
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:
|
kvark commentedAug 26, 2014
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<>Factoryto 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.RcandArc. Examples.GraphicsenforcesRc, while the general way goes withArcPR #633 covers the basics.
Issue #636 will cover
Rcusage.