mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[region-isolation] Fix handling of coroutine apply results.
In this part of the code, we are attempting to merge all of the operands into the same region and then assigning all non-Sendable results of the function to that same region. The problem that was occuring here was a thinko due to the control flow of the code here not separating nicely the case of whether or not we had operands or not. Previously this did not matter, since we just used the first result in such a case... but since we changed to assign to the first operand element in some cases, it matters now. To fix this, I split the confused logic into two different easy to follow control paths... one if we have operands and one where we do not have an operand. In the case where we have a first operand, we merge our elements into its region. If we do not have any operands, then we just perform one large region assign fresh. This was not exposed by code that used non-coroutines since in SIL only coroutines today have multiple results. rdar://132767643
This commit is contained in:
@@ -1159,8 +1159,16 @@ struct PartitionOpBuilder {
|
||||
Element getActorIntroducingRepresentative(SILIsolationInfo actorIsolation);
|
||||
|
||||
void addAssignFresh(SILValue value) {
|
||||
std::array<Element, 1> values = {lookupValueID(value)};
|
||||
currentInstPartitionOps.emplace_back(
|
||||
PartitionOp::AssignFresh(lookupValueID(value), currentInst));
|
||||
PartitionOp::AssignFresh(values, currentInst));
|
||||
}
|
||||
|
||||
void addAssignFresh(ArrayRef<SILValue> values) {
|
||||
auto transformedCollection = makeTransformRange(
|
||||
values, [&](SILValue value) { return lookupValueID(value); });
|
||||
currentInstPartitionOps.emplace_back(
|
||||
PartitionOp::AssignFresh(transformedCollection, currentInst));
|
||||
}
|
||||
|
||||
void addAssign(SILValue destValue, Operand *srcOperand) {
|
||||
@@ -1733,23 +1741,18 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
auto assignResultsRef = llvm::ArrayRef(assignResults);
|
||||
SILValue front = assignResultsRef.front();
|
||||
assignResultsRef = assignResultsRef.drop_front();
|
||||
|
||||
// If we do not have any non-Sendable srcs, then all of our results get one
|
||||
// large fresh region.
|
||||
if (assignOperands.empty()) {
|
||||
// If no non-sendable srcs, non-sendable tgts get a fresh region.
|
||||
builder.addAssignFresh(front);
|
||||
} else {
|
||||
builder.addAssign(front, assignOperands.front().first);
|
||||
builder.addAssignFresh(assignResults);
|
||||
return;
|
||||
}
|
||||
|
||||
// Assign all targets to the target region.
|
||||
while (assignResultsRef.size()) {
|
||||
SILValue next = assignResultsRef.front();
|
||||
assignResultsRef = assignResultsRef.drop_front();
|
||||
|
||||
builder.addAssign(next, assignOperands.front().first);
|
||||
// Otherwise, we need to assign all of the results to be in the same region
|
||||
// as the operands. Without losing generality, we just use the first
|
||||
// non-Sendable one.
|
||||
for (auto result : assignResults) {
|
||||
builder.addAssign(result, assignOperands.front().first);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user