Skip to content

Commit c2350df

Browse files
committed
[region-isolation] Change SILIsolationInfo to only traffic in ActorIsolation instead of that or nominal type decls.
This should be NFC since the only case where I used this was with self... and I found another way of doing that using the API I added in the previous commit.
1 parent 04e8bad commit c2350df

File tree

4 files changed

+26
-98
lines changed

4 files changed

+26
-98
lines changed

include/swift/SILOptimizer/Analysis/RegionAnalysis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class regionanalysisimpl::TrackableValueState {
162162
}
163163

164164
ActorIsolation getActorIsolation() const {
165-
return regionInfo.getActorIsolation().value();
165+
return regionInfo.getActorIsolation();
166166
}
167167

168168
void mergeIsolationRegionInfo(SILIsolationInfo newRegionInfo) {

include/swift/SILOptimizer/Utils/PartitionUtils.h

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,19 @@ class SILIsolationInfo {
110110
// clang-format off
111111
std::variant<
112112
// Used for actor isolated when we have ActorIsolation info from the AST.
113-
std::optional<ActorIsolation>,
114-
// Used for actor isolation when we infer the actor at the SIL level.
115-
NominalTypeDecl *,
113+
ActorIsolation,
116114
// The task isolated parameter when we find a task isolated value.
117115
SILValue
118116
> data;
119117
// clang-format on
120118

121-
SILIsolationInfo(Kind kind, std::optional<ActorIsolation> actorIsolation)
122-
: kind(kind), data(actorIsolation) {}
123-
SILIsolationInfo(Kind kind, NominalTypeDecl *decl) : kind(kind), data(decl) {}
119+
SILIsolationInfo(ActorIsolation actorIsolation)
120+
: kind(Actor), data(actorIsolation) {}
124121

125122
SILIsolationInfo(Kind kind, SILValue value) : kind(kind), data(value) {}
126123

124+
SILIsolationInfo(Kind kind) : kind(kind), data() {}
125+
127126
public:
128127
SILIsolationInfo() : kind(Kind::Unknown), data() {}
129128

@@ -146,18 +145,11 @@ class SILIsolationInfo {
146145

147146
void printForDiagnostics(llvm::raw_ostream &os) const;
148147

149-
std::optional<ActorIsolation> getActorIsolation() const {
148+
ActorIsolation getActorIsolation() const {
150149
assert(kind == Actor);
151-
assert(std::holds_alternative<std::optional<ActorIsolation>>(data) &&
150+
assert(std::holds_alternative<ActorIsolation>(data) &&
152151
"Doesn't have an actor isolation?!");
153-
return std::get<std::optional<ActorIsolation>>(data);
154-
}
155-
156-
NominalTypeDecl *getActorInstance() const {
157-
assert(kind == Actor);
158-
assert(std::holds_alternative<NominalTypeDecl *>(data) &&
159-
"Doesn't have an actor instance?!");
160-
return std::get<NominalTypeDecl *>(data);
152+
return std::get<ActorIsolation>(data);
161153
}
162154

163155
SILValue getTaskIsolatedValue() const {
@@ -167,45 +159,31 @@ class SILIsolationInfo {
167159
return std::get<SILValue>(data);
168160
}
169161

170-
bool hasActorIsolation() const {
171-
return kind == Actor &&
172-
std::holds_alternative<std::optional<ActorIsolation>>(data);
173-
}
174-
175-
bool hasActorInstance() const {
176-
return kind == Actor && std::holds_alternative<NominalTypeDecl *>(data);
177-
}
162+
bool hasActorIsolation() const { return kind == Actor; }
178163

179164
bool hasTaskIsolatedValue() const {
180165
return kind == Task && std::holds_alternative<SILValue>(data);
181166
}
182167

183-
/// If we actually have an actor decl, return that. Otherwise, see if we have
184-
/// an actor isolation if we can find one in there. Returns nullptr if we
185-
/// fail.
186-
NominalTypeDecl *tryInferActorDecl() const;
187-
188168
[[nodiscard]] SILIsolationInfo merge(SILIsolationInfo other) const;
189169

190170
SILIsolationInfo withActorIsolated(ActorIsolation isolation) {
191171
return SILIsolationInfo::getActorIsolated(isolation);
192172
}
193173

194-
static SILIsolationInfo getDisconnected() { return {Kind::Disconnected, {}}; }
174+
static SILIsolationInfo getDisconnected() { return {Kind::Disconnected}; }
195175

196176
static SILIsolationInfo getActorIsolated(ActorIsolation actorIsolation) {
197-
return {Kind::Actor, actorIsolation};
177+
return {actorIsolation};
198178
}
199179

200-
/// Sometimes we may have something that is actor isolated or that comes from
201-
/// a type. First try getActorIsolation and otherwise, just use the type.
202-
static SILIsolationInfo getActorIsolated(NominalTypeDecl *nomDecl) {
203-
auto actorIsolation = swift::getActorIsolation(nomDecl);
204-
if (actorIsolation.isActorIsolated())
205-
return getActorIsolated(actorIsolation);
206-
if (nomDecl->isActor())
207-
return {Kind::Actor, nomDecl};
208-
return SILIsolationInfo();
180+
static SILIsolationInfo getActorIsolated(NominalTypeDecl *typeDecl) {
181+
if (typeDecl->isActor())
182+
return {ActorIsolation::forActorInstanceSelf(typeDecl)};
183+
auto isolation = swift::getActorIsolation(typeDecl);
184+
if (isolation.isGlobalActor())
185+
return {isolation};
186+
return {};
209187
}
210188

211189
static SILIsolationInfo getGlobalActorIsolated(Type globalActorType) {

lib/SILOptimizer/Analysis/RegionAnalysis.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -624,11 +624,7 @@ void SILIsolationInfo::printForDiagnostics(llvm::raw_ostream &os) const {
624624
os << "disconnected";
625625
return;
626626
case Actor:
627-
if (hasActorIsolation() && getActorIsolation()) {
628-
getActorIsolation()->printForDiagnostics(os);
629-
} else {
630-
os << "actor-isolated";
631-
}
627+
getActorIsolation().printForDiagnostics(os);
632628
return;
633629
case Task:
634630
os << "task-isolated";

lib/SILOptimizer/Utils/PartitionUtils.cpp

Lines changed: 6 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,7 @@ SILIsolationInfo SILIsolationInfo::get(SILFunctionArgument *arg) {
9393
if (auto functionIsolation = arg->getFunction()->getActorIsolation()) {
9494
if (functionIsolation.isActorIsolated()) {
9595
if (auto *nomDecl = self->getType().getNominalOrBoundGenericNominal()) {
96-
if (auto isolationInfo =
97-
SILIsolationInfo::getActorIsolated(nomDecl)) {
98-
return isolationInfo;
99-
}
96+
return SILIsolationInfo::getActorIsolated(nomDecl);
10097
}
10198
}
10299
}
@@ -135,23 +132,6 @@ void SILIsolationInfo::print(llvm::raw_ostream &os) const {
135132
}
136133
}
137134

138-
NominalTypeDecl *SILIsolationInfo::tryInferActorDecl() const {
139-
if (hasActorIsolation()) {
140-
auto actorIsolation = getActorIsolation();
141-
if (auto *actor = actorIsolation->getActorOrNullPtr()) {
142-
return actor;
143-
}
144-
return nullptr;
145-
}
146-
147-
if (hasActorInstance()) {
148-
auto actorDecl = getActorInstance();
149-
return actorDecl;
150-
}
151-
152-
return nullptr;
153-
}
154-
155135
SILIsolationInfo SILIsolationInfo::merge(SILIsolationInfo other) const {
156136
// If we are greater than the other kind, then we are further along the
157137
// lattice. We ignore the change.
@@ -179,21 +159,9 @@ bool SILIsolationInfo::operator==(const SILIsolationInfo &other) const {
179159
return getTaskIsolatedValue() == other.getTaskIsolatedValue();
180160
case Actor:
181161
// First try to use actor isolation if we have them.
182-
if (hasActorIsolation() && other.hasActorIsolation()) {
183-
auto lhsIsolation = getActorIsolation();
184-
auto rhsIsolation = other.getActorIsolation();
185-
if (lhsIsolation && rhsIsolation)
186-
return *lhsIsolation == *rhsIsolation;
187-
}
188-
189-
// Otherwise, try to use the inferred actor decl.
190-
auto *lhsDecl = tryInferActorDecl();
191-
auto *rhsDecl = other.tryInferActorDecl();
192-
if (lhsDecl && rhsDecl)
193-
return lhsDecl == rhsDecl;
194-
195-
// Otherwise, false, they are not equal.
196-
return false;
162+
auto lhsIsolation = getActorIsolation();
163+
auto rhsIsolation = other.getActorIsolation();
164+
return lhsIsolation == rhsIsolation;
197165
}
198166
}
199167

@@ -207,22 +175,8 @@ void SILIsolationInfo::Profile(llvm::FoldingSetNodeID &id) const {
207175
id.AddPointer(getTaskIsolatedValue());
208176
return;
209177
case Actor:
210-
// We profile in integer cases here so that we can always distinguish in
211-
// between the various cases and the non-case. Just being paranoid.
212-
if (hasActorIsolation()) {
213-
if (auto isolation = getActorIsolation()) {
214-
id.AddInteger(1);
215-
return isolation->Profile(id);
216-
}
217-
}
218-
219-
if (hasActorInstance()) {
220-
id.AddInteger(2);
221-
return id.AddPointer(getActorInstance());
222-
}
223-
224-
id.AddInteger(3);
225-
break;
178+
getActorIsolation().Profile(id);
179+
return;
226180
}
227181
}
228182

0 commit comments

Comments
 (0)