Skip to content

Migrate remaining llvm::Optional to std::optional #8120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/PointerAuthOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
#define LLVM_CLANG_BASIC_POINTERAUTHOPTIONS_H

#include "clang/Basic/LLVM.h"
#include "llvm/ADT/Optional.h"
#include "llvm/Target/TargetOptions.h"
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include "llvm/Support/ErrorHandling.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include "clang/Tooling/Refactor/RefactoringOptionSet.h"
#include "clang/Tooling/Refactor/RefactoringReplacement.h"
#include "clang/Tooling/Refactor/SymbolOperation.h"
#include "llvm/ADT/None.h"
#include "llvm/Support/Error.h"
#include <optional>
#include <string>
#include <vector>

Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Tooling/Refactor/RefactoringContinuations.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ class SpecificRefactoringContinuation final : public RefactoringContinuation {
ConsumerFn Consumer;
std::unique_ptr<ASTQueryType> ASTQuery;
/// Inputs store state that's dependent on the original TU.
llvm::Optional<std::tuple<QueryOrState...>> Inputs;
std::optional<std::tuple<QueryOrState...>> Inputs;
/// State contains TU-independent values.
llvm::Optional<
std::optional<
std::tuple<typename StateTraits<QueryOrState>::PersistentType...>>
State;

Expand Down
1 change: 0 additions & 1 deletion clang/tools/IndexStore/IndexStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "clang/Index/IndexUnitWriter.h"
#include "clang/DirectoryWatcher/DirectoryWatcher.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/Chrono.h"
#include "llvm/Support/ManagedStatic.h"
Expand Down
12 changes: 6 additions & 6 deletions clang/tools/c-index-test/core_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ static std::string findRecordNameForFile(indexstore::IndexStore &store,
}

static int printStoreFileRecord(StringRef storePath, StringRef filePath,
Optional<unsigned> lineStart, unsigned lineCount,
std::optional<unsigned> lineStart, unsigned lineCount,
PathRemapper remapper, raw_ostream &OS) {
std::string error;
indexstore::IndexStore store(storePath, remapper, error);
Expand Down Expand Up @@ -698,7 +698,7 @@ static int scanDeps(ArrayRef<const char *> Args, std::string WorkingDirectory,
bool SerializeDiags, bool DependencyFile,
ArrayRef<std::string> DepTargets, std::string OutputPath,
CXCASDatabases DBs,
Optional<std::string> ModuleName = std::nullopt) {
std::optional<std::string> ModuleName = std::nullopt) {
CXDependencyScannerServiceOptions Opts =
clang_experimental_DependencyScannerServiceOptions_create();
auto CleanupOpts = llvm::make_scope_exit([&] {
Expand Down Expand Up @@ -1193,7 +1193,7 @@ static int watchDirectory(StringRef dirPath) {

bool deconstructPathAndRange(StringRef input,
std::string &filepath,
Optional<unsigned> &lineStart,
std::optional<unsigned> &lineStart,
unsigned &lineCount) {
StringRef path, start, end;
std::tie(path, end) = input.rsplit(':');
Expand Down Expand Up @@ -1272,7 +1272,7 @@ int indextest_core_main(int argc, const char **argv) {
if (options::Action == ActionType::PrintRecord) {
if (!options::FilePathAndRange.empty()) {
std::string filepath;
Optional<unsigned> lineStart;
std::optional<unsigned> lineStart;
unsigned lineCount;
if (deconstructPathAndRange(options::FilePathAndRange,
filepath, lineStart, lineCount))
Expand Down Expand Up @@ -1330,9 +1330,9 @@ int indextest_core_main(int argc, const char **argv) {
return aggregateDataAsJSON(storePath, PathRemapper, OS);
}

Optional<std::string> CASPath = options::CASPath.empty()
std::optional<std::string> CASPath = options::CASPath.empty()
? std::nullopt
: Optional<std::string>(options::CASPath);
: std::optional<std::string>(options::CASPath);

CXCASOptions CASOpts = nullptr;
CXCASDatabases DBs = nullptr;
Expand Down
1 change: 0 additions & 1 deletion clang/tools/libclang/CIndexDiagnostic.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "clang-c/Index.h"
#include "clang/Basic/LLVM.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringRef.h"
#include <assert.h>
#include <memory>
Expand Down
4 changes: 2 additions & 2 deletions lldb/include/lldb/Core/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/STLFunctionalExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Optional.h"
#include <optional>
#include "llvm/Support/Chrono.h"

#include <atomic>
Expand Down Expand Up @@ -820,7 +820,7 @@ class Module : public std::enable_shared_from_this<Module>,
#ifdef LLDB_ENABLE_SWIFT
void
ReportWarningToolchainMismatch(CompileUnit &comp_unit,
llvm::Optional<lldb::user_id_t> debugger_id);
std::optional<lldb::user_id_t> debugger_id);

bool IsSwiftCxxInteropEnabled();
#endif
Expand Down
2 changes: 1 addition & 1 deletion lldb/include/lldb/Core/ValueObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ class ValueObject {
virtual bool HasSyntheticValue();

#ifdef LLDB_ENABLE_SWIFT
llvm::Optional<SwiftScratchContextReader> GetSwiftScratchContext();
std::optional<SwiftScratchContextReader> GetSwiftScratchContext();
#endif // LLDB_ENABLE_SWIFT

virtual bool IsSynthetic() { return false; }
Expand Down
4 changes: 2 additions & 2 deletions lldb/include/lldb/Target/Target.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#include "lldb/Utility/Timeout.h"
#include "lldb/lldb-public.h"

#include "llvm/ADT/Optional.h"
#include <optional>

namespace lldb_private {

Expand Down Expand Up @@ -1281,7 +1281,7 @@ class Target : public std::enable_shared_from_this<Target>,
return m_scratch_typesystem_lock;
}

llvm::Optional<SwiftScratchContextReader>
std::optional<SwiftScratchContextReader>
GetSwiftScratchContext(Status &error, ExecutionContextScope &exe_scope,
bool create_on_demand = true);

Expand Down
10 changes: 5 additions & 5 deletions lldb/include/lldb/Utility/Either.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifndef liblldb_Either_h_
#define liblldb_Either_h_

#include "llvm/ADT/Optional.h"
#include <optional>

#include <functional>

Expand Down Expand Up @@ -51,23 +51,23 @@ template <typename T1, typename T2> class Either {

template <class X, typename std::enable_if<std::is_same<T1, X>::value>::type
* = nullptr>
llvm::Optional<T1> GetAs() const {
std::optional<T1> GetAs() const {
switch (m_selected) {
case Selected::One:
return m_t1;
default:
return llvm::Optional<T1>();
return std::optional<T1>();
}
}

template <class X, typename std::enable_if<std::is_same<T2, X>::value>::type
* = nullptr>
llvm::Optional<T2> GetAs() const {
std::optional<T2> GetAs() const {
switch (m_selected) {
case Selected::Two:
return m_t2;
default:
return llvm::Optional<T2>();
return std::optional<T2>();
}
}

Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Core/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,7 @@ static llvm::VersionTuple GetAdjustedVersion(llvm::VersionTuple version) {
}

void Module::ReportWarningToolchainMismatch(
CompileUnit &comp_unit, llvm::Optional<lldb::user_id_t> debugger_id) {
CompileUnit &comp_unit, std::optional<lldb::user_id_t> debugger_id) {
if (SymbolFile *sym_file = GetSymbolFile()) {
llvm::VersionTuple sym_file_version =
GetAdjustedVersion(sym_file->GetProducerVersion(comp_unit));
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Core/ValueObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1625,10 +1625,10 @@ bool ValueObject::GetDeclaration(Declaration &decl) {
}

#ifdef LLDB_ENABLE_SWIFT
llvm::Optional<SwiftScratchContextReader> ValueObject::GetSwiftScratchContext() {
std::optional<SwiftScratchContextReader> ValueObject::GetSwiftScratchContext() {
lldb::TargetSP target_sp(GetTargetSP());
if (!target_sp)
return llvm::None;
return std::nullopt;
Status error;
ExecutionContext ctx = GetExecutionContextRef().Lock(false);
auto *exe_scope = ctx.GetBestExecutionContextScope();
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Core/ValueObjectDynamicValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ bool ValueObjectDynamicValue::DynamicValueTypeInfoNeedsUpdate() {

#ifdef LLDB_ENABLE_SWIFT
auto cached_ctx = m_value.GetCompilerType().GetTypeSystem();
llvm::Optional<SwiftScratchContextReader> scratch_ctx(
std::optional<SwiftScratchContextReader> scratch_ctx(
GetSwiftScratchContext());

if (!scratch_ctx || !cached_ctx)
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Expression/DWARFExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ static bool Evaluate_DW_OP_entry_value(std::vector<Value> &stack,
}
#ifdef LLDB_ENABLE_SWIFT
}
llvm::Optional<DWARFExpressionList> subexpr;
std::optional<DWARFExpressionList> subexpr;
if (!matched_param) {
auto *ctx_func = parent_func ? parent_func : current_func;
subexpr.emplace(ctx_func->CalculateSymbolContextModule(),
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Expression/Materializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ class EntityResultVariable : public Materializer::Entity {
if (m_type.GetMinimumLanguage() == lldb::eLanguageTypeSwift) {
#ifdef LLDB_ENABLE_SWIFT
Status status;
llvm::Optional<SwiftScratchContextReader> maybe_type_system =
std::optional<SwiftScratchContextReader> maybe_type_system =
target_sp->GetSwiftScratchContext(status, *exe_scope);
if (!maybe_type_system) {
err.SetErrorStringWithFormat("Couldn't dematerialize a result variable: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ swift::FuncDecl *SwiftASTManipulator::GetFunctionToInjectVariableInto(
return m_function_decl;
}

llvm::Optional<swift::Type> SwiftASTManipulator::GetSwiftTypeForVariable(
std::optional<swift::Type> SwiftASTManipulator::GetSwiftTypeForVariable(
const SwiftASTManipulator::VariableInfo &variable) const {
auto type_system_swift =
variable.m_type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwift>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Casting.h"

#include <optional>

namespace swift {
class CaseStmt;
Expand Down Expand Up @@ -213,7 +214,7 @@ class SwiftASTManipulator : public SwiftASTManipulatorBase {
swift::VarDecl *GetVarDeclForVariableInFunction(
const SwiftASTManipulator::VariableInfo &variable,
swift::FuncDecl *containing_function);
llvm::Optional<swift::Type> GetSwiftTypeForVariable(
std::optional<swift::Type> GetSwiftTypeForVariable(
const SwiftASTManipulator::VariableInfo &variable) const;

bool AddExternalVariables(llvm::MutableArrayRef<VariableInfo> variables);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ CreateMainFile(SwiftASTContextForExpressions &swift_ast_context,
}

/// Attempt to materialize one variable.
static llvm::Optional<SwiftExpressionParser::SILVariableInfo>
static std::optional<SwiftExpressionParser::SILVariableInfo>
MaterializeVariable(SwiftASTManipulatorBase::VariableInfo &variable,
SwiftUserExpression &user_expression,
Materializer &materializer,
Expand Down Expand Up @@ -925,7 +925,7 @@ MaterializeVariable(SwiftASTManipulatorBase::VariableInfo &variable,
swift::Type actual_swift_type =
manipulator.GetScratchContext().GetSwiftType(actual_type);
if (!actual_swift_type)
return llvm::None;
return std::nullopt;

auto transformed_type =
actual_swift_type.transform([](swift::Type t) -> swift::Type {
Expand All @@ -939,7 +939,7 @@ MaterializeVariable(SwiftASTManipulatorBase::VariableInfo &variable,
});

if (!transformed_type)
return llvm::None;
return std::nullopt;

actual_type =
ToCompilerType(transformed_type->mapTypeOutOfContext().getPointer());
Expand All @@ -962,7 +962,7 @@ MaterializeVariable(SwiftASTManipulatorBase::VariableInfo &variable,
diagnostic_manager.Printf(
eDiagnosticSeverityError, "couldn't add %s variable to struct: %s.\n",
is_result ? "result" : "error", error.AsCString());
return llvm::None;
return std::nullopt;
}

LLDB_LOG(log, "Added {0} variable to struct at offset {1}",
Expand All @@ -978,7 +978,7 @@ MaterializeVariable(SwiftASTManipulatorBase::VariableInfo &variable,
diagnostic_manager.Printf(eDiagnosticSeverityError,
"couldn't add variable to struct: %s.\n",
error.AsCString());
return llvm::None;
return std::nullopt;
}

LLDB_LOG(log, "Added variable {0} to struct at offset {1}",
Expand All @@ -1000,7 +1000,7 @@ MaterializeVariable(SwiftASTManipulatorBase::VariableInfo &variable,
// this check scattered in several places in the codebase, we should at
// some point centralize it.
lldb::StackFrameSP stack_frame_sp = stack_frame_wp.lock();
llvm::Optional<uint64_t> size =
std::optional<uint64_t> size =
variable.GetType().GetByteSize(stack_frame_sp.get());
if (repl && size && *size == 0) {
auto &repl_mat = *llvm::cast<SwiftREPLMaterializer>(&materializer);
Expand All @@ -1026,7 +1026,7 @@ MaterializeVariable(SwiftASTManipulatorBase::VariableInfo &variable,
diagnostic_manager.Printf(eDiagnosticSeverityError,
"couldn't add variable to struct: %s.\n",
error.AsCString());
return llvm::None;
return std::nullopt;
}

LLDB_LOGF(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ using namespace lldb;
using namespace lldb_private;

namespace lldb_private {
llvm::Optional<std::pair<unsigned, unsigned>>
std::optional<std::pair<unsigned, unsigned>>
ParseSwiftGenericParameter(llvm::StringRef name) {
if (!name.consume_front("$τ_"))
return {};
Expand Down Expand Up @@ -136,7 +136,7 @@ struct CallsAndArgs {
/// $τ_0_0, $τ_0_1, ..., $τ_0_n)
static llvm::Expected<CallsAndArgs> MakeGenericSignaturesAndCalls(
llvm::ArrayRef<SwiftASTManipulator::VariableInfo> local_variables,
const llvm::Optional<SwiftLanguageRuntime::GenericSignature> &generic_sig,
const std::optional<SwiftLanguageRuntime::GenericSignature> &generic_sig,
bool needs_object_ptr) {
llvm::SmallVector<SwiftASTManipulator::VariableInfo> metadata_variables;
for (auto &var : local_variables)
Expand Down Expand Up @@ -256,7 +256,7 @@ static Status WrapExpression(
const EvaluateExpressionOptions &options, llvm::StringRef os_version,
uint32_t &first_body_line,
llvm::ArrayRef<SwiftASTManipulator::VariableInfo> local_variables,
const llvm::Optional<SwiftLanguageRuntime::GenericSignature> &generic_sig) {
const std::optional<SwiftLanguageRuntime::GenericSignature> &generic_sig) {
Status status;
first_body_line = 0; // set to invalid
// TODO make the extension private so we're not polluting the class
Expand Down Expand Up @@ -556,7 +556,7 @@ Status SwiftExpressionSourceCode::GetText(
std::string &text, lldb::LanguageType wrapping_language,
bool needs_object_ptr, bool static_method, bool is_class, bool weak_self,
const EvaluateExpressionOptions &options,
const llvm::Optional<SwiftLanguageRuntime::GenericSignature> &generic_sig,
const std::optional<SwiftLanguageRuntime::GenericSignature> &generic_sig,
ExecutionContext &exe_ctx, uint32_t &first_body_line,
llvm::ArrayRef<SwiftASTManipulator::VariableInfo> local_variables) const {
Status status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
namespace lldb_private {

/// Parse a name such as "$τ_0_0".
llvm::Optional<std::pair<unsigned, unsigned>>
std::optional<std::pair<unsigned, unsigned>>
ParseSwiftGenericParameter(llvm::StringRef name);

class SwiftExpressionSourceCode : public ExpressionSourceCode {
Expand Down Expand Up @@ -46,7 +46,7 @@ class SwiftExpressionSourceCode : public ExpressionSourceCode {
std::string &text, lldb::LanguageType wrapping_language,
bool needs_object_ptr, bool static_method, bool is_class, bool weak_self,
const EvaluateExpressionOptions &options,
const llvm::Optional<SwiftLanguageRuntime::GenericSignature> &generic_sig,
const std::optional<SwiftLanguageRuntime::GenericSignature> &generic_sig,
ExecutionContext &exe_ctx, uint32_t &first_body_line,
llvm::ArrayRef<SwiftASTManipulator::VariableInfo> local_variables) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ void SwiftPersistentExpressionState::RemovePersistentVariable(
}
}

llvm::Optional<CompilerType>
std::optional<CompilerType>
SwiftPersistentExpressionState::GetCompilerTypeFromPersistentDecl(
ConstString type_name) {
return llvm::None;
return std::nullopt;
}

bool SwiftPersistentExpressionState::SwiftDeclMap::DeclsAreEquivalent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class SwiftPersistentExpressionState : public PersistentExpressionState {

ConstString GetNextPersistentVariableName(bool is_error = false) override;

llvm::Optional<CompilerType>
std::optional<CompilerType>
GetCompilerTypeFromPersistentDecl(ConstString type_name) override;

void RegisterSwiftPersistentDecl(CompilerDecl value_decl);
Expand Down
Loading