Skip to content

Commit 4f20b5d

Browse files
committed
[send-non-sendable] Move utility functions into a utility section.
I also used a more general way to check for apply insts that are not builtins (ApplySite).
1 parent bfb2046 commit 4f20b5d

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

lib/SILOptimizer/Mandatory/SendNonSendable.cpp

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,41 @@
2929

3030
using namespace swift;
3131

32-
namespace {
33-
34-
static const char *SEP_STR = "╾──────────────────────────────╼\n";
32+
//===----------------------------------------------------------------------===//
33+
// MARK: Utilities
34+
//===----------------------------------------------------------------------===//
3535

36-
// SILApplyCrossesIsolation determines if a SIL instruction is an isolation
37-
// crossing apply expression. This is done by checking its correspondence
38-
// to an ApplyExpr AST node, and then checking the internal flags of that
39-
// AST node to see if the ActorIsolationChecker determined it crossed isolation.
40-
// It's possible this is brittle and a more nuanced check is needed, but this
41-
// suffices for all cases tested so far.
36+
/// SILApplyCrossesIsolation determines if a SIL instruction is an isolation
37+
/// crossing apply expression. This is done by checking its correspondence to an
38+
/// ApplyExpr AST node, and then checking the internal flags of that AST node to
39+
/// see if the ActorIsolationChecker determined it crossed isolation. It's
40+
/// possible this is brittle and a more nuanced check is needed, but this
41+
/// suffices for all cases tested so far.
4242
static bool SILApplyCrossesIsolation(const SILInstruction *inst) {
4343
if (ApplyExpr *apply = inst->getLoc().getAsASTNode<ApplyExpr>())
4444
return apply->getIsolationCrossing().has_value();
4545

46-
// if the instruction doesn't correspond to an ApplyExpr, then it can't
47-
// cross an isolation domain
46+
// We assume that any instruction that does not correspond to an ApplyExpr
47+
// cannot cross an isolation domain.
4848
return false;
4949
}
5050

51-
inline bool isAddress(SILValue val) {
51+
static bool isAddress(SILValue val) {
5252
return val->getType() && val->getType().isAddress();
5353
}
5454

55-
inline bool isApplyInst(const SILInstruction &inst) {
56-
return isa<ApplyInst,
57-
BeginApplyInst,
58-
BuiltinInst,
59-
PartialApplyInst,
60-
TryApplyInst>(inst);
55+
static bool isApplyInst(SILInstruction &inst) {
56+
return ApplySite::isa(&inst) || isa<BuiltinInst>(inst);
6157
}
6258

59+
//===----------------------------------------------------------------------===//
60+
// MARK: Main Computation
61+
//===----------------------------------------------------------------------===//
62+
63+
namespace {
64+
65+
static const char *SEP_STR = "╾──────────────────────────────╼\n";
66+
6367
using TrackableValueID = PartitionPrimitives::Element;
6468
using Region = PartitionPrimitives::Region;
6569

@@ -201,8 +205,8 @@ class PartitionOpTranslator {
201205
std::set<TrackableSILValue> capturedUIValues;
202206

203207
void initCapturedUIValues() {
204-
for (const SILBasicBlock &block: *function) {
205-
for (const SILInstruction &inst: block) {
208+
for (auto &block : *function) {
209+
for (auto &inst : block) {
206210
if (isApplyInst(inst)) {
207211
// add all nonsendable, uniquely identified arguments to applications
208212
// to capturedUIValues, because applications capture them

0 commit comments

Comments
 (0)