Skip to content

Commit 966aa32

Browse files
authored
Merge pull request llvm#8120 from bnbarham/std-optional-all-the-things
Migrate remaining llvm::Optional to std::optional
2 parents a9767a1 + d05e79d commit 966aa32

File tree

61 files changed

+312
-317
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+312
-317
lines changed

clang/include/clang/Basic/PointerAuthOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
#define LLVM_CLANG_BASIC_POINTERAUTHOPTIONS_H
1616

1717
#include "clang/Basic/LLVM.h"
18-
#include "llvm/ADT/Optional.h"
1918
#include "llvm/Target/TargetOptions.h"
2019
#include <map>
2120
#include <memory>
21+
#include <optional>
2222
#include <string>
2323
#include <vector>
2424
#include "llvm/Support/ErrorHandling.h"

clang/include/clang/Tooling/Refactor/RefactoringOperation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#include "clang/Tooling/Refactor/RefactoringOptionSet.h"
1616
#include "clang/Tooling/Refactor/RefactoringReplacement.h"
1717
#include "clang/Tooling/Refactor/SymbolOperation.h"
18-
#include "llvm/ADT/None.h"
1918
#include "llvm/Support/Error.h"
19+
#include <optional>
2020
#include <string>
2121
#include <vector>
2222

clang/lib/Tooling/Refactor/RefactoringContinuations.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,9 @@ class SpecificRefactoringContinuation final : public RefactoringContinuation {
266266
ConsumerFn Consumer;
267267
std::unique_ptr<ASTQueryType> ASTQuery;
268268
/// Inputs store state that's dependent on the original TU.
269-
llvm::Optional<std::tuple<QueryOrState...>> Inputs;
269+
std::optional<std::tuple<QueryOrState...>> Inputs;
270270
/// State contains TU-independent values.
271-
llvm::Optional<
271+
std::optional<
272272
std::tuple<typename StateTraits<QueryOrState>::PersistentType...>>
273273
State;
274274

clang/tools/IndexStore/IndexStore.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "clang/Index/IndexUnitWriter.h"
2020
#include "clang/DirectoryWatcher/DirectoryWatcher.h"
2121
#include "llvm/ADT/ArrayRef.h"
22-
#include "llvm/ADT/Optional.h"
2322
#include "llvm/ADT/SmallString.h"
2423
#include "llvm/Support/Chrono.h"
2524
#include "llvm/Support/ManagedStatic.h"

clang/tools/c-index-test/core_main.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ static std::string findRecordNameForFile(indexstore::IndexStore &store,
486486
}
487487

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

11941194
bool deconstructPathAndRange(StringRef input,
11951195
std::string &filepath,
1196-
Optional<unsigned> &lineStart,
1196+
std::optional<unsigned> &lineStart,
11971197
unsigned &lineCount) {
11981198
StringRef path, start, end;
11991199
std::tie(path, end) = input.rsplit(':');
@@ -1272,7 +1272,7 @@ int indextest_core_main(int argc, const char **argv) {
12721272
if (options::Action == ActionType::PrintRecord) {
12731273
if (!options::FilePathAndRange.empty()) {
12741274
std::string filepath;
1275-
Optional<unsigned> lineStart;
1275+
std::optional<unsigned> lineStart;
12761276
unsigned lineCount;
12771277
if (deconstructPathAndRange(options::FilePathAndRange,
12781278
filepath, lineStart, lineCount))
@@ -1330,9 +1330,9 @@ int indextest_core_main(int argc, const char **argv) {
13301330
return aggregateDataAsJSON(storePath, PathRemapper, OS);
13311331
}
13321332

1333-
Optional<std::string> CASPath = options::CASPath.empty()
1333+
std::optional<std::string> CASPath = options::CASPath.empty()
13341334
? std::nullopt
1335-
: Optional<std::string>(options::CASPath);
1335+
: std::optional<std::string>(options::CASPath);
13361336

13371337
CXCASOptions CASOpts = nullptr;
13381338
CXCASDatabases DBs = nullptr;

clang/tools/libclang/CIndexDiagnostic.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "clang-c/Index.h"
1717
#include "clang/Basic/LLVM.h"
1818
#include "llvm/ADT/DenseMap.h"
19-
#include "llvm/ADT/Optional.h"
2019
#include "llvm/ADT/StringRef.h"
2120
#include <assert.h>
2221
#include <memory>

lldb/include/lldb/Core/Module.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "llvm/ADT/DenseSet.h"
3232
#include "llvm/ADT/STLFunctionalExtras.h"
3333
#include "llvm/ADT/StringRef.h"
34-
#include "llvm/ADT/Optional.h"
34+
#include <optional>
3535
#include "llvm/Support/Chrono.h"
3636

3737
#include <atomic>
@@ -820,7 +820,7 @@ class Module : public std::enable_shared_from_this<Module>,
820820
#ifdef LLDB_ENABLE_SWIFT
821821
void
822822
ReportWarningToolchainMismatch(CompileUnit &comp_unit,
823-
llvm::Optional<lldb::user_id_t> debugger_id);
823+
std::optional<lldb::user_id_t> debugger_id);
824824

825825
bool IsSwiftCxxInteropEnabled();
826826
#endif

lldb/include/lldb/Core/ValueObject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ class ValueObject {
589589
virtual bool HasSyntheticValue();
590590

591591
#ifdef LLDB_ENABLE_SWIFT
592-
llvm::Optional<SwiftScratchContextReader> GetSwiftScratchContext();
592+
std::optional<SwiftScratchContextReader> GetSwiftScratchContext();
593593
#endif // LLDB_ENABLE_SWIFT
594594

595595
virtual bool IsSynthetic() { return false; }

lldb/include/lldb/Target/Target.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#include "lldb/Utility/Timeout.h"
4646
#include "lldb/lldb-public.h"
4747

48-
#include "llvm/ADT/Optional.h"
48+
#include <optional>
4949

5050
namespace lldb_private {
5151

@@ -1281,7 +1281,7 @@ class Target : public std::enable_shared_from_this<Target>,
12811281
return m_scratch_typesystem_lock;
12821282
}
12831283

1284-
llvm::Optional<SwiftScratchContextReader>
1284+
std::optional<SwiftScratchContextReader>
12851285
GetSwiftScratchContext(Status &error, ExecutionContextScope &exe_scope,
12861286
bool create_on_demand = true);
12871287

lldb/include/lldb/Utility/Either.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef liblldb_Either_h_
1010
#define liblldb_Either_h_
1111

12-
#include "llvm/ADT/Optional.h"
12+
#include <optional>
1313

1414
#include <functional>
1515

@@ -51,23 +51,23 @@ template <typename T1, typename T2> class Either {
5151

5252
template <class X, typename std::enable_if<std::is_same<T1, X>::value>::type
5353
* = nullptr>
54-
llvm::Optional<T1> GetAs() const {
54+
std::optional<T1> GetAs() const {
5555
switch (m_selected) {
5656
case Selected::One:
5757
return m_t1;
5858
default:
59-
return llvm::Optional<T1>();
59+
return std::optional<T1>();
6060
}
6161
}
6262

6363
template <class X, typename std::enable_if<std::is_same<T2, X>::value>::type
6464
* = nullptr>
65-
llvm::Optional<T2> GetAs() const {
65+
std::optional<T2> GetAs() const {
6666
switch (m_selected) {
6767
case Selected::Two:
6868
return m_t2;
6969
default:
70-
return llvm::Optional<T2>();
70+
return std::optional<T2>();
7171
}
7272
}
7373

lldb/source/Core/Module.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ static llvm::VersionTuple GetAdjustedVersion(llvm::VersionTuple version) {
11431143
}
11441144

11451145
void Module::ReportWarningToolchainMismatch(
1146-
CompileUnit &comp_unit, llvm::Optional<lldb::user_id_t> debugger_id) {
1146+
CompileUnit &comp_unit, std::optional<lldb::user_id_t> debugger_id) {
11471147
if (SymbolFile *sym_file = GetSymbolFile()) {
11481148
llvm::VersionTuple sym_file_version =
11491149
GetAdjustedVersion(sym_file->GetProducerVersion(comp_unit));

lldb/source/Core/ValueObject.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,10 +1625,10 @@ bool ValueObject::GetDeclaration(Declaration &decl) {
16251625
}
16261626

16271627
#ifdef LLDB_ENABLE_SWIFT
1628-
llvm::Optional<SwiftScratchContextReader> ValueObject::GetSwiftScratchContext() {
1628+
std::optional<SwiftScratchContextReader> ValueObject::GetSwiftScratchContext() {
16291629
lldb::TargetSP target_sp(GetTargetSP());
16301630
if (!target_sp)
1631-
return llvm::None;
1631+
return std::nullopt;
16321632
Status error;
16331633
ExecutionContext ctx = GetExecutionContextRef().Lock(false);
16341634
auto *exe_scope = ctx.GetBestExecutionContextScope();

lldb/source/Core/ValueObjectDynamicValue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ bool ValueObjectDynamicValue::DynamicValueTypeInfoNeedsUpdate() {
447447

448448
#ifdef LLDB_ENABLE_SWIFT
449449
auto cached_ctx = m_value.GetCompilerType().GetTypeSystem();
450-
llvm::Optional<SwiftScratchContextReader> scratch_ctx(
450+
std::optional<SwiftScratchContextReader> scratch_ctx(
451451
GetSwiftScratchContext());
452452

453453
if (!scratch_ctx || !cached_ctx)

lldb/source/Expression/DWARFExpression.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ static bool Evaluate_DW_OP_entry_value(std::vector<Value> &stack,
758758
}
759759
#ifdef LLDB_ENABLE_SWIFT
760760
}
761-
llvm::Optional<DWARFExpressionList> subexpr;
761+
std::optional<DWARFExpressionList> subexpr;
762762
if (!matched_param) {
763763
auto *ctx_func = parent_func ? parent_func : current_func;
764764
subexpr.emplace(ctx_func->CalculateSymbolContextModule(),

lldb/source/Expression/Materializer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ class EntityResultVariable : public Materializer::Entity {
10581058
if (m_type.GetMinimumLanguage() == lldb::eLanguageTypeSwift) {
10591059
#ifdef LLDB_ENABLE_SWIFT
10601060
Status status;
1061-
llvm::Optional<SwiftScratchContextReader> maybe_type_system =
1061+
std::optional<SwiftScratchContextReader> maybe_type_system =
10621062
target_sp->GetSwiftScratchContext(status, *exe_scope);
10631063
if (!maybe_type_system) {
10641064
err.SetErrorStringWithFormat("Couldn't dematerialize a result variable: "

lldb/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ swift::FuncDecl *SwiftASTManipulator::GetFunctionToInjectVariableInto(
878878
return m_function_decl;
879879
}
880880

881-
llvm::Optional<swift::Type> SwiftASTManipulator::GetSwiftTypeForVariable(
881+
std::optional<swift::Type> SwiftASTManipulator::GetSwiftTypeForVariable(
882882
const SwiftASTManipulator::VariableInfo &variable) const {
883883
auto type_system_swift =
884884
variable.m_type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwift>();

lldb/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "llvm/ADT/SmallVector.h"
2323
#include "llvm/Support/Casting.h"
2424

25+
#include <optional>
2526

2627
namespace swift {
2728
class CaseStmt;
@@ -213,7 +214,7 @@ class SwiftASTManipulator : public SwiftASTManipulatorBase {
213214
swift::VarDecl *GetVarDeclForVariableInFunction(
214215
const SwiftASTManipulator::VariableInfo &variable,
215216
swift::FuncDecl *containing_function);
216-
llvm::Optional<swift::Type> GetSwiftTypeForVariable(
217+
std::optional<swift::Type> GetSwiftTypeForVariable(
217218
const SwiftASTManipulator::VariableInfo &variable) const;
218219

219220
bool AddExternalVariables(llvm::MutableArrayRef<VariableInfo> variables);

lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ CreateMainFile(SwiftASTContextForExpressions &swift_ast_context,
875875
}
876876

877877
/// Attempt to materialize one variable.
878-
static llvm::Optional<SwiftExpressionParser::SILVariableInfo>
878+
static std::optional<SwiftExpressionParser::SILVariableInfo>
879879
MaterializeVariable(SwiftASTManipulatorBase::VariableInfo &variable,
880880
SwiftUserExpression &user_expression,
881881
Materializer &materializer,
@@ -925,7 +925,7 @@ MaterializeVariable(SwiftASTManipulatorBase::VariableInfo &variable,
925925
swift::Type actual_swift_type =
926926
manipulator.GetScratchContext().GetSwiftType(actual_type);
927927
if (!actual_swift_type)
928-
return llvm::None;
928+
return std::nullopt;
929929

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

941941
if (!transformed_type)
942-
return llvm::None;
942+
return std::nullopt;
943943

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

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

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

10321032
LLDB_LOGF(

lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionSourceCode.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ using namespace lldb;
2525
using namespace lldb_private;
2626

2727
namespace lldb_private {
28-
llvm::Optional<std::pair<unsigned, unsigned>>
28+
std::optional<std::pair<unsigned, unsigned>>
2929
ParseSwiftGenericParameter(llvm::StringRef name) {
3030
if (!name.consume_front("$τ_"))
3131
return {};
@@ -136,7 +136,7 @@ struct CallsAndArgs {
136136
/// $τ_0_0, $τ_0_1, ..., $τ_0_n)
137137
static llvm::Expected<CallsAndArgs> MakeGenericSignaturesAndCalls(
138138
llvm::ArrayRef<SwiftASTManipulator::VariableInfo> local_variables,
139-
const llvm::Optional<SwiftLanguageRuntime::GenericSignature> &generic_sig,
139+
const std::optional<SwiftLanguageRuntime::GenericSignature> &generic_sig,
140140
bool needs_object_ptr) {
141141
llvm::SmallVector<SwiftASTManipulator::VariableInfo> metadata_variables;
142142
for (auto &var : local_variables)
@@ -256,7 +256,7 @@ static Status WrapExpression(
256256
const EvaluateExpressionOptions &options, llvm::StringRef os_version,
257257
uint32_t &first_body_line,
258258
llvm::ArrayRef<SwiftASTManipulator::VariableInfo> local_variables,
259-
const llvm::Optional<SwiftLanguageRuntime::GenericSignature> &generic_sig) {
259+
const std::optional<SwiftLanguageRuntime::GenericSignature> &generic_sig) {
260260
Status status;
261261
first_body_line = 0; // set to invalid
262262
// TODO make the extension private so we're not polluting the class
@@ -556,7 +556,7 @@ Status SwiftExpressionSourceCode::GetText(
556556
std::string &text, lldb::LanguageType wrapping_language,
557557
bool needs_object_ptr, bool static_method, bool is_class, bool weak_self,
558558
const EvaluateExpressionOptions &options,
559-
const llvm::Optional<SwiftLanguageRuntime::GenericSignature> &generic_sig,
559+
const std::optional<SwiftLanguageRuntime::GenericSignature> &generic_sig,
560560
ExecutionContext &exe_ctx, uint32_t &first_body_line,
561561
llvm::ArrayRef<SwiftASTManipulator::VariableInfo> local_variables) const {
562562
Status status;

lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionSourceCode.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
namespace lldb_private {
1919

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

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

lldb/source/Plugins/ExpressionParser/Swift/SwiftPersistentExpressionState.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ void SwiftPersistentExpressionState::RemovePersistentVariable(
8484
}
8585
}
8686

87-
llvm::Optional<CompilerType>
87+
std::optional<CompilerType>
8888
SwiftPersistentExpressionState::GetCompilerTypeFromPersistentDecl(
8989
ConstString type_name) {
90-
return llvm::None;
90+
return std::nullopt;
9191
}
9292

9393
bool SwiftPersistentExpressionState::SwiftDeclMap::DeclsAreEquivalent(

lldb/source/Plugins/ExpressionParser/Swift/SwiftPersistentExpressionState.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class SwiftPersistentExpressionState : public PersistentExpressionState {
8484

8585
ConstString GetNextPersistentVariableName(bool is_error = false) override;
8686

87-
llvm::Optional<CompilerType>
87+
std::optional<CompilerType>
8888
GetCompilerTypeFromPersistentDecl(ConstString type_name) override;
8989

9090
void RegisterSwiftPersistentDecl(CompilerDecl value_decl);

0 commit comments

Comments
 (0)