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:
Allan Shortlidge
2025-08-15 16:09:49 -07:00
parent f96a5e5b2b
commit 678b0934d6
8 changed files with 73 additions and 10 deletions

View File

@@ -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) {