Skip to content

Commit 7fff6cd

Browse files
committed
[region-isolation] Only perform merge assignment if we capture an address in a partial_apply rather than if we send it to any function apply.
Semantically these are the only cases where we would want to force an address to be merged. Some notes: 1. When we have a box, the project_box is considered to come from the box and is considered non uniquely identified. 2. The only place this was really triggering was when we created temporary partial applies to pass to a function when using address only types. Since this temporaries are never reassigned to, there isn't any reason to require them to be merged. 3. In the case where we have an alloc_stack grabbed by a partial_apply, we still appropriately merge.
1 parent 9dfc9b6 commit 7fff6cd

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

lib/SILOptimizer/Mandatory/SendNonSendable.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "swift/SIL/BasicBlockData.h"
1818
#include "swift/SIL/BasicBlockDatastructures.h"
1919
#include "swift/SIL/MemAccessUtils.h"
20+
#include "swift/SIL/NodeDatastructures.h"
2021
#include "swift/SIL/OwnershipUtils.h"
2122
#include "swift/SIL/SILBasicBlock.h"
2223
#include "swift/SIL/SILFunction.h"
@@ -49,10 +50,6 @@ static bool SILApplyCrossesIsolation(const SILInstruction *inst) {
4950
return false;
5051
}
5152

52-
static bool isApplyInst(SILInstruction &inst) {
53-
return ApplySite::isa(&inst) || isa<BuiltinInst>(inst);
54-
}
55-
5653
static AccessStorage getAccessStorageFromAddr(SILValue value) {
5754
assert(value->getType().isAddress());
5855
auto accessStorage = AccessStorage::compute(value);
@@ -435,13 +432,26 @@ class PartitionOpTranslator {
435432

436433
for (auto &block : *function) {
437434
for (auto &inst : block) {
438-
if (isApplyInst(inst)) {
439-
// add all nonsendable, uniquely identified arguments to applications
440-
// to capturedUIValues, because applications capture them
435+
if (auto *pai = dyn_cast<PartialApplyInst>(&inst)) {
436+
// If we find an address or a box of a non-Sendable type that is
437+
// passed to a partial_apply, mark the value's representative as being
438+
// uniquely identified and captured.
441439
for (SILValue val : inst.getOperandValues()) {
442-
if (val->getType().isAddress()) {
440+
if (val->getType().isAddress() &&
441+
isNonSendableType(val->getType())) {
443442
auto trackVal = getTrackableValue(val, true);
443+
(void)trackVal;
444444
LLVM_DEBUG(trackVal.print(llvm::dbgs()));
445+
continue;
446+
}
447+
448+
if (auto *pbi = dyn_cast<ProjectBoxInst>(val)) {
449+
if (isNonSendableType(
450+
pbi->getType().getSILBoxFieldType(function))) {
451+
auto trackVal = getTrackableValue(val, true);
452+
(void)trackVal;
453+
continue;
454+
}
445455
}
446456
}
447457
}

0 commit comments

Comments
 (0)