Skip to content

Commit 8a92c9c

Browse files
committed
Convert ExpandMemberAttributeMacros to use split caching
1 parent 7dc1328 commit 8a92c9c

File tree

4 files changed

+41
-4
lines changed

4 files changed

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

363363
/// Whether this declaration is invalid.
@@ -388,7 +388,11 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
388388
/// True if \c ObjCInterfaceAndImplementationRequest has been computed
389389
/// and did \em not find anything. This is the fast path where we can bail
390390
/// out without checking other caches or computing anything.
391-
LacksObjCInterfaceOrImplementation : 1
391+
LacksObjCInterfaceOrImplementation : 1,
392+
393+
/// True if we're in the common case where the ExpandMemberAttributeMacros
394+
/// request returned an empty array.
395+
NoMemberAttributeMacros : 1
392396
);
393397

394398
SWIFT_INLINE_BITFIELD_FULL(PatternBindingDecl, Decl, 1+1+2+16,
@@ -827,6 +831,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
827831
friend class MemberLookupTable;
828832
friend class DeclDeserializer;
829833
friend class RawCommentRequest;
834+
friend class ExpandMemberAttributeMacros;
830835

831836
private:
832837
llvm::PointerUnion<DeclContext *, ASTContext *> Context;
@@ -845,6 +850,14 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
845850
/// Directly set the invalid bit
846851
void setInvalidBit();
847852

853+
bool hasNoMemberAttributeMacros() const {
854+
return Bits.Decl.NoMemberAttributeMacros;
855+
}
856+
857+
void setHasNoMemberAttributeMacros() {
858+
Bits.Decl.NoMemberAttributeMacros = true;
859+
}
860+
848861
protected:
849862

850863
Decl(DeclKind kind, llvm::PointerUnion<DeclContext *, ASTContext *> context)
@@ -857,6 +870,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
857870
Bits.Decl.EscapedFromIfConfig = false;
858871
Bits.Decl.Hoisted = false;
859872
Bits.Decl.LacksObjCInterfaceOrImplementation = false;
873+
Bits.Decl.NoMemberAttributeMacros = false;
860874
}
861875

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

include/swift/AST/TypeCheckRequests.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4503,7 +4503,8 @@ class ExpandExtensionMacros
45034503
class ExpandMemberAttributeMacros
45044504
: public SimpleRequest<ExpandMemberAttributeMacros,
45054505
ArrayRef<unsigned>(Decl *),
4506-
RequestFlags::Cached> {
4506+
RequestFlags::SeparatelyCached |
4507+
RequestFlags::SplitCached> {
45074508
public:
45084509
using SimpleRequest::SimpleRequest;
45094510

@@ -4514,6 +4515,9 @@ class ExpandMemberAttributeMacros
45144515

45154516
public:
45164517
bool isCached() const { return true; }
4518+
std::optional<ArrayRef<unsigned>> getCachedResult() const;
4519+
void cacheResult(ArrayRef<unsigned> result) const;
4520+
45174521
void diagnoseCycle(DiagnosticEngine &diags) const;
45184522
void noteCycleStep(DiagnosticEngine &diags) const;
45194523
};

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ SWIFT_REQUEST(TypeChecker, ExpandMacroExpansionExprRequest,
503503
Cached, NoLocationInfo)
504504
SWIFT_REQUEST(TypeChecker, ExpandMemberAttributeMacros,
505505
ArrayRef<unsigned>(Decl *),
506-
Cached, NoLocationInfo)
506+
SeparatelyCached | SplitCached, NoLocationInfo)
507507
SWIFT_REQUEST(TypeChecker, ExpandAccessorMacros,
508508
ArrayRef<unsigned>(AbstractStorageDecl *),
509509
Cached, NoLocationInfo)

lib/AST/TypeCheckRequests.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,6 +2081,25 @@ void ExpandExtensionMacros::noteCycleStep(DiagnosticEngine &diags) const {
20812081
decl->getName());
20822082
}
20832083

2084+
std::optional<ArrayRef<unsigned>> ExpandMemberAttributeMacros::getCachedResult() const {
2085+
auto decl = std::get<0>(getStorage());
2086+
if (decl->hasNoMemberAttributeMacros())
2087+
return ArrayRef<unsigned>();
2088+
2089+
return decl->getASTContext().evaluator.getCachedNonEmptyOutput(*this);
2090+
}
2091+
2092+
void ExpandMemberAttributeMacros::cacheResult(ArrayRef<unsigned> result) const {
2093+
auto decl = std::get<0>(getStorage());
2094+
2095+
if (result.empty()) {
2096+
decl->setHasNoMemberAttributeMacros();
2097+
return;
2098+
}
2099+
2100+
decl->getASTContext().evaluator.cacheNonEmptyOutput(*this, std::move(result));
2101+
}
2102+
20842103
void ExpandMemberAttributeMacros::diagnoseCycle(DiagnosticEngine &diags) const {
20852104
auto decl = std::get<0>(getStorage());
20862105
if (auto value = dyn_cast<ValueDecl>(decl)) {

0 commit comments

Comments
 (0)