AVAssetExportSession's export causes "Command SwiftCompile failed with a nonzero exit code" with new XCode 16 beta 4. Was fine on beta 3

I have a project I've been preparing for Swift6 and the complete concurrency checking. As of beta 3 I had everything compiling and running ok but as soon as I've installed beta 4 I'm unable to build the project using Swift6 mode (it still compiles and runs on Swift5 mode).

I don't see any clue on what the problem might be (I'm guessing the compiler is choking on some piece of code somewhere) and the logs don't help. All I see is the SwiftCompile command with all its parameters and a huge list of swift files. No specific error message. I also don't see anything on the console's crash reports.

Any clues how to get more info? Should I file a bug? I'm not sure how that can be helpful without any other information to share about the problem...

Or maybe I should just wait and see if this is fixed by next beta...

Edit: I've tried all the usual fixes such as clean build and deleting the derived data folder and resetting packages caches

Update: I've located the problem file and the problem line:

try await exporter.export(to: destinationURL, as: AVFileType.m4a)

Commenting that line removes the error and the project compiles fine. I had that inside an if #available(iOS 18, *) clause that reverted to the old (now deprecated) export() for iOS17 and below.

If you'll go to report navigator on the left panel (the last one icon there) and open failed build logs, you can find the log with this error like that:

By tap on this "hamburger" on the right side, you can expand actual error that caused this (you will need to scroll through the build command first to get to actual stack dump). It will then help to understand what's wrong (might be a compiler bug, for example).

Thanks. I can't find anything resembling an error on that text. It's basically a line starting with "SwiftCompile normal arm64..." and ending with "(in target 'TargetName' from project 'ProjectName)". Then another line with a cd command and then a huge line starting with "builtin-swiftTaskExecuion -- /path/to/swift-frontent -c -filelist" and a huge list of paths to different files ending with "-index-system-modules". Nothing like an actual error message in there...

Maybe there is another one "hamburger"? Sometimes Xcode (50% times, actually) goes nuts and gives you something like that:

And one of these have only information you mention, but another have more detailed logs. I'm more often than not finally manage to retrieve stack dump out of there, but it might not be from the first try.

You can also try run xcodebuild command from console by yourself, there at least Xcode's UI won't be an issue.

As last alternative, if possible, try to isolate code that you can suspect to cause an error (I think probably something migrated to new concurrency, especially if it uses region-based isolation or dynamic isolation – that's top from my experience that causes crashes for compiler right now).

No luck... There's no second hamburger menu and building using the terminal gives me exactly the same output with just the generic "Command SwiftCompile failed with a nonzero exit code"

Thanks for the help! I'll try to isolate possible code that may cause the issue. It's going to take a while but unless this is fixed on the next beta it looks like the only solution...

Here an example of a stack dump from a crash I found. You can probably find the stack dump starting after the program arguments (which are all the files passed as arguments to swift-frontend -frontend -c.

Thanks. I see nothing like a stack dump. It's just the command with all the parameters and options. Edit: In fact I can copy the whole command and run it in the terminal. And it doesn't produce anything I can identify as an error/crash. It's only when building (either on XCode or with xcodebuild) that the failure is reported, but nothing more

Edit: I've updated the first post. Commenting the line "try? await exporter.export(to: destinationURL, as: AVFileType.m4a)" fixes the compiler error.

I've tried to copy my function to a new project and it compiles fine. It also gives me a warning about the function status from AVAssetExportSession being deprecated and to use progressStates(updateInterval:) for which I find no documentation and XCode won't recognise it. I guess it's not ready yet...

It's strange that this code compiles fine under beta 3 and also using Swift5 mode with beta4. I'll file a bug but I'm guessing this should be fixed as we get near the final release...

This is the function (from a NSObject @MainActor class)

func convert(sourceURL: URL, destinationURL: URL, success: ( @Sendable ()->Void)?, failure: ( @Sendable ()->Void)? ) {
        Task {
            let started = now()
            print("started \(started)")
            let asset = AVURLAsset(url: sourceURL)
            if let exporter = AVAssetExportSession(asset: asset, presetName: AVAssetExportPresetAppleM4A) {
                if #available(iOS 18, *) {
                    try? await exporter.export(to: destinationURL, as: AVFileType.m4a)
                } else {
                    exporter.outputFileType = AVFileType.m4a
                    exporter.outputURL = destinationURL
                    await exporter.export()
                }
                
                switch exporter.status {
                case .failed:
                    print("failed \(exporter.error.debugDescription)")
                    if let c = failure {
                        c()
                    }
                case .cancelled:
                    print("cancelled \(exporter.error.debugDescription)")
                    if let c = failure {
                        c()
                    }
                default:
                    print("complete")
                    if let c = success {
                        c()
                    }
                }
                
            }
        }
    }

Edit: removed the line "let e = exporter". I had to add it or else XCode 16 beta 3 would complain (a bug I guess). This is no longer a problem in Beta 4

I think that's something to do with dynamic isolation and new #isolation macro, as this new export utilizes it:

And in GitHub repo you can find several issues with compiler crash related to that.

1 Like

Thanks! Glad to see it's been already documented then. For the record, I tried adding the isolation parameter with different values and the problem persists... Anyway, I don't think this will be a problem in the near future.