Skip to content

Implement code generation as a three-step process #583

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
Aug 23, 2022

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Aug 12, 2022

To make sure code generation works when adding new nodes, implement it as a three-stage process.

  1. Re-generate the gyb files in SwiftSyntaxBuilderGeneration. This only re-generates the Swift files which essentially match the Python files in gyb_syntax_support. This does not generate any new syntax nodes etc.
  2. Run code generation using SwiftSyntaxBuilder (i.e. run SwiftSyntaxBuilderGeneration). This still compiles because stage 1 did not modify any types in SwiftSyntax
  3. Generate the remaining gyb files to match the files that were generated using SwiftSyntaxBuilderGeneration in step 2. Since this is Python, it will always pass.

Resolves #577

@ahoppen
Copy link
Member Author

ahoppen commented Aug 12, 2022

@swift-ci Please test

Copy link
Contributor

@CodaFi CodaFi left a comment

Choose a reason for hiding this comment

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

Approach LGTM. I was able to successfully use swiftlang/swift#60629 to test this.

To make sure code generation works when adding new nodes, implement it as a three-stage process.

1. Re-generate the gyb files in SwiftSyntaxBuilderGeneration. This only re-generates the Swift files which essentially match the Python files in gyb_syntax_support. This does not generate any new syntax nodes etc.
2. Run code generation using SwiftSyntaxBuilder (i.e. run SwiftSyntaxBuilderGeneration). This still compiles because stage 1 did not modify any types in SwiftSyntax
3. Generate the remaining gyb files to match the files that were generated using SwiftSyntaxBuilderGeneration in step 2. Since this is Python, it will always pass.

Resolves swiftlang#577
@ahoppen ahoppen force-pushed the pr/three-stage-code-generation branch from d0a2302 to d5fdbbb Compare August 18, 2022 21:03
@ahoppen
Copy link
Member Author

ahoppen commented Aug 18, 2022

@swift-ci Please test

1 similar comment
@ahoppen
Copy link
Member Author

ahoppen commented Aug 23, 2022

@swift-ci Please test

@ahoppen ahoppen merged commit f9fab58 into swiftlang:main Aug 23, 2022
@ahoppen ahoppen deleted the pr/three-stage-code-generation branch August 23, 2022 12:25
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.

SwiftSyntaxBuilderGeneration Cannot Depend on SwiftSyntaxBuilder
2 participants