Skip to content

Migrate llvm::Optional to std::optional #71368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 5 additions & 7 deletions include/swift/ABI/ObjectFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#ifndef SWIFT_ABI_OBJECTFILE_H
#define SWIFT_ABI_OBJECTFILE_H

#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/ErrorHandling.h"
#include <optional>

namespace swift {

Expand All @@ -27,12 +27,10 @@ class SwiftObjectFileFormat {
public:
virtual ~SwiftObjectFileFormat() {}
virtual llvm::StringRef getSectionName(ReflectionSectionKind section) = 0;
virtual llvm::Optional<llvm::StringRef> getSegmentName() {
return {};
}
virtual std::optional<llvm::StringRef> getSegmentName() { return {}; }
/// Get the name of the segment in the symbol rich binary that may contain
/// Swift metadata.
virtual llvm::Optional<llvm::StringRef> getSymbolRichSegmentName() {
virtual std::optional<llvm::StringRef> getSymbolRichSegmentName() {
return {};
}
/// Predicate to identify if the named section can contain reflection data.
Expand All @@ -53,11 +51,11 @@ class SwiftObjectFileFormatMachO : public SwiftObjectFileFormat {
llvm_unreachable("Section type not found.");
}

llvm::Optional<llvm::StringRef> getSegmentName() override {
std::optional<llvm::StringRef> getSegmentName() override {
return {"__TEXT"};
}

llvm::Optional<llvm::StringRef> getSymbolRichSegmentName() override {
std::optional<llvm::StringRef> getSymbolRichSegmentName() override {
return {"__DWARF"};
}

Expand Down
3 changes: 1 addition & 2 deletions include/swift/ABI/TypeIdentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include "swift/Basic/LLVM.h"
#include "swift/Runtime/Config.h"
#include <llvm/ADT/Optional.h>
#include <llvm/ADT/StringRef.h>

namespace swift {
Expand Down Expand Up @@ -188,7 +187,7 @@ class ParsedTypeIdentity {
llvm::StringRef FullIdentity;

/// Any extended information that type might have.
llvm::Optional<TypeImportInfo<llvm::StringRef>> ImportInfo;
std::optional<TypeImportInfo<llvm::StringRef>> ImportInfo;

/// The ABI name of the type.
llvm::StringRef getABIName() const {
Expand Down
16 changes: 8 additions & 8 deletions include/swift/APIDigester/ModuleAnalyzerNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class SDKContext {
CheckerOptions Opts;
std::vector<BreakingAttributeInfo> BreakingAttrs;
// The common version of two ABI/API descriptors under comparison.
llvm::Optional<uint8_t> CommonVersion;
std::optional<uint8_t> CommonVersion;

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

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

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

class SDKNodeType: public SDKNode {
Expand Down Expand Up @@ -588,11 +588,11 @@ class SDKNodeDeclType: public SDKNodeDecl {
return InheritsConvenienceInitializers;
};

llvm::Optional<SDKNodeDeclType *> getSuperclass() const;
std::optional<SDKNodeDeclType *> getSuperclass() const;

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

protected:
SDKNodeDeclAbstractFunc(SDKNodeInitInfo Info, SDKNodeKind Kind);
Expand All @@ -695,7 +695,7 @@ class SDKNodeDeclAbstractFunc : public SDKNodeDecl {
bool isThrowing() const { return IsThrowing; }
bool reqNewWitnessTableEntry() const { return ReqNewWitnessTableEntry; }
uint8_t getSelfIndex() const { return SelfIndex.value(); }
llvm::Optional<uint8_t> getSelfIndexOptional() const { return SelfIndex; }
std::optional<uint8_t> getSelfIndexOptional() const { return SelfIndex; }
bool hasSelfIndex() const { return SelfIndex.has_value(); }
static bool classof(const SDKNode *N);
virtual void jsonize(json::Output &out) override;
Expand Down
8 changes: 4 additions & 4 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ enum class KnownFoundationEntity {

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

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

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

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

/// Instantiates "Impl.Converter" if needed, then translate Swift generic
Expand Down Expand Up @@ -1572,7 +1572,7 @@ class ASTContext final {
private:
friend Decl;

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

friend TypeBase;
Expand Down
10 changes: 5 additions & 5 deletions include/swift/AST/ASTDemangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#include "swift/Demangling/NamespaceMacros.h"
#include "swift/Demangling/TypeDecoder.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringRef.h"
#include <optional>

namespace swift {

Expand Down Expand Up @@ -151,7 +151,7 @@ class ASTBuilder {
Demangle::ImplParameterConvention calleeConvention,
ArrayRef<Demangle::ImplFunctionParam<Type>> params,
ArrayRef<Demangle::ImplFunctionResult<Type>> results,
llvm::Optional<Demangle::ImplFunctionResult<Type>> errorResult,
std::optional<Demangle::ImplFunctionResult<Type>> errorResult,
ImplFunctionTypeFlags flags);

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

Type createExistentialMetatypeType(
Type instance,
llvm::Optional<Demangle::ImplMetatypeRepresentation> repr = llvm::None);
std::optional<Demangle::ImplMetatypeRepresentation> repr = std::nullopt);

Type createMetatypeType(
Type instance,
llvm::Optional<Demangle::ImplMetatypeRepresentation> repr = llvm::None);
std::optional<Demangle::ImplMetatypeRepresentation> repr = std::nullopt);

void pushGenericParams(ArrayRef<std::pair<unsigned, unsigned>> parameterPacks);
void popGenericParams();
Expand Down Expand Up @@ -252,7 +252,7 @@ class ASTBuilder {
SynthesizedByImporter
};

llvm::Optional<ForeignModuleKind> getForeignModuleKind(NodePointer node);
std::optional<ForeignModuleKind> getForeignModuleKind(NodePointer node);

GenericTypeDecl *findTypeDecl(DeclContext *dc,
Identifier name,
Expand Down
6 changes: 3 additions & 3 deletions include/swift/AST/ASTMangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "swift/AST/Types.h"
#include "swift/Basic/Mangler.h"
#include "swift/Basic/TaggedUnion.h"
#include "llvm/ADT/Optional.h"
#include <optional>

namespace clang {
class NamedDecl;
Expand Down Expand Up @@ -255,7 +255,7 @@ class ASTMangler : public Mangler {
/// predefined in the Swift runtime for the given type signature.
std::string mangleObjCAsyncCompletionHandlerImpl(
CanSILFunctionType BlockType, CanType ResultType, CanGenericSignature Sig,
llvm::Optional<bool> FlagParamIsZeroOnError, bool predefined);
std::optional<bool> FlagParamIsZeroOnError, bool predefined);

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

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

static bool isCXXCFOptionsDefinition(const ValueDecl *decl);
Expand Down
13 changes: 6 additions & 7 deletions include/swift/AST/ASTPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class ASTPrinter {
///
/// Callers should use callPrintDeclPre().
virtual void printDeclPre(const Decl *D,
llvm::Optional<BracketOptions> Bracket) {}
std::optional<BracketOptions> Bracket) {}
/// Called before printing at the point which would be considered the location
/// of the declaration (normally the name of the declaration).
///
Expand All @@ -146,7 +146,7 @@ class ASTPrinter {
///
/// Callers should use callPrintDeclPost().
virtual void printDeclPost(const Decl *D,
llvm::Optional<BracketOptions> Bracket) {}
std::optional<BracketOptions> Bracket) {}

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

/// Called after printing a synthesized extension.
virtual void
printSynthesizedExtensionPost(const ExtensionDecl *ED,
TypeOrExtensionDecl TargetDecl,
llvm::Optional<BracketOptions> Bracket) {}
std::optional<BracketOptions> Bracket) {}

/// Called before printing a structured entity.
///
Expand Down Expand Up @@ -303,11 +303,10 @@ class ASTPrinter {
// MARK: Callback interface wrappers that perform ASTPrinter bookkeeping.

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

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

Expand Down
8 changes: 4 additions & 4 deletions include/swift/AST/ASTScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
#include "swift/Basic/LLVM.h"
#include "swift/Basic/NullablePtr.h"
#include "swift/Basic/SourceManager.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include <optional>

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

mutable llvm::Optional<SourceRange> cachedCharSourceRange;
mutable std::optional<SourceRange> cachedCharSourceRange;

#pragma mark - constructor / destructor
public:
Expand Down Expand Up @@ -995,11 +995,11 @@ class AbstractPatternEntryScope : public ASTScopeImpl {

class PatternEntryDeclScope final : public AbstractPatternEntryScope {
const bool isLocalBinding;
llvm::Optional<SourceLoc> endLoc;
std::optional<SourceLoc> endLoc;

public:
PatternEntryDeclScope(PatternBindingDecl *pbDecl, unsigned entryIndex,
bool isLocalBinding, llvm::Optional<SourceLoc> endLoc)
bool isLocalBinding, std::optional<SourceLoc> endLoc)
: AbstractPatternEntryScope(ScopeKind::PatternEntryDecl, pbDecl,
entryIndex),
isLocalBinding(isLocalBinding), endLoc(endLoc) {}
Expand Down
4 changes: 2 additions & 2 deletions include/swift/AST/ASTTypeIDZone.def
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ SWIFT_TYPEID_NAMED(NamedPattern *, NamedPattern)
SWIFT_TYPEID_NAMED(NominalTypeDecl *, NominalTypeDecl)
SWIFT_TYPEID_NAMED(OpaqueTypeDecl *, OpaqueTypeDecl)
SWIFT_TYPEID_NAMED(OperatorDecl *, OperatorDecl)
SWIFT_TYPEID_NAMED(llvm::Optional<PropertyWrapperLValueness>,
SWIFT_TYPEID_NAMED(std::optional<PropertyWrapperLValueness>,
PropertyWrapperLValueness)
SWIFT_TYPEID_NAMED(llvm::Optional<PropertyWrapperMutability>,
SWIFT_TYPEID_NAMED(std::optional<PropertyWrapperMutability>,
PropertyWrapperMutability)
SWIFT_TYPEID_NAMED(ParamDecl *, ParamDecl)
SWIFT_TYPEID_NAMED(PatternBindingEntry *, PatternBindingEntry)
Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/ASTTypeIDs.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "swift/Basic/LLVM.h"
#include "swift/Basic/TypeID.h"
#include "llvm/ADT/Optional.h"
#include <optional>

namespace swift {

Expand Down
Loading