-
Notifications
You must be signed in to change notification settings - Fork 422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use RawSyntax address as the 'rootId' of SyntaxIdentifier #635
Conversation
We don't need to guarantee the uniqueness throughout the process lifetime. but only need to guarantee the uniqueness while the object is alive. This removes `_CSwiftSyntax` dependency from `SwiftSyntax` module.
@swift-ci Please test |
Would this prevent sharing of RawSyntax objects? As I mentioned I'd suggest that we treat RawSyntax objects as "slabs of data" and not try to infer any kind of identity out of them. |
No, let raw: RawSyntax = ...
let tree1 = Syntax(raw: raw)
let tree2 = Syntax(raw: raw) Previously let tree1 = Syntax(raw: raw)
let tree2 = tree1 |
When sharing a let raw: RawSyntax = ...
let tree1 = Syntax(raw: raw)
let tree2 = Syntax(raw: raw.children[0])
let id1 = tree1.child(at: 0).id
let id2 = tree2.id here, let child: RawSyntax...
let tree1 = Syntax(raw: .makeLayout(elements: [child], arena: arena))
let tree2 = Syntax(raw: .makeLayout(elements: [child], arena: arena))
let id1 = tree1.child(at: 0).id
let id2 = tree2.child(at: 0).id
|
To make sure I understand the proposed semantic change, the notion of "syntax identity" changes from "identity is guaranteed to be different between created syntax trees" to "identity may be the same if you created 2 trees and they ended up with the same RawSyntax tree structure". So for example, if I parse the same file twice, previously I would be guaranteed to get different identities but after this change their identity could be the same. And from your example:
id1 and id2 are different now but they could be the same, right? A future implementation could re-use the same To clarify, I think such a change would be fine, I mainly want to make sure I'm following along with what is being proposed. |
To clarify, this is not just theoretical, a future implementation could be providing caching by associating source file contents with its associated RawSyntax tree, in which case parsing the same file twice would give you the same |
Right. if 1) we implement incremental parsing, 2) we detect the file is exactly the same as the previous parsing, and 3) we decide to reuse the existing root
Since |
Oh, maybe you are thinking |
Going back to my earlier comment:
Within this context I'm fine if the answer is that a |
I didn't think about it deeply. I was just adding BTW, I don't think I fully understand your first argument that "Would this prevent sharing of RawSyntax objects?". I haven't come up with a scenario where identifying |
This depends on the implementation. Using the raw pointer should be fine (given they are immutable), but, for example, imagine we got rid of "rooId+indexInTree" and replaced it with a "RawSyntax.uniqueId" construct where every RawSyntax gets its own |
When you merge this, you can also remove |
@akyrtzi Thank you for the explanation, and thank you for all your inputs! |
We don't need to guarantee the uniqueness throughout the lifetime of the process, but only need to guarantee the uniqueness while the object is alive.
This removes
_CSwiftSyntax
dependency fromSwiftSyntax
.