Closed CAD97 closed 4 years ago
Unsound fat pointer creation has been eliminated courtesy of @myrrlyn. We still have a laundry list of assumptions for the manual allocation, however.
Having walked the implementation a bit more, I understand where the benefit could come in: what was previously called TreeArc
and is now just SyntaxNode
. I'm playing with properly making GreenNode
?Sized
now, just to see where that goes.
Don’t have time to review right now, but yeah, this might not be as beneficial as the swift’s case, because we are storing tokens inline.
On Saturday, 26 October 2019, Christopher Durham notifications@github.com wrote:
Having walked the implementation a bit more, I understand where the benefit could come in: what was previously called TreeArc and is now just SyntaxNode. I'm playing with properly making GreenNode ?Sized now, just to see where that goes.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/rust-analyzer/rowan/pull/31?email_source=notifications&email_token=AANB3M7X6J3VNQ3IBKC2VLLQQSOORA5CNFSM4JFJMIX2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECKPXUY#issuecomment-546634707, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANB3M7YMJVNMKHGPXCOME3QQSOORANCNFSM4JFJMIXQ .
Closing in favor of #32.
This is "theoretically unsound" as of current as it requires creating a fat pointer from a thin pointer gotten fromalloc
. However, it should have enough paranoia checking to kill performance ofGreenNode::new
and ensure that it doesn't cause UB due to implementation details changing.The "
llvm::trailing_objects
trick" requires that the "trailing_objects
carrier" always be behind a pointer (as it is?Sized
). For simplicity of the PoC, I just put anArc
insideGreenNode
, so it's essentially C++ptr::shared<GreenNodeInner>
. Because of this we aren't even saving allocations, just moving the syntax kind and text length of theGreenNode
inside theArc
.This doesn't even give us space savings, as
GreenElement
remains 5usize
large, asGreenToken
is still 4usize
large and there is no way to nicheGreenNode
andGreenToken
together. This does reduce the size ofGreenNode
from 3usize
to 2usize
, but that benefit just can't proliferate toGreenElement
.Because of this I recommend removing the
llvm::trailing_objects
mention or otherwise clarifying how it might benefit the tree.