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

Prevent migration from handling declarations that come from a
module different from the current one, this is primarily a
problem for swiftinterfaces that can get rebuilt when the module
is imported by a model that has migration mode enabled.

Resolves: rdar://152687353
This commit is contained in:
Pavel Yaskevich
2025-06-11 00:06:36 -07:00
parent c14699310f
commit bcd6caaea4
2 changed files with 48 additions and 0 deletions

View File

@@ -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);

View File

@@ -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) {
}
}