Skip to content

Commit edf8237

Browse files
committed
Convert SPIGroupsRequest to use split caching
1 parent 80ddc32 commit edf8237

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
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+1,
360+
SWIFT_INLINE_BITFIELD_BASE(Decl, bitmax(NumDeclKindBits,8)+1+1+1+1+1+1+1+1+1+1,
361361
Kind : bitmax(NumDeclKindBits,8),
362362

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

397397
/// True if we're in the common case where the GlobalActorAttributeRequest
398398
/// request returned a pair of null pointers.
399-
NoGlobalActorAttribute : 1
399+
NoGlobalActorAttribute : 1,
400+
401+
/// True if we're in the common case where the SPIGroupsRequest
402+
/// request returned an empty array of identifiers.
403+
NoSPIGroups : 1
400404
);
401405

402406
SWIFT_INLINE_BITFIELD_FULL(PatternBindingDecl, Decl, 1+1+2+16,
@@ -840,6 +844,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
840844
friend class RawCommentRequest;
841845
friend class ExpandMemberAttributeMacros;
842846
friend class GlobalActorAttributeRequest;
847+
friend class SPIGroupsRequest;
843848

844849
private:
845850
llvm::PointerUnion<DeclContext *, ASTContext *> Context;
@@ -874,6 +879,14 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
874879
Bits.Decl.NoGlobalActorAttribute = true;
875880
}
876881

882+
bool hasNoSPIGroups() const {
883+
return Bits.Decl.NoSPIGroups;
884+
}
885+
886+
void setHasNoSPIGroups() {
887+
Bits.Decl.NoSPIGroups = true;
888+
}
889+
877890
protected:
878891

879892
Decl(DeclKind kind, llvm::PointerUnion<DeclContext *, ASTContext *> context)
@@ -888,6 +901,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
888901
Bits.Decl.LacksObjCInterfaceOrImplementation = false;
889902
Bits.Decl.NoMemberAttributeMacros = false;
890903
Bits.Decl.NoGlobalActorAttribute = false;
904+
Bits.Decl.NoSPIGroups = false;
891905
}
892906

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

include/swift/AST/TypeCheckRequests.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3374,7 +3374,8 @@ class PatternTypeRequest
33743374
class SPIGroupsRequest :
33753375
public SimpleRequest<SPIGroupsRequest,
33763376
llvm::ArrayRef<Identifier>(const Decl *),
3377-
RequestFlags::Cached> {
3377+
RequestFlags::SeparatelyCached |
3378+
RequestFlags::SplitCached> {
33783379
public:
33793380
using SimpleRequest::SimpleRequest;
33803381

@@ -3387,6 +3388,8 @@ class SPIGroupsRequest :
33873388

33883389
public:
33893390
bool isCached() const { return true; }
3391+
std::optional<llvm::ArrayRef<Identifier>> getCachedResult() const;
3392+
void cacheResult(llvm::ArrayRef<Identifier> result) const;
33903393
};
33913394

33923395

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ SWIFT_REQUEST(TypeChecker, ResolveRawLayoutLikeTypeRequest,
409409
SeparatelyCached, NoLocationInfo)
410410
SWIFT_REQUEST(TypeChecker, SPIGroupsRequest,
411411
llvm::ArrayRef<Identifier>(Decl *),
412-
Cached, NoLocationInfo)
412+
SeparatelyCached | SplitCached, NoLocationInfo)
413413
SWIFT_REQUEST(TypeChecker, SynthesizeMemberwiseInitRequest,
414414
ConstructorDecl *(NominalTypeDecl *), Cached, NoLocationInfo)
415415
SWIFT_REQUEST(TypeChecker, ResolveEffectiveMemberwiseInitRequest,

lib/AST/NameLookupRequests.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,28 @@ void UnqualifiedLookupRequest::writeDependencySink(
469469
track.addTopLevelName(desc.Name.getBaseName());
470470
}
471471

472+
//----------------------------------------------------------------------------//
473+
// SPIGroupsRequest computation.
474+
//----------------------------------------------------------------------------//
475+
476+
std::optional<llvm::ArrayRef<Identifier>> SPIGroupsRequest::getCachedResult() const {
477+
auto *decl = std::get<0>(getStorage());
478+
if (decl->hasNoSPIGroups())
479+
return ArrayRef<Identifier>();
480+
481+
return decl->getASTContext().evaluator.getCachedNonEmptyOutput(*this);
482+
}
483+
484+
void SPIGroupsRequest::cacheResult(llvm::ArrayRef<Identifier> result) const {
485+
auto *decl = std::get<0>(getStorage());
486+
if (result.empty()) {
487+
const_cast<Decl *>(decl)->setHasNoSPIGroups();
488+
return;
489+
}
490+
491+
decl->getASTContext().evaluator.cacheNonEmptyOutput(*this, std::move(result));
492+
}
493+
472494
// The following clang importer requests have some definitions here to prevent
473495
// linker errors when building lib syntax parser (which doesn't link with the
474496
// clang importer).

0 commit comments

Comments
 (0)