[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

@@ -288,7 +288,7 @@ Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc,
if (Core->Bits.HasEntryPoint) {
FileContext->getParentModule()->registerEntryPointFile(FileContext,
SourceLoc(),
None);
llvm::None);
}
return status;
@@ -561,7 +561,7 @@ void ModuleFile::getImportDecls(SmallVectorImpl<Decl *> &Results) {
TopLevelModule->lookupQualified(
TopLevelModule, DeclNameRef(ScopeID),
SourceLoc(), NL_QualifiedDefault, Decls);
Optional<ImportKind> FoundKind = ImportDecl::findBestImportKind(Decls);
llvm::Optional<ImportKind> FoundKind = ImportDecl::findBestImportKind(Decls);
assert(FoundKind.has_value() &&
"deserialized imports should not be ambiguous");
Kind = *FoundKind;
@@ -729,7 +729,7 @@ void ModuleFile::loadDerivativeFunctionConfigurations(
}
}
Optional<Fingerprint>
llvm::Optional<Fingerprint>
ModuleFile::loadFingerprint(const IterableDeclContext *IDC) const {
PrettyStackTraceDecl trace("loading fingerprints for", IDC->getDecl());
@@ -737,12 +737,12 @@ ModuleFile::loadFingerprint(const IterableDeclContext *IDC) const {
assert(IDC->getDeclID() != 0);
if (!Core->DeclFingerprints) {
return None;
return llvm::None;
}
auto it = Core->DeclFingerprints->find(IDC->getDeclID());
if (it == Core->DeclFingerprints->end()) {
return None;
return llvm::None;
}
return *it;
}
@@ -1051,7 +1051,7 @@ void ModuleFile::getDisplayDecls(SmallVectorImpl<Decl *> &results, bool recursiv
getTopLevelDecls(results);
}
Optional<CommentInfo> ModuleFile::getCommentForDecl(const Decl *D) const {
llvm::Optional<CommentInfo> ModuleFile::getCommentForDecl(const Decl *D) const {
assert(D);
// Keep these as assertions instead of early exits to ensure that we are not
@@ -1062,14 +1062,14 @@ Optional<CommentInfo> ModuleFile::getCommentForDecl(const Decl *D) const {
"Decl is from a different serialized file");
if (!Core->DeclCommentTable)
return None;
return llvm::None;
if (D->isImplicit())
return None;
return llvm::None;
// Compute the USR.
llvm::SmallString<128> USRBuffer;
llvm::raw_svector_ostream OS(USRBuffer);
if (ide::printDeclUSR(D, OS))
return None;
return llvm::None;
return getCommentForDeclByUSR(USRBuffer.str());
}
@@ -1159,7 +1159,7 @@ static void readRawLoc(ExternalSourceLocs::RawLoc &Loc, const char *&Data,
Loc.Directive.Name = readLocString(Data, StringData);
}
Optional<ExternalSourceLocs::RawLocs>
llvm::Optional<ExternalSourceLocs::RawLocs>
ModuleFile::getExternalRawLocsForDecl(const Decl *D) const {
assert(D);
// Keep these as assertions instead of early exits to ensure that we are not
@@ -1170,22 +1170,22 @@ ModuleFile::getExternalRawLocsForDecl(const Decl *D) const {
"Decl is from a different serialized file");
if (!Core->DeclUSRsTable)
return None;
return llvm::None;
// Future compilers may not provide BasicDeclLocsData anymore.
if (Core->BasicDeclLocsData.empty())
return None;
return llvm::None;
if (D->isImplicit())
return None;
return llvm::None;
// Compute the USR.
llvm::SmallString<128> USRBuffer;
llvm::raw_svector_ostream OS(USRBuffer);
if (ide::printDeclUSR(D, OS))
return None;
return llvm::None;
auto It = Core->DeclUSRsTable->find(OS.str());
if (It == Core->DeclUSRsTable->end())
return None;
return llvm::None;
auto UsrId = *It;
uint32_t RecordSize =
@@ -1224,31 +1224,31 @@ ModuleFile::getExternalRawLocsForDecl(const Decl *D) const {
const static StringRef Separator = "/";
Optional<StringRef> ModuleFile::getGroupNameById(unsigned Id) const {
llvm::Optional<StringRef> ModuleFile::getGroupNameById(unsigned Id) const {
if (!Core->GroupNamesMap)
return None;
return llvm::None;
const auto &GroupNamesMap = *Core->GroupNamesMap;
auto it = GroupNamesMap.find(Id);
if (it == GroupNamesMap.end())
return None;
return llvm::None;
StringRef Original = it->second;
if (Original.empty())
return None;
return llvm::None;
auto SepPos = Original.find_last_of(Separator);
assert(SepPos != StringRef::npos && "Cannot find Separator.");
return StringRef(Original.data(), SepPos);
}
Optional<StringRef> ModuleFile::getSourceFileNameById(unsigned Id) const {
llvm::Optional<StringRef> ModuleFile::getSourceFileNameById(unsigned Id) const {
if (!Core->GroupNamesMap)
return None;
return llvm::None;
const auto &GroupNamesMap = *Core->GroupNamesMap;
auto it = GroupNamesMap.find(Id);
if (it == GroupNamesMap.end())
return None;
return llvm::None;
StringRef Original = it->second;
if (Original.empty())
return None;
return llvm::None;
auto SepPos = Original.find_last_of(Separator);
assert(SepPos != StringRef::npos && "Cannot find Separator.");
auto Start = Original.data() + SepPos + 1;
@@ -1256,29 +1256,29 @@ Optional<StringRef> ModuleFile::getSourceFileNameById(unsigned Id) const {
return StringRef(Start, Len);
}
Optional<StringRef> ModuleFile::getGroupNameForDecl(const Decl *D) const {
llvm::Optional<StringRef> ModuleFile::getGroupNameForDecl(const Decl *D) const {
auto Triple = getCommentForDecl(D);
if (!Triple.has_value()) {
return None;
return llvm::None;
}
return getGroupNameById(Triple.value().Group);
}
Optional<StringRef>
llvm::Optional<StringRef>
ModuleFile::getSourceFileNameForDecl(const Decl *D) const {
auto Triple = getCommentForDecl(D);
if (!Triple.has_value()) {
return None;
return llvm::None;
}
return getSourceFileNameById(Triple.value().Group);
}
Optional<unsigned>
llvm::Optional<unsigned>
ModuleFile::getSourceOrderForDecl(const Decl *D) const {
auto Triple = getCommentForDecl(D);
if (!Triple.has_value()) {
return None;
return llvm::None;
}
return Triple.value().SourceOrder;
}
@@ -1301,10 +1301,10 @@ void ModuleFile::collectAllGroups(SmallVectorImpl<StringRef> &Names) const {
}
}
Optional<CommentInfo>
llvm::Optional<CommentInfo>
ModuleFile::getCommentForDeclByUSR(StringRef USR) const {
if (!Core->DeclCommentTable)
return None;
return llvm::None;
// Use the comment cache to preserve the memory that the array of
// `SingleRawComment`s, inside `CommentInfo`, points to, and generally avoid
@@ -1313,25 +1313,25 @@ ModuleFile::getCommentForDeclByUSR(StringRef USR) const {
if (it != CommentsCache.end()) {
const auto &cachePtr = it->second;
if (!cachePtr)
return None;
return llvm::None;
return cachePtr->Info;
}
auto I = Core->DeclCommentTable->find(USR);
if (I == Core->DeclCommentTable->end())
return None;
return llvm::None;
auto &cachePtr = CommentsCache[USR];
cachePtr = *I;
return cachePtr->Info;
}
Optional<StringRef>
llvm::Optional<StringRef>
ModuleFile::getGroupNameByUSR(StringRef USR) const {
if (auto Comment = getCommentForDeclByUSR(USR)) {
return getGroupNameById(Comment.value().Group);
}
return None;
return llvm::None;
}
Identifier ModuleFile::getDiscriminatorForPrivateDecl(const Decl *D) {