Skip to content

Enforce Swift 6 strict concurrency during Swift compilation - #181654

Closed
jmagman wants to merge 7 commits into
flutter:masterfrom
jmagman:swiftc-strict-concurrency
Closed

jmagman wants to merge 7 commits into
flutter:masterfrom
jmagman:swiftc-strict-concurrency

Conversation

@jmagman

@jmagman jmagman commented Jan 29, 2026 •

Copy link
Copy Markdown
Member

Enforce Swift 6 strict concurrency during swift compilation to catch thread checker and other main actor errors and regressions as we migrate the engine to Swift 6 #181684

See https://www.swift.org/documentation/concurrency.

This only enforces for our few Swift files, not Objective-C headers being called from Swift.

@github-actions github-actions Bot added the engine flutter/engine related. See also e: labels. label Jan 29, 2026
@jmagman
jmagman marked this pull request as ready for review January 29, 2026 17:29
@jmagman jmagman added the team-ios Owned by iOS platform team label Jan 29, 2026
@flutter-dashboard

Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enforces Swift 6 strict concurrency by adding the -strict-concurrency=complete flag to the Swift compiler. The change is applied in both the GN build configuration and the swiftc.py build script. While this correctly enables the desired feature, it introduces redundancy. My review includes a suggestion to remove this duplication for better maintainability.

@jmagman
jmagman marked this pull request as draft January 29, 2026 18:39
@github-actions github-actions Bot removed the team-ios Owned by iOS platform team label Jan 29, 2026
@jmagman

jmagman commented Jan 29, 2026

Copy link
Copy Markdown
Member Author

My first version of this actually worked, but we don't have warnings-as-errors on:

  41 | @objc(FlutterLogger) public final class Logger: NSObject {
  42 |   private static var shared = Logger()
     |                      |- warning: static property 'shared' is not concurrency-safe because it is nonisolated global shared mutable state; this is an error in the Swift 6 language mode
     |                      |- note: convert 'shared' to a 'let' constant to make 'Sendable' shared state immutable
     |                      |- note: annotate 'shared' with '@MainActor' if property should only be accessed from the main actor
     |                      `- note: disable concurrency-safety checks if accesses are protected by an external synchronization mechanism

https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8691364718599217841/+/u/build_ci_ios_debug_sim/stdout#L6663_2

@github-actions github-actions Bot added platform-ios iOS applications specifically a: desktop Running on desktop team-ios Owned by iOS platform team labels Jan 30, 2026
@github-actions github-actions Bot removed platform-ios iOS applications specifically a: desktop Running on desktop team-ios Owned by iOS platform team labels Feb 4, 2026
@jmagman

jmagman commented Feb 5, 2026

Copy link
Copy Markdown
Member Author
/Volumes/Work/s/w/ir/cache/builder/engine/src/flutter/shell/platform/darwin/common/SwiftTestingMain.swift:14:26: error: passing argument of non-sendable type 'SwiftTestingRunner' outside of main actor-isolated context may introduce data races; this is an error in the Swift 6 language mode
12 |   static func main() async {
13 |     let runner = SwiftTestingRunner()
14 |     let exitCode = await runner.run()
   |                          `- error: passing argument of non-sendable type 'SwiftTestingRunner' outside of main actor-isolated context may introduce data races; this is an error in the Swift 6 language mode
15 |     exit(exitCode)
16 |   }

@jmagman

jmagman commented Feb 5, 2026

Copy link
Copy Markdown
Member Author

Closing this, @LongCatIsLooong is going to take it over during the larger Swift 6 concurrency work.

@jmagman jmagman closed this Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine flutter/engine related. See also e: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant