[cfe-dev] Reference-counted statements
Douglas Gregor
dgregor at apple.com
Fri Aug 7 10:43:27 PDT 2009
On Aug 7, 2009, at 10:25 AM, Fariborz Jahanian wrote:
>
> On Aug 7, 2009, at 10:20 AM, Douglas Gregor wrote:
>
>>
>> On Aug 7, 2009, at 10:15 AM, Fariborz Jahanian wrote:
>>
>>> Ref counting is fine. One issue I see is when traversing the tree
>>> (for whatever reason)
>>> with shared nodes. Need a special flag in the node (or some other
>>> mechanism) to not revisit the shared sub-tree.
>>
>> Is there a particular use case you have in mind?
>
> It depends on who the consumer of the shared trees are. Are we going
> to see AST trees with
> shared nodes because of this? Then maybe the Indexer when caching
> the AST nodes. If this
> is all internal to Sema and Sema has no need to traverse the tree
> then it is a non-issue.
AST nodes still have ownership of the statements and expressions they
refer to, and there's no way to actually determine whether a node you
own is shared by someone else. This is generally okay, since
statements and expressions aren't meant to be mutated once they've
been constructed [*]. I haven't seen a use case that would need to
avoid revising nodes in a shared sub-tree; when such a use case comes
up, we'll figure something out.
- Doug
[*] Sema does some limited mutation of AST nodes, as does the PCH
reader, but most clients won't ever see these AST nodes until all
mutation has already been performed.
More information about the cfe-dev
mailing list