Skip to content

Add a version indicator macro to indicate the swift-syntax version a client is building against #2050

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 22, 2023

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Aug 11, 2023

All swift-syntax versions ≥ 509 will include a module SwiftSyntax509 and all swift-syntax versions ≥ 510 will include both SwiftSyntax509 and SwiftSyntax510. This way clients can check which version of swift-syntax they are building against using e.g.

#if canImport(SwiftSyntax510)
// code specific to swift-syntax version >= 510
#else
// code for swift-syntax < 510
#endif


## Detailed Explanation

All the ideas described in the following apply to all packages that depend on swift-syntax, not only macros.

For simplicity, this article assumes that `509` is the current swift-syntax version and `510` the next, but everything applies to any other major swift-syntax version update, including version jumps to `600`.
For simplicity, this article assumes that 509 is the current swift-syntax version and `510` the next, but everything applies to any other major swift-syntax version update, including version jumps to e.g. 600.
Copy link
Contributor

Choose a reason for hiding this comment

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

Inconsistent with wrapping version in `` and not. I think it's just the one 510 that is wrapped now.


Any client package that depends on the macro using an `from: "1.0"` and doesn’t have any other transitive dependencies on swift-syntax will automatically receive version `1.3` of the macro when updating the package dependencies using `swift package update` or Xcode’s *Update to Latest Package Versions* command.
Since swift-syntax 510 might have introduced source-breaking changes. If the macro uses any of the APIs that have changes it needs to use conditional compilation clauses that check the version of swift-syntax it is building against. For that purpose, swift-syntax contains marker modules. All versions of swift-syntax ≥ 509 include a `SwiftSyntax509` module. Similarly, swift-syntax ≥ 510 includes a `SwiftSyntax510` and `SwiftSyntax509` module. This allows clients to write
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Since swift-syntax 510 might have introduced source-breaking changes. If the macro uses any of the APIs that have changes it needs to use conditional compilation clauses that check the version of swift-syntax it is building against. For that purpose, swift-syntax contains marker modules. All versions of swift-syntax ≥ 509 include a `SwiftSyntax509` module. Similarly, swift-syntax ≥ 510 includes a `SwiftSyntax510` and `SwiftSyntax509` module. This allows clients to write
In order to handle breaking API changes, clients can wrap uses of such APIs in conditional compilation clauses that check the version of swift-syntax it is building against. Empty version modules will be used to allow such a check. All versions of swift-syntax ≥ 509 will include an empty `SwiftSyntaxVersion509` module, swift-syntax ≥ 510 will include both a `SwiftSyntaxVersion510` and `SwiftSyntaxVersion509` module, and so on for any new releases. This allows clients to write

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed the Empty version modules will be used to allow such a check from your suggestion and added the following at the end instead:

The `SwiftSyntax<version>` modules are empty and don’t contain any code. Their only purpose is to serve as targets for the `canImport` checks.

@ahoppen ahoppen force-pushed the ahoppen/version-indicator-module branch from 78209c1 to 38f9b2b Compare August 11, 2023 18:40
@ahoppen
Copy link
Member Author

ahoppen commented Aug 18, 2023

@swift-ci Please test


When starting to write a macro, no special considerations need to be made with regard to versioning. Depending on swift-syntax as with `from: "509.0.0"` will make sure that the macro receives any bug fix updates to swift-syntax 509. For example, a macro depending on swift-syntax 509 might be released as version 1.0, 1.2, 2.0, …
Any given version macro can depend on multiple major swift-syntax versions at once. For example, if a macro supports both swift-syntax 509 and swift-syntax 510 may declare its dependency on swift-syntax as
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Any given version macro can depend on multiple major swift-syntax versions at once. For example, if a macro supports both swift-syntax 509 and swift-syntax 510 may declare its dependency on swift-syntax as
Any given version macro can depend on multiple major swift-syntax versions at once. For example, if a macro supports both swift-syntax 509 and swift-syntax 510, it may declare its dependency on swift-syntax as

…client is building against

All swift-syntax versions ≥ 509 will include a module `SwiftSyntax509` and all swift-syntax versions ≥ 510 will include both `SwiftSyntax509` and `SwiftSyntax510`. This way clients can check which version of swift-syntax they are building against using e.g.

```swift
#if canImport(SwiftSyntax510)
// code specific to swift-syntax version >= 510
#else
// code for swift-syntax < 510
#endif
```
@ahoppen ahoppen force-pushed the ahoppen/version-indicator-module branch from 38f9b2b to 002bbbd Compare August 21, 2023 21:48
@ahoppen
Copy link
Member Author

ahoppen commented Aug 21, 2023

@swift-ci Please test

@ahoppen ahoppen enabled auto-merge August 21, 2023 21:48
@ahoppen
Copy link
Member Author

ahoppen commented Aug 21, 2023

@swift-ci Please test Windows

@ahoppen ahoppen merged commit 75e68f3 into swiftlang:main Aug 22, 2023
@ahoppen ahoppen deleted the ahoppen/version-indicator-module branch August 22, 2023 20:58
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.

3 participants