Skip to content

Commit 6b9267a

Browse files
committed
Convert ExpandPeerMacroRequest to use split caching
1 parent edf8237 commit 6b9267a

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

include/swift/AST/Decl.h

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

363363
/// Whether this declaration is invalid.
@@ -394,6 +394,10 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
394394
/// request returned an empty array.
395395
NoMemberAttributeMacros : 1,
396396

397+
/// True if we're in the common case where the ExpandPeerMacroRequest
398+
/// request returned an empty array.
399+
NoPeerMacros : 1,
400+
397401
/// True if we're in the common case where the GlobalActorAttributeRequest
398402
/// request returned a pair of null pointers.
399403
NoGlobalActorAttribute : 1,
@@ -519,7 +523,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
519523

520524
/// Whether this function is a distributed thunk for a distributed
521525
/// function or computed property.
522-
DistributedThunk: 1
526+
DistributedThunk : 1
523527
);
524528

525529
SWIFT_INLINE_BITFIELD(FuncDecl, AbstractFunctionDecl,
@@ -843,6 +847,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
843847
friend class DeclDeserializer;
844848
friend class RawCommentRequest;
845849
friend class ExpandMemberAttributeMacros;
850+
friend class ExpandPeerMacroRequest;
846851
friend class GlobalActorAttributeRequest;
847852
friend class SPIGroupsRequest;
848853

@@ -871,6 +876,14 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
871876
Bits.Decl.NoMemberAttributeMacros = true;
872877
}
873878

879+
bool hasNoPeerMacros() const {
880+
return Bits.Decl.NoPeerMacros;
881+
}
882+
883+
void setHasNoPeerMacros() {
884+
Bits.Decl.NoPeerMacros = true;
885+
}
886+
874887
bool hasNoGlobalActorAttribute() const {
875888
return Bits.Decl.NoGlobalActorAttribute;
876889
}

include/swift/AST/TypeCheckRequests.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4608,7 +4608,8 @@ class CompilerPluginLoadRequest
46084608
class ExpandPeerMacroRequest
46094609
: public SimpleRequest<ExpandPeerMacroRequest,
46104610
ArrayRef<unsigned>(Decl *),
4611-
RequestFlags::Cached> {
4611+
RequestFlags::SeparatelyCached |
4612+
RequestFlags::SplitCached> {
46124613
public:
46134614
using SimpleRequest::SimpleRequest;
46144615

@@ -4618,7 +4619,11 @@ class ExpandPeerMacroRequest
46184619
ArrayRef<unsigned> evaluate(Evaluator &evaluator, Decl *decl) const;
46194620

46204621
public:
4622+
// Separate caching.
46214623
bool isCached() const { return true; }
4624+
std::optional<ArrayRef<unsigned>> getCachedResult() const;
4625+
void cacheResult(ArrayRef<unsigned> result) const;
4626+
46224627
void diagnoseCycle(DiagnosticEngine &diags) const;
46234628
void noteCycleStep(DiagnosticEngine &diags) const;
46244629
};

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ SWIFT_REQUEST(TypeChecker, ExpandSynthesizedMemberMacroRequest,
516516
Cached, NoLocationInfo)
517517
SWIFT_REQUEST(TypeChecker, ExpandPeerMacroRequest,
518518
ArrayRef<unsigned>(Decl *),
519-
Cached, NoLocationInfo)
519+
SeparatelyCached | SplitCached, NoLocationInfo)
520520
SWIFT_REQUEST(TypeChecker, ExpandPreambleMacroRequest,
521521
ArrayRef<unsigned>(AbstractFunctionDecl *),
522522
Cached, NoLocationInfo)

lib/AST/TypeCheckRequests.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2231,6 +2231,30 @@ void ExpandSynthesizedMemberMacroRequest::noteCycleStep(DiagnosticEngine &diags)
22312231
}
22322232
}
22332233

2234+
//----------------------------------------------------------------------------//
2235+
// ExpandPeerMacroRequest computation.
2236+
//----------------------------------------------------------------------------//
2237+
2238+
std::optional<ArrayRef<unsigned>> ExpandPeerMacroRequest::getCachedResult() const {
2239+
auto decl = std::get<0>(getStorage());
2240+
if (decl->hasNoPeerMacros())
2241+
return ArrayRef<unsigned>();
2242+
2243+
return decl->getASTContext().evaluator.getCachedNonEmptyOutput(*this);
2244+
}
2245+
2246+
void ExpandPeerMacroRequest::cacheResult(ArrayRef<unsigned> result) const {
2247+
auto decl = std::get<0>(getStorage());
2248+
2249+
if (result.empty()) {
2250+
decl->setHasNoPeerMacros();
2251+
return;
2252+
}
2253+
2254+
decl->getASTContext().evaluator
2255+
.cacheNonEmptyOutput<ExpandPeerMacroRequest>(*this, std::move(result));
2256+
}
2257+
22342258
void ExpandPeerMacroRequest::diagnoseCycle(DiagnosticEngine &diags) const {
22352259
auto decl = std::get<0>(getStorage());
22362260
if (auto value = dyn_cast<ValueDecl>(decl)) {
@@ -2380,6 +2404,10 @@ void UniqueUnderlyingTypeSubstitutionsRequest::cacheResult(
23802404
->LazySemanticInfo.UniqueUnderlyingTypeComputed = true;
23812405
}
23822406

2407+
//----------------------------------------------------------------------------//
2408+
// ExpandPreambleMacroRequest computation.
2409+
//----------------------------------------------------------------------------//
2410+
23832411
void ExpandPreambleMacroRequest::diagnoseCycle(DiagnosticEngine &diags) const {
23842412
auto decl = std::get<0>(getStorage());
23852413
diags.diagnose(decl->getLoc(),
@@ -2396,6 +2424,10 @@ void ExpandPreambleMacroRequest::noteCycleStep(DiagnosticEngine &diags) const {
23962424
decl->getName());
23972425
}
23982426

2427+
//----------------------------------------------------------------------------//
2428+
// ExpandBodyMacroRequest computation.
2429+
//----------------------------------------------------------------------------//
2430+
23992431
void ExpandBodyMacroRequest::diagnoseCycle(DiagnosticEngine &diags) const {
24002432
auto decl = std::get<0>(getStorage());
24012433
diags.diagnose(decl->getLoc(),

0 commit comments

Comments
 (0)