Skip to content

[libSyntax] Make RawSyntax a struct #18276

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

Merged
merged 2 commits into from
Jul 27, 2018

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Jul 27, 2018

SourcePresence and ID are already shared between the two node kinds and the node's length will soon be cached in RawSyntax as well. By making it a struct, this shared data can be stored more easily.

ahoppen added 2 commits July 26, 2018 20:46
SourcePresence and ID are already shared between the two node kinds and
the node's length will soon be cached in RawSyntax as well. By making it
a struct, we will be able to compute the node's length when it is being
constructed in the initialiser.
@ahoppen ahoppen requested review from rintaro and nkcsgexi July 27, 2018 03:49
@ahoppen
Copy link
Member Author

ahoppen commented Jul 27, 2018

@swift-ci Please smoke test

@nkcsgexi
Copy link
Contributor

Probably @harlanhaskins should take a look at this.

@nkcsgexi nkcsgexi requested a review from harlanhaskins July 27, 2018 05:22
@harlanhaskins
Copy link
Contributor

LGTM, this refactoring was bound to happen. Thanks for doing it @ahoppen!

@@ -43,53 +53,57 @@ struct SyntaxNodeId: Hashable, Codable {
}
}

/// The data that is specific to a tree or token node
fileprivate indirect enum RawSyntaxData {
Copy link
Member

@rintaro rintaro Jul 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this is declared as indirect? I know the original RawSyntax was also indirect. @harlanhaskins, what was the reason? maybe MemoryLayout<RawSyntax>.size?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the time of writing, it ensured both cases were heap allocated and that a copy = a retain, so we could share raw data. Pretty sure that is still the case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because .node has RawSyntax as its member which again has RawSyntaxData as one of its members. That's a cycle and thus the object size wouldn't be determined at runtime if the enum is not indirect.

Or TL;DR: It doesn't compile if the enum isn't indirect.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should still compile. It’s already got a layer of indirection via the array of RawSyntax?.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahoppen It does compile because [RawSyntaxData] provides indirect semantics.

Copy link
Member

@rintaro rintaro Jul 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the time of writing, it ensured both cases were heap allocated and that a copy = a retain, so we could share raw data.

Makes sense. Thanks :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does compile because [RawSyntaxData] provides indirect semantics.

Hmm. I was pretty sure it didn't compile at some point without indirect. But maybe that was just my imagination. @harlanhaskins's explanation makes sense. I'll leave it as is.

@ahoppen ahoppen merged commit 4483276 into swiftlang:master Jul 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants