Skip to content

[Concurrency] NonisolatedNonsendingByDefault: Migration applies only to the current module declarations #82173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Sema/NonisolatedNonsendingByDefaultMigration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ void NonisolatedNonsendingByDefaultMigrationTarget::diagnose() const {

const auto featureName = feature.getName();
if (decl) {
// Only diagnose declarations from the current module.
if (decl->getModuleContext() != ctx.MainModule)
return;

// Diagnose the function, but slap the attribute on the storage declaration
// instead if the function is an accessor.
auto *functionDecl = dyn_cast<AbstractFunctionDecl>(decl);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// RUN: %empty-directory(%t/src)
// RUN: split-file %s %t/src

/// Build the library
// RUN: %target-swift-frontend -emit-module %t/src/Lib.swift \
// RUN: -target %target-swift-5.1-abi-triple \
// RUN: -module-name Lib -swift-version 5 -enable-library-evolution \
// RUN: -emit-module-path %t/Lib.swiftmodule \
// RUN: -emit-module-interface-path %t/Lib.swiftinterface

// RUN: rm %t/Lib.swiftmodule

// Build the client using interface
// RUN: %target-swift-frontend -typecheck -verify -target %target-swift-5.1-abi-triple -swift-version 5 -I %t %t/src/Test.swift -enable-upcoming-feature NonisolatedNonsendingByDefault:migrate

// REQUIRES: asserts
// REQUIRES: swift_feature_NonisolatedNonsendingByDefault

//--- Lib.swift
public struct Counter: AsyncSequence {
public typealias Element = Int

public init(howHigh: Int) {
}

public struct AsyncIterator: AsyncIteratorProtocol {
public mutating func next() async -> Int? {
nil
}
}

public func makeAsyncIterator() -> AsyncIterator {
AsyncIterator()
}
}

//--- Test.swift
import Lib

func count(n: Int) async {
// expected-warning@-1 {{feature 'NonisolatedNonsendingByDefault' will cause nonisolated async global function 'count' to run on the caller's actor; use '@concurrent' to preserve behavior}}
for await _ in Counter(howHigh: n) {
}
}