swiftlang / swift

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

Project-wide "Pattern that the region based isolation checker does not understand how to check" #76005

Open Supereg opened 2 months ago

Supereg commented 2 months ago

Description

There have been previous reports of this compiler warning popping up, that was fixed in Xcode Beta 5 (#75439, #75128, #75238). I just now installed Xcode Beta 6 and have hoped this warning to disappear but it remains. However, for me the warning is not associated with a specific line or file but is printed as:

<unknown>:0: warning: pattern that the region based isolation checker does not understand how to check. Please file a bug; this is an error in the Swift 6 language mode

This error occurs when compiling the StanfordSpezi/SpeziBluetooth SPM package (commit hash as of time of writing 8ee8ba902cff833aa6a6062fc8433e5d0e0338f3). The warning is printed 8 times, each when compiling the files resource_bunle_accessor.swift (file generated by Xcode), Bluetooth.swift, DeviceDiscoveryDescriptor.swift, Discover.swift, DiscoveryDescriptorBuilder, BluetoothManager.swift, BluetoothPeripheral.swift and CharacteristicDescription.swift. Except for the first file, all of the files are part of the project.

Most of these files are non-trivial. The project is otherwise compatible with Swift 6 strict concurrency checking.

This issue is intended to ask for assistance in tracking down the exact issue for this warning. Are there any magic switches to pull that would provide more information where the warning is generated from? Or might this be related to a known issue that was reported somewhere else (hopefully in a more reproducible manner) that is about to be fixed?

Reproduction

As explained above, I currently cannot isolate it to a single line of code due to the cryptic compiler warning. The only steps for reproduction I can point to is the project where the error occurs.

Expected behavior

Report a more useful diagnostic that includes the file and line number where this error/warning occurs.

Environment

Xcode Beta 6

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx14.0

Additional information

No response

Supereg commented 2 months ago

cc @gottesmm you seem to get mentioned with these warnings in the other issue reports.

Supereg commented 2 months ago

Attaching the full build log

Build SpeziBluetooth-Package_2024-08-21T09-26-58.txt

Supereg commented 2 months ago

The issue persists with Xcode 16 RC release today.

xedin commented 2 months ago

cc @gottesmm

Supereg commented 5 days ago

Any updates on this? This issue persists in Version 16.1 (16B40) and remains a significant blocker for adopting Swift 6.

I’ve eventually managed to isolate the problem to a minimal setup, which consistently reproduces the error.

It will yield the following error for one or more files (even if the code is only contained in a single file):

<unknown>:0: error: pattern that the region based isolation checker does not understand how to check. Please file a bug

The example defines a type TestClass that is isolated to a custom global actor TestActor and contains a property wrapper PropertyWrapper that is isolated to the @MainActor. Note, this example doesn't trigger when using simple types like Int but only triggers with a type like Values.

@propertyWrapper
class PropertyWrapper<Value> {
    var wrappedValue: Value

    init(wrappedValue: Value) {
        self.wrappedValue = wrappedValue
    }
}

@MainActor
struct Values {
    nonisolated init() {}
}

@globalActor
actor TestActor {
    static let shared = TestActor()
}

@TestActor
final class TestClass: Sendable {
    @MainActor @PropertyWrapper var property: Values

    @MainActor
    init(_ value: Int) {
        self.property = Values()
    }
}

You cannot initialize the underlying storage property of the property wrapper as this yields the error shown below. Annotating the property wrapper with @MainActor, I would have suspected that the underlying storage property is also initialized to the MainActor(?). Independent of the correctness of the code, they main point this issue raises is that the error message is not meaningful and really doesn't help to explain nor locate the issue.


    @MainActor
    init(_ value: Int) {
        self._property = PropertyWrapper(wrappedValue: Values()) // error: Global actor 'TestActor'-isolated property '_property' can not be mutated from the main actor
    }
``