Skip to content

Commit ef8825b

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.
1 parent d3d4bd2 commit ef8825b

File tree

810 files changed

+8060
-8743
lines changed

Some content is hidden

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

810 files changed

+8060
-8743
lines changed

include/swift/ABI/ObjectFile.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
#ifndef SWIFT_ABI_OBJECTFILE_H
88
#define SWIFT_ABI_OBJECTFILE_H
99

10-
#include "llvm/ADT/Optional.h"
1110
#include "llvm/ADT/StringRef.h"
1211
#include "llvm/Support/ErrorHandling.h"
12+
#include <optional>
1313

1414
namespace swift {
1515

@@ -27,12 +27,10 @@ class SwiftObjectFileFormat {
2727
public:
2828
virtual ~SwiftObjectFileFormat() {}
2929
virtual llvm::StringRef getSectionName(ReflectionSectionKind section) = 0;
30-
virtual llvm::Optional<llvm::StringRef> getSegmentName() {
31-
return {};
32-
}
30+
virtual std::optional<llvm::StringRef> getSegmentName() { return {}; }
3331
/// Get the name of the segment in the symbol rich binary that may contain
3432
/// Swift metadata.
35-
virtual llvm::Optional<llvm::StringRef> getSymbolRichSegmentName() {
33+
virtual std::optional<llvm::StringRef> getSymbolRichSegmentName() {
3634
return {};
3735
}
3836
/// Predicate to identify if the named section can contain reflection data.
@@ -53,11 +51,11 @@ class SwiftObjectFileFormatMachO : public SwiftObjectFileFormat {
5351
llvm_unreachable("Section type not found.");
5452
}
5553

56-
llvm::Optional<llvm::StringRef> getSegmentName() override {
54+
std::optional<llvm::StringRef> getSegmentName() override {
5755
return {"__TEXT"};
5856
}
5957

60-
llvm::Optional<llvm::StringRef> getSymbolRichSegmentName() override {
58+
std::optional<llvm::StringRef> getSymbolRichSegmentName() override {
6159
return {"__DWARF"};
6260
}
6361

include/swift/ABI/TypeIdentity.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
#include "swift/Basic/LLVM.h"
2222
#include "swift/Runtime/Config.h"
23-
#include <llvm/ADT/Optional.h>
2423
#include <llvm/ADT/StringRef.h>
2524

2625
namespace swift {
@@ -188,7 +187,7 @@ class ParsedTypeIdentity {
188187
llvm::StringRef FullIdentity;
189188

190189
/// Any extended information that type might have.
191-
llvm::Optional<TypeImportInfo<llvm::StringRef>> ImportInfo;
190+
std::optional<TypeImportInfo<llvm::StringRef>> ImportInfo;
192191

193192
/// The ABI name of the type.
194193
llvm::StringRef getABIName() const {

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
@@ -172,7 +172,7 @@ enum class KnownFoundationEntity {
172172

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

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

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

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

851851
/// Instantiates "Impl.Converter" if needed, then translate Swift generic
@@ -1572,7 +1572,7 @@ class ASTContext final {
15721572
private:
15731573
friend Decl;
15741574

1575-
llvm::Optional<ExternalSourceLocs *> getExternalSourceLocs(const Decl *D);
1575+
std::optional<ExternalSourceLocs *> getExternalSourceLocs(const Decl *D);
15761576
void setExternalSourceLocs(const Decl *D, ExternalSourceLocs *Locs);
15771577

15781578
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;
@@ -255,7 +255,7 @@ class ASTMangler : public Mangler {
255255
/// predefined in the Swift runtime for the given type signature.
256256
std::string mangleObjCAsyncCompletionHandlerImpl(
257257
CanSILFunctionType BlockType, CanType ResultType, CanGenericSignature Sig,
258-
llvm::Optional<bool> FlagParamIsZeroOnError, bool predefined);
258+
std::optional<bool> FlagParamIsZeroOnError, bool predefined);
259259

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

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

383383
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

0 commit comments

Comments
 (0)