Skip to content

Commit f3ff561

Browse files
committed
[NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the next rebranch. llvm::Optional was removed from upstream LLVM, so we need to migrate off rather soon. On Darwin, std::optional, and llvm::Optional have the same layout, so we don't need to be as concerned about ABI beyond the name mangling. `llvm::Optional` is only returned from one function in ``` getStandardTypeSubst(StringRef TypeName, bool allowConcurrencyManglings); ``` It's the return value, so it should not impact the mangling of the function, and the layout is the same as `std::optional`, so it should be mostly okay. This function doesn't appear to have users, and the ABI was already broken 2 years ago for concurrency and no one seemed to notice so this should be "okay". I'm doing the migration incrementally so that folks working on main can cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked away, then we can go through and finish the replacement. Since `None` and `Optional` show up in contexts where they are not `llvm::None` and `llvm::Optional`, I'm preparing the work now by going through and removing the namespace unwrapping and making the `llvm` namespace explicit. This should make it fairly mechanical to go through and replace llvm::Optional with std::optional, and llvm::None with std::nullopt. It's also a change that can be brought onto the release/5.9 with minimal impact. This should be an NFC change.
1 parent 50d2f4d commit f3ff561

File tree

684 files changed

+5854
-5806
lines changed

Some content is hidden

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

684 files changed

+5854
-5806
lines changed

include/swift/APIDigester/ModuleAnalyzerNodes.h

Lines changed: 7 additions & 7 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-
Optional<uint8_t> CommonVersion;
182+
llvm::Optional<uint8_t> CommonVersion;
183183
public:
184184
// Define the set of known identifiers.
185185
#define IDENTIFIER_WITH_NAME(Name, IdStr) StringRef Id_##Name = IdStr;
@@ -231,7 +231,7 @@ class SDKContext {
231231
const CheckerOptions &getOpts() const { return Opts; }
232232
bool shouldIgnore(Decl *D, const Decl* Parent = nullptr) const;
233233
ArrayRef<BreakingAttributeInfo> getBreakingAttributeInfo() const { return BreakingAttrs; }
234-
Optional<uint8_t> getFixedBinaryOrder(ValueDecl *VD) const;
234+
llvm::Optional<uint8_t> getFixedBinaryOrder(ValueDecl *VD) const;
235235

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

@@ -586,11 +586,11 @@ class SDKNodeDeclType: public SDKNodeDecl {
586586
return InheritsConvenienceInitializers;
587587
};
588588

589-
Optional<SDKNodeDeclType*> getSuperclass() const;
589+
llvm::Optional<SDKNodeDeclType*> getSuperclass() const;
590590

591591
/// Finding the node through all children, including the inherited ones,
592592
/// whose printed name matches with the given name.
593-
Optional<SDKNodeDecl*> lookupChildByPrintedName(StringRef Name) const;
593+
llvm::Optional<SDKNodeDecl*> lookupChildByPrintedName(StringRef Name) const;
594594
SDKNodeType *getRawValueType() const;
595595
bool isConformingTo(KnownProtocolKind Kind) const;
596596
void jsonize(json::Output &out) override;
@@ -684,7 +684,7 @@ class SDKNodeDeclMacro : public SDKNodeDecl {
684684
class SDKNodeDeclAbstractFunc : public SDKNodeDecl {
685685
bool IsThrowing;
686686
bool ReqNewWitnessTableEntry;
687-
Optional<uint8_t> SelfIndex;
687+
llvm::Optional<uint8_t> SelfIndex;
688688

689689
protected:
690690
SDKNodeDeclAbstractFunc(SDKNodeInitInfo Info, SDKNodeKind Kind);
@@ -693,7 +693,7 @@ class SDKNodeDeclAbstractFunc : public SDKNodeDecl {
693693
bool isThrowing() const { return IsThrowing; }
694694
bool reqNewWitnessTableEntry() const { return ReqNewWitnessTableEntry; }
695695
uint8_t getSelfIndex() const { return SelfIndex.value(); }
696-
Optional<uint8_t> getSelfIndexOptional() const { return SelfIndex; }
696+
llvm::Optional<uint8_t> getSelfIndexOptional() const { return SelfIndex; }
697697
bool hasSelfIndex() const { return SelfIndex.has_value(); }
698698
static bool classof(const SDKNode *N);
699699
virtual void jsonize(json::Output &out) override;

include/swift/AST/ASTContext.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ enum class KnownFoundationEntity {
168168

169169
/// Retrieve the Foundation entity kind for the given Objective-C
170170
/// entity name.
171-
Optional<KnownFoundationEntity> getKnownFoundationEntity(StringRef name);
171+
llvm::Optional<KnownFoundationEntity> getKnownFoundationEntity(StringRef name);
172172

173173
/// Retrieve the Swift name for the given Foundation entity, where
174174
/// "NS" prefix stripping will apply under omit-needless-words.
@@ -343,7 +343,7 @@ class ASTContext final {
343343
unsigned NumTypoCorrections = 0;
344344

345345
/// Cached mapping from types to their associated tangent spaces.
346-
llvm::DenseMap<Type, Optional<TangentSpace>> AutoDiffTangentSpaces;
346+
llvm::DenseMap<Type, llvm::Optional<TangentSpace>> AutoDiffTangentSpaces;
347347

348348
/// A cache of derivative function types per configuration.
349349
llvm::DenseMap<SILAutoDiffDerivativeFunctionKey, CanSILFunctionType>
@@ -804,7 +804,7 @@ class ASTContext final {
804804
/// SIL analog of \c ASTContext::getClangFunctionType .
805805
const clang::Type *
806806
getCanonicalClangFunctionType(
807-
ArrayRef<SILParameterInfo> params, Optional<SILResultInfo> result,
807+
ArrayRef<SILParameterInfo> params, llvm::Optional<SILResultInfo> result,
808808
SILFunctionType::Representation trueRep);
809809

810810
/// Instantiates "Impl.Converter" if needed, then translate Swift generic
@@ -1031,22 +1031,22 @@ class ASTContext final {
10311031

10321032
/// Retrieve the module dependencies for the module with the given name.
10331033
///
1034-
Optional<const ModuleDependencyInfo*> getModuleDependencies(
1034+
llvm::Optional<const ModuleDependencyInfo*> getModuleDependencies(
10351035
StringRef moduleName,
10361036
ModuleDependenciesCache &cache,
10371037
InterfaceSubContextDelegate &delegate,
10381038
bool optionalDependencyLookup = false,
10391039
bool isTestableImport = false,
1040-
llvm::Optional<std::pair<std::string, swift::ModuleDependencyKind>> dependencyOf = None);
1040+
llvm::Optional<std::pair<std::string, swift::ModuleDependencyKind>> dependencyOf = llvm::None);
10411041

10421042
/// Retrieve the module dependencies for the Clang module with the given name.
1043-
Optional<const ModuleDependencyInfo*> getClangModuleDependencies(
1043+
llvm::Optional<const ModuleDependencyInfo*> getClangModuleDependencies(
10441044
StringRef moduleName,
10451045
ModuleDependenciesCache &cache,
10461046
InterfaceSubContextDelegate &delegate);
10471047

10481048
/// Retrieve the module dependencies for the Swift module with the given name.
1049-
Optional<const ModuleDependencyInfo*> getSwiftModuleDependencies(
1049+
llvm::Optional<const ModuleDependencyInfo*> getSwiftModuleDependencies(
10501050
StringRef moduleName,
10511051
ModuleDependenciesCache &cache,
10521052
InterfaceSubContextDelegate &delegate);
@@ -1519,7 +1519,7 @@ class ASTContext final {
15191519
private:
15201520
friend Decl;
15211521

1522-
Optional<ExternalSourceLocs *> getExternalSourceLocs(const Decl *D);
1522+
llvm::Optional<ExternalSourceLocs *> getExternalSourceLocs(const Decl *D);
15231523
void setExternalSourceLocs(const Decl *D, ExternalSourceLocs *Locs);
15241524

15251525
friend TypeBase;

include/swift/AST/ASTDemangler.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include "llvm/ADT/ArrayRef.h"
2626
#include "llvm/ADT/StringRef.h"
27+
#include "llvm/ADT/Optional.h"
2728
#include "swift/AST/Types.h"
2829
#include "swift/Demangling/Demangler.h"
2930
#include "swift/Demangling/NamespaceMacros.h"
@@ -126,7 +127,7 @@ class ASTBuilder {
126127
Demangle::ImplParameterConvention calleeConvention,
127128
ArrayRef<Demangle::ImplFunctionParam<Type>> params,
128129
ArrayRef<Demangle::ImplFunctionResult<Type>> results,
129-
Optional<Demangle::ImplFunctionResult<Type>> errorResult,
130+
llvm::Optional<Demangle::ImplFunctionResult<Type>> errorResult,
130131
ImplFunctionTypeFlags flags);
131132

132133
Type createProtocolCompositionType(ArrayRef<ProtocolDecl *> protocols,
@@ -143,10 +144,10 @@ class ASTBuilder {
143144
ArrayRef<Type> genArgs);
144145

145146
Type createExistentialMetatypeType(Type instance,
146-
Optional<Demangle::ImplMetatypeRepresentation> repr=None);
147+
llvm::Optional<Demangle::ImplMetatypeRepresentation> repr=llvm::None);
147148

148149
Type createMetatypeType(Type instance,
149-
Optional<Demangle::ImplMetatypeRepresentation> repr=None);
150+
llvm::Optional<Demangle::ImplMetatypeRepresentation> repr=llvm::None);
150151

151152
Type createGenericTypeParameterType(unsigned depth, unsigned index);
152153

@@ -222,7 +223,7 @@ class ASTBuilder {
222223
SynthesizedByImporter
223224
};
224225

225-
Optional<ForeignModuleKind>
226+
llvm::Optional<ForeignModuleKind>
226227
getForeignModuleKind(NodePointer node);
227228

228229
GenericTypeDecl *findTypeDecl(DeclContext *dc,

include/swift/AST/ASTMangler.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "swift/AST/Decl.h"
1919
#include "swift/AST/FreestandingMacroExpansion.h"
2020
#include "swift/Basic/TaggedUnion.h"
21+
#include "llvm/ADT/Optional.h"
2122

2223
namespace clang {
2324
class NamedDecl;
@@ -254,7 +255,7 @@ class ASTMangler : public Mangler {
254255
std::string mangleObjCAsyncCompletionHandlerImpl(CanSILFunctionType BlockType,
255256
CanType ResultType,
256257
CanGenericSignature Sig,
257-
Optional<bool> FlagParamIsZeroOnError,
258+
llvm::Optional<bool> FlagParamIsZeroOnError,
258259
bool predefined);
259260

260261
/// Mangle the derivative function (JVP/VJP), or optionally its vtable entry
@@ -381,7 +382,7 @@ class ASTMangler : public Mangler {
381382
ClangImporterContext,
382383
};
383384

384-
static Optional<SpecialContext>
385+
static llvm::Optional<SpecialContext>
385386
getSpecialManglingContext(const ValueDecl *decl, bool useObjCProtocolNames);
386387

387388
static bool isCXXCFOptionsDefinition(const ValueDecl *decl);

include/swift/AST/ASTPrinter.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class ASTPrinter {
133133
/// Called before printing of a declaration.
134134
///
135135
/// Callers should use callPrintDeclPre().
136-
virtual void printDeclPre(const Decl *D, Optional<BracketOptions> Bracket) {}
136+
virtual void printDeclPre(const Decl *D, llvm::Optional<BracketOptions> Bracket) {}
137137
/// Called before printing at the point which would be considered the location
138138
/// of the declaration (normally the name of the declaration).
139139
///
@@ -147,7 +147,7 @@ class ASTPrinter {
147147
/// Called after finishing printing of a declaration.
148148
///
149149
/// Callers should use callPrintDeclPost().
150-
virtual void printDeclPost(const Decl *D, Optional<BracketOptions> Bracket) {}
150+
virtual void printDeclPost(const Decl *D, llvm::Optional<BracketOptions> Bracket) {}
151151

152152
/// Called before printing the result type of the declaration. Printer can
153153
/// replace \p TL to customize the input.
@@ -176,12 +176,12 @@ class ASTPrinter {
176176
/// Called before printing a synthesized extension.
177177
virtual void printSynthesizedExtensionPre(const ExtensionDecl *ED,
178178
TypeOrExtensionDecl NTD,
179-
Optional<BracketOptions> Bracket) {}
179+
llvm::Optional<BracketOptions> Bracket) {}
180180

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

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

306306
/// Make a callback to printDeclPre(), performing any necessary bookkeeping.
307-
void callPrintDeclPre(const Decl *D, Optional<BracketOptions> Bracket);
307+
void callPrintDeclPre(const Decl *D, llvm::Optional<BracketOptions> Bracket);
308308

309309
/// Make a callback to printDeclPost(), performing any necessary bookkeeping.
310-
void callPrintDeclPost(const Decl *D, Optional<BracketOptions> Bracket) {
310+
void callPrintDeclPost(const Decl *D, llvm::Optional<BracketOptions> Bracket) {
311311
printDeclPost(D, Bracket);
312312
}
313313

include/swift/AST/ASTScope.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "llvm/ADT/PointerIntPair.h"
4040
#include "llvm/ADT/STLExtras.h"
4141
#include "llvm/ADT/SmallVector.h"
42+
#include "llvm/ADT/Optional.h"
4243

4344
/// In case there's a bug in the ASTScope lookup system, suggest that the user
4445
/// try disabling it.
@@ -152,7 +153,7 @@ class ASTScopeImpl : public ASTAllocated<ASTScopeImpl> {
152153
/// Child scopes, sorted by source range.
153154
Children storedChildren;
154155

155-
mutable Optional<CharSourceRange> cachedCharSourceRange;
156+
mutable llvm::Optional<CharSourceRange> cachedCharSourceRange;
156157

157158
#pragma mark - constructor / destructor
158159
public:
@@ -922,11 +923,11 @@ class AbstractPatternEntryScope : public ASTScopeImpl {
922923

923924
class PatternEntryDeclScope final : public AbstractPatternEntryScope {
924925
const bool isLocalBinding;
925-
Optional<SourceLoc> endLoc;
926+
llvm::Optional<SourceLoc> endLoc;
926927

927928
public:
928929
PatternEntryDeclScope(PatternBindingDecl *pbDecl, unsigned entryIndex,
929-
bool isLocalBinding, Optional<SourceLoc> endLoc)
930+
bool isLocalBinding, llvm::Optional<SourceLoc> endLoc)
930931
: AbstractPatternEntryScope(pbDecl, entryIndex),
931932
isLocalBinding(isLocalBinding), endLoc(endLoc) {}
932933
virtual ~PatternEntryDeclScope() {}

include/swift/AST/ASTTypeIDZone.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ SWIFT_TYPEID_NAMED(NamedPattern *, NamedPattern)
6262
SWIFT_TYPEID_NAMED(NominalTypeDecl *, NominalTypeDecl)
6363
SWIFT_TYPEID_NAMED(OpaqueTypeDecl *, OpaqueTypeDecl)
6464
SWIFT_TYPEID_NAMED(OperatorDecl *, OperatorDecl)
65-
SWIFT_TYPEID_NAMED(Optional<PropertyWrapperLValueness>,
65+
SWIFT_TYPEID_NAMED(llvm::Optional<PropertyWrapperLValueness>,
6666
PropertyWrapperLValueness)
67-
SWIFT_TYPEID_NAMED(Optional<PropertyWrapperMutability>,
67+
SWIFT_TYPEID_NAMED(llvm::Optional<PropertyWrapperMutability>,
6868
PropertyWrapperMutability)
6969
SWIFT_TYPEID_NAMED(ParamDecl *, ParamDecl)
7070
SWIFT_TYPEID_NAMED(PatternBindingEntry *, PatternBindingEntry)

include/swift/AST/ASTTypeIDs.h

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

2020
#include "swift/Basic/LLVM.h"
2121
#include "swift/Basic/TypeID.h"
22+
#include "llvm/ADT/Optional.h"
2223

2324
namespace swift {
2425

include/swift/AST/ASTWalker.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ struct ReferenceMetaData {
5151
bool isImplicitCtorType = false;
5252

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

5656
ReferenceMetaData(
5757
SemaReferenceKind Kind, llvm::Optional<AccessKind> AccKind,
5858
bool isImplicit = false,
59-
Optional<std::pair<const CustomAttr *, Decl *>> customAttrRef
60-
= None
59+
llvm::Optional<std::pair<const CustomAttr *, Decl *>> customAttrRef
60+
= llvm::None
6161
) : Kind(Kind), AccKind(AccKind), isImplicit(isImplicit),
6262
CustomAttrRef(customAttrRef) {}
6363
};
@@ -319,7 +319,7 @@ class ASTWalker {
319319
template <typename T>
320320
struct PreWalkResult {
321321
PreWalkAction Action;
322-
Optional<T> Value;
322+
llvm::Optional<T> Value;
323323

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

355355
PreWalkResult(_Detail::StopWalkAction)
356-
: Action(PreWalkAction::Stop), Value(None) {}
356+
: Action(PreWalkAction::Stop), Value(llvm::None) {}
357357
};
358358

359359
/// Do not construct directly, use \c Action::<action> instead.
@@ -364,7 +364,7 @@ class ASTWalker {
364364
template <typename T>
365365
struct PostWalkResult {
366366
PostWalkAction Action;
367-
Optional<T> Value;
367+
llvm::Optional<T> Value;
368368

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

394394
PostWalkResult(_Detail::StopWalkAction)
395-
: Action(PostWalkAction::Stop), Value(None) {}
395+
: Action(PostWalkAction::Stop), Value(llvm::None) {}
396396
};
397397

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

include/swift/AST/AbstractSourceFileDepGraphFactory.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "swift/AST/DeclContext.h"
1818
#include "swift/AST/FineGrainedDependencies.h"
1919
#include "llvm/Support/VirtualOutputBackend.h"
20+
#include "llvm/ADT/Optional.h"
2021

2122
namespace swift {
2223
class DiagnosticEngine;
@@ -90,26 +91,26 @@ class AbstractSourceFileDepGraphFactory {
9091
/// represent some \c Decl defined in this source file. \param key the
9192
/// interface key of the pair
9293
void addADefinedDecl(const DependencyKey &key,
93-
Optional<Fingerprint> fingerprint);
94+
llvm::Optional<Fingerprint> fingerprint);
9495

9596
void addAUsedDecl(const DependencyKey &def, const DependencyKey &use);
9697

9798
/// Add an external dependency node to the graph. If the provided fingerprint
9899
/// is not \c None, it is added to the def key.
99100
void addAnExternalDependency(const DependencyKey &def,
100101
const DependencyKey &use,
101-
Optional<Fingerprint> dependencyFingerprint);
102+
llvm::Optional<Fingerprint> dependencyFingerprint);
102103

103-
static Optional<Fingerprint>
104+
static llvm::Optional<Fingerprint>
104105
getFingerprintIfAny(std::pair<const NominalTypeDecl *, const ValueDecl *>) {
105-
return None;
106+
return llvm::None;
106107
}
107108

108-
static Optional<Fingerprint> getFingerprintIfAny(const Decl *d) {
109+
static llvm::Optional<Fingerprint> getFingerprintIfAny(const Decl *d) {
109110
if (const auto *idc = dyn_cast<IterableDeclContext>(d)) {
110111
return idc->getBodyFingerprint();
111112
}
112-
return None;
113+
return llvm::None;
113114
}
114115
};
115116

0 commit comments

Comments
 (0)