-
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
Bump allocated RawSyntax #544
Conversation
switch kind { | ||
case 0: | ||
return false | ||
return .spaces(text.count / 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not emit a division when the base is 1 like this?
@@ -0,0 +1,113 @@ | |||
//===------------------ RawSyntax.swift - Raw Syntax nodes ----------------===// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Header should reflect the file name.
* Introduce 'SyntaxArena' that manages the memory of RawSyntax * 'RawSyntax' now has - Unowned pointer to the 'SyntaxArena' - Tagged union of "token" or "layout" where all data are managed by the 'SyntaxArena' * Root 'SyntaxData' now 'SyntaxArena' of the root 'RawSyntax'
219743b
to
6511704
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You love to see it.
1c41cae
to
c08a749
Compare
c08a749
to
95daf90
Compare
@swift-ci Please test |
The test error is:
The difference is NOTE: This happens because I removed the stored "source presence" flag from RawSyntax, and tokens with empty string is now considered |
@swift-ci Please test |
@swift-ci Please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, looks really good to me. I’ve got a few comments, mostly regarding doc comments, inline. Some general comments:
- I’m not sure we should use
RawTriviaPiece.make
instead of an initializer. But we can discuss this as a follow-up. - Looking through this, I’m not sure if you’re always consistent whether
SyntaxArena
is the first or last parameter. I think we should be consistent in this. - Should the preconditions be assertions instead that are disabled in Release builds?
- Would it make sense to group methods on
RawSyntax
into three different categories (which are different extensions, separated by a// MARK: -
):- Methods that work on all
RawSyntax
nodes - Methods that fail a
precondition
when invoked on tokens - Methods that fail a
precondition
when invoked on layouts
- Methods that work on all
And if you make any changes to this PR, could you make them in separate commits. That would make reviewing of these changes a lot easier because I don’t have to look through all the other changes again. And then you can squash once we agree this PR is good to merge.
// Allocate and initialize the list. | ||
let layoutBuffer = arena.allocateRawSyntaxBuffer(count: count) | ||
initializer(layoutBuffer) | ||
// validateLayout(layout: RawSyntaxBuffer(layoutBuffer), as: kind) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you intend to add the validation again or are we dropping it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding. To be precise, I'm moving the validation from Syntax
to RawSyntax
.
https://github.com/rintaro/swift-syntax/blob/bump-ptr-allocation-and-everything/Sources/SwiftSyntax/gyb_generated/SyntaxValidation.swift
And do it whenever it's created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I’m fine with adding validation again in a follow-up PR.
The current rule is:
I think |
I only used |
Yes totally. I think we could even split them into separate files. But I just tried to keep the existing code/method order to keep this PR as small as possible. |
- arena: SyntaxArena goes the last - Remove RawSyntax: Identifiable
swiftlang/swift-stress-tester#183 |
1 similar comment
swiftlang/swift-stress-tester#183 |
This reverts commit 2cb6af7.
swiftlang/swift-stress-tester#183 |
1 similar comment
swiftlang/swift-stress-tester#183 |
a3e87ba
to
57fa10d
Compare
swiftlang/swift-stress-tester#183 |
SyntaxArena
that manages the memory ofRawSyntax
RawSyntaxData
is the "data" of raw syntax managed bySyntaxArena
, and it hasSyntaxArena
SyntaxArena
RawSyntax
is now just a pointer wrapper ofRawSyntaxData
and APIs.SyntaxData
now owns theSyntaxArena
of the rootRawSyntax
.For intermediate solution
SyntaxArena
hasstatic var default
which is used by Factory methods. This cannot be a permanent solution because it's never deallocate the memory. In future all factory methods will require explicitarena
to use.