Skip to content

Commit a75501e

Browse files
committed
[region-isolation] Eliminate the last non-SIL test case usage of SILIsolationInfo::getWithIsolationCrossing().
The reason that I am changing this code is that getWithIsolationCrossing is a bad API that was being used to infer actor isolation straight from an ApplyExpr without adding an actor instance. This can cause us to reject programs unnecessarily if we in other parts of the code correctly infer the SILValue actor instance for the isolation. Rather than allow for that, I am removing this code and I improved the rest of the pattern matching here to ensure that we handled that with the normal actor instance inferring code. This will prevent this type of mismerge from happening by mistake. I fixed up the changes in the test cases. The only usage of this left is for ApplyIsolationCrossings parsed straight from SIL that we use only when testing. This is safe since if a test writer is using the parsed SIL in this manner, they can make sure that mismerges do not happen.
1 parent f89db53 commit a75501e

File tree

2 files changed

+36
-25
lines changed

2 files changed

+36
-25
lines changed

include/swift/SILOptimizer/Utils/SILIsolationInfo.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -346,18 +346,6 @@ class SILIsolationInfo {
346346
Flag::UnappliedIsolatedAnyParameter};
347347
}
348348

349-
/// Only use this as a fallback if we cannot find better information.
350-
static SILIsolationInfo
351-
getWithIsolationCrossing(ApplyIsolationCrossing crossing) {
352-
if (crossing.getCalleeIsolation().isActorIsolated()) {
353-
// SIL level, just let it through
354-
return SILIsolationInfo(SILValue(), SILValue(),
355-
crossing.getCalleeIsolation());
356-
}
357-
358-
return {};
359-
}
360-
361349
static SILIsolationInfo getActorInstanceIsolated(SILValue isolatedValue,
362350
SILValue actorInstance,
363351
NominalTypeDecl *typeDecl) {
@@ -463,6 +451,20 @@ class SILIsolationInfo {
463451

464452
private:
465453
void printOptions(llvm::raw_ostream &os) const;
454+
455+
/// This is used only to let through apply isolation crossings that we define
456+
/// in SIL just for testing. Do not use this in any other contexts!
457+
static SILIsolationInfo
458+
getWithIsolationCrossing(ApplyIsolationCrossing crossing) {
459+
if (!crossing.getCalleeIsolation().isActorIsolated())
460+
return {};
461+
462+
// SIL level, just let it through without an actor instance. We assume since
463+
// we are using this for SIL tests that we do not need to worry about having
464+
// a null actor instance.
465+
return SILIsolationInfo(SILValue(), SILValue(),
466+
crossing.getCalleeIsolation());
467+
}
466468
};
467469

468470
/// A SILIsolationInfo that has gone through merging and represents the dynamic

lib/SILOptimizer/Utils/SILIsolationInfo.cpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,11 @@ inferIsolationInfoForTempAllocStack(AllocStackInst *asi) {
358358

359359
SILIsolationInfo SILIsolationInfo::get(SILInstruction *inst) {
360360
if (auto fas = FullApplySite::isa(inst)) {
361+
// Check if we have SIL based "faked" isolation crossings that we use for
362+
// testing purposes.
363+
//
364+
// NOTE: Please do not use getWithIsolationCrossing in more places! We only
365+
// want to use it here!
361366
if (auto crossing = fas.getIsolationCrossing()) {
362367
if (auto info = SILIsolationInfo::getWithIsolationCrossing(*crossing))
363368
return info;
@@ -754,19 +759,6 @@ SILIsolationInfo SILIsolationInfo::get(SILInstruction *inst) {
754759
}
755760
}
756761

757-
// Try to infer using SIL first since we might be able to get the source name
758-
// of the actor.
759-
if (ApplyExpr *apply = inst->getLoc().getAsASTNode<ApplyExpr>()) {
760-
if (auto crossing = apply->getIsolationCrossing()) {
761-
if (auto info = SILIsolationInfo::getWithIsolationCrossing(*crossing))
762-
return info;
763-
764-
if (crossing->getCalleeIsolation().isNonisolated()) {
765-
return SILIsolationInfo::getDisconnected(false /*nonisolated(unsafe)*/);
766-
}
767-
}
768-
}
769-
770762
if (auto *asi = dyn_cast<AllocStackInst>(inst)) {
771763
if (asi->isFromVarDecl()) {
772764
if (auto *varDecl = asi->getLoc().getAsASTNode<VarDecl>()) {
@@ -801,6 +793,23 @@ SILIsolationInfo SILIsolationInfo::get(SILInstruction *inst) {
801793
}
802794
}
803795

796+
// Check if we have an ApplyInst with nonisolated.
797+
//
798+
// NOTE: We purposely avoid using other isolation info from an ApplyExpr since
799+
// when we use the isolation crossing on the ApplyExpr at this point,w e are
800+
// unable to find out what the appropriate instance is (since we would have
801+
// found it earlier if we could). This ensures that we can eliminate a case
802+
// where we get a SILIsolationInfo with actor isolation and without a SILValue
803+
// actor instance. This prevents a class of bad SILIsolationInfo merge errors
804+
// caused by the actor instances not matching.
805+
if (ApplyExpr *apply = inst->getLoc().getAsASTNode<ApplyExpr>()) {
806+
if (auto crossing = apply->getIsolationCrossing()) {
807+
if (crossing->getCalleeIsolation().isNonisolated()) {
808+
return SILIsolationInfo::getDisconnected(false /*nonisolated(unsafe)*/);
809+
}
810+
}
811+
}
812+
804813
return SILIsolationInfo();
805814
}
806815

0 commit comments

Comments
 (0)