mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[rbi] Ensure that we properly handle nonisolated(nonsending) for forward declared vars.
rdar://164042741
This commit is contained in:
@@ -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)) {
|
||||
|
||||
@@ -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 //
|
||||
////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user