Skip to content

Commit 80ddc32

Browse files
committed
Convert PropertyWrapperAuxiliaryVariablesRequest to use split caching
1 parent 9d163c4 commit 80ddc32

File tree

5 files changed

+53
-5
lines changed

5 files changed

+53
-5
lines changed

include/swift/AST/Decl.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
444444
IsStatic : 1
445445
);
446446

447-
SWIFT_INLINE_BITFIELD(VarDecl, AbstractStorageDecl, 2+1+1+1+1+1,
447+
SWIFT_INLINE_BITFIELD(VarDecl, AbstractStorageDecl, 2+1+1+1+1+1+1,
448448
/// Encodes whether this is a 'let' binding.
449449
Introducer : 2,
450450

@@ -462,7 +462,10 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
462462
IsPropertyWrapperBackingProperty : 1,
463463

464464
/// Whether this is a lazily top-level global variable from the main file.
465-
IsTopLevelGlobal : 1
465+
IsTopLevelGlobal : 1,
466+
467+
/// Whether this variable has no property wrapper auxiliary variables.
468+
NoPropertyWrapperAuxiliaryVariables : 1
466469
);
467470

468471
SWIFT_INLINE_BITFIELD(ParamDecl, VarDecl, 1+2+NumDefaultArgumentKindBits,
@@ -6118,8 +6121,19 @@ enum class PropertyWrapperSynthesizedPropertyKind {
61186121
/// VarDecl - 'var' and 'let' declarations.
61196122
class VarDecl : public AbstractStorageDecl {
61206123
friend class NamingPatternRequest;
6124+
friend class PropertyWrapperAuxiliaryVariablesRequest;
6125+
61216126
NamedPattern *NamingPattern = nullptr;
61226127

6128+
/// True if this is a top-level global variable from the main source file.
6129+
bool hasNoPropertyWrapperAuxiliaryVariables() const {
6130+
return Bits.VarDecl.NoPropertyWrapperAuxiliaryVariables;
6131+
}
6132+
6133+
void setHasNoPropertyWrapperAuxiliaryVariables() {
6134+
Bits.VarDecl.NoPropertyWrapperAuxiliaryVariables = true;
6135+
}
6136+
61236137
public:
61246138
enum class Introducer : uint8_t {
61256139
Let = 0,

include/swift/AST/TypeCheckRequests.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,8 @@ class PropertyWrapperLValuenessRequest
902902
class PropertyWrapperAuxiliaryVariablesRequest :
903903
public SimpleRequest<PropertyWrapperAuxiliaryVariablesRequest,
904904
PropertyWrapperAuxiliaryVariables(VarDecl *),
905-
RequestFlags::Cached> {
905+
RequestFlags::SeparatelyCached |
906+
RequestFlags::SplitCached> {
906907
public:
907908
using SimpleRequest::SimpleRequest;
908909

@@ -914,8 +915,10 @@ class PropertyWrapperAuxiliaryVariablesRequest :
914915
evaluate(Evaluator &evaluator, VarDecl *var) const;
915916

916917
public:
917-
// Caching
918+
// Separate caching.
918919
bool isCached() const { return true; }
920+
std::optional<PropertyWrapperAuxiliaryVariables> getCachedResult() const;
921+
void cacheResult(PropertyWrapperAuxiliaryVariables value) const;
919922
};
920923

921924
/// Request information about initialization of the backing property

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ SWIFT_REQUEST(TypeChecker, PatternBindingCheckedAndContextualizedInitRequest,
272272
SWIFT_REQUEST(TypeChecker, PrimarySourceFilesRequest,
273273
ArrayRef<SourceFile *>(ModuleDecl *), Cached, NoLocationInfo)
274274
SWIFT_REQUEST(TypeChecker, PropertyWrapperAuxiliaryVariablesRequest,
275-
PropertyWrapperAuxiliaryVariables(VarDecl *), Cached,
275+
PropertyWrapperAuxiliaryVariables(VarDecl *),
276+
SeparatelyCached | SplitCached,
276277
NoLocationInfo)
277278
SWIFT_REQUEST(TypeChecker, PropertyWrapperInitializerInfoRequest,
278279
PropertyWrapperInitializerInfo(VarDecl *), Cached,

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.NoPropertyWrapperAuxiliaryVariables = false;
74127413
}
74137414

74147415
Type VarDecl::getTypeInContext() const {

lib/AST/TypeCheckRequests.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,35 @@ void UnderlyingTypeRequest::diagnoseCycle(DiagnosticEngine &diags) const {
862862
diags.diagnose(aliasDecl, diag::recursive_decl_reference, aliasDecl);
863863
}
864864

865+
//----------------------------------------------------------------------------//
866+
// PropertyWrapperAuxiliaryVariablesRequest computation.
867+
//----------------------------------------------------------------------------//
868+
869+
std::optional<PropertyWrapperAuxiliaryVariables>
870+
PropertyWrapperAuxiliaryVariablesRequest::getCachedResult() const {
871+
auto storage = getStorage();
872+
auto *var = std::get<0>(storage);
873+
874+
if (var->hasNoPropertyWrapperAuxiliaryVariables())
875+
return PropertyWrapperAuxiliaryVariables();
876+
877+
return var->getASTContext().evaluator.getCachedNonEmptyOutput(*this);
878+
}
879+
880+
881+
void PropertyWrapperAuxiliaryVariablesRequest::cacheResult(
882+
PropertyWrapperAuxiliaryVariables value) const {
883+
auto storage = getStorage();
884+
auto *var = std::get<0>(storage);
885+
886+
if (!value) {
887+
var->setHasNoPropertyWrapperAuxiliaryVariables();
888+
return;
889+
}
890+
891+
var->getASTContext().evaluator.cacheNonEmptyOutput(*this, std::move(value));
892+
}
893+
865894
//----------------------------------------------------------------------------//
866895
// StructuralTypeRequest computation.
867896
//----------------------------------------------------------------------------//

0 commit comments

Comments
 (0)