mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
AST: Request-ify getting the AvailabilityDomain from a ValueDecl.
Cache the result of turning a `ValueDecl` into an `AvailabilityDomain`. Use split caching to make the common case of the decl not representing an availability domain efficient. NFC.
This commit is contained in:
@@ -39,7 +39,7 @@ getCustomDomainKind(clang::FeatureAvailKind featureAvailKind) {
|
||||
}
|
||||
|
||||
static const CustomAvailabilityDomain *
|
||||
customDomainForClangDecl(ValueDecl *decl, const ASTContext &ctx) {
|
||||
customDomainForClangDecl(ValueDecl *decl) {
|
||||
auto *clangDecl = decl->getClangDecl();
|
||||
ASSERT(clangDecl);
|
||||
|
||||
@@ -57,6 +57,7 @@ customDomainForClangDecl(ValueDecl *decl, const ASTContext &ctx) {
|
||||
if (featureInfo.second.Kind == clang::FeatureAvailKind::None)
|
||||
return nullptr;
|
||||
|
||||
auto &ctx = decl->getASTContext();
|
||||
FuncDecl *predicate = nullptr;
|
||||
if (featureInfo.second.Kind == clang::FeatureAvailKind::Dynamic)
|
||||
predicate =
|
||||
@@ -68,12 +69,13 @@ customDomainForClangDecl(ValueDecl *decl, const ASTContext &ctx) {
|
||||
}
|
||||
|
||||
std::optional<AvailabilityDomain>
|
||||
AvailabilityDomain::forCustom(ValueDecl *decl, const ASTContext &ctx) {
|
||||
AvailabilityDomainForDeclRequest::evaluate(Evaluator &evaluator,
|
||||
ValueDecl *decl) const {
|
||||
if (!decl)
|
||||
return std::nullopt;
|
||||
|
||||
if (decl->hasClangNode()) {
|
||||
if (auto *customDomain = customDomainForClangDecl(decl, ctx))
|
||||
if (auto *customDomain = customDomainForClangDecl(decl))
|
||||
return AvailabilityDomain::forCustom(customDomain);
|
||||
} else {
|
||||
// FIXME: [availability] Handle Swift availability domains decls.
|
||||
@@ -82,6 +84,15 @@ AvailabilityDomain::forCustom(ValueDecl *decl, const ASTContext &ctx) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<AvailabilityDomain>
|
||||
AvailabilityDomain::forCustom(ValueDecl *decl) {
|
||||
if (!decl)
|
||||
return std::nullopt;
|
||||
|
||||
return evaluateOrDefault(decl->getASTContext().evaluator,
|
||||
AvailabilityDomainForDeclRequest{decl}, {});
|
||||
}
|
||||
|
||||
std::optional<AvailabilityDomain>
|
||||
AvailabilityDomain::builtinDomainForString(StringRef string,
|
||||
const DeclContext *declContext) {
|
||||
|
||||
Reference in New Issue
Block a user