mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
AST/Sema: Resolve AvailabilityDomain in SemanticAvailableAttrRequest.
Look up the AvailabilityDomain given its name during type checking, instead of parsing.
This commit is contained in:
@@ -912,6 +912,12 @@ private:
|
||||
private:
|
||||
friend class SemanticAvailableAttrRequest;
|
||||
|
||||
void setCachedDomain(AvailabilityDomain domain) {
|
||||
assert(!Bits.AvailableAttr.HasDomain);
|
||||
Domain = domain;
|
||||
Bits.AvailableAttr.HasDomain = true;
|
||||
}
|
||||
|
||||
bool hasComputedSemanticAttr() const {
|
||||
return Bits.AvailableAttr.HasComputedSemanticAttr;
|
||||
}
|
||||
|
||||
@@ -140,6 +140,10 @@ public:
|
||||
return AvailabilityDomain(Kind::Embedded);
|
||||
}
|
||||
|
||||
/// Returns the built-in availability domain identified by the given string.
|
||||
static std::optional<AvailabilityDomain>
|
||||
builtinDomainForString(StringRef string);
|
||||
|
||||
Kind getKind() const {
|
||||
if (auto inlineDomain = getInlineDomain())
|
||||
return inlineDomain->getKind();
|
||||
|
||||
@@ -13,9 +13,28 @@
|
||||
#include "swift/AST/AvailabilityDomain.h"
|
||||
#include "swift/AST/ASTContext.h"
|
||||
#include "swift/AST/Decl.h"
|
||||
#include "llvm/ADT/StringSwitch.h"
|
||||
|
||||
using namespace swift;
|
||||
|
||||
std::optional<AvailabilityDomain>
|
||||
AvailabilityDomain::builtinDomainForString(StringRef string) {
|
||||
auto domain = llvm::StringSwitch<std::optional<AvailabilityDomain>>(string)
|
||||
.Case("*", AvailabilityDomain::forUniversal())
|
||||
.Case("swift", AvailabilityDomain::forSwiftLanguage())
|
||||
.Case("_PackageDescription",
|
||||
AvailabilityDomain::forPackageDescription())
|
||||
.Default(std::nullopt);
|
||||
|
||||
if (domain)
|
||||
return domain;
|
||||
|
||||
if (auto platformKind = platformFromString(string))
|
||||
return AvailabilityDomain::forPlatform(*platformKind);
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
bool AvailabilityDomain::isActive(const ASTContext &ctx) const {
|
||||
switch (getKind()) {
|
||||
case Kind::Universal:
|
||||
|
||||
@@ -628,8 +628,8 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
|
||||
}
|
||||
|
||||
auto Attr = new (Context) AvailableAttr(
|
||||
AtLoc, SourceRange(AttrLoc, Tok.getLoc()), Domain, PlatformLoc, AttrKind,
|
||||
Message, Renamed, Introduced.Version, Introduced.Range,
|
||||
AtLoc, SourceRange(AttrLoc, Tok.getLoc()), Platform, PlatformLoc,
|
||||
AttrKind, Message, Renamed, Introduced.Version, Introduced.Range,
|
||||
Deprecated.Version, Deprecated.Range, Obsoleted.Version, Obsoleted.Range,
|
||||
/*Implicit=*/false, AttrName == SPI_AVAILABLE_ATTRNAME);
|
||||
return makeParserResult(Attr);
|
||||
|
||||
@@ -8270,6 +8270,17 @@ std::optional<SemanticAvailableAttr>
|
||||
SemanticAvailableAttrRequest::evaluate(swift::Evaluator &evaluator,
|
||||
const AvailableAttr *attr,
|
||||
const Decl *decl) const {
|
||||
if (attr->hasCachedDomain())
|
||||
return SemanticAvailableAttr(attr);
|
||||
|
||||
auto string = attr->getDomainString();
|
||||
ASSERT(string);
|
||||
|
||||
auto domain = AvailabilityDomain::builtinDomainForString(*string);
|
||||
if (!domain)
|
||||
return std::nullopt;
|
||||
|
||||
const_cast<AvailableAttr *>(attr)->setCachedDomain(*domain);
|
||||
return SemanticAvailableAttr(attr);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user