Skip to content

Commit 1d8ea84

Browse files
committed
[region-isolation] When determining isolation of a full apply site... use the isolated parameter, not self.
This was ok in the small since most of the time we were processing a self parameter as isolated... but that isn't always true...
1 parent f45a87c commit 1d8ea84

File tree

3 files changed

+45
-18
lines changed

3 files changed

+45
-18
lines changed

include/swift/SIL/ApplySite.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,21 @@ class ApplySite {
470470
llvm_unreachable("covered switch");
471471
}
472472

473+
/// Return the sil_isolated operand if we have one.
474+
Operand *getIsolatedArgumentOperandOrNullPtr() {
475+
switch (ApplySiteKind(Inst->getKind())) {
476+
case ApplySiteKind::ApplyInst:
477+
return cast<ApplyInst>(Inst)->getIsolatedArgumentOperandOrNullPtr();
478+
case ApplySiteKind::BeginApplyInst:
479+
return cast<BeginApplyInst>(Inst)->getIsolatedArgumentOperandOrNullPtr();
480+
case ApplySiteKind::TryApplyInst:
481+
return cast<TryApplyInst>(Inst)->getIsolatedArgumentOperandOrNullPtr();
482+
case ApplySiteKind::PartialApplyInst:
483+
llvm_unreachable("Unhandled case");
484+
}
485+
llvm_unreachable("covered switch");
486+
}
487+
473488
/// Return a list of applied arguments without self.
474489
OperandValueArrayRef getArgumentsWithoutSelf() const {
475490
switch (ApplySiteKind(Inst->getKind())) {

include/swift/SIL/SILInstruction.h

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2972,14 +2972,15 @@ class ApplyInstBase<Impl, Base, true>
29722972
const Impl &asImpl() const { return static_cast<const Impl &>(*this); }
29732973

29742974
public:
2975+
using super::getArgument;
2976+
using super::getArgumentOperands;
2977+
using super::getArguments;
29752978
using super::getCallee;
2976-
using super::getSubstCalleeType;
2979+
using super::getCalleeOperand;
2980+
using super::getNumArguments;
29772981
using super::getSubstCalleeConv;
2982+
using super::getSubstCalleeType;
29782983
using super::hasSubstitutions;
2979-
using super::getNumArguments;
2980-
using super::getArgument;
2981-
using super::getArguments;
2982-
using super::getArgumentOperands;
29832984

29842985
/// The collection of following routines wrap the representation difference in
29852986
/// between the self substitution being first, but the self parameter of a
@@ -3064,6 +3065,21 @@ class ApplyInstBase<Impl, Base, true>
30643065
return getSubstCalleeType()->hasSelfParam();
30653066
}
30663067

3068+
Operand *getIsolatedArgumentOperandOrNullPtr() {
3069+
SILFunctionConventions conv = getSubstCalleeConv();
3070+
for (Operand &argOp : getOperandsWithoutIndirectResults()) {
3071+
// Skip the callee.
3072+
if (getCalleeOperand() == &argOp)
3073+
continue;
3074+
3075+
auto opNum = argOp.getOperandNumber() - 1;
3076+
auto paramInfo = conv.getParamInfoForSILArg(opNum);
3077+
if (paramInfo.getOptions().contains(SILParameterInfo::Isolated))
3078+
return &argOp;
3079+
}
3080+
return nullptr;
3081+
}
3082+
30673083
bool hasGuaranteedSelfArgument() const {
30683084
auto C = getSubstCalleeType()->getSelfParameter().getConvention();
30693085
return C == ParameterConvention::Direct_Guaranteed;
@@ -3077,7 +3093,7 @@ class ApplyInstBase<Impl, Base, true>
30773093
return getArguments().slice(getNumIndirectResults());
30783094
}
30793095

3080-
MutableArrayRef<Operand> getOperandsWithoutIndirectResults() const {
3096+
MutableArrayRef<Operand> getOperandsWithoutIndirectResults() {
30813097
return getArgumentOperands().slice(getNumIndirectResults());
30823098
}
30833099

lib/SILOptimizer/Utils/SILIsolationInfo.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -348,21 +348,17 @@ SILIsolationInfo SILIsolationInfo::get(SILInstruction *inst) {
348348
return info;
349349
}
350350

351-
if (fas.hasSelfArgument()) {
352-
auto &selfOp = fas.getSelfArgumentOperand();
353-
CanType selfASTType = selfOp.get()->getType().getASTType();
351+
if (auto *isolatedOp = fas.getIsolatedArgumentOperandOrNullPtr()) {
352+
CanType selfASTType = isolatedOp->get()->getType().getASTType();
354353
selfASTType =
355354
selfASTType->lookThroughAllOptionalTypes()->getCanonicalType();
356355

357-
if (fas.getArgumentParameterInfo(selfOp).hasOption(
358-
SILParameterInfo::Isolated)) {
359-
if (auto *nomDecl = selfASTType->getAnyActor()) {
360-
// TODO: We really should be doing this based off of an Operand. Then
361-
// we would get the SILValue() for the first element. Today this can
362-
// only mess up isolation history.
363-
return SILIsolationInfo::getActorInstanceIsolated(
364-
SILValue(), selfOp.get(), nomDecl);
365-
}
356+
if (auto *nomDecl = selfASTType->getAnyActor()) {
357+
// TODO: We really should be doing this based off of an Operand. Then
358+
// we would get the SILValue() for the first element. Today this can
359+
// only mess up isolation history.
360+
return SILIsolationInfo::getActorInstanceIsolated(
361+
SILValue(), isolatedOp->get(), nomDecl);
366362
}
367363
}
368364

0 commit comments

Comments
 (0)