-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Thank you for your very interesting work!
One thing i really really wish to be taken into consideration, is runtime-storable versions of lease, aka, "non-temporary lifetime".
Currently rust lifetime has been doing quite well at inter-procedure ownership/borrowing relations. However most non-arena and non-static lifetimes occur with temporaries. It does not work so well when expressing data structures and business domain objects, where the ownership has to be stored.
Storable leases
Personally i think with a runtime-storable and usable version of lease, these issues can be eased or maybe even solved.
I'd like to take your Modeling graphs in Rust using vector indices blog as an example, the NodeIndex and EdgeIndex is a poor man's untyped runtime version of lease.
I believe allowing some (even restricted) version of runtime lease will fundamentally improve the ergonomics of writing a graph.
POC naive proposal without deep thinking
A runtime lease consists of two parts: a root and a selector.(Need better names). The root part will be used for static analysis, while the selector part is stored in memory and used for runtime checking and accesses.
Introduce a new mode for places, called ScopedLeased, with surface syntax its{LeaseRootType} PlaceType, that stores LeaseSelector alongside with the value.
class Graph(
nodes: [NodeData]
edges: [EdgeData]
)
// Not valid Tada, borrowing surface syntax from rust.
impl LeaseBook<NodeData> for Graph {
type Selector = usize;
// TODO
}
impl LeaseBook<EdgeData> for Graph {
type Selector = usize;
// TODO
}
class NodeData(
first_outgoing_edge: Option<its{Graph} EdgeData>
)
class EdgeData {
target: its{Graph} NodeData,
next_outgoing_edge: Option<its{Graph} EdgeData>
}
impl EdgeData {
fn target(its{Graph} self) -> its{Graph} NodeData {
self.target{root(self)} // the `root(self)` expression returns the `borrowed Graph` and we pass it along.
}
}
Unresolved questions:
- How this fits into the
uniqueness/ownershipaxes. - How to deal with out-of-bound errors (the
leaseis previously actually retrieved from anotherLeaseBook, so the root and selector doesn't match) - How to prevent unsafety. eg. Incorrectly specifying unpinned-pointers as
Selector.