Skip to content

[NFC][ASTGen] Add wrapping structs for commonly bridged types #66044

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 1 commit into from
Jun 6, 2023

Conversation

bnbarham
Copy link
Contributor

@bnbarham bnbarham commented May 21, 2023

Adds wrapping structs for a bunch of commonly bridged types (but not all the AST nodes yet).

@bnbarham
Copy link
Contributor Author

@swift-ci please test

@bnbarham
Copy link
Contributor Author

@swift-ci please test

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Some comments from an initial review of the first couple of lines.

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Thank you so much for making ASTGent at least a little bit less awful.

Comment on lines 262 to 265
Diagnostic_create(
cxxDiagnosticEngine, bridgedSeverity,
cxxSourceLocation(at: position),
messageBuffer.baseAddress, messageBuffer.count)
bridgedSourceLoc(at: position),
bridgedMessage)
Copy link
Member

Choose a reason for hiding this comment

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

Note to myself: We should also run swift-format on the ASTGen sources, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that'd be nice.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Note to myself: We should also run swift-format on the ASTGen sources, I think.

I’ve been doing some progress on ASTGen the past few days as well and I figured to borrow the .swift-format file from swift-syntax with a line length adjusted to 100. Do we want it to be 80 as in the Standard Library?

Copy link
Member

@ahoppen ahoppen May 26, 2023

Choose a reason for hiding this comment

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

Just for the record: I very much like not having a maximum line length in swift-syntax because in my experience the line length limitation sometimes causes us choose less descriptive, shorter variable names. And in my opinion it hasn’t lead to excessively long lines.

Also, just to make an informed decision, here’s a chart of the line lengths in non-generated SwiftSyntax code.

Screenshot 2023-05-26 at 10 31 06

Some key data points:

  • ≤160 characters: 99.9%
  • ≤150 characters: 99.8%
  • ≤140 characters: 99.7%
  • ≤130 characters: 99.5%
  • ≤120 characters: 99.1%
  • ≤110 characters: 98.6%
  • ≤100 characters: 97.9%
  • ≤90 characters: 96.7%
  • ≤80 characters: 94.4%

Also, I think that the format (and thus the maximum line length) should be consistent between swift-syntax and ASTGen.

So: If we want to impose a maximum line length (and just to be clear, I like the freedom of not having a maximum line length but the general consensus is that people want a restriction here), I would like to pick one for swift-syntax and then also use that for ASTGen.

I just did some tests on swift-syntax and all changes for the line length to 160 seemed reasonable to me. Dropping it to 150 already gave me a couple cases where I preferred the previous formatting. The trend continue as I dropped it further.

Copy link
Collaborator

@AnthonyLatsis AnthonyLatsis May 27, 2023

Choose a reason for hiding this comment

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

Thanks for the visuals!

Also, I think that the format (and thus the maximum line length) should be consistent between swift-syntax and ASTGen.

Sure, I generally think having a single format across swift-syntax and Swift parts of the compiler would be great.

I just did some tests on swift-syntax and all changes for the line length to 160 seemed reasonable to me. Dropping it to 150 already gave me a couple cases where I preferred the previous formatting. The trend continue as I dropped it further.

I guess it has to be a compromise based on what line length reasonably fits on most of our screens without wrapping. Either way I do believe we need some kind of limit below 200 that we can use and refer to in reviews or else this is bound to get out of control. Personally, I probably wouldn’t be fine with anything more than 160.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Something is better than nothing, so if that's 160 I'm personally fine with that :)

@bnbarham bnbarham force-pushed the cleanup-astgen branch 3 times, most recently from 3e7af98 to 0cb2560 Compare May 27, 2023 03:24
@bnbarham bnbarham changed the title [NFC] ASTGen cleanup [NFC][ASTGen] Add wrapping structs for commonly bridged types May 27, 2023
@bnbarham
Copy link
Contributor Author

@swift-ci please test

@bnbarham
Copy link
Contributor Author

@swift-ci please test macOS platform

@bnbarham
Copy link
Contributor Author

@swift-ci please test Linux platform

Adds wrapping structs for a bunch of commonly bridged types (but not all
the AST nodes yet).
@bnbarham
Copy link
Contributor Author

bnbarham commented Jun 2, 2023

@swift-ci please test

@bnbarham
Copy link
Contributor Author

bnbarham commented Jun 3, 2023

@swift-ci please test macOS platform

@bnbarham bnbarham merged commit 2ab4d7b into swiftlang:main Jun 6, 2023
@bnbarham bnbarham deleted the cleanup-astgen branch June 6, 2023 18:14
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