Skip to content

Commit d64795c

Browse files
authored
Merge pull request swiftlang#74792 from gottesmm/release/6.0-rdar130544081
[6.0][region-isolation] Treat sendable return values as Sendable when the returning function has a known actor isolation.
2 parents 3c08b2a + ec5e7e3 commit d64795c

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

lib/SILOptimizer/Analysis/RegionAnalysis.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3419,6 +3419,14 @@ RegionAnalysisValueMap::initializeTrackableValue(
34193419

34203420
// If we did not insert, just return the already stored value.
34213421
self->stateIndexToEquivalenceClass[iter.first->second.getID()] = value;
3422+
3423+
// Before we do anything, see if we have a Sendable value.
3424+
if (!SILIsolationInfo::isNonSendableType(value->getType(), fn)) {
3425+
iter.first->getSecond().addFlag(TrackableValueFlag::isSendable);
3426+
return {{iter.first->first, iter.first->second}, true};
3427+
}
3428+
3429+
// Otherwise, we have a non-Sendable type... so wire up the isolation.
34223430
iter.first->getSecond().setIsolationRegionInfo(newInfo);
34233431

34243432
return {{iter.first->first, iter.first->second}, true};

test/Concurrency/async_let_isolation.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ actor MyActor {
2323
async let z = synchronous()
2424

2525
var localText = text
26-
// TODO: We should allow this since text is Sendable and localText is a
27-
// separate box. localText should be disconnected.
26+
2827
async let w = localText.removeLast() // expected-without-transferring-warning {{mutation of captured var 'localText' in concurrently-executing code}}
29-
// expected-tns-warning @-1 {{task or actor isolated value cannot be sent}}
3028

3129
_ = await x
3230
_ = await y

test/Concurrency/transfernonsendable.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,3 +1784,18 @@ public func doNotCrashOrEmitUnhandledPatternErrors<T: Sendable>(
17841784
throw CancellationError()
17851785
}
17861786
}
1787+
1788+
/// The following makes sure that when we have a function like test2 with an
1789+
/// assigned isolation that returns a Sendable value... we treat the value as
1790+
/// actually Sendable. This occurs in this example via the result of the default
1791+
/// parameter function for string.
1792+
///
1793+
/// We shouldn't emit any diagnostic here.
1794+
actor FunctionWithSendableResultAndIsolationActor {
1795+
func foo() -> String {
1796+
return string()
1797+
}
1798+
func string(someCondition: Bool = false) -> String {
1799+
return ""
1800+
}
1801+
}

0 commit comments

Comments
 (0)