Skip to content

Commit 4380ee6

Browse files
authored
Merge pull request #63227 from bnbarham/optional-api-update
Update `llvm::Optional` API uses
2 parents 516e616 + 3ec878d commit 4380ee6

14 files changed

+68
-68
lines changed

include/swift/Basic/BlotMapVector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class BlotMapVector {
148148
if (Iter == Map.end())
149149
return ValueT();
150150
auto &P = Vector[Iter->second];
151-
if (!P.hasValue())
151+
if (!P.has_value())
152152
return ValueT();
153153
return P->second;
154154
}

include/swift/Basic/SuccessorMap.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,13 +375,13 @@ class SuccessorMap {
375375
assert(Traits::precedes(node->Begin, node->End));
376376

377377
// The first key must be strictly higher than the lower bound.
378-
if (lowerBound.hasValue())
379-
assert(Traits::precedes(lowerBound.getValue(), node->Begin));
378+
if (lowerBound.has_value())
379+
assert(Traits::precedes(lowerBound.value(), node->Begin));
380380

381381
// The last key (i.e. End-1) must be strictly lower than
382382
// upperBound-1, or in other words, End must precede upperBound.
383-
if (upperBound.hasValue())
384-
assert(Traits::precedes(node->End, upperBound.getValue()));
383+
if (upperBound.has_value())
384+
assert(Traits::precedes(node->End, upperBound.value()));
385385

386386
// The keys in the left sub-tree must all be strictly less than
387387
// Begin-1, because if any key equals Begin-1, that node should

lib/Basic/Unix/TaskQueue.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ TaskProcessInformation::TaskProcessInformation(ProcessId Pid, struct rusage Usag
5959
Usage.ru_maxrss) {
6060
#ifndef __APPLE__
6161
// Apple systems report bytes; everything else appears to report KB.
62-
this->ProcessUsage.getValue().Maxrss <<= 10;
62+
this->ProcessUsage.value().Maxrss <<= 10;
6363
#endif // __APPLE__
6464
}
6565
#endif // defined(HAVE_GETRUSAGE) && !defined(__HAIKU__)

tools/SourceKit/tools/sourcekitd/lib/API/sourcekitdAPI-InProc.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,8 @@ class SKDObjectVisitor {
352352
return static_cast<ImplClass*>(this)->visitString(CString);
353353
}
354354
auto OptInt = Object->getInt64();
355-
if (OptInt.hasValue()) {
356-
return static_cast<ImplClass*>(this)->visitInt64(OptInt.getValue());
355+
if (OptInt.has_value()) {
356+
return static_cast<ImplClass*>(this)->visitInt64(OptInt.value());
357357
}
358358
llvm_unreachable("unknown sourcekitd_object_t");
359359
}
@@ -789,15 +789,15 @@ bool RequestDict::getInt64(SourceKit::UIdent Key, int64_t &Val,
789789
auto Object = static_cast<SKDObject *>(Dict)->get(SKDUIDFromUIdent(Key));
790790
if (!Object)
791791
return !isOptional;
792-
Val = Object->getInt64().getValueOr(0);
792+
Val = Object->getInt64().value_or(0);
793793
return false;
794794
}
795795

796796
Optional<int64_t> RequestDict::getOptionalInt64(SourceKit::UIdent Key) const {
797797
auto Object = static_cast<SKDObject *>(Dict)->get(SKDUIDFromUIdent(Key));
798798
if (!Object)
799799
return None;
800-
return Object->getInt64().getValueOr(0);
800+
return Object->getInt64().value_or(0);
801801
}
802802

803803
sourcekitd_response_t
@@ -849,7 +849,7 @@ static size_t SKDVar_array_get_count(sourcekitd_variant_t array) {
849849
}
850850

851851
static int64_t SKDVar_array_get_int64(sourcekitd_variant_t array, size_t index) {
852-
return SKD_OBJ(array)->get(index)->getInt64().getValueOr(0);
852+
return SKD_OBJ(array)->get(index)->getInt64().value_or(0);
853853
}
854854

855855
static const char *
@@ -891,7 +891,7 @@ SKDVar_dictionary_get_bool(sourcekitd_variant_t dict, sourcekitd_uid_t key) {
891891
static int64_t
892892
SKDVar_dictionary_get_int64(sourcekitd_variant_t dict, sourcekitd_uid_t key) {
893893
if (auto Object = SKD_OBJ(dict)->get(key)) {
894-
return Object->getInt64().getValueOr(0);
894+
return Object->getInt64().value_or(0);
895895
}
896896
return 0;
897897
}
@@ -919,15 +919,15 @@ SKDVar_dictionary_get_uid(sourcekitd_variant_t dict, sourcekitd_uid_t key) {
919919

920920
static size_t SKDVar_string_get_length(sourcekitd_variant_t obj) {
921921
auto String = SKD_OBJ(obj)->getString();
922-
return String.hasValue() ? String->size() : 0;
922+
return String.has_value() ? String->size() : 0;
923923
}
924924

925925
static const char *SKDVar_string_get_ptr(sourcekitd_variant_t obj) {
926926
return SKD_OBJ(obj)->getCString();
927927
}
928928

929929
static int64_t SKDVar_int64_get_value(sourcekitd_variant_t obj) {
930-
return SKD_OBJ(obj)->getInt64().getValueOr(0);
930+
return SKD_OBJ(obj)->getInt64().value_or(0);
931931
}
932932

933933
static sourcekitd_uid_t SKDVar_uid_get_value(sourcekitd_variant_t obj) {

unittests/Basic/BlotMapVectorTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,9 +632,9 @@ TEST(BlotMapVectorCustomTest, FindAsTest) {
632632

633633
// Normal lookup tests
634634
EXPECT_EQ(1u, map.count(1));
635-
EXPECT_EQ(1u, map.find(0)->getValue().second);
636-
EXPECT_EQ(2u, map.find(1)->getValue().second);
637-
EXPECT_EQ(3u, map.find(2)->getValue().second);
635+
EXPECT_EQ(1u, map.find(0)->value().second);
636+
EXPECT_EQ(2u, map.find(1)->value().second);
637+
EXPECT_EQ(3u, map.find(2)->value().second);
638638
EXPECT_TRUE(map.find(3) == map.end());
639639
}
640640

unittests/Basic/EditorPlaceholderTest.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ TEST(EditorPlaceholder, EditorPlaceholders) {
4949
TEST(EditorPlaceholder, InvalidEditorPlaceholders) {
5050
const char *Text = "<#foo";
5151
Optional<EditorPlaceholderData> DataOpt = parseEditorPlaceholder(Text);
52-
EXPECT_FALSE(DataOpt.hasValue());
52+
EXPECT_FALSE(DataOpt.has_value());
5353

5454
Text = "foo#>";
5555
DataOpt = parseEditorPlaceholder(Text);
56-
EXPECT_FALSE(DataOpt.hasValue());
56+
EXPECT_FALSE(DataOpt.has_value());
5757

5858
Text = "#foo#>";
5959
DataOpt = parseEditorPlaceholder(Text);
60-
EXPECT_FALSE(DataOpt.hasValue());
60+
EXPECT_FALSE(DataOpt.has_value());
6161

6262
Text = " <#foo#>";
6363
DataOpt = parseEditorPlaceholder(Text);
64-
EXPECT_FALSE(DataOpt.hasValue());
64+
EXPECT_FALSE(DataOpt.has_value());
6565
}

unittests/Basic/FrozenMultiMapTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ TEST(FrozenMultiMapCustomTest, SimpleFind) {
7575
EXPECT_EQ(map.size(), 5u);
7676
{
7777
auto r = map.find(key1);
78-
EXPECT_TRUE(r.hasValue());
78+
EXPECT_TRUE(r.has_value());
7979
EXPECT_EQ(r->size(), 3u);
8080
EXPECT_EQ((*r)[0].getID(), 2u);
8181
EXPECT_EQ((*r)[1].getID(), 3u);
@@ -84,7 +84,7 @@ TEST(FrozenMultiMapCustomTest, SimpleFind) {
8484

8585
{
8686
auto r = map.find(key2);
87-
EXPECT_TRUE(r.hasValue());
87+
EXPECT_TRUE(r.has_value());
8888
EXPECT_EQ(r->size(), 2u);
8989
EXPECT_EQ((*r)[0].getID(), 5u);
9090
EXPECT_EQ((*r)[1].getID(), 6u);

unittests/Driver/MockingFineGrainedDependencyGraphs.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ mocking_fine_grained_dependency_graphs::getChangesForSimulatedLoad(
4343
auto swiftDeps =
4444
cmd->getOutput().getAdditionalOutputForType(file_types::TY_SwiftDeps).str();
4545
auto swiftDepsFingerprint =
46-
swift::mockFingerprintFromString(swiftDeps).getValue();
47-
auto interfaceHash = interfaceHashIfNonEmpty.getValueOr(swiftDepsFingerprint);
46+
swift::mockFingerprintFromString(swiftDeps).value();
47+
auto interfaceHash = interfaceHashIfNonEmpty.value_or(swiftDepsFingerprint);
4848

4949
SourceManager sm;
5050
DiagnosticEngine diags(sm);
@@ -70,7 +70,7 @@ mocking_fine_grained_dependency_graphs::simulateReload(
7070
hadCompilationError);
7171
if (!changedNodes)
7272
return g.getAllJobs();
73-
return g.findJobsToRecompileWhenNodesChange(changedNodes.getValue());
73+
return g.findJobsToRecompileWhenNodesChange(changedNodes.value());
7474
}
7575

7676
LLVM_ATTRIBUTE_UNUSED

unittests/Driver/UnitTestSourceFileDepGraphFactory.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void UnitTestSourceFileDepGraphFactory::addADefinedDecl(StringRef s,
5858
const Optional<Fingerprint> fingerprint =
5959
swift::mockFingerprintFromString(fingerprintString);
6060

61-
AbstractSourceFileDepGraphFactory::addADefinedDecl(key.getValue(),
61+
AbstractSourceFileDepGraphFactory::addADefinedDecl(key.value(),
6262
fingerprint);
6363
}
6464

@@ -80,7 +80,7 @@ UnitTestSourceFileDepGraphFactory::computeUseKey(StringRef s,
8080
isCascadingUse ? DeclAspect::interface : DeclAspect::implementation;
8181

8282
if (!s.empty())
83-
return parseADefinedDecl(s, kindOfUse, aspectOfUse).getValue();
83+
return parseADefinedDecl(s, kindOfUse, aspectOfUse).value();
8484
StringRef swiftDepsRef(swiftDeps);
8585
return DependencyKey::Builder(NodeKind::sourceFileProvide, aspectOfUse)
8686
.withName(swiftDepsRef)
@@ -155,15 +155,15 @@ UnitTestSourceFileDepGraphFactory::parseContext(const StringRef s,
155155
const NodeKind kind) {
156156
return !singleNameIsContext(kind)
157157
? s.split(nameContextSeparator).first.str()
158-
: singleNameIsContext(kind).getValue() ? s.str() : "";
158+
: singleNameIsContext(kind).value() ? s.str() : "";
159159
}
160160

161161
std::string UnitTestSourceFileDepGraphFactory::parseName(const StringRef s,
162162
const NodeKind kind) {
163163
const std::string name =
164164
!singleNameIsContext(kind)
165165
? s.split(nameContextSeparator).second.str()
166-
: singleNameIsContext(kind).getValue() ? "" : s.str();
166+
: singleNameIsContext(kind).value() ? "" : s.str();
167167
assert(kind != NodeKind::member ||
168168
!name.empty() && "Should be a potentialMember");
169169
return name;

unittests/Parse/BuildConfigTests.cpp

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,25 @@ Optional<version::Version> V(const char *VersionString) {
2222

2323
TEST_F(CompilerVersionTest, VersionComparison) {
2424
auto currentVersion = version::getCurrentCompilerVersion();
25-
EXPECT_GE(CV("700").getValue(), CV("602").getValue());
26-
EXPECT_GE(CV("700.*").getValue(), CV("700.*").getValue());
27-
EXPECT_GE(CV("700.*.1").getValue(), CV("700.*.0").getValue());
28-
EXPECT_GE(CV("700.*.23").getValue(), CV("700.*.21").getValue());
29-
EXPECT_GE(CV("700.*.1.1.0").getValue(), CV("700.*.1.1").getValue());
25+
EXPECT_GE(CV("700").value(), CV("602").value());
26+
EXPECT_GE(CV("700.*").value(), CV("700.*").value());
27+
EXPECT_GE(CV("700.*.1").value(), CV("700.*.0").value());
28+
EXPECT_GE(CV("700.*.23").value(), CV("700.*.21").value());
29+
EXPECT_GE(CV("700.*.1.1.0").value(), CV("700.*.1.1").value());
3030
EXPECT_GE(currentVersion, currentVersion);
31-
EXPECT_GE(currentVersion, CV("9223371.*.999.999.999").getValue());
31+
EXPECT_GE(currentVersion, CV("9223371.*.999.999.999").value());
3232
}
3333

3434
TEST_F(VersionTest, VersionComparison) {
3535
auto currentVersion = version::Version::getCurrentLanguageVersion();
36-
EXPECT_GE(V("3").getValue(), V("2").getValue());
37-
EXPECT_GE(V("2.0").getValue(), V("2.0").getValue());
38-
EXPECT_GE(V("2.1").getValue(), V("2.0").getValue());
39-
EXPECT_GE(V("3.1").getValue(), V("3.0.1").getValue());
40-
EXPECT_GE(V("2.0").getValue(), V("2").getValue());
36+
EXPECT_GE(V("3").value(), V("2").value());
37+
EXPECT_GE(V("2.0").value(), V("2.0").value());
38+
EXPECT_GE(V("2.1").value(), V("2.0").value());
39+
EXPECT_GE(V("3.1").value(), V("3.0.1").value());
40+
EXPECT_GE(V("2.0").value(), V("2").value());
4141
EXPECT_GE(currentVersion, currentVersion);
42-
EXPECT_GE(currentVersion, V("1.0").getValue());
43-
EXPECT_GE(currentVersion, V("2").getValue());
42+
EXPECT_GE(currentVersion, V("1.0").value());
43+
EXPECT_GE(currentVersion, V("2").value());
4444
EXPECT_FALSE(V("2.n").hasValue());
4545
EXPECT_FALSE(V("").hasValue());
4646
EXPECT_FALSE(V("\"2.0\"").hasValue());
@@ -53,23 +53,23 @@ TEST_F(VersionTest, VersionComparison) {
5353
}
5454

5555
TEST_F(CompilerVersionUnpackingTest, VersionComparison) {
56-
EXPECT_EQ(CV("700").getValue(), V("0.700").getValue());
57-
EXPECT_EQ(CV("700.*").getValue(), V("0.700").getValue());
58-
EXPECT_EQ(CV("700.*.1").getValue(), V("0.700.1").getValue());
59-
EXPECT_EQ(CV("700.*.23").getValue(), V("0.700.23").getValue());
60-
EXPECT_EQ(CV("700.*.1.1").getValue(), V("0.700.1.1").getValue());
56+
EXPECT_EQ(CV("700").value(), V("0.700").value());
57+
EXPECT_EQ(CV("700.*").value(), V("0.700").value());
58+
EXPECT_EQ(CV("700.*.1").value(), V("0.700.1").value());
59+
EXPECT_EQ(CV("700.*.23").value(), V("0.700.23").value());
60+
EXPECT_EQ(CV("700.*.1.1").value(), V("0.700.1.1").value());
6161

62-
EXPECT_EQ(CV("1300").getValue(), V("1.300").getValue());
63-
EXPECT_EQ(CV("1300.*").getValue(), V("1.300").getValue());
64-
EXPECT_EQ(CV("1300.*.1").getValue(), V("1.300.1").getValue());
65-
EXPECT_EQ(CV("1300.*.23").getValue(), V("1.300.23").getValue());
66-
EXPECT_EQ(CV("1300.*.1.1").getValue(), V("1.300.1.1").getValue());
62+
EXPECT_EQ(CV("1300").value(), V("1.300").value());
63+
EXPECT_EQ(CV("1300.*").value(), V("1.300").value());
64+
EXPECT_EQ(CV("1300.*.1").value(), V("1.300.1").value());
65+
EXPECT_EQ(CV("1300.*.23").value(), V("1.300.23").value());
66+
EXPECT_EQ(CV("1300.*.1.1").value(), V("1.300.1.1").value());
6767

68-
EXPECT_EQ(CV("5007").getValue(), V("5.7").getValue());
69-
EXPECT_EQ(CV("5007.*").getValue(), V("5.7").getValue());
70-
EXPECT_EQ(CV("5007.*.1").getValue(), V("5.7.1").getValue());
71-
EXPECT_EQ(CV("5007.*.23").getValue(), V("5.7.23").getValue());
72-
EXPECT_EQ(CV("5007.*.1.1").getValue(), V("5.7.1.1").getValue());
68+
EXPECT_EQ(CV("5007").value(), V("5.7").value());
69+
EXPECT_EQ(CV("5007.*").value(), V("5.7").value());
70+
EXPECT_EQ(CV("5007.*.1").value(), V("5.7.1").value());
71+
EXPECT_EQ(CV("5007.*.23").value(), V("5.7.23").value());
72+
EXPECT_EQ(CV("5007.*.1.1").value(), V("5.7.1.1").value());
7373

7474
// Since this test was added during 5.7, we expect all of these comparisons to
7575
// be GE, either because we are comparing to the empty version or because we

unittests/Sema/BindingInferenceTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ TEST_F(SemaTest, TestNoDoubleVoidClosureResultInference) {
348348
llvm::SmallPtrSet<Type, 2> inferredTypes;
349349

350350
while (auto binding = producer()) {
351-
ASSERT_TRUE(binding.hasValue());
351+
ASSERT_TRUE(binding.has_value());
352352
ASSERT_EQ(binding->getTypeVariable(), typeVar);
353353
ASSERT_TRUE(inferredTypes.insert(binding->getType()).second);
354354
}

unittests/Sema/PlaceholderTypeInferenceTests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ TEST_F(SemaTest, TestPlaceholderInferenceForArrayLiteral) {
4848
auto &solution = solutions[0];
4949

5050
auto eltTy = ConstraintSystem::isArrayType(solution.simplifyType(solution.getType(arrayExpr)));
51-
ASSERT_TRUE(eltTy.hasValue());
51+
ASSERT_TRUE(eltTy.has_value());
5252
ASSERT_TRUE((*eltTy)->is<StructType>());
5353
ASSERT_EQ((*eltTy)->getAs<StructType>()->getDecl(), intTypeDecl);
5454
}
@@ -89,7 +89,7 @@ TEST_F(SemaTest, TestPlaceholderInferenceForDictionaryLiteral) {
8989
auto &solution = solutions[0];
9090

9191
auto keyValTys = ConstraintSystem::isDictionaryType(solution.simplifyType(solution.getType(dictExpr)));
92-
ASSERT_TRUE(keyValTys.hasValue());
92+
ASSERT_TRUE(keyValTys.has_value());
9393

9494
Type keyTy;
9595
Type valTy;

unittests/Sema/SolutionFilteringTests.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ TEST_F(SemaTest, TestFilteringBasedOnSolutionScore) {
5555

5656
auto best = CS.findBestSolution(solutions, /*minimize=*/true);
5757

58-
ASSERT_FALSE(best.hasValue());
58+
ASSERT_FALSE(best.has_value());
5959
ASSERT_EQ(solutions.size(), 2u);
6060
ASSERT_EQ(solutions[0].getFixedScore(), bestScore);
6161
ASSERT_EQ(solutions[1].getFixedScore(), bestScore);
@@ -73,7 +73,7 @@ TEST_F(SemaTest, TestFilteringBasedOnSolutionScore) {
7373

7474
auto best = CS.findBestSolution(solutions, /*minimize=*/true);
7575

76-
ASSERT_FALSE(best.hasValue());
76+
ASSERT_FALSE(best.has_value());
7777
ASSERT_EQ(solutions.size(), 2u);
7878
ASSERT_EQ(solutions[0].getFixedScore(), bestScore);
7979
ASSERT_EQ(solutions[1].getFixedScore(), bestScore);
@@ -92,7 +92,7 @@ TEST_F(SemaTest, TestFilteringBasedOnSolutionScore) {
9292

9393
auto best = CS.findBestSolution(solutions, /*minimize=*/true);
9494

95-
ASSERT_FALSE(best.hasValue());
95+
ASSERT_FALSE(best.has_value());
9696
ASSERT_EQ(solutions.size(), 2u);
9797
ASSERT_EQ(solutions[0].getFixedScore(), bestScore);
9898
ASSERT_EQ(solutions[1].getFixedScore(), bestScore);
@@ -110,7 +110,7 @@ TEST_F(SemaTest, TestFilteringBasedOnSolutionScore) {
110110

111111
auto best = CS.findBestSolution(solutions, /*minimize=*/true);
112112

113-
ASSERT_FALSE(best.hasValue());
113+
ASSERT_FALSE(best.has_value());
114114
ASSERT_EQ(solutions.size(), 2u);
115115
ASSERT_EQ(solutions[0].getFixedScore(), bestScore);
116116
ASSERT_EQ(solutions[1].getFixedScore(), bestScore);
@@ -130,7 +130,7 @@ TEST_F(SemaTest, TestFilteringBasedOnSolutionScore) {
130130

131131
auto best = CS.findBestSolution(solutions, /*minimize=*/true);
132132

133-
ASSERT_FALSE(best.hasValue());
133+
ASSERT_FALSE(best.has_value());
134134
ASSERT_EQ(solutions.size(), 2u);
135135
ASSERT_EQ(solutions[0].getFixedScore(), bestScore);
136136
ASSERT_EQ(solutions[1].getFixedScore(), bestScore);

unittests/SourceKit/SwiftLang/CursorInfoTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ class CursorInfoTest : public ::testing::Test {
142142

143143
void open(const char *DocName, StringRef Text,
144144
Optional<ArrayRef<const char *>> CArgs = llvm::None) {
145-
auto Args = CArgs.hasValue() ? makeArgs(DocName, *CArgs)
146-
: std::vector<const char *>{};
145+
auto Args = CArgs.has_value() ? makeArgs(DocName, *CArgs)
146+
: std::vector<const char *>{};
147147
auto Buf = MemoryBuffer::getMemBufferCopy(Text, DocName);
148148
getLang().editorOpen(DocName, Buf.get(), Consumer, Args, None);
149149
}

0 commit comments

Comments
 (0)