Skip to content

Commit 89358d6

Browse files
committed
Make ConformanceIsolationRequest cache per-ProtocolConformance
This request was looking through to the root conformance, which could mess with the caching bits. Sink the "is nonisolated conformance" bit down into ProtocolConformance, and have the request for a non-root conformance be defined in terms of the request for the root conformance.
1 parent 2ec6fbe commit 89358d6

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

include/swift/AST/ProtocolConformance.h

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance
131131
/// conformance definition.
132132
Type ConformingType;
133133

134+
friend class ConformanceIsolationRequest;
135+
134136
protected:
135137
// clang-format off
136138
//
@@ -139,9 +141,13 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance
139141
union { uint64_t OpaqueBits;
140142

141143
SWIFT_INLINE_BITFIELD_BASE(ProtocolConformance,
144+
1+
142145
bitmax(NumProtocolConformanceKindBits, 8),
143146
/// The kind of protocol conformance.
144-
Kind : bitmax(NumProtocolConformanceKindBits, 8)
147+
Kind : bitmax(NumProtocolConformanceKindBits, 8),
148+
149+
/// Whether the computed actor isolation is nonisolated.
150+
IsComputedNonisolated : 1
145151
);
146152

147153
SWIFT_INLINE_BITFIELD_EMPTY(RootProtocolConformance, ProtocolConformance);
@@ -161,9 +167,6 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance
161167
/// this conformance.
162168
IsPreconcurrencyEffectful : 1,
163169

164-
/// Whether the computed actor isolation is nonisolated.
165-
IsComputedNonisolated : 1,
166-
167170
/// Whether there is an explicit global actor specified for this
168171
/// conformance.
169172
HasExplicitGlobalActor : 1,
@@ -198,6 +201,15 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance
198201
ProtocolConformance(ProtocolConformanceKind kind, Type conformingType)
199202
: ConformingType(conformingType) {
200203
Bits.ProtocolConformance.Kind = unsigned(kind);
204+
Bits.ProtocolConformance.IsComputedNonisolated = false;
205+
}
206+
207+
bool isComputedNonisolated() const {
208+
return Bits.ProtocolConformance.IsComputedNonisolated;
209+
}
210+
211+
void setComputedNonnisolated(bool value = true) {
212+
Bits.ProtocolConformance.IsComputedNonisolated = value;
201213
}
202214

203215
public:
@@ -591,14 +603,6 @@ class NormalProtocolConformance : public RootProtocolConformance,
591603
// Record the explicitly-specified global actor isolation.
592604
void setExplicitGlobalActorIsolation(TypeExpr *typeExpr);
593605

594-
bool isComputedNonisolated() const {
595-
return Bits.NormalProtocolConformance.IsComputedNonisolated;
596-
}
597-
598-
void setComputedNonnisolated(bool value = true) {
599-
Bits.NormalProtocolConformance.IsComputedNonisolated = value;
600-
}
601-
602606
public:
603607
NormalProtocolConformance(Type conformingType, ProtocolDecl *protocol,
604608
SourceLoc loc, DeclContext *dc,
@@ -622,7 +626,6 @@ class NormalProtocolConformance : public RootProtocolConformance,
622626
Bits.NormalProtocolConformance.HasComputedAssociatedConformances = false;
623627
Bits.NormalProtocolConformance.SourceKind =
624628
unsigned(ConformanceEntryKind::Explicit);
625-
Bits.NormalProtocolConformance.IsComputedNonisolated = false;
626629
Bits.NormalProtocolConformance.HasExplicitGlobalActor = false;
627630
setExplicitGlobalActorIsolation(options.getGlobalActorIsolationType());
628631
}

lib/AST/TypeCheckRequests.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,31 +1378,25 @@ ConformanceIsolationRequest::getCachedResult() const {
13781378
// everything else, which is nearly every conformance, this request quickly
13791379
// returns "nonisolated" so there is no point in caching it.
13801380
auto conformance = std::get<0>(getStorage());
1381-
auto rootNormal =
1382-
dyn_cast<NormalProtocolConformance>(conformance->getRootConformance());
1383-
if (!rootNormal)
1384-
return ActorIsolation::forNonisolated(false);
13851381

13861382
// Was actor isolation non-isolated?
1387-
if (rootNormal->isComputedNonisolated())
1383+
if (conformance->isComputedNonisolated())
13881384
return ActorIsolation::forNonisolated(false);
13891385

1390-
ASTContext &ctx = rootNormal->getDeclContext()->getASTContext();
1386+
ASTContext &ctx = conformance->getDeclContext()->getASTContext();
13911387
return ctx.evaluator.getCachedNonEmptyOutput(*this);
13921388
}
13931389

13941390
void ConformanceIsolationRequest::cacheResult(ActorIsolation result) const {
13951391
auto conformance = std::get<0>(getStorage());
1396-
auto rootNormal =
1397-
cast<NormalProtocolConformance>(conformance->getRootConformance());
13981392

13991393
// Common case: conformance is nonisolated.
14001394
if (result.isNonisolated()) {
1401-
rootNormal->setComputedNonnisolated();
1395+
conformance->setComputedNonnisolated();
14021396
return;
14031397
}
14041398

1405-
ASTContext &ctx = rootNormal->getDeclContext()->getASTContext();
1399+
ASTContext &ctx = conformance->getDeclContext()->getASTContext();
14061400
ctx.evaluator.cacheNonEmptyOutput(*this, std::move(result));
14071401
}
14081402

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7954,6 +7954,9 @@ ConformanceIsolationRequest::evaluate(Evaluator &evaluator, ProtocolConformance
79547954
if (!rootNormal)
79557955
return ActorIsolation::forNonisolated(false);
79567956

7957+
if (conformance != rootNormal)
7958+
return rootNormal->getIsolation();
7959+
79577960
// If the conformance is explicitly non-isolated, report that.
79587961
if (rootNormal->getOptions().contains(ProtocolConformanceFlags::Nonisolated))
79597962
return ActorIsolation::forNonisolated(false);

0 commit comments

Comments
 (0)