async let combination crashes on XCode 16 with iOS 15 as minimum deployment

We started building our project in XCode 16 only to find a super weird crash that was 100% reproducible.

I couldn't really understand why it was crashing, so I tried to trim down the problematic piece of code to something that I could provide in a side project. The actual piece of code crashing for us is significantly different, but this small example showcases the crash as well.

https://github.com/Elih96/XCode16CrashReproducer

our observation is, that this combination of async let usage + struct structure leads to a SIGABRT crash in the concurrency library.

In both the main project and the example project, moving away from async let and using any other concurrency mechanism fixes the crash.

This was reproducible only on Xcode 16 with iOS 15 set as minimum deployment for the target. It works fine on Xcode 15, and if we bump the min deployment to 16 on Xcode 16, it also runs fine. I've attached a small project that reproduces the error.

I'm sure I didn't provide the ideal reproduction scenario, but that's what I managed to trim it down to. Making random changes such as removing some properties from the B struct or remove the: let _ = A().arrayItems.map { _ in "123" } will stop the crash from happening, so I just stopped making changes.

The stack trace from the crash:

    frame #0: 0x00000001036d1008 libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x0000000102ecf408 libsystem_pthread.dylib`pthread_kill + 256
    frame #2: 0x00000001801655c0 libsystem_c.dylib`abort + 104
    frame #3: 0x000000020a8b7de0 libswift_Concurrency.dylib`swift::swift_Concurrency_fatalErrorv(unsigned int, char const*, char*) + 28
    frame #4: 0x000000020a8b7dfc libswift_Concurrency.dylib`swift::swift_Concurrency_fatalError(unsigned int, char const*, ...) + 28
    frame #5: 0x000000020a8baf54 libswift_Concurrency.dylib`swift_task_dealloc + 124
    frame #6: 0x000000020a8b72c8 libswift_Concurrency.dylib`asyncLet_finish_after_task_completion(swift::AsyncContext*, swift::AsyncLet*, void (swift::AsyncContext* swift_async_context) swiftasynccall*, swift::AsyncContext*, void*) + 72
  * frame #7: 0x000000010344e6e4 CrashReproducer.debug.dylib`closure #1 in closure #1 in CrashReproducerApp.body.getter at CrashReproducerApp.swift:17:46
    frame #8: 0x00000001cca0a560 SwiftUI`___lldb_unnamed_symbol158883
    frame #9: 0x00000001cca09fc0 SwiftUI`___lldb_unnamed_symbol158825
    frame #10: 0x00000001cca063a0 SwiftUI`___lldb_unnamed_symbol158636
    frame #11: 0x00000001cca09268 SwiftUI`___lldb_unnamed_symbol158726
Answered by DTS Engineer in 809218022

Have you reported this officially yet? If not, please do. See Bug Reporting: How and Why? for advice on how to do that.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Have you reported this officially yet? If not, please do. See Bug Reporting: How and Why? for advice on how to do that.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

If that may help, I noticed other cases (SwiftUI Mac app) where Xcode 16 generates code that does not work properly when run on MacOS 14 but OK on MacOS 15.

And the same code works OK when compiled on Xcode 15.

Here is the FB for reference: FB15429756

Reported officially today, here's the number for reference: FB15517397

The same crash happens on visionOS regardless of minimum deployment.

To replicate, just create a target in the example project for visionOS and run the same code.

The crash might be related to SWIFT_STRUCTURED_CONCURRENCY = complete. If the value is set to minimal or targeted, the crash doesn't occur even with iOS 15 set as minimum deployment for the target.

async let combination crashes on XCode 16 with iOS 15 as minimum deployment
 
 
Q