[NFC] add llvm namespace to Optional and None

This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
This commit is contained in:
Evan Wilde
2023-06-15 11:20:33 -07:00
parent 50d2f4d3ed
commit f3ff561c6f
684 changed files with 5846 additions and 5798 deletions

View File

@@ -35,7 +35,7 @@ struct swift::ide::api::SDKNodeInitInfo {
#include "swift/IDE/DigesterEnums.def"
#define KEY_BOOL(X, Y) bool X = false;
#include "swift/IDE/DigesterEnums.def"
#define KEY_UINT(X, Y) Optional<uint8_t> X;
#define KEY_UINT(X, Y) llvm::Optional<uint8_t> X;
#include "swift/IDE/DigesterEnums.def"
#define KEY_STRING_ARR(X, Y) std::vector<StringRef> X;
#include "swift/IDE/DigesterEnums.def"
@@ -550,19 +550,19 @@ StringRef SDKNodeTypeWitness::getWitnessedTypeName() const {
getName()) + "." + getName()).str());
}
Optional<SDKNodeDeclType*> SDKNodeDeclType::getSuperclass() const {
llvm::Optional<SDKNodeDeclType*> SDKNodeDeclType::getSuperclass() const {
if (SuperclassUsr.empty())
return None;
return llvm::None;
auto Descendants = getRootNode()->getDescendantsByUsr(SuperclassUsr);
if (!Descendants.empty()) {
return Descendants.front()->getAs<SDKNodeDeclType>();
}
return None;
return llvm::None;
}
/// Finding the node through all children, including the inherited ones,
/// whose printed name matches with the given name.
Optional<SDKNodeDecl*>
llvm::Optional<SDKNodeDecl*>
SDKNodeDeclType::lookupChildByPrintedName(StringRef Name) const {
for (auto C : getChildren()) {
if (C->getPrintedName() == Name)
@@ -572,7 +572,7 @@ SDKNodeDeclType::lookupChildByPrintedName(StringRef Name) const {
if (auto Super = getSuperclass()) {
return (*Super)->lookupChildByPrintedName(Name);
}
return None;
return llvm::None;
}
SDKNodeType *SDKNodeDeclType::getRawValueType() const {
@@ -614,11 +614,11 @@ StringRef SDKNodeDeclAbstractFunc::getTypeRoleDescription(SDKContext &Ctx,
}
#include "swift/IDE/DigesterEnums.def"
static Optional<KeyKind> parseKeyKind(StringRef Content) {
return llvm::StringSwitch<Optional<KeyKind>>(Content)
static llvm::Optional<KeyKind> parseKeyKind(StringRef Content) {
return llvm::StringSwitch<llvm::Optional<KeyKind>>(Content)
#define KEY(NAME) .Case(#NAME, KeyKind::KK_##NAME)
#include "swift/IDE/DigesterEnums.def"
.Default(None);
.Default(llvm::None);
}
static StringRef getKeyContent(SDKContext &Ctx, KeyKind Kind) {
@@ -751,11 +751,11 @@ SDKNode* SDKNode::constructSDKNode(SDKContext &Ctx,
break;
}
case KeyKind::KK_declKind: {
auto dKind = llvm::StringSwitch<Optional<DeclKind>>(
auto dKind = llvm::StringSwitch<llvm::Optional<DeclKind>>(
GetScalarString(Pair.getValue()))
#define DECL(X, PARENT) .Case(#X, DeclKind::X)
#include "swift/AST/DeclNodes.def"
.Default(None);
.Default(llvm::None);
if (dKind)
Info.DKind = *dKind;
else
@@ -848,7 +848,7 @@ static bool hasSameParameterFlags(const SDKNodeType *Left, const SDKNodeType *Ri
}
// Return whether a decl has been moved in/out to an extension
static Optional<bool> isFromExtensionChanged(const SDKNode &L, const SDKNode &R) {
static llvm::Optional<bool> isFromExtensionChanged(const SDKNode &L, const SDKNode &R) {
assert(L.getKind() == R.getKind());
// Version 8 starts to include whether a decl is from an extension.
if (L.getJsonFormatVersion() + R.getJsonFormatVersion() < 2 * 8) {
@@ -1185,12 +1185,12 @@ static bool isFuncThrowing(ValueDecl *VD) {
return false;
}
static Optional<uint8_t> getSelfIndex(ValueDecl *VD) {
static llvm::Optional<uint8_t> getSelfIndex(ValueDecl *VD) {
if (auto AF = dyn_cast<AbstractFunctionDecl>(VD)) {
if (AF->isImportAsInstanceMember())
return AF->getSelfIndex();
}
return None;
return llvm::None;
}
static ReferenceOwnership getReferenceOwnership(ValueDecl *VD) {
@@ -1262,26 +1262,26 @@ StringRef printGenericSignature(SDKContext &Ctx, ProtocolConformance *Conf, bool
return printGenericSignature(Ctx, Conf->getConditionalRequirements(), Canonical);
}
static Optional<uint8_t> getSimilarMemberCount(NominalTypeDecl *NTD,
static llvm::Optional<uint8_t> getSimilarMemberCount(NominalTypeDecl *NTD,
ValueDecl *VD,
llvm::function_ref<bool(Decl*)> Check) {
if (!Check(VD))
return None;
return llvm::None;
auto Members = NTD->getMembers();
auto End = std::find(Members.begin(), Members.end(), VD);
assert(End != Members.end());
return std::count_if(Members.begin(), End, Check);
}
Optional<uint8_t> SDKContext::getFixedBinaryOrder(ValueDecl *VD) const {
llvm::Optional<uint8_t> SDKContext::getFixedBinaryOrder(ValueDecl *VD) const {
// We don't need fixed binary order when checking API stability.
if (!checkingABI())
return None;
return llvm::None;
auto *NTD = dyn_cast_or_null<NominalTypeDecl>(VD->getDeclContext()->
getAsDecl());
if (!NTD || isa<ProtocolDecl>(NTD) || NTD->isResilient())
return None;
return llvm::None;
// The relative order of stored properties matters for non-resilient type.
auto isStored = [](Decl *M) {