Skip to content

Reduce number of raw: interpolations in CodeGeneration #1977

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

Closed
ahoppen opened this issue Aug 2, 2023 · 5 comments · Fixed by #2086
Closed

Reduce number of raw: interpolations in CodeGeneration #1977

ahoppen opened this issue Aug 2, 2023 · 5 comments · Fixed by #2086
Assignees
Labels
CodeGeneration Changes to the CodeGeneration package that generates code in swift-syntax refactoring An internal refactoring of the codebase

Comments

@ahoppen
Copy link
Member

ahoppen commented Aug 2, 2023

CodeGeneration still uses many raw: interpolations, which should be avoided unless it’s really necessary. Some of these raw: interpolations don’t need to the raw: label anymore. For some others, we could restructure how nodes are represented in SyntaxSupport to use TokenSyntax instead of String, similar to what I’ve done in #1914.

@ahoppen ahoppen added refactoring An internal refactoring of the codebase CodeGeneration Changes to the CodeGeneration package that generates code in swift-syntax labels Aug 2, 2023
@ahoppen
Copy link
Member Author

ahoppen commented Aug 2, 2023

Tracked in Apple’s issue tracker as rdar://113237456

@Matejkob
Copy link
Contributor

Matejkob commented Aug 13, 2023

I've grabbed the lowest-hanging fruit and removed all the no-longer-needed raw: interpolations. Further reductions in the use of raw: will require changing types.

@Matejkob
Copy link
Contributor

So actually, if I've already started doing things related to this issue, I can do the whole thing.

@Matejkob
Copy link
Contributor

We've already eliminated most of the raw: interpolations in CodeGeneration. I have a few more potential places in mind where we could eliminate them, but some of them seem to be incorrect. I would love to hear your feedback @ahoppen @kimdv

  • Node.getter:parserFunction - I'm thinking of changing the type to TokenSyntax. If I'm not mistaken, the function identifier is of this type, right?
  • let optionalMark = child.isOptional ? "?" : "" into let optionalMark: TokenSyntax = child.isOptional ? TokenSyntax.postfixQuestionMarkToken() : TokenSyntax(""). The second branch of this condition seems to be incorrect. TokenSyntax = "" doesn't feel right, does it?
  • let iuoMark = child.isOptional ? "" : "!" into let iuoMark: TokenSyntax = child.isOptional ? TokenSyntax("") : TokenSyntax.exclamationMarkToken().

Let me know if there are any issues with these changes or if you can identify other potential usages of raw: that could be eliminated but I've missed them.

@ahoppen
Copy link
Member Author

ahoppen commented Aug 18, 2023

  • Node.getter:parserFunction - I'm thinking of changing the type to TokenSyntax. If I'm not mistaken, the function identifier is of this type, right?

Yes, that seems like a good change to me

  • let optionalMark = child.isOptional ? "?" : "" into let optionalMark: TokenSyntax = child.isOptional ? TokenSyntax.postfixQuestionMarkToken() : TokenSyntax(""). The second branch of this condition seems to be incorrect. TokenSyntax = "" doesn't feel right, does it?
  • let iuoMark = child.isOptional ? "" : "!" into let iuoMark: TokenSyntax = child.isOptional ? TokenSyntax("") : TokenSyntax.exclamationMarkToken().

You are correct, TokenSyntax("") doesn’t make any sense. What we could do, is add a new appendInterpolation method to SyntaxStringInterpolation that takes an optional syntax nodes. If the node is nil, it just doesn’t add any interpolation. In that case you could have let optionalMark = child.isOptional ? TokenSyntax.postfixQuestionMarkToken() : nil.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CodeGeneration Changes to the CodeGeneration package that generates code in swift-syntax refactoring An internal refactoring of the codebase
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants