Skip to content

Commit ab1b343

Browse files
committed
use new llvm::Optional API
`getValue` -> `value` `getValueOr` -> `value_or` `hasValue` -> `has_value` `map` -> `transform` The old API will be deprecated in the rebranch. To avoid merge conflicts, use the new API already in the main branch. rdar://102362022
1 parent 567b68a commit ab1b343

File tree

328 files changed

+1537
-1536
lines changed

Some content is hidden

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

328 files changed

+1537
-1536
lines changed

include/swift/APIDigester/ModuleAnalyzerNodes.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class SDKContext {
212212
DiagnosticEngine &getDiags(SourceLoc Loc = SourceLoc());
213213
void addDiagConsumer(DiagnosticConsumer &Consumer);
214214
void setCommonVersion(uint8_t Ver) {
215-
assert(!CommonVersion.hasValue());
215+
assert(!CommonVersion.has_value());
216216
CommonVersion = Ver;
217217
}
218218
uint8_t getCommonVersion() const {
@@ -401,7 +401,7 @@ class SDKNodeDecl: public SDKNode {
401401
StringRef getGenericSignature() const { return GenericSig; }
402402
StringRef getSugaredGenericSignature() const { return SugaredGenericSig; }
403403
StringRef getScreenInfo() const;
404-
bool hasFixedBinaryOrder() const { return FixedBinaryOrder.hasValue(); }
404+
bool hasFixedBinaryOrder() const { return FixedBinaryOrder.has_value(); }
405405
uint8_t getFixedBinaryOrder() const { return *FixedBinaryOrder; }
406406
PlatformIntroVersion getIntroducingVersion() const { return introVersions; }
407407
StringRef getObjCName() const { return ObjCName; }
@@ -685,9 +685,9 @@ class SDKNodeDeclAbstractFunc : public SDKNodeDecl {
685685
public:
686686
bool isThrowing() const { return IsThrowing; }
687687
bool reqNewWitnessTableEntry() const { return ReqNewWitnessTableEntry; }
688-
uint8_t getSelfIndex() const { return SelfIndex.getValue(); }
688+
uint8_t getSelfIndex() const { return SelfIndex.value(); }
689689
Optional<uint8_t> getSelfIndexOptional() const { return SelfIndex; }
690-
bool hasSelfIndex() const { return SelfIndex.hasValue(); }
690+
bool hasSelfIndex() const { return SelfIndex.has_value(); }
691691
static bool classof(const SDKNode *N);
692692
virtual void jsonize(json::Output &out) override;
693693
static StringRef getTypeRoleDescription(SDKContext &Ctx, unsigned Index);

include/swift/AST/ArgumentList.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class alignas(Argument) ArgumentList final
154154
assert(!firstTrailingClosureIndex || *firstTrailingClosureIndex < numArgs &&
155155
"Invalid trailing closure index");
156156
RawFirstTrailingClosureIndex =
157-
firstTrailingClosureIndex.getValueOr(numArgs);
157+
firstTrailingClosureIndex.value_or(numArgs);
158158
}
159159

160160
ArgumentList(const ArgumentList &) = delete;
@@ -400,7 +400,7 @@ class alignas(Argument) ArgumentList final
400400

401401
/// Whether any unlabeled or labeled trailing closures are present.
402402
bool hasAnyTrailingClosures() const {
403-
return getOriginalArgs()->getFirstTrailingClosureIndex().hasValue();
403+
return getOriginalArgs()->getFirstTrailingClosureIndex().has_value();
404404
}
405405

406406
/// Whether a given index is for an unlabeled trailing closure, which is the
@@ -443,7 +443,7 @@ class alignas(Argument) ArgumentList final
443443
iterator_range<iterator> getNonTrailingArgs() const {
444444
assert(!HasOriginalArgs && "Query original args instead");
445445
auto idx = getFirstTrailingClosureIndex();
446-
if (!idx.hasValue())
446+
if (!idx.has_value())
447447
return *this;
448448

449449
return {begin(), iterator(this, *idx)};
@@ -456,7 +456,7 @@ class alignas(Argument) ArgumentList final
456456
iterator_range<iterator> getTrailingClosures() const {
457457
assert(!HasOriginalArgs && "Query original args instead");
458458
auto idx = getFirstTrailingClosureIndex();
459-
if (!idx.hasValue())
459+
if (!idx.has_value())
460460
return {end(), end()};
461461

462462
return {iterator(this, *idx), end()};
@@ -470,7 +470,7 @@ class alignas(Argument) ArgumentList final
470470
Optional<Argument> getFirstTrailingClosure() const {
471471
assert(!HasOriginalArgs && "Query original args instead");
472472
auto idx = getFirstTrailingClosureIndex();
473-
if (!idx.hasValue())
473+
if (!idx.has_value())
474474
return None;
475475
return get(*idx);
476476
}

include/swift/AST/Attr.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2634,13 +2634,13 @@ class TypeAttributes {
26342634
return true;
26352635
}
26362636

2637-
bool hasConvention() const { return ConventionArguments.hasValue(); }
2637+
bool hasConvention() const { return ConventionArguments.has_value(); }
26382638

26392639
/// Returns the primary calling convention string.
26402640
///
26412641
/// Note: For C conventions, this may not represent the full convention.
26422642
StringRef getConventionName() const {
2643-
return ConventionArguments.getValue().Name;
2643+
return ConventionArguments.value().Name;
26442644
}
26452645

26462646
/// Show the string enclosed between @convention(..)'s parentheses.
@@ -2664,10 +2664,10 @@ class TypeAttributes {
26642664
#include "swift/AST/ReferenceStorage.def"
26652665
}
26662666

2667-
bool hasOpenedID() const { return OpenedID.hasValue(); }
2667+
bool hasOpenedID() const { return OpenedID.has_value(); }
26682668
UUID getOpenedID() const { return *OpenedID; }
26692669

2670-
bool hasConstraintType() const { return ConstraintType.hasValue(); }
2670+
bool hasConstraintType() const { return ConstraintType.has_value(); }
26712671
TypeRepr *getConstraintType() const { return *ConstraintType; }
26722672

26732673
/// Given a name like "autoclosure", return the type attribute ID that

include/swift/AST/Decl.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3002,18 +3002,18 @@ class OpaqueTypeDecl final :
30023002
}
30033003

30043004
void setUniqueUnderlyingTypeSubstitutions(SubstitutionMap subs) {
3005-
assert(!UniqueUnderlyingType.hasValue() && "resetting underlying type?!");
3005+
assert(!UniqueUnderlyingType.has_value() && "resetting underlying type?!");
30063006
UniqueUnderlyingType = subs;
30073007
}
30083008

30093009
bool hasConditionallyAvailableSubstitutions() const {
3010-
return ConditionallyAvailableTypes.hasValue();
3010+
return ConditionallyAvailableTypes.has_value();
30113011
}
30123012

30133013
ArrayRef<ConditionallyAvailableSubstitutions *>
30143014
getConditionallyAvailableSubstitutions() const {
30153015
assert(ConditionallyAvailableTypes);
3016-
return ConditionallyAvailableTypes.getValue();
3016+
return ConditionallyAvailableTypes.value();
30173017
}
30183018

30193019
void setConditionallyAvailableSubstitutions(
@@ -4891,7 +4891,7 @@ class ProtocolDecl final : public NominalTypeDecl {
48914891

48924892
/// Has the requirement signature been computed yet?
48934893
bool isRequirementSignatureComputed() const {
4894-
return RequirementSig.hasValue();
4894+
return RequirementSig.has_value();
48954895
}
48964896

48974897
void setRequirementSignature(RequirementSignature requirementSig);
@@ -6451,8 +6451,8 @@ class BodyAndFingerprint {
64516451

64526452
public:
64536453
BodyAndFingerprint(BraceStmt *body, Optional<Fingerprint> fp)
6454-
: BodyAndHasFp(body, fp.hasValue()),
6455-
Fp(fp.hasValue() ? *fp : Fingerprint::ZERO()) {}
6454+
: BodyAndHasFp(body, fp.has_value()),
6455+
Fp(fp.has_value() ? *fp : Fingerprint::ZERO()) {}
64566456
BodyAndFingerprint() : BodyAndFingerprint(nullptr, None) {}
64576457

64586458
BraceStmt *getBody() const { return BodyAndHasFp.getPointer(); }
@@ -6465,7 +6465,7 @@ class BodyAndFingerprint {
64656465
}
64666466

64676467
void setFingerprint(Optional<Fingerprint> fp) {
6468-
if (fp.hasValue()) {
6468+
if (fp.has_value()) {
64696469
Fp = *fp;
64706470
BodyAndHasFp.setInt(true);
64716471
} else {

include/swift/AST/FineGrainedDependencies.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ template <typename KeyT, typename ValueT> class Memoizer {
116116
findExistingOrCreateIfNew(KeyT key,
117117
function_ref<ValueT(const KeyT &)> createFn) {
118118
if (auto existing = findExisting(key))
119-
return existing.getValue();
119+
return existing.value();
120120
ValueT v = createFn(key);
121121
(void)insert(key, v);
122122
return v;
@@ -324,10 +324,10 @@ class BiIndexedTwoStageMap {
324324
unsigned index)>
325325
verifyFn) const {
326326
map1.verify([&](const Key1 &k1, const Key2 &k2, Value v) {
327-
assertConsistent(map2.find(k2, k1).getValue(), v);
327+
assertConsistent(map2.find(k2, k1).value(), v);
328328
});
329329
map2.verify([&](const Key2 &k2, const Key1 &k1, Value v) {
330-
assertConsistent(map1.find(k1, k2).getValue(), v);
330+
assertConsistent(map1.find(k1, k2).value(), v);
331331
});
332332
map1.verify([&](const Key1 &k1, const Key2 &k2, Value v) {
333333
verifyFn(k1, k2, v, 0);

include/swift/AST/ModuleLoader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class ModuleLoader {
214214

215215
public:
216216
/// Returns true if the version has a valid source kind.
217-
bool isValid() const { return SourceKind.hasValue(); }
217+
bool isValid() const { return SourceKind.has_value(); }
218218

219219
/// Returns the version, which may be empty if a version was not present or
220220
/// was unparsable.
@@ -223,7 +223,7 @@ class ModuleLoader {
223223
/// Returns the kind of source of the module version. Do not call if
224224
/// \c isValid() returns false.
225225
ModuleVersionSourceKind getSourceKind() const {
226-
return SourceKind.getValue();
226+
return SourceKind.value();
227227
}
228228

229229
void setVersion(llvm::VersionTuple version, ModuleVersionSourceKind kind) {

include/swift/AST/SourceFile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ class SourceFile final : public FileUnit {
333333
~SourceFile();
334334

335335
bool hasImports() const {
336-
return Imports.hasValue();
336+
return Imports.has_value();
337337
}
338338

339339
/// Retrieve an immutable view of the source file's imports.

include/swift/AST/Stmt.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class alignas(8) Stmt : public ASTAllocated<Stmt> {
101101
/// Return the given value for the 'implicit' flag if present, or if None,
102102
/// return true if the location is invalid.
103103
static bool getDefaultImplicitFlag(Optional<bool> implicit, SourceLoc keyLoc){
104-
return implicit.hasValue() ? *implicit : keyLoc.isInvalid();
104+
return implicit.has_value() ? *implicit : keyLoc.isInvalid();
105105
}
106106

107107
public:
@@ -1093,7 +1093,7 @@ class CaseStmt final
10931093
void setBody(BraceStmt *body) { BodyAndHasFallthrough.setPointer(body); }
10941094

10951095
/// True if the case block declares any patterns with local variable bindings.
1096-
bool hasBoundDecls() const { return CaseBodyVariables.hasValue(); }
1096+
bool hasBoundDecls() const { return CaseBodyVariables.has_value(); }
10971097

10981098
/// Get the source location of the 'case', 'default', or 'catch' of the first
10991099
/// label.
@@ -1152,7 +1152,7 @@ class CaseStmt final
11521152
return a;
11531153
}
11541154

1155-
bool hasCaseBodyVariables() const { return CaseBodyVariables.hasValue(); }
1155+
bool hasCaseBodyVariables() const { return CaseBodyVariables.has_value(); }
11561156

11571157
/// Return an MutableArrayRef containing the case body variables of this
11581158
/// CaseStmt.

include/swift/AST/Types.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3107,15 +3107,15 @@ class AnyFunctionType : public TypeBase {
31073107
RecursiveTypeProperties properties, unsigned NumParams,
31083108
Optional<ExtInfo> Info)
31093109
: TypeBase(Kind, CanTypeContext, properties), Output(Output) {
3110-
if (Info.hasValue()) {
3110+
if (Info.has_value()) {
31113111
Bits.AnyFunctionType.HasExtInfo = true;
3112-
Bits.AnyFunctionType.ExtInfoBits = Info.getValue().getBits();
3112+
Bits.AnyFunctionType.ExtInfoBits = Info.value().getBits();
31133113
Bits.AnyFunctionType.HasClangTypeInfo =
3114-
!Info.getValue().getClangTypeInfo().empty();
3114+
!Info.value().getClangTypeInfo().empty();
31153115
Bits.AnyFunctionType.HasGlobalActor =
3116-
!Info.getValue().getGlobalActor().isNull();
3116+
!Info.value().getGlobalActor().isNull();
31173117
// The use of both assert() and static_assert() is intentional.
3118-
assert(Bits.AnyFunctionType.ExtInfoBits == Info.getValue().getBits() &&
3118+
assert(Bits.AnyFunctionType.ExtInfoBits == Info.value().getBits() &&
31193119
"Bits were dropped!");
31203120
static_assert(
31213121
ASTExtInfoBuilder::NumMaskBits == NumAFTExtInfoBits,
@@ -4929,8 +4929,8 @@ class SILFunctionType final
49294929
kind == innerty::ABIEscapeToNoEscapeConversion;
49304930
}
49314931

4932-
bool hasPayload() const { return payload.hasValue(); }
4933-
uintptr_t getPayload() const { return payload.getValue(); }
4932+
bool hasPayload() const { return payload.has_value(); }
4933+
uintptr_t getPayload() const { return payload.value(); }
49344934
StringRef getMessage() const;
49354935
};
49364936

include/swift/Basic/BlotMapVector.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class BlotMapVector {
6363
Vector.push_back({std::make_pair(Arg, ValueT())});
6464
return (*Vector[Num]).second;
6565
}
66-
return Vector[Pair.first->second].getValue().second;
66+
return Vector[Pair.first->second].value().second;
6767
}
6868

6969
template <typename... Ts>
@@ -107,7 +107,7 @@ class BlotMapVector {
107107
if (It == Map.end())
108108
return Vector.end();
109109
auto Iter = Vector.begin() + It->second;
110-
if (!Iter->hasValue())
110+
if (!Iter->has_value())
111111
return Vector.end();
112112
return Iter;
113113
}

0 commit comments

Comments
 (0)