Migrate llvm::Optional to std::optional

LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
This commit is contained in:
Ben Barham
2024-02-02 22:19:39 -08:00
parent d3d4bd203c
commit ef8825bfe6
810 changed files with 8035 additions and 8718 deletions

View File

@@ -902,7 +902,7 @@ ModuleDecl::getOriginalLocation(SourceLoc loc) const {
SourceLoc startLoc = loc;
unsigned startBufferID = bufferID;
while (llvm::Optional<GeneratedSourceInfo> info =
while (std::optional<GeneratedSourceInfo> info =
SM.getGeneratedSourceInfo(bufferID)) {
switch (info->kind) {
#define MACRO_ROLE(Name, Description) \
@@ -1202,9 +1202,9 @@ CustomAttr *SourceFile::getAttachedMacroAttribute() const {
return genInfo.attachedMacroCustomAttr;
}
llvm::Optional<MacroRole> SourceFile::getFulfilledMacroRole() const {
std::optional<MacroRole> SourceFile::getFulfilledMacroRole() const {
if (Kind != SourceFileKind::MacroExpansion)
return llvm::None;
return std::nullopt;
auto genInfo =
*getASTContext().SourceMgr.getGeneratedSourceInfo(*getBufferID());
@@ -1217,7 +1217,7 @@ llvm::Optional<MacroRole> SourceFile::getFulfilledMacroRole() const {
case GeneratedSourceInfo::ReplacedFunctionBody:
case GeneratedSourceInfo::PrettyPrinted:
case GeneratedSourceInfo::DefaultArgument:
return llvm::None;
return std::nullopt;
}
}
@@ -1472,18 +1472,18 @@ TypeDecl *SourceFile::lookupLocalType(llvm::StringRef mangledName) const {
return nullptr;
}
llvm::Optional<ExternalSourceLocs::RawLocs>
std::optional<ExternalSourceLocs::RawLocs>
SourceFile::getExternalRawLocsForDecl(const Decl *D) const {
auto *FileCtx = D->getDeclContext()->getModuleScopeContext();
assert(FileCtx == this && "D doesn't belong to this source file");
if (FileCtx != this) {
// D doesn't belong to this file. This shouldn't happen in practice.
return llvm::None;
return std::nullopt;
}
SourceLoc MainLoc = D->getLoc(/*SerializedOK=*/false);
if (MainLoc.isInvalid())
return llvm::None;
return std::nullopt;
// TODO: Rather than grabbing the location of the macro expansion, we should
// instead add the generated buffer tree - that would need to include source
@@ -1496,7 +1496,7 @@ SourceFile::getExternalRawLocsForDecl(const Decl *D) const {
std::tie(UnderlyingBufferID, MainLoc) =
D->getModuleContext()->getOriginalLocation(MainLoc);
if (BufferID != UnderlyingBufferID)
return llvm::None;
return std::nullopt;
}
auto setLoc = [&](ExternalSourceLocs::RawLoc &RawLoc, SourceLoc Loc) {
@@ -1576,7 +1576,7 @@ Fingerprint SourceFile::getInterfaceHash() const {
assert(hasInterfaceHash() && "Interface hash not enabled");
auto &eval = getASTContext().evaluator;
auto *mutableThis = const_cast<SourceFile *>(this);
llvm::Optional<StableHasher> interfaceHasher =
std::optional<StableHasher> interfaceHasher =
evaluateOrDefault(eval, ParseSourceFileRequest{mutableThis}, {})
.InterfaceHasher;
return Fingerprint{StableHasher{interfaceHasher.value()}.finalize()};
@@ -1962,8 +1962,7 @@ NominalTypeDecl *ModuleDecl::getMainTypeDecl() const {
}
bool ModuleDecl::registerEntryPointFile(
FileUnit *file, SourceLoc diagLoc,
llvm::Optional<ArtificialMainKind> kind) {
FileUnit *file, SourceLoc diagLoc, std::optional<ArtificialMainKind> kind) {
if (!EntryPointInfo.hasEntryPoint()) {
EntryPointInfo.setEntryPointFile(file);
return false;
@@ -2612,13 +2611,13 @@ bool HasImportsMatchingFlagRequest::evaluate(Evaluator &evaluator,
return false;
}
llvm::Optional<bool> HasImportsMatchingFlagRequest::getCachedResult() const {
std::optional<bool> HasImportsMatchingFlagRequest::getCachedResult() const {
SourceFile *sourceFile = std::get<0>(getStorage());
ImportFlags flag = std::get<1>(getStorage());
if (sourceFile->validCachedImportOptions.contains(flag))
return sourceFile->cachedImportOptions.contains(flag);
return llvm::None;
return std::nullopt;
}
void HasImportsMatchingFlagRequest::cacheResult(bool value) const {
@@ -2765,7 +2764,7 @@ SourceFile::getImportAccessLevel(const ModuleDecl *targetModule) const {
"getImportAccessLevel doesn't support checking for a self-import");
auto &imports = getASTContext().getImportCache();
ImportAccessLevel restrictiveImport = llvm::None;
ImportAccessLevel restrictiveImport = std::nullopt;
for (auto &import : *Imports) {
if ((!restrictiveImport.has_value() ||
@@ -3297,7 +3296,7 @@ ModuleDecl::computeFileIDMap(bool shouldDiagnose) const {
}
SourceFile::SourceFile(ModuleDecl &M, SourceFileKind K,
llvm::Optional<unsigned> bufferID,
std::optional<unsigned> bufferID,
ParsingOptions parsingOpts, bool isPrimary)
: FileUnit(FileUnitKind::Source, M), BufferID(bufferID ? *bufferID : -1),
ParsingOpts(parsingOpts), IsPrimary(isPrimary), Kind(K) {
@@ -3307,7 +3306,7 @@ SourceFile::SourceFile(ModuleDecl &M, SourceFileKind K,
"A primary cannot appear outside the main module");
if (isScriptMode()) {
bool problem = M.registerEntryPointFile(this, SourceLoc(), llvm::None);
bool problem = M.registerEntryPointFile(this, SourceLoc(), std::nullopt);
assert(!problem && "multiple main files?");
(void)problem;
}