Skip to content

Commit c42989a

Browse files
committed
[region-isolation] Fix code where we were not properly mapping a type into a SILFunction's context to actually do so.
rdar://138667211
1 parent 1fbbebe commit c42989a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/SILOptimizer/Mandatory/SendNonSendable.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,7 @@ bool SentNeverSendableDiagnosticInferrer::initForSendingPartialApply(
16671667
for (auto capture : ce->getCaptureInfo().getCaptures()) {
16681668
auto *decl = capture.getDecl();
16691669
auto type = decl->getInterfaceType()->getCanonicalType();
1670+
type = pai->getFunction()->mapTypeIntoContext(type)->getCanonicalType();
16701671
auto silType = SILType::getPrimitiveObjectType(type);
16711672
if (!SILIsolationInfo::isNonSendableType(silType, pai->getFunction()))
16721673
continue;

test/Concurrency/transfernonsendable.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,3 +1906,20 @@ func offByOneWithImplicitPartialApply() {
19061906
}
19071907
}
19081908
}
1909+
1910+
protocol Progress {
1911+
associatedtype AssocType
1912+
var x: AssocType { get }
1913+
func checkCancellation() throws
1914+
}
1915+
1916+
// We used to crash here since the closure diagnostic would not map z's type
1917+
// into the current context.
1918+
func testCaptureDiagnosticMapsTypeIntoContext<T : Progress>(_ x: NonSendableKlass, y: T) async throws {
1919+
let z = y.x
1920+
await withTaskGroup(of: Void.self) { group in
1921+
group.addTask { // expected-tns-warning {{passing closure as a 'sending' parameter risks causing data races between code in the current task and concurrent execution of the closure}}
1922+
print(z) // expected-tns-note {{closure captures 'z' which is accessible to code in the current task}}
1923+
}
1924+
}
1925+
}

0 commit comments

Comments
 (0)