[rbi] Ensure that we properly handle nonisolated(nonsending) for forward declared vars.

rdar://164042741
This commit is contained in:
Michael Gottesman
2025-11-04 14:50:22 -08:00
parent df6a05c103
commit f0a4571fdd
2 changed files with 25 additions and 0 deletions

View File

@@ -965,6 +965,19 @@ SILIsolationInfo SILIsolationInfo::get(SILInstruction *inst) {
}
}
if (auto *bbi = dyn_cast<BeginBorrowInst>(inst)) {
if (bbi->isFromVarDecl()) {
// See if we have the actual AST information on our instruction.
if (auto *varDecl = bbi->getLoc().getAsASTNode<VarDecl>()) {
auto isolation = swift::getActorIsolation(varDecl);
if (isolation.getKind() == ActorIsolation::NonisolatedUnsafe) {
return SILIsolationInfo::getDisconnected(
true /*is nonisolated(unsafe)*/);
}
}
}
}
/// Consider non-Sendable metatypes to be task-isolated, so they cannot cross
/// into another isolation domain.
if (auto *mi = dyn_cast<MetatypeInst>(inst)) {

View File

@@ -329,6 +329,18 @@ func useAfterTransferLetSquelchedIndirectAddressOnly<T : ProvidesStaticValue>(_
print(ns4)
}
func testNonisolatedUnsafeForwardDeclaredVar<T: Sendable>(_ body: @escaping @Sendable () async throws -> T) throws -> T {
nonisolated(unsafe) var result: Result<T, Error>!
Task {
do {
result = .success(try await body())
} catch {
result = .failure(error)
}
}
return try result.get()
}
////////////////////////
// MARK: Global Tests //
////////////////////////