From 34bcadc38c2240807cd079fd03b93fc96cf64c84 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Wed, 23 Nov 2022 14:16:04 -0800 Subject: [PATCH] Use std::nullopt_t instead of NoneType (NFC) This patch replaces those occurrences of NoneType that would trigger an error if the definition of NoneType were missing in None.h. To keep this patch focused, I am deliberately not replacing None with std::nullopt in this patch or updating comments. They will be addressed in subsequent patches. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716 Differential Revision: https://reviews.llvm.org/D138539 --- bolt/lib/Profile/DataAggregator.cpp | 2 +- bolt/lib/Profile/YAMLProfileWriter.cpp | 2 +- .../utils/RenamerClangTidyCheck.cpp | 2 +- .../clangd/support/ThreadsafeFS.h | 2 +- .../Analysis/Analyses/PostOrderCFGView.h | 2 +- clang/include/clang/Basic/DirectoryEntry.h | 5 +-- clang/include/clang/Basic/FileEntry.h | 4 +-- clang/include/clang/Sema/Template.h | 2 +- clang/lib/AST/ExprConstant.cpp | 4 +-- clang/lib/Tooling/Transformer/Parsing.cpp | 2 +- lldb/include/lldb/Utility/Timeout.h | 2 +- .../TypeSystem/Clang/TypeSystemClang.cpp | 2 +- .../TypeSystem/Clang/TypeSystemClang.h | 2 +- llvm/include/llvm/ADT/ArrayRef.h | 4 +-- llvm/include/llvm/ADT/Optional.h | 32 +++++++++++-------- llvm/include/llvm/ADT/StringMapEntry.h | 7 ++-- llvm/include/llvm/ADT/StringSet.h | 4 +-- llvm/include/llvm/FuzzMutate/OpDescriptor.h | 2 +- llvm/include/llvm/Support/SMLoc.h | 2 +- llvm/lib/CodeGen/MIRParser/MILexer.cpp | 2 +- llvm/lib/Support/Optional.cpp | 2 +- mlir/include/mlir/IR/OpDefinition.h | 2 +- mlir/include/mlir/IR/OperationSupport.h | 4 +-- mlir/include/mlir/Support/Timing.h | 2 +- mlir/lib/Support/Timing.cpp | 2 +- 25 files changed, 52 insertions(+), 46 deletions(-) diff --git a/bolt/lib/Profile/DataAggregator.cpp b/bolt/lib/Profile/DataAggregator.cpp index 1cf2e72fba8d..3befa8bac2d9 100644 --- a/bolt/lib/Profile/DataAggregator.cpp +++ b/bolt/lib/Profile/DataAggregator.cpp @@ -2233,7 +2233,7 @@ DataAggregator::writeAggregatedFile(StringRef OutputFilename) const { OutFile << "boltedcollection\n"; if (opts::BasicAggregation) { OutFile << "no_lbr"; - for (const StringMapEntry &Entry : EventNames) + for (const StringMapEntry &Entry : EventNames) OutFile << " " << Entry.getKey(); OutFile << "\n"; diff --git a/bolt/lib/Profile/YAMLProfileWriter.cpp b/bolt/lib/Profile/YAMLProfileWriter.cpp index 03f3ac36f373..84c060fef136 100644 --- a/bolt/lib/Profile/YAMLProfileWriter.cpp +++ b/bolt/lib/Profile/YAMLProfileWriter.cpp @@ -161,7 +161,7 @@ std::error_code YAMLProfileWriter::writeProfile(const RewriteInstance &RI) { StringSet<> EventNames = RI.getProfileReader()->getEventNames(); if (!EventNames.empty()) { std::string Sep; - for (const StringMapEntry &EventEntry : EventNames) { + for (const StringMapEntry &EventEntry : EventNames) { BP.Header.EventNames += Sep + EventEntry.first().str(); Sep = ","; } diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp index 73b47dca2093..ba1f4d4ebe2e 100644 --- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp +++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp @@ -214,7 +214,7 @@ class NameLookup { public: explicit NameLookup(const NamedDecl *ND) : Data(ND, false) {} - explicit NameLookup(llvm::NoneType) : Data(nullptr, true) {} + explicit NameLookup(std::nullopt_t) : Data(nullptr, true) {} explicit NameLookup(std::nullptr_t) : Data(nullptr, false) {} NameLookup() : NameLookup(nullptr) {} diff --git a/clang-tools-extra/clangd/support/ThreadsafeFS.h b/clang-tools-extra/clangd/support/ThreadsafeFS.h index b518c03e3696..7268ac742ce3 100644 --- a/clang-tools-extra/clangd/support/ThreadsafeFS.h +++ b/clang-tools-extra/clangd/support/ThreadsafeFS.h @@ -30,7 +30,7 @@ public: /// Obtain a vfs::FileSystem with an arbitrary initial working directory. llvm::IntrusiveRefCntPtr - view(llvm::NoneType CWD) const { + view(std::nullopt_t CWD) const { return viewImpl(); } diff --git a/clang/include/clang/Analysis/Analyses/PostOrderCFGView.h b/clang/include/clang/Analysis/Analyses/PostOrderCFGView.h index 100029894560..0b306d14be4d 100644 --- a/clang/include/clang/Analysis/Analyses/PostOrderCFGView.h +++ b/clang/include/clang/Analysis/Analyses/PostOrderCFGView.h @@ -48,7 +48,7 @@ public: /// Set the bit associated with a particular CFGBlock. /// This is the important method for the SetType template parameter. - std::pair insert(const CFGBlock *Block) { + std::pair insert(const CFGBlock *Block) { // Note that insert() is called by po_iterator, which doesn't check to // make sure that Block is non-null. Moreover, the CFGBlock iterator will // occasionally hand out null pointers for pruned edges, so we catch those diff --git a/clang/include/clang/Basic/DirectoryEntry.h b/clang/include/clang/Basic/DirectoryEntry.h index 9ddeb65ef194..46121e491f4f 100644 --- a/clang/include/clang/Basic/DirectoryEntry.h +++ b/clang/include/clang/Basic/DirectoryEntry.h @@ -264,13 +264,14 @@ public: OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr & operator=(const OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &) = default; - OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(llvm::NoneType) {} + OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(std::nullopt_t) {} OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(DirectoryEntryRef Ref) : Optional(Ref) {} OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(Optional MaybeRef) : Optional(MaybeRef) {} - OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &operator=(llvm::NoneType) { + OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr & + operator=(std::nullopt_t) { Optional::operator=(None); return *this; } diff --git a/clang/include/clang/Basic/FileEntry.h b/clang/include/clang/Basic/FileEntry.h index 4f2d6436b333..b001422a8440 100644 --- a/clang/include/clang/Basic/FileEntry.h +++ b/clang/include/clang/Basic/FileEntry.h @@ -308,13 +308,13 @@ public: OptionalFileEntryRefDegradesToFileEntryPtr & operator=(const OptionalFileEntryRefDegradesToFileEntryPtr &) = default; - OptionalFileEntryRefDegradesToFileEntryPtr(llvm::NoneType) {} + OptionalFileEntryRefDegradesToFileEntryPtr(std::nullopt_t) {} OptionalFileEntryRefDegradesToFileEntryPtr(FileEntryRef Ref) : Optional(Ref) {} OptionalFileEntryRefDegradesToFileEntryPtr(Optional MaybeRef) : Optional(MaybeRef) {} - OptionalFileEntryRefDegradesToFileEntryPtr &operator=(llvm::NoneType) { + OptionalFileEntryRefDegradesToFileEntryPtr &operator=(std::nullopt_t) { Optional::operator=(None); return *this; } diff --git a/clang/include/clang/Sema/Template.h b/clang/include/clang/Sema/Template.h index 7afe0d2afcaf..0899069fea51 100644 --- a/clang/include/clang/Sema/Template.h +++ b/clang/include/clang/Sema/Template.h @@ -222,7 +222,7 @@ enum class TemplateSubstitutionKind : char { TemplateArgumentLists.push_back({{}, Args}); } - void addOuterTemplateArguments(llvm::NoneType) { + void addOuterTemplateArguments(std::nullopt_t) { assert(!NumRetainedOuterLevels && "substituted args outside retained args?"); TemplateArgumentLists.push_back({}); diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index b5281a660bcf..df8b420e55a6 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -7044,14 +7044,14 @@ class BufferToAPValueConverter { // Emit an unsupported bit_cast type error. Sema refuses to build a bit_cast // with an invalid type, so anything left is a deficiency on our part (FIXME). // Ideally this will be unreachable. - llvm::NoneType unsupportedType(QualType Ty) { + std::nullopt_t unsupportedType(QualType Ty) { Info.FFDiag(BCE->getBeginLoc(), diag::note_constexpr_bit_cast_unsupported_type) << Ty; return None; } - llvm::NoneType unrepresentableValue(QualType Ty, const APSInt &Val) { + std::nullopt_t unrepresentableValue(QualType Ty, const APSInt &Val) { Info.FFDiag(BCE->getBeginLoc(), diag::note_constexpr_bit_cast_unrepresentable_value) << Ty << toString(Val, /*Radix=*/10); diff --git a/clang/lib/Tooling/Transformer/Parsing.cpp b/clang/lib/Tooling/Transformer/Parsing.cpp index 4f41e2e90def..bf0a29db7bec 100644 --- a/clang/lib/Tooling/Transformer/Parsing.cpp +++ b/clang/lib/Tooling/Transformer/Parsing.cpp @@ -152,7 +152,7 @@ static StringRef consumeWhitespace(StringRef S) { // Parses a single expected character \c c from \c State, skipping preceding // whitespace. Error if the expected character isn't found. -static ExpectedProgress parseChar(char c, ParseState State) { +static ExpectedProgress parseChar(char c, ParseState State) { State.Input = consumeWhitespace(State.Input); if (State.Input.empty() || State.Input.front() != c) return makeParseError(State, diff --git a/lldb/include/lldb/Utility/Timeout.h b/lldb/include/lldb/Utility/Timeout.h index 29f8c1bbee38..f656138eb44b 100644 --- a/lldb/include/lldb/Utility/Timeout.h +++ b/lldb/include/lldb/Utility/Timeout.h @@ -36,7 +36,7 @@ private: using Base = llvm::Optional>; public: - Timeout(llvm::NoneType none) : Base(none) {} + Timeout(std::nullopt_t none) : Base(none) {} template ::type> diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp index 510d84e37ba1..2d541baf2aa7 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -9890,7 +9890,7 @@ public: } // namespace char ScratchTypeSystemClang::ID; -const llvm::NoneType ScratchTypeSystemClang::DefaultAST = llvm::None; +const std::nullopt_t ScratchTypeSystemClang::DefaultAST = llvm::None; ScratchTypeSystemClang::ScratchTypeSystemClang(Target &target, llvm::Triple triple) diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h index dd57fa69bbde..e656563b89fa 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h @@ -1157,7 +1157,7 @@ public: /// Alias for requesting the default scratch TypeSystemClang in GetForTarget. // This isn't constexpr as gtest/llvm::Optional comparison logic is trying // to get the address of this for pretty-printing. - static const llvm::NoneType DefaultAST; + static const std::nullopt_t DefaultAST; /// Infers the appropriate sub-AST from Clang's LangOptions. static llvm::Optional diff --git a/llvm/include/llvm/ADT/ArrayRef.h b/llvm/include/llvm/ADT/ArrayRef.h index acfa324e6b10..773c7a85f03c 100644 --- a/llvm/include/llvm/ADT/ArrayRef.h +++ b/llvm/include/llvm/ADT/ArrayRef.h @@ -68,7 +68,7 @@ namespace llvm { /*implicit*/ ArrayRef() = default; /// Construct an empty ArrayRef from None. - /*implicit*/ ArrayRef(NoneType) {} + /*implicit*/ ArrayRef(std::nullopt_t) {} /// Construct an ArrayRef from a single element. /*implicit*/ ArrayRef(const T &OneElt) @@ -321,7 +321,7 @@ namespace llvm { /*implicit*/ MutableArrayRef() = default; /// Construct an empty MutableArrayRef from None. - /*implicit*/ MutableArrayRef(NoneType) : ArrayRef() {} + /*implicit*/ MutableArrayRef(std::nullopt_t) : ArrayRef() {} /// Construct a MutableArrayRef from a single element. /*implicit*/ MutableArrayRef(T &OneElt) : ArrayRef(OneElt) {} diff --git a/llvm/include/llvm/ADT/Optional.h b/llvm/include/llvm/ADT/Optional.h index d504560cfae4..6bc17c419ca1 100644 --- a/llvm/include/llvm/ADT/Optional.h +++ b/llvm/include/llvm/ADT/Optional.h @@ -239,7 +239,7 @@ public: using value_type = T; constexpr Optional() = default; - constexpr Optional(NoneType) {} + constexpr Optional(std::nullopt_t) {} constexpr Optional(const T &y) : Storage(std::in_place, y) {} constexpr Optional(const Optional &O) = default; @@ -396,58 +396,62 @@ constexpr bool operator>=(const Optional &X, const Optional &Y) { } template -constexpr bool operator==(const Optional &X, NoneType) { +constexpr bool operator==(const Optional &X, std::nullopt_t) { return !X; } template -constexpr bool operator==(NoneType, const Optional &X) { +constexpr bool operator==(std::nullopt_t, const Optional &X) { return X == None; } template -constexpr bool operator!=(const Optional &X, NoneType) { +constexpr bool operator!=(const Optional &X, std::nullopt_t) { return !(X == None); } template -constexpr bool operator!=(NoneType, const Optional &X) { +constexpr bool operator!=(std::nullopt_t, const Optional &X) { return X != None; } -template constexpr bool operator<(const Optional &, NoneType) { +template +constexpr bool operator<(const Optional &, std::nullopt_t) { return false; } -template constexpr bool operator<(NoneType, const Optional &X) { +template +constexpr bool operator<(std::nullopt_t, const Optional &X) { return X.has_value(); } template -constexpr bool operator<=(const Optional &X, NoneType) { +constexpr bool operator<=(const Optional &X, std::nullopt_t) { return !(None < X); } template -constexpr bool operator<=(NoneType, const Optional &X) { +constexpr bool operator<=(std::nullopt_t, const Optional &X) { return !(X < None); } -template constexpr bool operator>(const Optional &X, NoneType) { +template +constexpr bool operator>(const Optional &X, std::nullopt_t) { return None < X; } -template constexpr bool operator>(NoneType, const Optional &X) { +template +constexpr bool operator>(std::nullopt_t, const Optional &X) { return X < None; } template -constexpr bool operator>=(const Optional &X, NoneType) { +constexpr bool operator>=(const Optional &X, std::nullopt_t) { return None <= X; } template -constexpr bool operator>=(NoneType, const Optional &X) { +constexpr bool operator>=(std::nullopt_t, const Optional &X) { return X <= None; } @@ -511,7 +515,7 @@ constexpr bool operator>=(const T &X, const Optional &Y) { return !(X < Y); } -raw_ostream &operator<<(raw_ostream &OS, NoneType); +raw_ostream &operator<<(raw_ostream &OS, std::nullopt_t); template () << std::declval())> diff --git a/llvm/include/llvm/ADT/StringMapEntry.h b/llvm/include/llvm/ADT/StringMapEntry.h index 664340683fc6..fb4ec66d04b2 100644 --- a/llvm/include/llvm/ADT/StringMapEntry.h +++ b/llvm/include/llvm/ADT/StringMapEntry.h @@ -85,13 +85,14 @@ public: void setValue(const ValueTy &V) { second = V; } }; -template <> class StringMapEntryStorage : public StringMapEntryBase { +template <> +class StringMapEntryStorage : public StringMapEntryBase { public: - explicit StringMapEntryStorage(size_t keyLength, NoneType = None) + explicit StringMapEntryStorage(size_t keyLength, std::nullopt_t = None) : StringMapEntryBase(keyLength) {} StringMapEntryStorage(StringMapEntryStorage &entry) = delete; - NoneType getValue() const { return None; } + std::nullopt_t getValue() const { return None; } }; /// StringMapEntry - This is used to represent one value that is inserted into diff --git a/llvm/include/llvm/ADT/StringSet.h b/llvm/include/llvm/ADT/StringSet.h index ed8a7e6073d7..d7b63bc9c968 100644 --- a/llvm/include/llvm/ADT/StringSet.h +++ b/llvm/include/llvm/ADT/StringSet.h @@ -20,8 +20,8 @@ namespace llvm { /// StringSet - A wrapper for StringMap that provides set-like functionality. template -class StringSet : public StringMap { - using Base = StringMap; +class StringSet : public StringMap { + using Base = StringMap; public: StringSet() = default; diff --git a/llvm/include/llvm/FuzzMutate/OpDescriptor.h b/llvm/include/llvm/FuzzMutate/OpDescriptor.h index 11550bb7947f..6ea477a33ade 100644 --- a/llvm/include/llvm/FuzzMutate/OpDescriptor.h +++ b/llvm/include/llvm/FuzzMutate/OpDescriptor.h @@ -57,7 +57,7 @@ private: public: /// Create a fully general source predicate. SourcePred(PredT Pred, MakeT Make) : Pred(Pred), Make(Make) {} - SourcePred(PredT Pred, NoneType) : Pred(Pred) { + SourcePred(PredT Pred, std::nullopt_t) : Pred(Pred) { Make = [Pred](ArrayRef Cur, ArrayRef BaseTypes) { // Default filter just calls Pred on each of the base types. std::vector Result; diff --git a/llvm/include/llvm/Support/SMLoc.h b/llvm/include/llvm/Support/SMLoc.h index d8607034ee86..17a67885edb7 100644 --- a/llvm/include/llvm/Support/SMLoc.h +++ b/llvm/include/llvm/Support/SMLoc.h @@ -50,7 +50,7 @@ public: SMLoc Start, End; SMRange() = default; - SMRange(NoneType) {} + SMRange(std::nullopt_t) {} SMRange(SMLoc St, SMLoc En) : Start(St), End(En) { assert(Start.isValid() == End.isValid() && "Start and End should either both be valid or both be invalid!"); diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.cpp b/llvm/lib/CodeGen/MIRParser/MILexer.cpp index 3774c1084648..b70eaa6cab74 100644 --- a/llvm/lib/CodeGen/MIRParser/MILexer.cpp +++ b/llvm/lib/CodeGen/MIRParser/MILexer.cpp @@ -33,7 +33,7 @@ class Cursor { const char *End = nullptr; public: - Cursor(NoneType) {} + Cursor(std::nullopt_t) {} explicit Cursor(StringRef Str) { Ptr = Str.data(); diff --git a/llvm/lib/Support/Optional.cpp b/llvm/lib/Support/Optional.cpp index 2425739c845d..8f553fa60656 100644 --- a/llvm/lib/Support/Optional.cpp +++ b/llvm/lib/Support/Optional.cpp @@ -9,6 +9,6 @@ #include "llvm/ADT/Optional.h" #include "llvm/Support/raw_ostream.h" -llvm::raw_ostream &llvm::operator<<(raw_ostream &OS, NoneType) { +llvm::raw_ostream &llvm::operator<<(raw_ostream &OS, std::nullopt_t) { return OS << "None"; } diff --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h index 973cae3fd014..864affd9a6af 100644 --- a/mlir/include/mlir/IR/OpDefinition.h +++ b/mlir/include/mlir/IR/OpDefinition.h @@ -41,7 +41,7 @@ public: OptionalParseResult(ParseResult result) : impl(result) {} OptionalParseResult(const InFlightDiagnostic &) : OptionalParseResult(failure()) {} - OptionalParseResult(llvm::NoneType) : impl(llvm::None) {} + OptionalParseResult(std::nullopt_t) : impl(llvm::None) {} /// Returns true if we contain a valid ParseResult value. bool has_value() const { return impl.has_value(); } diff --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h index aa34cd3a960d..c64dbdb68efe 100644 --- a/mlir/include/mlir/IR/OperationSupport.h +++ b/mlir/include/mlir/IR/OperationSupport.h @@ -490,7 +490,7 @@ public: using size_type = size_t; NamedAttrList() : dictionarySorted({}, true) {} - NamedAttrList(llvm::NoneType none) : NamedAttrList() {} + NamedAttrList(std::nullopt_t none) : NamedAttrList() {} NamedAttrList(ArrayRef attributes); NamedAttrList(DictionaryAttr attributes); NamedAttrList(const_iterator inStart, const_iterator inEnd); @@ -759,7 +759,7 @@ private: class OpPrintingFlags { public: OpPrintingFlags(); - OpPrintingFlags(llvm::NoneType) : OpPrintingFlags() {} + OpPrintingFlags(std::nullopt_t) : OpPrintingFlags() {} /// Enables the elision of large elements attributes by printing a lexically /// valid but otherwise meaningless form instead of the element data. The diff --git a/mlir/include/mlir/Support/Timing.h b/mlir/include/mlir/Support/Timing.h index e33fba5c13f4..180559c91243 100644 --- a/mlir/include/mlir/Support/Timing.h +++ b/mlir/include/mlir/Support/Timing.h @@ -43,7 +43,7 @@ class DefaultTimingManagerImpl; /// This is a POD type with pointer size, so it should be passed around by /// value. The underlying data is owned by the `TimingManager`. class TimingIdentifier { - using EntryType = llvm::StringMapEntry; + using EntryType = llvm::StringMapEntry; public: TimingIdentifier(const TimingIdentifier &) = default; diff --git a/mlir/lib/Support/Timing.cpp b/mlir/lib/Support/Timing.cpp index b6ab40e13ebf..4fd00c69413b 100644 --- a/mlir/lib/Support/Timing.cpp +++ b/mlir/lib/Support/Timing.cpp @@ -50,7 +50,7 @@ public: llvm::sys::SmartRWMutex identifierMutex; /// A thread local cache of identifiers to reduce lock contention. - ThreadLocalCache *>> + ThreadLocalCache *>> localIdentifierCache; TimingManagerImpl() : identifiers(identifierAllocator) {}