swiftlang / swiftlang/swift

Inferred main-isolated conformance could mask warning for un-annotated objc protocols

Open
#89,618 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

triage needed
Dominant language
Swift
Stars
70.4k
Forks
10.8k
PR merge metrics
PR metrics pending

Description

Description

Based on https://github.com/swiftlang/swift-evolution/blob/main/proposals/0470-isolated-conformances.md#infer-mainactor-conformances, when we set "default actor isolation" to main, and when conforming to a non-isolated protocol, it will be inferred to use isolated conformance.

For example,

struct Foo: Equatable {}

is equivalent to

struct Foo: @MainActor Equatable {}

However, if there's a legacy objective-c API that hasn't been annotated, then this "inferred isolated conformance" feature would "mask" the compilation error.

struct Foo: ObjCProtocol {}

This can be dangerous, because ObjCProtocol would very well be nonisolated, and have its members called on background thread.

Reproduction

You can create your own ObjC protocol, or just use any un-annotated protocol from Apple, such as VNDocumentCameraViewControllerDelegate.

Then in your project, set default actor isolation to main actor, notice the following has no error:

// DocumentScanDelegate is main actor (default setting)
class DocumentScanDelegate: NSObject, VNDocumentCameraViewControllerDelegate
Expected behavior

Having a main-actor-isolated type conforming to this unannotated protocol should have trigger an error. Masking this error can hide the real problem that this protocol is unannotated and could be called in background thread.

I think we can keep inferred isolated conformance for nonisolated protocols that are intended to be nonisolated, but don't do it for yet-to-be-annotated objc protocols.

Environment

Xcode 26.2

Additional information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the behavior with default actor isolation set to main and an unannotated Objective-C protocol such as VNDocumentCameraViewControllerDelegate. Trace the compiler's inferred isolated-conformance and diagnostic handling; done means the unannotated Objective-C conformance reports an error without breaking intended inference for nonisolated protocols.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.