swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.31k stars 10.34k forks source link

Regression: withTaskGroup crashes immediately for iOSAppOnMac #75771

Open KaiOelfke opened 1 month ago

KaiOelfke commented 1 month ago

Description

With Xcode 16.0 beta 5 and Swift 6.0 (6.0.0.7.6) the code sample below crashes, when running as iOS app on mac (iOS apps can run on macOS devices with Apple Silicon). E.g. this applies to destinations where https://developer.apple.com/documentation/foundation/processinfo/3608556-isiosapponmac ProcessInfo.processInfo.isiOSAppOnMac is true.

Reproduction

Create a new iOS SwiftUI project with the default template and extend the template ContentView with a task modifier and a task group or just use withTaskGroup anywhere else.

import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundStyle(.tint)
            Text("Hello, world!")
        }
        .padding()
        .task {
            await withTaskGroup(of: Void.self) { _ in } // Thread 1: EXC_BAD_ACCESS (code=1, address=0x4)
        }
    }
}

Stack dump

Thread 1: EXC_BAD_ACCESS (code=1, address=0x4)

    0x102e3d1cc <+204>: str    x10, [x22]
    0x102e3d1d0 <+208>: adrp   x10, 0
    0x102e3d1d4 <+212>: add    x10, x10, #0x260          ; (1) await resume partial function for back deployment thunk for Swift.withTaskGroup<ChildTaskResult, GroupResult where ChildTaskResult: Swift.Sendable>(of: ChildTaskResult.Type, returning: GroupResult.Type, isolation: isolated Swift.Optional<Swift.Actor>, body: (inout Swift.TaskGroup<ChildTaskResult>) async -> GroupResult) async -> GroupResult at <compiler-generated>
    0x102e3d1d8 <+216>: str    x10, [x22, #0x8]
    0x102e3d1dc <+220>: str    x9, [x29, #0x10]
    0x102e3d1e0 <+224>: ldp    x29, x30, [sp, #0x70]
    0x102e3d1e4 <+228>: and    x29, x29, #0xefffffffffffffff
    0x102e3d1e8 <+232>: add    sp, sp, #0x80
    0x102e3d1ec <+236>: br     x8
    0x102e3d1f0 <+240>: adrp   x8, 7
    0x102e3d1f4 <+244>: ldr    x8, [x8, #0x288]
->  0x102e3d1f8 <+248>: ldr    w8, [x8, #0x4]
    0x102e3d1fc <+252>: mov    x0, x8
    0x102e3d200 <+256>: bl     0x102e40670               ; symbol stub for: swift_task_alloc
    0x102e3d204 <+260>: ldur   x10, [x29, #-0x20]
    0x102e3d208 <+264>: ldur   x9, [x29, #-0x18]
    0x102e3d20c <+268>: ldur   x8, [x29, #-0x28]
    0x102e3d210 <+272>: ldr    x1, [sp, #0x38]
    0x102e3d214 <+276>: ldr    x2, [sp, #0x30]
    0x102e3d218 <+280>: ldr    x3, [sp, #0x28]
    0x102e3d21c <+284>: ldr    x4, [sp, #0x20]

Expected behavior

withTaskGroup should not crash and behave as in previous Xcode / Swift versions.

Environment

Xcode 16.0 beta 5 (16A5221g) Swift 6.0 (6.0.0.7.6) iOSAppOnMac

Additional information

No response

tcwalther commented 1 month ago

I have the same problem on a physical iOS 18.0 beta 4 device where the code is crashing on a withTaskGroup call. However, my project still runs on Swift 5, so I believe this is an error in the libraries, not the Swift language.

It runs fine on an iOS 17.5 simulator (I have another regression on the iOS 18 simulator and thus cannot test my project there yet). It worked fine on previous Xcode 16 betas before Xcode 16.0 beta 5.

WillBishop commented 1 month ago

I'm getting crashes using withTaskGroup on-device (but not in Simulator) running Xcode 16 Beta 5, on an iPad

Benny-Nottonson commented 3 weeks ago

Can confirm, happening on-device and on iPhone 15, both on iOS 18 Dev Beta, also seems to affect withThrowingTaskGroup

KaiOelfke commented 3 weeks ago

Update for Xcode 16 beta 6 for the sample above:

msdrigg commented 2 weeks ago

I am seeing this on iPhone iOS 18 and Xcode 16 beta 6 with withTaskGroup and withDiscardingTaskGroup configurations. All my task groups are crashing, without fail in my application (which is open source here https://github.com/msdrigg/roam).

This is not iOSAppOnMac, it's running a SwiftUI application on a native iOS device (not simulator).

Additionally I don't see this error when I run the same application directly on macOS (it's cross-platform through swiftui)

hborla commented 2 weeks ago

I have the same problem on a physical iOS 18.0 beta 4

It worked fine on previous Xcode 16 betas before Xcode 16.0 beta 5.

There is an ABI mismatch between iOS/macOS Beta 4 and Xcode 16 Beta 5 for the withTaskGroup APIs. The issue should be resolved if you match the betas, i.e. build with Xcode 16 Beta 5+ and run on iOS 18 Beta 5+. This ABI mismatch does not apply when back deploying to a previous macOS or iOS release.

KaiOelfke commented 2 weeks ago

This ABI mismatch does not apply when back deploying to a previous macOS or iOS release.

Isn't compiling with Xcode 16 beta 6 to run an iOS app on macOS Sonoma 14.6.1 (23G93) back deploying to a previous iOS(AppOnMac) release?

Because this crashes as mentioned in my last comment. So we currently can't use Xcode 16 beta for the development of iOSAppOnMac apps on macOS Sonoma.