18
18
#include " swift/AST/ASTContext.h"
19
19
#include " swift/AST/AvailabilityDomain.h"
20
20
#include " swift/AST/DiagnosticsParse.h"
21
+ #include " swift/AST/TypeCheckRequests.h"
21
22
#include " llvm/Support/raw_ostream.h"
22
23
23
24
using namespace swift ;
@@ -70,16 +71,21 @@ void AvailabilitySpec::print(llvm::raw_ostream &os) const {
70
71
os << " " << getRawVersion ().getAsString ();
71
72
}
72
73
74
+ std::optional<AvailabilityDomain>
75
+ AvailabilitySpec::resolveInDeclContext (const DeclContext *declContext) {
76
+ auto domainOrIdentifier = getDomainOrIdentifier ();
77
+ auto result =
78
+ domainOrIdentifier.resolveInDeclContext (getStartLoc (), declContext);
79
+ DomainOrIdentifier = domainOrIdentifier;
80
+ return result;
81
+ }
82
+
73
83
std::optional<SemanticAvailabilitySpec>
74
84
AvailabilitySpec::getSemanticAvailabilitySpec (
75
85
const DeclContext *declContext) const {
76
- AvailabilitySpec *mutableThis = const_cast <AvailabilitySpec *>(this );
77
- auto domain = mutableThis->DomainOrIdentifier .resolveInDeclContext (
78
- getStartLoc (), declContext);
79
-
80
- if (domain)
81
- return SemanticAvailabilitySpec (this );
82
- return std::nullopt ;
86
+ return evaluateOrDefault (declContext->getASTContext ().evaluator ,
87
+ SemanticAvailabilitySpecRequest{this , declContext},
88
+ std::nullopt );
83
89
}
84
90
85
91
llvm::VersionTuple SemanticAvailabilitySpec::getVersion () const {
@@ -105,3 +111,33 @@ SemanticAvailabilitySpecs::Filter::operator()(
105
111
return semanticSpec;
106
112
return std::nullopt ;
107
113
}
114
+
115
+ std::optional<SemanticAvailabilitySpec>
116
+ SemanticAvailabilitySpecRequest::evaluate (
117
+ Evaluator &evaluator, const AvailabilitySpec *spec,
118
+ const DeclContext *declContext) const {
119
+ AvailabilitySpec *mutableSpec = const_cast <AvailabilitySpec *>(spec);
120
+ if (mutableSpec->resolveInDeclContext (declContext).has_value ())
121
+ return SemanticAvailabilitySpec (spec);
122
+ return std::nullopt ;
123
+ }
124
+
125
+ std::optional<std::optional<SemanticAvailabilitySpec>>
126
+ SemanticAvailabilitySpecRequest::getCachedResult () const {
127
+ auto *spec = std::get<0 >(getStorage ());
128
+ auto domainOrIdentifier = spec->getDomainOrIdentifier ();
129
+ if (!domainOrIdentifier.isResolved ())
130
+ return {};
131
+
132
+ if (spec->isInvalid ())
133
+ return {std::nullopt };
134
+
135
+ return SemanticAvailabilitySpec (spec);
136
+ }
137
+
138
+ void SemanticAvailabilitySpecRequest::cacheResult (
139
+ std::optional<SemanticAvailabilitySpec> value) const {
140
+ auto *mutableSpec = const_cast <AvailabilitySpec *>(std::get<0 >(getStorage ()));
141
+ if (!value)
142
+ mutableSpec->setInvalid ();
143
+ }
0 commit comments