Skip to content

Commit 7255281

Browse files
committed
[region-isolation] Use a hard to use API correctly.
Specifically, this API has some hard edges where instead of just returning an invalid value to signal that we do not have self, we assert or return something bogus. This commit just fixes our usage of that API to be correct. rdar://132545626
1 parent bd4827f commit 7255281

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/SILOptimizer/Mandatory/TransferNonSendable.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1982,7 +1982,8 @@ void AssignIsolatedIntoSendingResultDiagnosticEmitter::emit() {
19821982
// string a path component for that class_method.
19831983
if (info.srcOperand->get()->getType() != info.outSendingResult->getType()) {
19841984
if (auto fas = FullApplySite::isa(info.srcOperand->getUser())) {
1985-
if (fas.getSelfArgument() == info.srcOperand->get() &&
1985+
if (fas.hasSelfArgument() &&
1986+
fas.getSelfArgument() == info.srcOperand->get() &&
19861987
fas.getNumIndirectSILResults() == 1) {
19871988
// First check if our function argument is exactly our out parameter.
19881989
bool canEmit =

test/Concurrency/transfernonsendable.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,3 +1849,18 @@ func testBooleanCapture(_ x: inout NonSendableKlass) {
18491849
print(z)
18501850
}
18511851
}
1852+
1853+
public class Context {
1854+
let value: Int
1855+
1856+
init(value: Int) {
1857+
self.value = value
1858+
}
1859+
}
1860+
1861+
extension MyActor {
1862+
public func withContext<T>(_ block: sending (NonSendableKlass) throws -> T) async throws -> sending T {
1863+
return try block(klass) // expected-tns-warning {{returning 'self'-isolated 'self.klass' as a 'sending' result risks causing data races}}
1864+
// expected-tns-note @-1 {{returning 'self'-isolated 'self.klass' risks causing data races since the caller assumes that 'self.klass' can be safely sent to other isolation domains}}
1865+
}
1866+
}

0 commit comments

Comments
 (0)