Skip to content

Commit 9d163c4

Browse files
committed
Convert GlobalActorAttributeRequest to use split caching
1 parent 8a92c9c commit 9d163c4

File tree

5 files changed

+86
-8
lines changed

5 files changed

+86
-8
lines changed

include/swift/AST/Decl.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
357357
// for the inline bitfields.
358358
union { uint64_t OpaqueBits;
359359

360-
SWIFT_INLINE_BITFIELD_BASE(Decl, bitmax(NumDeclKindBits,8)+1+1+1+1+1+1+1+1,
360+
SWIFT_INLINE_BITFIELD_BASE(Decl, bitmax(NumDeclKindBits,8)+1+1+1+1+1+1+1+1+1,
361361
Kind : bitmax(NumDeclKindBits,8),
362362

363363
/// Whether this declaration is invalid.
@@ -392,7 +392,11 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
392392

393393
/// True if we're in the common case where the ExpandMemberAttributeMacros
394394
/// request returned an empty array.
395-
NoMemberAttributeMacros : 1
395+
NoMemberAttributeMacros : 1,
396+
397+
/// True if we're in the common case where the GlobalActorAttributeRequest
398+
/// request returned a pair of null pointers.
399+
NoGlobalActorAttribute : 1
396400
);
397401

398402
SWIFT_INLINE_BITFIELD_FULL(PatternBindingDecl, Decl, 1+1+2+16,
@@ -832,6 +836,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
832836
friend class DeclDeserializer;
833837
friend class RawCommentRequest;
834838
friend class ExpandMemberAttributeMacros;
839+
friend class GlobalActorAttributeRequest;
835840

836841
private:
837842
llvm::PointerUnion<DeclContext *, ASTContext *> Context;
@@ -858,6 +863,14 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
858863
Bits.Decl.NoMemberAttributeMacros = true;
859864
}
860865

866+
bool hasNoGlobalActorAttribute() const {
867+
return Bits.Decl.NoGlobalActorAttribute;
868+
}
869+
870+
void setHasNoGlobalActorAttribute() {
871+
Bits.Decl.NoGlobalActorAttribute = true;
872+
}
873+
861874
protected:
862875

863876
Decl(DeclKind kind, llvm::PointerUnion<DeclContext *, ASTContext *> context)
@@ -871,6 +884,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
871884
Bits.Decl.Hoisted = false;
872885
Bits.Decl.LacksObjCInterfaceOrImplementation = false;
873886
Bits.Decl.NoMemberAttributeMacros = false;
887+
Bits.Decl.NoGlobalActorAttribute = false;
874888
}
875889

876890
/// Get the Clang node associated with this declaration.

include/swift/AST/Expr.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class alignas(8) Expr : public ASTAllocated<Expr> {
266266
Kind : 2
267267
);
268268

269-
SWIFT_INLINE_BITFIELD(ClosureExpr, AbstractClosureExpr, 1+1+1+1+1,
269+
SWIFT_INLINE_BITFIELD(ClosureExpr, AbstractClosureExpr, 1+1+1+1+1+1,
270270
/// True if closure parameters were synthesized from anonymous closure
271271
/// variables.
272272
HasAnonymousClosureVars : 1,
@@ -284,7 +284,11 @@ class alignas(8) Expr : public ASTAllocated<Expr> {
284284
IsolatedByPreconcurrency : 1,
285285

286286
/// True if this is a closure literal that is passed to a sending parameter.
287-
IsPassedToSendingParameter : 1
287+
IsPassedToSendingParameter : 1,
288+
289+
/// True if we're in the common case where the GlobalActorAttributeRequest
290+
/// request returned a pair of null pointers.
291+
NoGlobalActorAttribute : 1
288292
);
289293

290294
SWIFT_INLINE_BITFIELD_FULL(BindOptionalExpr, Expr, 16,
@@ -4124,6 +4128,16 @@ class ClosureExpr : public AbstractClosureExpr {
41244128
/// The body of the closure.
41254129
BraceStmt *Body;
41264130

4131+
friend class GlobalActorAttributeRequest;
4132+
4133+
bool hasNoGlobalActorAttribute() const {
4134+
return Bits.ClosureExpr.NoGlobalActorAttribute;
4135+
}
4136+
4137+
void setHasNoGlobalActorAttribute() {
4138+
Bits.ClosureExpr.NoGlobalActorAttribute = true;
4139+
}
4140+
41274141
public:
41284142
ClosureExpr(const DeclAttributes &attributes,
41294143
SourceRange bracketRange, VarDecl *capturedSelfDecl,
@@ -4143,6 +4157,7 @@ class ClosureExpr : public AbstractClosureExpr {
41434157
Bits.ClosureExpr.ImplicitSelfCapture = false;
41444158
Bits.ClosureExpr.InheritActorContext = false;
41454159
Bits.ClosureExpr.IsPassedToSendingParameter = false;
4160+
Bits.ClosureExpr.NoGlobalActorAttribute = false;
41464161
}
41474162

41484163
SourceRange getSourceRange() const;

include/swift/AST/TypeCheckRequests.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,21 +1507,24 @@ class GlobalActorAttributeRequest
15071507
: public SimpleRequest<GlobalActorAttributeRequest,
15081508
std::optional<CustomAttrNominalPair>(
15091509
llvm::PointerUnion<Decl *, ClosureExpr *>),
1510-
RequestFlags::Cached> {
1510+
RequestFlags::SeparatelyCached |
1511+
RequestFlags::SplitCached> {
15111512
public:
15121513
using SimpleRequest::SimpleRequest;
15131514

15141515
private:
15151516
friend SimpleRequest;
15161517

15171518
// Evaluation.
1518-
std::optional<std::pair<CustomAttr *, NominalTypeDecl *>>
1519+
std::optional<CustomAttrNominalPair>
15191520
evaluate(Evaluator &evaluator,
15201521
llvm::PointerUnion<Decl *, ClosureExpr *>) const;
15211522

15221523
public:
1523-
// Caching
1524+
// Separate caching.
15241525
bool isCached() const { return true; }
1526+
std::optional<std::optional<CustomAttrNominalPair>> getCachedResult() const;
1527+
void cacheResult(std::optional<CustomAttrNominalPair> value) const;
15251528
};
15261529

15271530
/// Determine the actor isolation for the given declaration.

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ SWIFT_REQUEST(TypeChecker, GlobalActorInstanceRequest,
174174
SWIFT_REQUEST(TypeChecker, GlobalActorAttributeRequest,
175175
Optional<CustomAttrNominalPair>(
176176
llvm::PointerUnion<Decl *, ClosureExpr *>),
177-
Cached, NoLocationInfo)
177+
SeparatelyCached | SplitCached, NoLocationInfo)
178178
SWIFT_REQUEST(TypeChecker, ActorIsolationRequest,
179179
ActorIsolationState(ValueDecl *),
180180
Cached, NoLocationInfo)

lib/AST/TypeCheckRequests.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,6 +1868,52 @@ void swift::simple_display(
18681868
simple_display(out, initKindAndExpr.initExpr);
18691869
}
18701870

1871+
//----------------------------------------------------------------------------//
1872+
// GlobalActorAttributeRequest computation.
1873+
//----------------------------------------------------------------------------//
1874+
1875+
std::optional<std::optional<CustomAttrNominalPair>>
1876+
GlobalActorAttributeRequest::getCachedResult() const {
1877+
auto storage = getStorage();
1878+
auto subject = std::get<0>(storage);
1879+
1880+
if (auto decl = subject.dyn_cast<Decl *>()) {
1881+
if (decl->hasNoGlobalActorAttribute())
1882+
return std::optional(std::optional<CustomAttrNominalPair>());
1883+
1884+
return decl->getASTContext().evaluator.getCachedNonEmptyOutput(*this);
1885+
} else {
1886+
auto closure = subject.get<ClosureExpr *>();
1887+
if (closure->hasNoGlobalActorAttribute())
1888+
return std::optional(std::optional<CustomAttrNominalPair>());
1889+
1890+
return closure->getASTContext().evaluator.getCachedNonEmptyOutput(*this);
1891+
}
1892+
}
1893+
1894+
void
1895+
GlobalActorAttributeRequest::cacheResult(std::optional<CustomAttrNominalPair> value) const {
1896+
auto storage = getStorage();
1897+
auto subject = std::get<0>(storage);
1898+
1899+
if (auto decl = subject.dyn_cast<Decl *>()) {
1900+
if (!value) {
1901+
decl->setHasNoGlobalActorAttribute();
1902+
return;
1903+
}
1904+
1905+
decl->getASTContext().evaluator.cacheNonEmptyOutput(*this, std::move(value));
1906+
} else {
1907+
auto closure = subject.get<ClosureExpr *>();
1908+
if (!value) {
1909+
closure->setHasNoGlobalActorAttribute();
1910+
return;
1911+
}
1912+
1913+
closure->getASTContext().evaluator.cacheNonEmptyOutput(*this, std::move(value));
1914+
}
1915+
}
1916+
18711917
//----------------------------------------------------------------------------//
18721918
// ResolveMacroRequest computation.
18731919
//----------------------------------------------------------------------------//

0 commit comments

Comments
 (0)