Significant changes in the latest swift-syntax 509 prerelease

The swift-syntax 509.0.0 prerelease snapshot published today has a large number of changes compared to previous 509 prereleases. It contains, among others:

  • Renames of syntax node, making their names more consistent and descriptive. Most of these changes should be API-compatible by continuing to offer the old API as deprecated alternatives.
  • Improved documentation, like a Children section on each that lists the children that node can have as well as a Contained In section that lists all possible parents of a node.
  • An updated implementation of assertMacroExpansion that is more closely aligned to the implementation the compiler uses #1946

Overall, we judged that it causes less churn to make these changes now compared to releasing the changes in the Swift 5.10-aligned release of swift-syntax, after its user base has grown more. Compared to the last swift-syntax 509 prerelease, most changes should be API-compatible through the introduction of deprecated compatibility APIs.

We feel that swift-syntax's API has matured a lot over the last months and are hoping to keep future releases more API-compatible than they have been in the past. Some amount of breaking changes may always be necessary as the language evolves, but these will be reflected by incrementing the major version.


Another notable change is that as per SE-0402, ConformanceMacro no longer exists and is now covered by ExtensionMacro instead.

Rather than constructing separate TypeSyntax and GenericWhereClauseSyntax for the conforming type and its where clause, ExtensionMacro returns the extensions themselves. Taking a simple example:

  public static func expansion(
    of node: AttributeSyntax,
    providingConformancesOf declaration: some DeclGroupSyntax,
    in context: some MacroExpansionContext
  ) throws -> [(TypeSyntax, GenericWhereClauseSyntax?)] {
    return [("SomeProto", nil)]

Would become:

  public static func expansion(
    of node: AttributeSyntax,
    attachedTo declaration: some DeclGroupSyntax,
    providingExtensionsOf type: some TypeSyntaxProtocol,
    conformingTo protocols: [TypeSyntax],
    in context: some MacroExpansionContext
  ) throws -> [ExtensionDeclSyntax] {
    let newExtension = try ExtensionDeclSyntax("extension \(type): SomeProto") {}
    return [newExtension]

And there's a PR up to allow try ExtensionDeclSyntax("extension \(type): SomeProto {}") instead.

1 Like