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
This commit is contained in:
Kazu Hirata 2022-11-23 14:16:04 -08:00
parent 4b4cbbd7fb
commit 34bcadc38c
25 changed files with 52 additions and 46 deletions

View File

@ -2233,7 +2233,7 @@ DataAggregator::writeAggregatedFile(StringRef OutputFilename) const {
OutFile << "boltedcollection\n"; OutFile << "boltedcollection\n";
if (opts::BasicAggregation) { if (opts::BasicAggregation) {
OutFile << "no_lbr"; OutFile << "no_lbr";
for (const StringMapEntry<NoneType> &Entry : EventNames) for (const StringMapEntry<std::nullopt_t> &Entry : EventNames)
OutFile << " " << Entry.getKey(); OutFile << " " << Entry.getKey();
OutFile << "\n"; OutFile << "\n";

View File

@ -161,7 +161,7 @@ std::error_code YAMLProfileWriter::writeProfile(const RewriteInstance &RI) {
StringSet<> EventNames = RI.getProfileReader()->getEventNames(); StringSet<> EventNames = RI.getProfileReader()->getEventNames();
if (!EventNames.empty()) { if (!EventNames.empty()) {
std::string Sep; std::string Sep;
for (const StringMapEntry<NoneType> &EventEntry : EventNames) { for (const StringMapEntry<std::nullopt_t> &EventEntry : EventNames) {
BP.Header.EventNames += Sep + EventEntry.first().str(); BP.Header.EventNames += Sep + EventEntry.first().str();
Sep = ","; Sep = ",";
} }

View File

@ -214,7 +214,7 @@ class NameLookup {
public: public:
explicit NameLookup(const NamedDecl *ND) : Data(ND, false) {} 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) {} explicit NameLookup(std::nullptr_t) : Data(nullptr, false) {}
NameLookup() : NameLookup(nullptr) {} NameLookup() : NameLookup(nullptr) {}

View File

@ -30,7 +30,7 @@ public:
/// Obtain a vfs::FileSystem with an arbitrary initial working directory. /// Obtain a vfs::FileSystem with an arbitrary initial working directory.
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
view(llvm::NoneType CWD) const { view(std::nullopt_t CWD) const {
return viewImpl(); return viewImpl();
} }

View File

@ -48,7 +48,7 @@ public:
/// Set the bit associated with a particular CFGBlock. /// Set the bit associated with a particular CFGBlock.
/// This is the important method for the SetType template parameter. /// This is the important method for the SetType template parameter.
std::pair<llvm::NoneType, bool> insert(const CFGBlock *Block) { std::pair<std::nullopt_t, bool> insert(const CFGBlock *Block) {
// Note that insert() is called by po_iterator, which doesn't check to // 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 // make sure that Block is non-null. Moreover, the CFGBlock iterator will
// occasionally hand out null pointers for pruned edges, so we catch those // occasionally hand out null pointers for pruned edges, so we catch those

View File

@ -264,13 +264,14 @@ public:
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr & OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &
operator=(const OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &) = default; operator=(const OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &) = default;
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(llvm::NoneType) {} OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(std::nullopt_t) {}
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(DirectoryEntryRef Ref) OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(DirectoryEntryRef Ref)
: Optional<DirectoryEntryRef>(Ref) {} : Optional<DirectoryEntryRef>(Ref) {}
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(Optional<DirectoryEntryRef> MaybeRef) OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(Optional<DirectoryEntryRef> MaybeRef)
: Optional<DirectoryEntryRef>(MaybeRef) {} : Optional<DirectoryEntryRef>(MaybeRef) {}
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &operator=(llvm::NoneType) { OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &
operator=(std::nullopt_t) {
Optional<DirectoryEntryRef>::operator=(None); Optional<DirectoryEntryRef>::operator=(None);
return *this; return *this;
} }

View File

@ -308,13 +308,13 @@ public:
OptionalFileEntryRefDegradesToFileEntryPtr & OptionalFileEntryRefDegradesToFileEntryPtr &
operator=(const OptionalFileEntryRefDegradesToFileEntryPtr &) = default; operator=(const OptionalFileEntryRefDegradesToFileEntryPtr &) = default;
OptionalFileEntryRefDegradesToFileEntryPtr(llvm::NoneType) {} OptionalFileEntryRefDegradesToFileEntryPtr(std::nullopt_t) {}
OptionalFileEntryRefDegradesToFileEntryPtr(FileEntryRef Ref) OptionalFileEntryRefDegradesToFileEntryPtr(FileEntryRef Ref)
: Optional<FileEntryRef>(Ref) {} : Optional<FileEntryRef>(Ref) {}
OptionalFileEntryRefDegradesToFileEntryPtr(Optional<FileEntryRef> MaybeRef) OptionalFileEntryRefDegradesToFileEntryPtr(Optional<FileEntryRef> MaybeRef)
: Optional<FileEntryRef>(MaybeRef) {} : Optional<FileEntryRef>(MaybeRef) {}
OptionalFileEntryRefDegradesToFileEntryPtr &operator=(llvm::NoneType) { OptionalFileEntryRefDegradesToFileEntryPtr &operator=(std::nullopt_t) {
Optional<FileEntryRef>::operator=(None); Optional<FileEntryRef>::operator=(None);
return *this; return *this;
} }

View File

@ -222,7 +222,7 @@ enum class TemplateSubstitutionKind : char {
TemplateArgumentLists.push_back({{}, Args}); TemplateArgumentLists.push_back({{}, Args});
} }
void addOuterTemplateArguments(llvm::NoneType) { void addOuterTemplateArguments(std::nullopt_t) {
assert(!NumRetainedOuterLevels && assert(!NumRetainedOuterLevels &&
"substituted args outside retained args?"); "substituted args outside retained args?");
TemplateArgumentLists.push_back({}); TemplateArgumentLists.push_back({});

View File

@ -7044,14 +7044,14 @@ class BufferToAPValueConverter {
// Emit an unsupported bit_cast type error. Sema refuses to build a bit_cast // 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). // with an invalid type, so anything left is a deficiency on our part (FIXME).
// Ideally this will be unreachable. // Ideally this will be unreachable.
llvm::NoneType unsupportedType(QualType Ty) { std::nullopt_t unsupportedType(QualType Ty) {
Info.FFDiag(BCE->getBeginLoc(), Info.FFDiag(BCE->getBeginLoc(),
diag::note_constexpr_bit_cast_unsupported_type) diag::note_constexpr_bit_cast_unsupported_type)
<< Ty; << Ty;
return None; return None;
} }
llvm::NoneType unrepresentableValue(QualType Ty, const APSInt &Val) { std::nullopt_t unrepresentableValue(QualType Ty, const APSInt &Val) {
Info.FFDiag(BCE->getBeginLoc(), Info.FFDiag(BCE->getBeginLoc(),
diag::note_constexpr_bit_cast_unrepresentable_value) diag::note_constexpr_bit_cast_unrepresentable_value)
<< Ty << toString(Val, /*Radix=*/10); << Ty << toString(Val, /*Radix=*/10);

View File

@ -152,7 +152,7 @@ static StringRef consumeWhitespace(StringRef S) {
// Parses a single expected character \c c from \c State, skipping preceding // Parses a single expected character \c c from \c State, skipping preceding
// whitespace. Error if the expected character isn't found. // whitespace. Error if the expected character isn't found.
static ExpectedProgress<llvm::NoneType> parseChar(char c, ParseState State) { static ExpectedProgress<std::nullopt_t> parseChar(char c, ParseState State) {
State.Input = consumeWhitespace(State.Input); State.Input = consumeWhitespace(State.Input);
if (State.Input.empty() || State.Input.front() != c) if (State.Input.empty() || State.Input.front() != c)
return makeParseError(State, return makeParseError(State,

View File

@ -36,7 +36,7 @@ private:
using Base = llvm::Optional<Dur<Ratio>>; using Base = llvm::Optional<Dur<Ratio>>;
public: public:
Timeout(llvm::NoneType none) : Base(none) {} Timeout(std::nullopt_t none) : Base(none) {}
template <typename Ratio2, template <typename Ratio2,
typename = typename EnableIf<int64_t, Ratio2>::type> typename = typename EnableIf<int64_t, Ratio2>::type>

View File

@ -9890,7 +9890,7 @@ public:
} // namespace } // namespace
char ScratchTypeSystemClang::ID; char ScratchTypeSystemClang::ID;
const llvm::NoneType ScratchTypeSystemClang::DefaultAST = llvm::None; const std::nullopt_t ScratchTypeSystemClang::DefaultAST = llvm::None;
ScratchTypeSystemClang::ScratchTypeSystemClang(Target &target, ScratchTypeSystemClang::ScratchTypeSystemClang(Target &target,
llvm::Triple triple) llvm::Triple triple)

View File

@ -1157,7 +1157,7 @@ public:
/// Alias for requesting the default scratch TypeSystemClang in GetForTarget. /// Alias for requesting the default scratch TypeSystemClang in GetForTarget.
// This isn't constexpr as gtest/llvm::Optional comparison logic is trying // This isn't constexpr as gtest/llvm::Optional comparison logic is trying
// to get the address of this for pretty-printing. // 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. /// Infers the appropriate sub-AST from Clang's LangOptions.
static llvm::Optional<IsolatedASTKind> static llvm::Optional<IsolatedASTKind>

View File

@ -68,7 +68,7 @@ namespace llvm {
/*implicit*/ ArrayRef() = default; /*implicit*/ ArrayRef() = default;
/// Construct an empty ArrayRef from None. /// Construct an empty ArrayRef from None.
/*implicit*/ ArrayRef(NoneType) {} /*implicit*/ ArrayRef(std::nullopt_t) {}
/// Construct an ArrayRef from a single element. /// Construct an ArrayRef from a single element.
/*implicit*/ ArrayRef(const T &OneElt) /*implicit*/ ArrayRef(const T &OneElt)
@ -321,7 +321,7 @@ namespace llvm {
/*implicit*/ MutableArrayRef() = default; /*implicit*/ MutableArrayRef() = default;
/// Construct an empty MutableArrayRef from None. /// Construct an empty MutableArrayRef from None.
/*implicit*/ MutableArrayRef(NoneType) : ArrayRef<T>() {} /*implicit*/ MutableArrayRef(std::nullopt_t) : ArrayRef<T>() {}
/// Construct a MutableArrayRef from a single element. /// Construct a MutableArrayRef from a single element.
/*implicit*/ MutableArrayRef(T &OneElt) : ArrayRef<T>(OneElt) {} /*implicit*/ MutableArrayRef(T &OneElt) : ArrayRef<T>(OneElt) {}

View File

@ -239,7 +239,7 @@ public:
using value_type = T; using value_type = T;
constexpr Optional() = default; constexpr Optional() = default;
constexpr Optional(NoneType) {} constexpr Optional(std::nullopt_t) {}
constexpr Optional(const T &y) : Storage(std::in_place, y) {} constexpr Optional(const T &y) : Storage(std::in_place, y) {}
constexpr Optional(const Optional &O) = default; constexpr Optional(const Optional &O) = default;
@ -396,58 +396,62 @@ constexpr bool operator>=(const Optional<T> &X, const Optional<U> &Y) {
} }
template <typename T> template <typename T>
constexpr bool operator==(const Optional<T> &X, NoneType) { constexpr bool operator==(const Optional<T> &X, std::nullopt_t) {
return !X; return !X;
} }
template <typename T> template <typename T>
constexpr bool operator==(NoneType, const Optional<T> &X) { constexpr bool operator==(std::nullopt_t, const Optional<T> &X) {
return X == None; return X == None;
} }
template <typename T> template <typename T>
constexpr bool operator!=(const Optional<T> &X, NoneType) { constexpr bool operator!=(const Optional<T> &X, std::nullopt_t) {
return !(X == None); return !(X == None);
} }
template <typename T> template <typename T>
constexpr bool operator!=(NoneType, const Optional<T> &X) { constexpr bool operator!=(std::nullopt_t, const Optional<T> &X) {
return X != None; return X != None;
} }
template <typename T> constexpr bool operator<(const Optional<T> &, NoneType) { template <typename T>
constexpr bool operator<(const Optional<T> &, std::nullopt_t) {
return false; return false;
} }
template <typename T> constexpr bool operator<(NoneType, const Optional<T> &X) { template <typename T>
constexpr bool operator<(std::nullopt_t, const Optional<T> &X) {
return X.has_value(); return X.has_value();
} }
template <typename T> template <typename T>
constexpr bool operator<=(const Optional<T> &X, NoneType) { constexpr bool operator<=(const Optional<T> &X, std::nullopt_t) {
return !(None < X); return !(None < X);
} }
template <typename T> template <typename T>
constexpr bool operator<=(NoneType, const Optional<T> &X) { constexpr bool operator<=(std::nullopt_t, const Optional<T> &X) {
return !(X < None); return !(X < None);
} }
template <typename T> constexpr bool operator>(const Optional<T> &X, NoneType) { template <typename T>
constexpr bool operator>(const Optional<T> &X, std::nullopt_t) {
return None < X; return None < X;
} }
template <typename T> constexpr bool operator>(NoneType, const Optional<T> &X) { template <typename T>
constexpr bool operator>(std::nullopt_t, const Optional<T> &X) {
return X < None; return X < None;
} }
template <typename T> template <typename T>
constexpr bool operator>=(const Optional<T> &X, NoneType) { constexpr bool operator>=(const Optional<T> &X, std::nullopt_t) {
return None <= X; return None <= X;
} }
template <typename T> template <typename T>
constexpr bool operator>=(NoneType, const Optional<T> &X) { constexpr bool operator>=(std::nullopt_t, const Optional<T> &X) {
return X <= None; return X <= None;
} }
@ -511,7 +515,7 @@ constexpr bool operator>=(const T &X, const Optional<T> &Y) {
return !(X < Y); return !(X < Y);
} }
raw_ostream &operator<<(raw_ostream &OS, NoneType); raw_ostream &operator<<(raw_ostream &OS, std::nullopt_t);
template <typename T, typename = decltype(std::declval<raw_ostream &>() template <typename T, typename = decltype(std::declval<raw_ostream &>()
<< std::declval<const T &>())> << std::declval<const T &>())>

View File

@ -85,13 +85,14 @@ public:
void setValue(const ValueTy &V) { second = V; } void setValue(const ValueTy &V) { second = V; }
}; };
template <> class StringMapEntryStorage<NoneType> : public StringMapEntryBase { template <>
class StringMapEntryStorage<std::nullopt_t> : public StringMapEntryBase {
public: public:
explicit StringMapEntryStorage(size_t keyLength, NoneType = None) explicit StringMapEntryStorage(size_t keyLength, std::nullopt_t = None)
: StringMapEntryBase(keyLength) {} : StringMapEntryBase(keyLength) {}
StringMapEntryStorage(StringMapEntryStorage &entry) = delete; 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 /// StringMapEntry - This is used to represent one value that is inserted into

View File

@ -20,8 +20,8 @@ namespace llvm {
/// StringSet - A wrapper for StringMap that provides set-like functionality. /// StringSet - A wrapper for StringMap that provides set-like functionality.
template <class AllocatorTy = MallocAllocator> template <class AllocatorTy = MallocAllocator>
class StringSet : public StringMap<NoneType, AllocatorTy> { class StringSet : public StringMap<std::nullopt_t, AllocatorTy> {
using Base = StringMap<NoneType, AllocatorTy>; using Base = StringMap<std::nullopt_t, AllocatorTy>;
public: public:
StringSet() = default; StringSet() = default;

View File

@ -57,7 +57,7 @@ private:
public: public:
/// Create a fully general source predicate. /// Create a fully general source predicate.
SourcePred(PredT Pred, MakeT Make) : Pred(Pred), Make(Make) {} 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<Value *> Cur, ArrayRef<Type *> BaseTypes) { Make = [Pred](ArrayRef<Value *> Cur, ArrayRef<Type *> BaseTypes) {
// Default filter just calls Pred on each of the base types. // Default filter just calls Pred on each of the base types.
std::vector<Constant *> Result; std::vector<Constant *> Result;

View File

@ -50,7 +50,7 @@ public:
SMLoc Start, End; SMLoc Start, End;
SMRange() = default; SMRange() = default;
SMRange(NoneType) {} SMRange(std::nullopt_t) {}
SMRange(SMLoc St, SMLoc En) : Start(St), End(En) { SMRange(SMLoc St, SMLoc En) : Start(St), End(En) {
assert(Start.isValid() == End.isValid() && assert(Start.isValid() == End.isValid() &&
"Start and End should either both be valid or both be invalid!"); "Start and End should either both be valid or both be invalid!");

View File

@ -33,7 +33,7 @@ class Cursor {
const char *End = nullptr; const char *End = nullptr;
public: public:
Cursor(NoneType) {} Cursor(std::nullopt_t) {}
explicit Cursor(StringRef Str) { explicit Cursor(StringRef Str) {
Ptr = Str.data(); Ptr = Str.data();

View File

@ -9,6 +9,6 @@
#include "llvm/ADT/Optional.h" #include "llvm/ADT/Optional.h"
#include "llvm/Support/raw_ostream.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"; return OS << "None";
} }

View File

@ -41,7 +41,7 @@ public:
OptionalParseResult(ParseResult result) : impl(result) {} OptionalParseResult(ParseResult result) : impl(result) {}
OptionalParseResult(const InFlightDiagnostic &) OptionalParseResult(const InFlightDiagnostic &)
: OptionalParseResult(failure()) {} : OptionalParseResult(failure()) {}
OptionalParseResult(llvm::NoneType) : impl(llvm::None) {} OptionalParseResult(std::nullopt_t) : impl(llvm::None) {}
/// Returns true if we contain a valid ParseResult value. /// Returns true if we contain a valid ParseResult value.
bool has_value() const { return impl.has_value(); } bool has_value() const { return impl.has_value(); }

View File

@ -490,7 +490,7 @@ public:
using size_type = size_t; using size_type = size_t;
NamedAttrList() : dictionarySorted({}, true) {} NamedAttrList() : dictionarySorted({}, true) {}
NamedAttrList(llvm::NoneType none) : NamedAttrList() {} NamedAttrList(std::nullopt_t none) : NamedAttrList() {}
NamedAttrList(ArrayRef<NamedAttribute> attributes); NamedAttrList(ArrayRef<NamedAttribute> attributes);
NamedAttrList(DictionaryAttr attributes); NamedAttrList(DictionaryAttr attributes);
NamedAttrList(const_iterator inStart, const_iterator inEnd); NamedAttrList(const_iterator inStart, const_iterator inEnd);
@ -759,7 +759,7 @@ private:
class OpPrintingFlags { class OpPrintingFlags {
public: public:
OpPrintingFlags(); OpPrintingFlags();
OpPrintingFlags(llvm::NoneType) : OpPrintingFlags() {} OpPrintingFlags(std::nullopt_t) : OpPrintingFlags() {}
/// Enables the elision of large elements attributes by printing a lexically /// Enables the elision of large elements attributes by printing a lexically
/// valid but otherwise meaningless form instead of the element data. The /// valid but otherwise meaningless form instead of the element data. The

View File

@ -43,7 +43,7 @@ class DefaultTimingManagerImpl;
/// This is a POD type with pointer size, so it should be passed around by /// This is a POD type with pointer size, so it should be passed around by
/// value. The underlying data is owned by the `TimingManager`. /// value. The underlying data is owned by the `TimingManager`.
class TimingIdentifier { class TimingIdentifier {
using EntryType = llvm::StringMapEntry<llvm::NoneType>; using EntryType = llvm::StringMapEntry<std::nullopt_t>;
public: public:
TimingIdentifier(const TimingIdentifier &) = default; TimingIdentifier(const TimingIdentifier &) = default;

View File

@ -50,7 +50,7 @@ public:
llvm::sys::SmartRWMutex<true> identifierMutex; llvm::sys::SmartRWMutex<true> identifierMutex;
/// A thread local cache of identifiers to reduce lock contention. /// A thread local cache of identifiers to reduce lock contention.
ThreadLocalCache<llvm::StringMap<llvm::StringMapEntry<llvm::NoneType> *>> ThreadLocalCache<llvm::StringMap<llvm::StringMapEntry<std::nullopt_t> *>>
localIdentifierCache; localIdentifierCache;
TimingManagerImpl() : identifiers(identifierAllocator) {} TimingManagerImpl() : identifiers(identifierAllocator) {}