Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions include/swift/AST/AvailabilityDomain.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ class AvailabilityDomain final {

/// If `decl` represents an availability domain, returns the corresponding
/// `AvailabilityDomain` value. Otherwise, returns `std::nullopt`.
static std::optional<AvailabilityDomain> forCustom(ValueDecl *decl,
const ASTContext &ctx);
static std::optional<AvailabilityDomain> forCustom(ValueDecl *decl);

static AvailabilityDomain forCustom(const CustomAvailabilityDomain *domain) {
return AvailabilityDomain(domain);
Expand Down
5 changes: 5 additions & 0 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2925,6 +2925,10 @@ class ValueDecl : public Decl {

/// Whether we've evaluated the ApplyAccessNoteRequest.
unsigned accessNoteApplied : 1;

/// Whether the AvailabilityDomainForDeclRequest request was evaluated and
/// yielded no availability domain.
unsigned noAvailabilityDomain : 1;
} LazySemanticInfo = { };

friend class DynamicallyReplacedDeclRequest;
Expand All @@ -2938,6 +2942,7 @@ class ValueDecl : public Decl {
friend class ActorIsolationRequest;
friend class OpaqueResultTypeRequest;
friend class ApplyAccessNoteRequest;
friend class AvailabilityDomainForDeclRequest;

friend class Decl;
SourceLoc getLocFromSource() const { return NameLoc; }
Expand Down
20 changes: 20 additions & 0 deletions include/swift/AST/TypeCheckRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -5424,6 +5424,26 @@ class ModuleHasTypeCheckerPerformanceHacksEnabledRequest
bool isCached() const { return true; }
};

class AvailabilityDomainForDeclRequest
: public SimpleRequest<AvailabilityDomainForDeclRequest,
std::optional<AvailabilityDomain>(ValueDecl *),
RequestFlags::Cached | RequestFlags::SplitCached> {
public:
using SimpleRequest::SimpleRequest;

private:
friend SimpleRequest;

// Evaluation.
std::optional<AvailabilityDomain> evaluate(Evaluator &evaluator,
ValueDecl *decl) const;

public:
bool isCached() const { return true; }
std::optional<std::optional<AvailabilityDomain>> getCachedResult() const;
void cacheResult(std::optional<AvailabilityDomain> domain) const;
};

#define SWIFT_TYPEID_ZONE TypeChecker
#define SWIFT_TYPEID_HEADER "swift/AST/TypeCheckerTypeIDZone.def"
#include "swift/Basic/DefineTypeIDZone.h"
Expand Down
4 changes: 4 additions & 0 deletions include/swift/AST/TypeCheckerTypeIDZone.def
Original file line number Diff line number Diff line change
Expand Up @@ -648,3 +648,7 @@ SWIFT_REQUEST(TypeChecker, BindExtensionsForIDEInspectionRequest,
SWIFT_REQUEST(TypeChecker, ModuleHasTypeCheckerPerformanceHacksEnabledRequest,
bool(const ModuleDecl *),
Cached, NoLocationInfo)

SWIFT_REQUEST(TypeChecker, AvailabilityDomainForDeclRequest,
std::optional<AvailabilityDomain>(ValueDecl *),
Cached | SplitCached, NoLocationInfo)
17 changes: 14 additions & 3 deletions lib/AST/AvailabilityDomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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 =
Expand All @@ -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.
Expand All @@ -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) {
Expand Down
25 changes: 25 additions & 0 deletions lib/AST/TypeCheckRequests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2837,3 +2837,28 @@ void SemanticAvailableAttrRequest::cacheResult(
if (!value)
attr->setInvalid();
}

//----------------------------------------------------------------------------//
// AvailabilityDomainForDeclRequest computation.
//----------------------------------------------------------------------------//

std::optional<std::optional<AvailabilityDomain>>
AvailabilityDomainForDeclRequest::getCachedResult() const {
auto decl = std::get<0>(getStorage());

if (decl->LazySemanticInfo.noAvailabilityDomain)
return std::optional<AvailabilityDomain>();
return decl->getASTContext().evaluator.getCachedNonEmptyOutput(*this);
}

void AvailabilityDomainForDeclRequest::cacheResult(
std::optional<AvailabilityDomain> domain) const {
auto decl = std::get<0>(getStorage());

if (!domain) {
decl->LazySemanticInfo.noAvailabilityDomain = 1;
return;
}

decl->getASTContext().evaluator.cacheNonEmptyOutput(*this, std::move(domain));
}
2 changes: 1 addition & 1 deletion lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4103,7 +4103,7 @@ void ClangModuleUnit::lookupAvailabilityDomains(
if (!imported)
return;

auto customDomain = AvailabilityDomain::forCustom(imported, ctx);
auto customDomain = AvailabilityDomain::forCustom(imported);
ASSERT(customDomain);
results.push_back(*customDomain);
}
Expand Down
7 changes: 3 additions & 4 deletions lib/Serialization/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5824,8 +5824,7 @@ decodeDomainKind(uint8_t kind) {

static std::optional<AvailabilityDomain>
decodeAvailabilityDomain(AvailabilityDomainKind domainKind,
PlatformKind platformKind, ValueDecl *decl,
const ASTContext &ctx) {
PlatformKind platformKind, ValueDecl *decl) {
switch (domainKind) {
case AvailabilityDomainKind::Universal:
return AvailabilityDomain::forUniversal();
Expand All @@ -5838,7 +5837,7 @@ decodeAvailabilityDomain(AvailabilityDomainKind domainKind,
case AvailabilityDomainKind::Platform:
return AvailabilityDomain::forPlatform(platformKind);
case AvailabilityDomainKind::Custom:
return AvailabilityDomain::forCustom(decl, ctx);
return AvailabilityDomain::forCustom(decl);
}
}

Expand Down Expand Up @@ -5905,7 +5904,7 @@ DeclDeserializer::readAvailable_DECL_ATTR(SmallVectorImpl<uint64_t> &scratch,
}
}

auto domain = decodeAvailabilityDomain(domainKind, platform, domainDecl, ctx);
auto domain = decodeAvailabilityDomain(domainKind, platform, domainDecl);
if (!domain)
return llvm::make_error<InavalidAvailabilityDomainError>();

Expand Down