Skip to content

Commit cb31d6c

Browse files
committed
AST: Move ResilienceExpansion to a request
1 parent 1a211e6 commit cb31d6c

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

include/swift/AST/ASTTypeIDZone.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ SWIFT_TYPEID(TypePair)
2424
SWIFT_TYPEID(PropertyWrapperBackingPropertyInfo)
2525
SWIFT_TYPEID(PropertyWrapperTypeInfo)
2626
SWIFT_TYPEID(CtorInitializerKind)
27+
SWIFT_TYPEID(ResilienceExpansion)
2728
SWIFT_TYPEID_NAMED(Optional<PropertyWrapperMutability>, PropertyWrapperMutability)
2829
SWIFT_TYPEID_NAMED(CustomAttr *, CustomAttr)
2930
SWIFT_TYPEID_NAMED(TypeAliasDecl *, TypeAliasDecl)

include/swift/AST/TypeCheckRequests.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,29 @@ class StructuralTypeRequest :
662662
bool isCached() const { return true; }
663663
};
664664

665+
/// Request the most optimal resilience expansion for the code in the context.
666+
class ResilienceExpansionRequest :
667+
public SimpleRequest<ResilienceExpansionRequest,
668+
ResilienceExpansion(DeclContext*),
669+
CacheKind::Cached> {
670+
public:
671+
using SimpleRequest::SimpleRequest;
672+
673+
private:
674+
friend SimpleRequest;
675+
676+
// Evaluation.
677+
llvm::Expected<ResilienceExpansion> evaluate(Evaluator &eval,
678+
DeclContext *context) const;
679+
680+
public:
681+
// Caching.
682+
bool isCached() const { return true; }
683+
};
684+
685+
void simple_display(llvm::raw_ostream &out,
686+
const ResilienceExpansion &value);
687+
665688
/// Request the custom attribute which attaches a function builder to the
666689
/// given declaration.
667690
class AttachedFunctionBuilderRequest :

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ SWIFT_TYPEID(RequirementSignatureRequest)
3030
SWIFT_TYPEID(DefaultDefinitionTypeRequest)
3131
SWIFT_TYPEID(USRGenerationRequest)
3232
SWIFT_TYPEID(StructuralTypeRequest)
33+
SWIFT_TYPEID(ResilienceExpansionRequest)
3334
SWIFT_TYPEID(DefaultTypeRequest)
3435
SWIFT_TYPEID(MangleLocalTypeDeclRequest)
3536
SWIFT_TYPEID(PropertyWrapperTypeInfoRequest)

lib/AST/DeclContext.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "swift/AST/LazyResolver.h"
2121
#include "swift/AST/Module.h"
2222
#include "swift/AST/Types.h"
23+
#include "swift/AST/TypeCheckRequests.h"
2324
#include "swift/Basic/SourceManager.h"
2425
#include "swift/Basic/Statistic.h"
2526
#include "llvm/ADT/DenseMap.h"
@@ -310,7 +311,16 @@ bool DeclContext::isGenericContext() const {
310311
/// domains, this ensures that only sufficiently-conservative access patterns
311312
/// are used.
312313
ResilienceExpansion DeclContext::getResilienceExpansion() const {
313-
for (const auto *dc = getLocalContext(); dc && dc->isLocalContext();
314+
auto &context = getASTContext();
315+
return evaluateOrDefault(context.evaluator,
316+
ResilienceExpansionRequest { const_cast<DeclContext *>(this) },
317+
ResilienceExpansion::Minimal);
318+
}
319+
320+
llvm::Expected<ResilienceExpansion>
321+
swift::ResilienceExpansionRequest::evaluate(Evaluator &eval,
322+
DeclContext *context) const {
323+
for (const auto *dc = context->getLocalContext(); dc && dc->isLocalContext();
314324
dc = dc->getParent()) {
315325
// Default argument initializer contexts have their resilience expansion
316326
// set when they're type checked.

lib/AST/TypeCheckRequests.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,11 @@ void swift::simple_display(llvm::raw_ostream &os, PropertyWrapperMutability m) {
615615
os << "getter " << names[m.Getter] << ", setter " << names[m.Setter];
616616
}
617617

618+
void swift::simple_display(llvm::raw_ostream &out,
619+
const ResilienceExpansion &value) {
620+
out << value;
621+
}
622+
618623
//----------------------------------------------------------------------------//
619624
// FunctionBuilder-related requests.
620625
//----------------------------------------------------------------------------//

0 commit comments

Comments
 (0)