Skip to content

Commit 246ea41

Browse files
DougGregorCatfish-Man
authored andcommitted
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 926a4cb commit 246ea41

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:
@@ -587,14 +599,6 @@ class NormalProtocolConformance : public RootProtocolConformance,
587599
// Record the explicitly-specified global actor isolation.
588600
void setExplicitGlobalActorIsolation(TypeExpr *typeExpr);
589601

590-
bool isComputedNonisolated() const {
591-
return Bits.NormalProtocolConformance.IsComputedNonisolated;
592-
}
593-
594-
void setComputedNonnisolated(bool value = true) {
595-
Bits.NormalProtocolConformance.IsComputedNonisolated = value;
596-
}
597-
598602
public:
599603
NormalProtocolConformance(Type conformingType, ProtocolDecl *protocol,
600604
SourceLoc loc, DeclContext *dc,
@@ -618,7 +622,6 @@ class NormalProtocolConformance : public RootProtocolConformance,
618622
Bits.NormalProtocolConformance.HasComputedAssociatedConformances = false;
619623
Bits.NormalProtocolConformance.SourceKind =
620624
unsigned(ConformanceEntryKind::Explicit);
621-
Bits.NormalProtocolConformance.IsComputedNonisolated = false;
622625
Bits.NormalProtocolConformance.HasExplicitGlobalActor = false;
623626
setExplicitGlobalActorIsolation(options.getGlobalActorIsolationType());
624627
}

lib/AST/TypeCheckRequests.cpp

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

13811377
// Was actor isolation non-isolated?
1382-
if (rootNormal->isComputedNonisolated())
1378+
if (conformance->isComputedNonisolated())
13831379
return ActorIsolation::forNonisolated(false);
13841380

1385-
ASTContext &ctx = rootNormal->getDeclContext()->getASTContext();
1381+
ASTContext &ctx = conformance->getDeclContext()->getASTContext();
13861382
return ctx.evaluator.getCachedNonEmptyOutput(*this);
13871383
}
13881384

13891385
void ConformanceIsolationRequest::cacheResult(ActorIsolation result) const {
13901386
auto conformance = std::get<0>(getStorage());
1391-
auto rootNormal =
1392-
cast<NormalProtocolConformance>(conformance->getRootConformance());
13931387

13941388
// Common case: conformance is nonisolated.
13951389
if (result.isNonisolated()) {
1396-
rootNormal->setComputedNonnisolated();
1390+
conformance->setComputedNonnisolated();
13971391
return;
13981392
}
13991393

1400-
ASTContext &ctx = rootNormal->getDeclContext()->getASTContext();
1394+
ASTContext &ctx = conformance->getDeclContext()->getASTContext();
14011395
ctx.evaluator.cacheNonEmptyOutput(*this, std::move(result));
14021396
}
14031397

lib/Sema/TypeCheckConcurrency.cpp

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

7913+
if (conformance != rootNormal)
7914+
return rootNormal->getIsolation();
7915+
79137916
// If the conformance is explicitly non-isolated, report that.
79147917
if (rootNormal->getOptions().contains(ProtocolConformanceFlags::Nonisolated))
79157918
return ActorIsolation::forNonisolated(false);

0 commit comments

Comments
 (0)