Skip to content

Commit c09b9f8

Browse files
committed
[region-isolation] Add a helper for getting an ApplyIsolationCrossing from an instruction.
I am making this specific API since I am going to make it so that SILIsolationInfo::get(SILInstruction *) can infer isolation info from self even from functions that are not apply isolation crossing points. For example, in the following, we need to understand that test is main actor isolated and we shouldn't emit an error. ```swift @mainactor func test(_ x: NonSendable) {} @OtherActor func doSomething() { let x = NonSendable() Task.init { @mainactor in print(x) } test(x) } ```
1 parent 5b81712 commit c09b9f8

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

include/swift/SILOptimizer/Analysis/RegionAnalysis.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ inline bool isNonSendableType(SILType type, SILFunction *fn) {
5252
return !type.isSendable(fn);
5353
}
5454

55+
/// Return the ApplyIsolationCrossing for a specific \p inst if it
56+
/// exists. Returns std::nullopt otherwise.
57+
std::optional<ApplyIsolationCrossing>
58+
getApplyIsolationCrossing(SILInstruction *inst);
59+
5560
// This is our PImpl type that we use to hide all of the internal details of
5661
// the computation.
5762
class PartitionOpTranslator;

lib/SILOptimizer/Analysis/RegionAnalysis.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ using namespace swift::regionanalysisimpl;
4848
// MARK: Utilities
4949
//===----------------------------------------------------------------------===//
5050

51+
std::optional<ApplyIsolationCrossing>
52+
regionanalysisimpl::getApplyIsolationCrossing(SILInstruction *inst) {
53+
if (ApplyExpr *apply = inst->getLoc().getAsASTNode<ApplyExpr>())
54+
if (auto crossing = apply->getIsolationCrossing())
55+
return crossing;
56+
57+
if (auto fas = FullApplySite::isa(inst)) {
58+
if (auto crossing = fas.getIsolationCrossing())
59+
return crossing;
60+
}
61+
62+
return {};
63+
}
64+
5165
namespace {
5266

5367
struct UnderlyingTrackedValueInfo {
@@ -1903,11 +1917,9 @@ class PartitionOpTranslator {
19031917
}
19041918
}
19051919

1906-
auto isolationRegionInfo = SILIsolationInfo::get(inst);
1907-
19081920
// If this apply does not cross isolation domains, it has normal
19091921
// non-transferring multi-assignment semantics
1910-
if (!bool(isolationRegionInfo))
1922+
if (!getApplyIsolationCrossing(*fas))
19111923
return translateNonIsolationCrossingSILApply(fas);
19121924

19131925
if (auto cast = dyn_cast<ApplyInst>(inst))

0 commit comments

Comments
 (0)