You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A common need is to have a more complex data structure that has internal references. This can be modeled with vectors or arcs but it would be nice to have a way to create a ref-counted arena specific to each function and allocate memory from there. This is meant to model things like MIR, where we have some data structure that represents a function, and to allow it to go through phases where it is changed and updated, but without requiring everything to be in vectors nor requiring everything to be cloned constantly. I'm not sure the ergonomics exactly but the idea is roughly that you can declare a struct with two lifetimes...
...and the procedural macro will create a type AstRoot that "hides" the first one:
structAstRoot<'db>{arena:Arc<MemoryArena>,root:&'static Ast<'static 'static>,// <-- the lifetimes here are obviously lies}
Later you can do root.open(|r| { .. }) to work with the data. One of the goals is that you can create new, derived values based on the same arena that have different pointers -- so e.g. it should be possible to extra subvalues from the tree. Each of them would carry a reference count to the same base arena.
A common need is to have a more complex data structure that has internal references. This can be modeled with vectors or arcs but it would be nice to have a way to create a ref-counted arena specific to each function and allocate memory from there. This is meant to model things like MIR, where we have some data structure that represents a function, and to allow it to go through phases where it is changed and updated, but without requiring everything to be in vectors nor requiring everything to be cloned constantly. I'm not sure the ergonomics exactly but the idea is roughly that you can declare a struct with two lifetimes...
...and the procedural macro will create a type
AstRoot
that "hides" the first one:Later you can do
root.open(|r| { .. })
to work with the data. One of the goals is that you can create new, derived values based on the same arena that have different pointers -- so e.g. it should be possible to extra subvalues from the tree. Each of them would carry a reference count to the same base arena.Originally posted by @nikomatsakis in #490 (comment)
The text was updated successfully, but these errors were encountered: