[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

@@ -50,7 +50,7 @@ void forEachTargetModuleBasename(const ASTContext &Ctx,
auto normalizedTarget = getTargetSpecificModuleTriple(Ctx.LangOpts.Target);
// An arm64 module can import an arm64e module.
Optional<llvm::Triple> normalizedAltTarget;
llvm::Optional<llvm::Triple> normalizedAltTarget;
if ((normalizedTarget.getArch() == llvm::Triple::ArchType::aarch64) &&
(normalizedTarget.getSubArch() !=
llvm::Triple::SubArchType::AArch64SubArch_arm64e)) {
@@ -86,9 +86,9 @@ void forEachTargetModuleBasename(const ASTContext &Ctx,
/// Apply \p body for each module search path in \p Ctx until \p body returns
/// non-None value. Returns the return value from \p body, or \c None.
Optional<bool> forEachModuleSearchPath(
llvm::Optional<bool> forEachModuleSearchPath(
const ASTContext &Ctx,
llvm::function_ref<Optional<bool>(StringRef, ModuleSearchPathKind,
llvm::function_ref<llvm::Optional<bool>(StringRef, ModuleSearchPathKind,
bool isSystem)>
callback) {
for (const auto &path : Ctx.SearchPathOpts.getImportSearchPaths())
@@ -118,7 +118,7 @@ Optional<bool> forEachModuleSearchPath(
return result;
}
return None;
return llvm::None;
}
} // end unnamed namespace
@@ -203,7 +203,7 @@ void SerializedModuleLoaderBase::collectVisibleTopLevelModuleNamesImpl(
auto name = llvm::sys::path::filename(path).drop_back(pathExt.size());
names.push_back(Ctx.getIdentifier(name));
});
return None;
return llvm::None;
}
case ModuleSearchPathKind::RuntimeLibrary: {
// Look for:
@@ -230,7 +230,7 @@ void SerializedModuleLoaderBase::collectVisibleTopLevelModuleNamesImpl(
auto name = llvm::sys::path::filename(path).drop_back(pathExt.size());
names.push_back(Ctx.getIdentifier(name));
});
return None;
return llvm::None;
}
case ModuleSearchPathKind::Framework:
case ModuleSearchPathKind::DarwinImplicitFramework: {
@@ -252,7 +252,7 @@ void SerializedModuleLoaderBase::collectVisibleTopLevelModuleNamesImpl(
names.push_back(Ctx.getIdentifier(name));
});
return None;
return llvm::None;
}
}
llvm_unreachable("covered switch");
@@ -628,7 +628,7 @@ bool SerializedModuleLoaderBase::findModule(
/// was diagnosed, or None if neither one happened and the search should
/// continue.
auto findTargetSpecificModuleFiles = [&](bool IsFramework) -> SearchResult {
Optional<SerializedModuleBaseName> firstAbsoluteBaseName;
llvm::Optional<SerializedModuleBaseName> firstAbsoluteBaseName;
for (const auto &targetSpecificBaseName : targetSpecificBaseNames) {
SerializedModuleBaseName
@@ -782,7 +782,7 @@ getOSAndVersionForDiagnostics(const llvm::Triple &triple) {
}
LoadedFile *SerializedModuleLoaderBase::loadAST(
ModuleDecl &M, Optional<SourceLoc> diagLoc, StringRef moduleInterfacePath,
ModuleDecl &M, llvm::Optional<SourceLoc> diagLoc, StringRef moduleInterfacePath,
StringRef moduleInterfaceSourcePath,
std::unique_ptr<llvm::MemoryBuffer> moduleInputBuffer,
std::unique_ptr<llvm::MemoryBuffer> moduleDocInputBuffer,
@@ -1625,7 +1625,7 @@ void SerializedASTFile::lookupObjCMethods(
File.lookupObjCMethods(selector, results);
}
Optional<Fingerprint>
llvm::Optional<Fingerprint>
SerializedASTFile::loadFingerprint(const IterableDeclContext *IDC) const {
return File.loadFingerprint(IDC);
}
@@ -1647,7 +1647,7 @@ void SerializedASTFile::lookupImportedSPIGroups(
}
}
Optional<CommentInfo>
llvm::Optional<CommentInfo>
SerializedASTFile::getCommentForDecl(const Decl *D) const {
return File.getCommentForDecl(D);
}
@@ -1656,23 +1656,23 @@ bool SerializedASTFile::hasLoadedSwiftDoc() const {
return File.hasLoadedSwiftDoc();
}
Optional<ExternalSourceLocs::RawLocs>
llvm::Optional<ExternalSourceLocs::RawLocs>
SerializedASTFile::getExternalRawLocsForDecl(const Decl *D) const {
return File.getExternalRawLocsForDecl(D);
}
Optional<StringRef>
llvm::Optional<StringRef>
SerializedASTFile::getGroupNameForDecl(const Decl *D) const {
return File.getGroupNameForDecl(D);
}
Optional<StringRef>
llvm::Optional<StringRef>
SerializedASTFile::getSourceFileNameForDecl(const Decl *D) const {
return File.getSourceFileNameForDecl(D);
}
Optional<unsigned>
llvm::Optional<unsigned>
SerializedASTFile::getSourceOrderForDecl(const Decl *D) const {
return File.getSourceOrderForDecl(D);
}
@@ -1682,7 +1682,7 @@ void SerializedASTFile::collectAllGroups(
File.collectAllGroups(Names);
}
Optional<StringRef>
llvm::Optional<StringRef>
SerializedASTFile::getGroupNameByUSR(StringRef USR) const {
return File.getGroupNameByUSR(USR);
}