Support for swift-format on Xcode-beta 13.0b1?

So I'm building a library that supports 5.4 but would also like to support some newer async APIs when swift 5.5 is available.

The problem I have is that the formatter in the 5.4 branch doesn't understand that try await is valid syntax, and instead does this:

--- a/Sources/APIBuilder/DefaultRequestExecutor.swift
+++ b/Sources/APIBuilder/DefaultRequestExecutor.swift
@@ -25,7 +25,7 @@ public class DefaultRequestExecutor: RequestExecutor {
     @available(swift 5.5)
     @available(macOS 12.0, *)
     public func execute(_ request: URLRequest) async throws -> Response {
-        let (data, response) = try await urlSession.data(for: request)
+        let (data, response) = try awaiturlSession.data(for: request)
         guard let httpResponse = response as? HTTPURLResponse else {
             throw StringError("Unknown error")
         }

where it joins the await keyword to the statement to await (which is somewhat weird since I'd expect it to fail on unknown syntax instead, but I digress)

I guess my question is about general guidance on what to do here. I tried building swift-format from main, but it then fails with The loaded '_InternalSwiftSyntaxParser' library is from a toolchain that is not compatible with this version of SwiftSyntax, this is on macOS 12.0 beta 1 with Xcode 13 beta 1.

Am I out of luck for now and need to disable the formatter? Ideally what I want is for the formatter to skip #if swift(>=5.5) ... #endif but I can see how that might not be trivial.

1 Like

To build the formatter against a newer toolchain, you'd need to update the swift-syntax dependency to be the one that matches the toolchain you're building against, since the syntax hash in the swift-syntax sources need to match the one in the toolchain's parser dylib to verify that they're compatible.

After the extended holiday weekend, I can start a 5.5-compatible branch that's compatible with the Xcode 13 beta and adds breaks in appropriate places for some of the new syntax additions (like the AwaitExpr node, in this case).

1 Like

This is (finally!) done; the swift-5.5-branch is currently compatible with Xcode 13.0 beta 3, and I'll keep it updated as needed when new betas and the final release land.

The latest updates should produce better results when using the newer concurrency constructs. One new language feature, postfix-#if expressions, is still a work in progress.

5 Likes

:partying_face: For anyone using GitHub Actions for their formatting, this is what's working for us:

1 Like

And since Xcode 13.0 beta 4 (13A5201i) was released a day after I cut that branch, I'm relieved happy to report that it's still compatible with that version too.

(There is an incompatible change in the swift-syntax 5.5 release branch that I thought might require an update, but it looks like it's not included in the most recent Xcode yet.)

Terms of Service

Privacy Policy

Cookie Policy