Skip to content

Commit ec28d62

Browse files
committed
Convert AttachedPropertyWrappersRequest to use split caching
1 parent 6489b60 commit ec28d62

File tree

5 files changed

+48
-5
lines changed

5 files changed

+48
-5
lines changed

include/swift/AST/Decl.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
452452
IsStatic : 1
453453
);
454454

455-
SWIFT_INLINE_BITFIELD(VarDecl, AbstractStorageDecl, 2+1+1+1+1+1+1,
455+
SWIFT_INLINE_BITFIELD(VarDecl, AbstractStorageDecl, 2+1+1+1+1+1+1+1,
456456
/// Encodes whether this is a 'let' binding.
457457
Introducer : 2,
458458

@@ -472,6 +472,9 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
472472
/// Whether this is a lazily top-level global variable from the main file.
473473
IsTopLevelGlobal : 1,
474474

475+
/// Whether this variable has no attached property wrappers.
476+
NoAttachedPropertyWrappers : 1,
477+
475478
/// Whether this variable has no property wrapper auxiliary variables.
476479
NoPropertyWrapperAuxiliaryVariables : 1
477480
);
@@ -6158,11 +6161,19 @@ enum class PropertyWrapperSynthesizedPropertyKind {
61586161
/// VarDecl - 'var' and 'let' declarations.
61596162
class VarDecl : public AbstractStorageDecl {
61606163
friend class NamingPatternRequest;
6164+
friend class AttachedPropertyWrappersRequest;
61616165
friend class PropertyWrapperAuxiliaryVariablesRequest;
61626166

61636167
NamedPattern *NamingPattern = nullptr;
61646168

6165-
/// True if this is a top-level global variable from the main source file.
6169+
bool hasNoAttachedPropertyWrappers() const {
6170+
return Bits.VarDecl.NoAttachedPropertyWrappers;
6171+
}
6172+
6173+
void setHasNoAttachedPropertyWrappers() {
6174+
Bits.VarDecl.NoAttachedPropertyWrappers = true;
6175+
}
6176+
61666177
bool hasNoPropertyWrapperAuxiliaryVariables() const {
61676178
return Bits.VarDecl.NoPropertyWrapperAuxiliaryVariables;
61686179
}

include/swift/AST/TypeCheckRequests.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,8 @@ class PropertyWrapperTypeInfoRequest
800800
class AttachedPropertyWrappersRequest :
801801
public SimpleRequest<AttachedPropertyWrappersRequest,
802802
llvm::TinyPtrVector<CustomAttr *>(VarDecl *),
803-
RequestFlags::Cached> {
803+
RequestFlags::SeparatelyCached |
804+
RequestFlags::SplitCached> {
804805
public:
805806
using SimpleRequest::SimpleRequest;
806807

@@ -812,8 +813,10 @@ class AttachedPropertyWrappersRequest :
812813
evaluate(Evaluator &evaluator, VarDecl *) const;
813814

814815
public:
815-
// Caching
816+
// Separate caching.
816817
bool isCached() const { return true; }
818+
std::optional<llvm::TinyPtrVector<CustomAttr *>> getCachedResult() const;
819+
void cacheResult(llvm::TinyPtrVector<CustomAttr *> result) const;
817820
};
818821

819822
/// Request the raw (possibly unbound generic) type of the property wrapper

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ SWIFT_REQUEST(TypeChecker, AttachedResultBuilderRequest,
2828
SWIFT_REQUEST(TypeChecker, AttachedPropertyWrapperTypeRequest,
2929
Type(VarDecl *, unsigned), Cached, NoLocationInfo)
3030
SWIFT_REQUEST(TypeChecker, AttachedPropertyWrappersRequest,
31-
llvm::TinyPtrVector<CustomAttr *>(VarDecl *), Cached,
31+
llvm::TinyPtrVector<CustomAttr *>(VarDecl *),
32+
SeparatelyCached | SplitCached,
3233
NoLocationInfo)
3334
SWIFT_REQUEST(TypeChecker, CallerSideDefaultArgExprRequest,
3435
Expr *(DefaultArgumentExpr *), SeparatelyCached, NoLocationInfo)

lib/AST/Decl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7409,6 +7409,7 @@ VarDecl::VarDecl(DeclKind kind, bool isStatic, VarDecl::Introducer introducer,
74097409
Bits.VarDecl.IsLazyStorageProperty = false;
74107410
Bits.VarDecl.IsPropertyWrapperBackingProperty = false;
74117411
Bits.VarDecl.IsTopLevelGlobal = false;
7412+
Bits.VarDecl.NoAttachedPropertyWrappers = false;
74127413
Bits.VarDecl.NoPropertyWrapperAuxiliaryVariables = false;
74137414
}
74147415

lib/AST/TypeCheckRequests.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,33 @@ void swift::simple_display(llvm::raw_ostream &out,
647647
llvm_unreachable("Bad FragileFunctionKind");
648648
}
649649

650+
//----------------------------------------------------------------------------//
651+
// AttachedPropertyWrappersRequest computation.
652+
//----------------------------------------------------------------------------//
653+
654+
std::optional<llvm::TinyPtrVector<CustomAttr *>>
655+
AttachedPropertyWrappersRequest::getCachedResult() const {
656+
auto *decl = std::get<0>(getStorage());
657+
658+
if (decl->hasNoAttachedPropertyWrappers())
659+
return llvm::TinyPtrVector<CustomAttr *>();
660+
661+
return decl->getASTContext().evaluator.getCachedNonEmptyOutput(*this);
662+
}
663+
664+
665+
void AttachedPropertyWrappersRequest::cacheResult(
666+
llvm::TinyPtrVector<CustomAttr *> result) const {
667+
auto *decl = std::get<0>(getStorage());
668+
669+
if (result.empty()) {
670+
decl->setHasNoAttachedPropertyWrappers();
671+
return;
672+
}
673+
674+
decl->getASTContext().evaluator.cacheNonEmptyOutput(*this, std::move(result));
675+
}
676+
650677
//----------------------------------------------------------------------------//
651678
// SelfAccessKindRequest computation.
652679
//----------------------------------------------------------------------------//

0 commit comments

Comments
 (0)