Skip to content

Commit a29341e

Browse files
committed
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 doesn't move ABI/Demangling/Remote*/Threading, which we need to look into more.
1 parent 0735629 commit a29341e

File tree

759 files changed

+7713
-7805
lines changed

Some content is hidden

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

759 files changed

+7713
-7805
lines changed

include/swift/APIDigester/ModuleAnalyzerNodes.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class SDKContext {
179179
CheckerOptions Opts;
180180
std::vector<BreakingAttributeInfo> BreakingAttrs;
181181
// The common version of two ABI/API descriptors under comparison.
182-
llvm::Optional<uint8_t> CommonVersion;
182+
std::optional<uint8_t> CommonVersion;
183183

184184
public:
185185
// Define the set of known identifiers.
@@ -232,7 +232,7 @@ class SDKContext {
232232
const CheckerOptions &getOpts() const { return Opts; }
233233
bool shouldIgnore(Decl *D, const Decl* Parent = nullptr) const;
234234
ArrayRef<BreakingAttributeInfo> getBreakingAttributeInfo() const { return BreakingAttrs; }
235-
llvm::Optional<uint8_t> getFixedBinaryOrder(ValueDecl *VD) const;
235+
std::optional<uint8_t> getFixedBinaryOrder(ValueDecl *VD) const;
236236

237237
CompilerInstance &newCompilerInstance() {
238238
CIs.emplace_back(new CompilerInstance());
@@ -364,7 +364,7 @@ class SDKNodeDecl: public SDKNode {
364364
// In ABI mode, this field is populated as a user-friendly version of GenericSig.
365365
// Diagnostic preferes the sugared versions if they differ as well.
366366
StringRef SugaredGenericSig;
367-
llvm::Optional<uint8_t> FixedBinaryOrder;
367+
std::optional<uint8_t> FixedBinaryOrder;
368368
PlatformIntroVersion introVersions;
369369
StringRef ObjCName;
370370

@@ -446,7 +446,7 @@ class SDKNodeRoot: public SDKNode {
446446
ArrayRef<SDKNodeDecl*> getDescendantsByUsr(StringRef Usr) {
447447
return DescendantDeclTable[Usr].getArrayRef();
448448
}
449-
llvm::Optional<StringRef> getSingleModuleName() const;
449+
std::optional<StringRef> getSingleModuleName() const;
450450
};
451451

452452
class SDKNodeType: public SDKNode {
@@ -588,11 +588,11 @@ class SDKNodeDeclType: public SDKNodeDecl {
588588
return InheritsConvenienceInitializers;
589589
};
590590

591-
llvm::Optional<SDKNodeDeclType *> getSuperclass() const;
591+
std::optional<SDKNodeDeclType *> getSuperclass() const;
592592

593593
/// Finding the node through all children, including the inherited ones,
594594
/// whose printed name matches with the given name.
595-
llvm::Optional<SDKNodeDecl *> lookupChildByPrintedName(StringRef Name) const;
595+
std::optional<SDKNodeDecl *> lookupChildByPrintedName(StringRef Name) const;
596596
SDKNodeType *getRawValueType() const;
597597
bool isConformingTo(KnownProtocolKind Kind) const;
598598
void jsonize(json::Output &out) override;
@@ -686,7 +686,7 @@ class SDKNodeDeclMacro : public SDKNodeDecl {
686686
class SDKNodeDeclAbstractFunc : public SDKNodeDecl {
687687
bool IsThrowing;
688688
bool ReqNewWitnessTableEntry;
689-
llvm::Optional<uint8_t> SelfIndex;
689+
std::optional<uint8_t> SelfIndex;
690690

691691
protected:
692692
SDKNodeDeclAbstractFunc(SDKNodeInitInfo Info, SDKNodeKind Kind);
@@ -695,7 +695,7 @@ class SDKNodeDeclAbstractFunc : public SDKNodeDecl {
695695
bool isThrowing() const { return IsThrowing; }
696696
bool reqNewWitnessTableEntry() const { return ReqNewWitnessTableEntry; }
697697
uint8_t getSelfIndex() const { return SelfIndex.value(); }
698-
llvm::Optional<uint8_t> getSelfIndexOptional() const { return SelfIndex; }
698+
std::optional<uint8_t> getSelfIndexOptional() const { return SelfIndex; }
699699
bool hasSelfIndex() const { return SelfIndex.has_value(); }
700700
static bool classof(const SDKNode *N);
701701
virtual void jsonize(json::Output &out) override;

include/swift/AST/ASTContext.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ enum class KnownFoundationEntity {
171171

172172
/// Retrieve the Foundation entity kind for the given Objective-C
173173
/// entity name.
174-
llvm::Optional<KnownFoundationEntity> getKnownFoundationEntity(StringRef name);
174+
std::optional<KnownFoundationEntity> getKnownFoundationEntity(StringRef name);
175175

176176
/// Retrieve the Swift name for the given Foundation entity, where
177177
/// "NS" prefix stripping will apply under omit-needless-words.
@@ -360,7 +360,7 @@ class ASTContext final {
360360
unsigned NumTypoCorrections = 0;
361361

362362
/// Cached mapping from types to their associated tangent spaces.
363-
llvm::DenseMap<Type, llvm::Optional<TangentSpace>> AutoDiffTangentSpaces;
363+
llvm::DenseMap<Type, std::optional<TangentSpace>> AutoDiffTangentSpaces;
364364

365365
/// A cache of derivative function types per configuration.
366366
llvm::DenseMap<SILAutoDiffDerivativeFunctionKey, CanSILFunctionType>
@@ -846,7 +846,7 @@ class ASTContext final {
846846
/// SIL analog of \c ASTContext::getClangFunctionType .
847847
const clang::Type *
848848
getCanonicalClangFunctionType(ArrayRef<SILParameterInfo> params,
849-
llvm::Optional<SILResultInfo> result,
849+
std::optional<SILResultInfo> result,
850850
SILFunctionType::Representation trueRep);
851851

852852
/// Instantiates "Impl.Converter" if needed, then translate Swift generic
@@ -1566,7 +1566,7 @@ class ASTContext final {
15661566
private:
15671567
friend Decl;
15681568

1569-
llvm::Optional<ExternalSourceLocs *> getExternalSourceLocs(const Decl *D);
1569+
std::optional<ExternalSourceLocs *> getExternalSourceLocs(const Decl *D);
15701570
void setExternalSourceLocs(const Decl *D, ExternalSourceLocs *Locs);
15711571

15721572
friend TypeBase;

include/swift/AST/ASTDemangler.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
#include "swift/Demangling/NamespaceMacros.h"
2828
#include "swift/Demangling/TypeDecoder.h"
2929
#include "llvm/ADT/ArrayRef.h"
30-
#include "llvm/ADT/Optional.h"
3130
#include "llvm/ADT/StringRef.h"
31+
#include <optional>
3232

3333
namespace swift {
3434

@@ -151,7 +151,7 @@ class ASTBuilder {
151151
Demangle::ImplParameterConvention calleeConvention,
152152
ArrayRef<Demangle::ImplFunctionParam<Type>> params,
153153
ArrayRef<Demangle::ImplFunctionResult<Type>> results,
154-
llvm::Optional<Demangle::ImplFunctionResult<Type>> errorResult,
154+
std::optional<Demangle::ImplFunctionResult<Type>> errorResult,
155155
ImplFunctionTypeFlags flags);
156156

157157
Type createProtocolCompositionType(ArrayRef<ProtocolDecl *> protocols,
@@ -169,11 +169,11 @@ class ASTBuilder {
169169

170170
Type createExistentialMetatypeType(
171171
Type instance,
172-
llvm::Optional<Demangle::ImplMetatypeRepresentation> repr = llvm::None);
172+
std::optional<Demangle::ImplMetatypeRepresentation> repr = std::nullopt);
173173

174174
Type createMetatypeType(
175175
Type instance,
176-
llvm::Optional<Demangle::ImplMetatypeRepresentation> repr = llvm::None);
176+
std::optional<Demangle::ImplMetatypeRepresentation> repr = std::nullopt);
177177

178178
void pushGenericParams(ArrayRef<std::pair<unsigned, unsigned>> parameterPacks);
179179
void popGenericParams();
@@ -252,7 +252,7 @@ class ASTBuilder {
252252
SynthesizedByImporter
253253
};
254254

255-
llvm::Optional<ForeignModuleKind> getForeignModuleKind(NodePointer node);
255+
std::optional<ForeignModuleKind> getForeignModuleKind(NodePointer node);
256256

257257
GenericTypeDecl *findTypeDecl(DeclContext *dc,
258258
Identifier name,

include/swift/AST/ASTMangler.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "swift/AST/Types.h"
1919
#include "swift/Basic/Mangler.h"
2020
#include "swift/Basic/TaggedUnion.h"
21-
#include "llvm/ADT/Optional.h"
21+
#include <optional>
2222

2323
namespace clang {
2424
class NamedDecl;
@@ -254,7 +254,7 @@ class ASTMangler : public Mangler {
254254
/// predefined in the Swift runtime for the given type signature.
255255
std::string mangleObjCAsyncCompletionHandlerImpl(
256256
CanSILFunctionType BlockType, CanType ResultType, CanGenericSignature Sig,
257-
llvm::Optional<bool> FlagParamIsZeroOnError, bool predefined);
257+
std::optional<bool> FlagParamIsZeroOnError, bool predefined);
258258

259259
/// Mangle the derivative function (JVP/VJP), or optionally its vtable entry
260260
/// thunk, for the given:
@@ -376,7 +376,7 @@ class ASTMangler : public Mangler {
376376
ClangImporterContext,
377377
};
378378

379-
static llvm::Optional<SpecialContext>
379+
static std::optional<SpecialContext>
380380
getSpecialManglingContext(const ValueDecl *decl, bool useObjCProtocolNames);
381381

382382
static bool isCXXCFOptionsDefinition(const ValueDecl *decl);

include/swift/AST/ASTPrinter.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class ASTPrinter {
131131
///
132132
/// Callers should use callPrintDeclPre().
133133
virtual void printDeclPre(const Decl *D,
134-
llvm::Optional<BracketOptions> Bracket) {}
134+
std::optional<BracketOptions> Bracket) {}
135135
/// Called before printing at the point which would be considered the location
136136
/// of the declaration (normally the name of the declaration).
137137
///
@@ -146,7 +146,7 @@ class ASTPrinter {
146146
///
147147
/// Callers should use callPrintDeclPost().
148148
virtual void printDeclPost(const Decl *D,
149-
llvm::Optional<BracketOptions> Bracket) {}
149+
std::optional<BracketOptions> Bracket) {}
150150

151151
/// Called before printing the result type of the declaration. Printer can
152152
/// replace \p TL to customize the input.
@@ -175,13 +175,13 @@ class ASTPrinter {
175175
/// Called before printing a synthesized extension.
176176
virtual void
177177
printSynthesizedExtensionPre(const ExtensionDecl *ED, TypeOrExtensionDecl NTD,
178-
llvm::Optional<BracketOptions> Bracket) {}
178+
std::optional<BracketOptions> Bracket) {}
179179

180180
/// Called after printing a synthesized extension.
181181
virtual void
182182
printSynthesizedExtensionPost(const ExtensionDecl *ED,
183183
TypeOrExtensionDecl TargetDecl,
184-
llvm::Optional<BracketOptions> Bracket) {}
184+
std::optional<BracketOptions> Bracket) {}
185185

186186
/// Called before printing a structured entity.
187187
///
@@ -303,11 +303,10 @@ class ASTPrinter {
303303
// MARK: Callback interface wrappers that perform ASTPrinter bookkeeping.
304304

305305
/// Make a callback to printDeclPre(), performing any necessary bookkeeping.
306-
void callPrintDeclPre(const Decl *D, llvm::Optional<BracketOptions> Bracket);
306+
void callPrintDeclPre(const Decl *D, std::optional<BracketOptions> Bracket);
307307

308308
/// Make a callback to printDeclPost(), performing any necessary bookkeeping.
309-
void callPrintDeclPost(const Decl *D,
310-
llvm::Optional<BracketOptions> Bracket) {
309+
void callPrintDeclPost(const Decl *D, std::optional<BracketOptions> Bracket) {
311310
printDeclPost(D, Bracket);
312311
}
313312

include/swift/AST/ASTScope.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
#include "swift/Basic/LLVM.h"
3838
#include "swift/Basic/NullablePtr.h"
3939
#include "swift/Basic/SourceManager.h"
40-
#include "llvm/ADT/Optional.h"
4140
#include "llvm/ADT/PointerIntPair.h"
4241
#include "llvm/ADT/STLExtras.h"
4342
#include "llvm/ADT/SmallVector.h"
43+
#include <optional>
4444

4545
/// In case there's a bug in the ASTScope lookup system, suggest that the user
4646
/// try disabling it.
@@ -164,7 +164,7 @@ class ASTScopeImpl : public ASTAllocated<ASTScopeImpl> {
164164
/// Child scopes, sorted by source range.
165165
Children storedChildren;
166166

167-
mutable llvm::Optional<SourceRange> cachedCharSourceRange;
167+
mutable std::optional<SourceRange> cachedCharSourceRange;
168168

169169
#pragma mark - constructor / destructor
170170
public:
@@ -995,11 +995,11 @@ class AbstractPatternEntryScope : public ASTScopeImpl {
995995

996996
class PatternEntryDeclScope final : public AbstractPatternEntryScope {
997997
const bool isLocalBinding;
998-
llvm::Optional<SourceLoc> endLoc;
998+
std::optional<SourceLoc> endLoc;
999999

10001000
public:
10011001
PatternEntryDeclScope(PatternBindingDecl *pbDecl, unsigned entryIndex,
1002-
bool isLocalBinding, llvm::Optional<SourceLoc> endLoc)
1002+
bool isLocalBinding, std::optional<SourceLoc> endLoc)
10031003
: AbstractPatternEntryScope(ScopeKind::PatternEntryDecl, pbDecl,
10041004
entryIndex),
10051005
isLocalBinding(isLocalBinding), endLoc(endLoc) {}

include/swift/AST/ASTTypeIDZone.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ SWIFT_TYPEID_NAMED(NamedPattern *, NamedPattern)
6161
SWIFT_TYPEID_NAMED(NominalTypeDecl *, NominalTypeDecl)
6262
SWIFT_TYPEID_NAMED(OpaqueTypeDecl *, OpaqueTypeDecl)
6363
SWIFT_TYPEID_NAMED(OperatorDecl *, OperatorDecl)
64-
SWIFT_TYPEID_NAMED(llvm::Optional<PropertyWrapperLValueness>,
64+
SWIFT_TYPEID_NAMED(std::optional<PropertyWrapperLValueness>,
6565
PropertyWrapperLValueness)
66-
SWIFT_TYPEID_NAMED(llvm::Optional<PropertyWrapperMutability>,
66+
SWIFT_TYPEID_NAMED(std::optional<PropertyWrapperMutability>,
6767
PropertyWrapperMutability)
6868
SWIFT_TYPEID_NAMED(ParamDecl *, ParamDecl)
6969
SWIFT_TYPEID_NAMED(PatternBindingEntry *, PatternBindingEntry)

include/swift/AST/ASTTypeIDs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include "swift/Basic/LLVM.h"
2121
#include "swift/Basic/TypeID.h"
22-
#include "llvm/ADT/Optional.h"
22+
#include <optional>
2323

2424
namespace swift {
2525

include/swift/AST/ASTWalker.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
#define SWIFT_AST_ASTWALKER_H
1515

1616
#include "swift/Basic/LLVM.h"
17-
#include "llvm/ADT/Optional.h"
1817
#include "llvm/ADT/None.h"
1918
#include "llvm/ADT/PointerUnion.h"
19+
#include <optional>
2020
#include <utility>
2121

2222
namespace swift {
@@ -48,17 +48,17 @@ enum class SemaReferenceKind : uint8_t {
4848

4949
struct ReferenceMetaData {
5050
SemaReferenceKind Kind;
51-
llvm::Optional<AccessKind> AccKind;
51+
std::optional<AccessKind> AccKind;
5252
bool isImplicit = false;
5353
bool isImplicitCtorType = false;
5454

5555
/// When non-none, this is a custom attribute reference.
56-
llvm::Optional<std::pair<const CustomAttr *, Decl *>> CustomAttrRef;
56+
std::optional<std::pair<const CustomAttr *, Decl *>> CustomAttrRef;
5757

58-
ReferenceMetaData(SemaReferenceKind Kind, llvm::Optional<AccessKind> AccKind,
58+
ReferenceMetaData(SemaReferenceKind Kind, std::optional<AccessKind> AccKind,
5959
bool isImplicit = false,
60-
llvm::Optional<std::pair<const CustomAttr *, Decl *>>
61-
customAttrRef = llvm::None)
60+
std::optional<std::pair<const CustomAttr *, Decl *>>
61+
customAttrRef = std::nullopt)
6262
: Kind(Kind), AccKind(AccKind), isImplicit(isImplicit),
6363
CustomAttrRef(customAttrRef) {}
6464
};
@@ -320,7 +320,7 @@ class ASTWalker {
320320
template <typename T>
321321
struct PreWalkResult {
322322
PreWalkAction Action;
323-
llvm::Optional<T> Value;
323+
std::optional<T> Value;
324324

325325
template <typename U,
326326
typename std::enable_if<std::is_convertible<U, T>::value>::type
@@ -354,7 +354,7 @@ class ASTWalker {
354354
Value(std::move(Result.Value)) {}
355355

356356
PreWalkResult(_Detail::StopWalkAction)
357-
: Action(PreWalkAction::Stop), Value(llvm::None) {}
357+
: Action(PreWalkAction::Stop), Value(std::nullopt) {}
358358
};
359359

360360
/// Do not construct directly, use \c Action::<action> instead.
@@ -365,7 +365,7 @@ class ASTWalker {
365365
template <typename T>
366366
struct PostWalkResult {
367367
PostWalkAction Action;
368-
llvm::Optional<T> Value;
368+
std::optional<T> Value;
369369

370370
template <typename U,
371371
typename std::enable_if<std::is_convertible<U, T>::value>::type
@@ -393,7 +393,7 @@ class ASTWalker {
393393
Value(std::move(Result.Value)) {}
394394

395395
PostWalkResult(_Detail::StopWalkAction)
396-
: Action(PostWalkAction::Stop), Value(llvm::None) {}
396+
: Action(PostWalkAction::Stop), Value(std::nullopt) {}
397397
};
398398

399399
/// This method is called when first visiting an expression

include/swift/AST/AbstractSourceFileDepGraphFactory.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
#include "swift/AST/Decl.h"
1717
#include "swift/AST/DeclContext.h"
1818
#include "swift/AST/FineGrainedDependencies.h"
19-
#include "llvm/ADT/Optional.h"
2019
#include "llvm/Support/VirtualOutputBackend.h"
20+
#include <optional>
2121

2222
namespace swift {
2323
class DiagnosticEngine;
@@ -91,26 +91,26 @@ class AbstractSourceFileDepGraphFactory {
9191
/// represent some \c Decl defined in this source file. \param key the
9292
/// interface key of the pair
9393
void addADefinedDecl(const DependencyKey &key,
94-
llvm::Optional<Fingerprint> fingerprint);
94+
std::optional<Fingerprint> fingerprint);
9595

9696
void addAUsedDecl(const DependencyKey &def, const DependencyKey &use);
9797

9898
/// Add an external dependency node to the graph. If the provided fingerprint
9999
/// is not \c None, it is added to the def key.
100100
void
101101
addAnExternalDependency(const DependencyKey &def, const DependencyKey &use,
102-
llvm::Optional<Fingerprint> dependencyFingerprint);
102+
std::optional<Fingerprint> dependencyFingerprint);
103103

104-
static llvm::Optional<Fingerprint>
104+
static std::optional<Fingerprint>
105105
getFingerprintIfAny(std::pair<const NominalTypeDecl *, const ValueDecl *>) {
106-
return llvm::None;
106+
return std::nullopt;
107107
}
108108

109-
static llvm::Optional<Fingerprint> getFingerprintIfAny(const Decl *d) {
109+
static std::optional<Fingerprint> getFingerprintIfAny(const Decl *d) {
110110
if (const auto *idc = dyn_cast<IterableDeclContext>(d)) {
111111
return idc->getBodyFingerprint();
112112
}
113-
return llvm::None;
113+
return std::nullopt;
114114
}
115115
};
116116

0 commit comments

Comments
 (0)