[clang-tools-extra] 2c675be - [clang-tools-extra] Use std::optional instead of llvm::Optional (NFC)

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 2 16:17:47 PST 2023


Author: Kazu Hirata
Date: 2023-01-02T16:17:40-08:00
New Revision: 2c675be9b232c1d0b5c55cbcb196e71036c681ea

URL: https://github.com/llvm/llvm-project/commit/2c675be9b232c1d0b5c55cbcb196e71036c681ea
DIFF: https://github.com/llvm/llvm-project/commit/2c675be9b232c1d0b5c55cbcb196e71036c681ea.diff

LOG: [clang-tools-extra] Use std::optional instead of llvm::Optional (NFC)

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

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/ClangTidyOptions.h
    clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp
    clang-tools-extra/clang-tidy/ClangTidyProfiling.h
    clang-tools-extra/clangd/ConfigFragment.h
    clang-tools-extra/clangd/ConfigProvider.cpp
    clang-tools-extra/clangd/ConfigYAML.cpp
    clang-tools-extra/clangd/FuzzyMatch.cpp
    clang-tools-extra/clangd/FuzzyMatch.h
    clang-tools-extra/clangd/PathMapping.cpp
    clang-tools-extra/clangd/PathMapping.h
    clang-tools-extra/clangd/TidyProvider.cpp
    clang-tools-extra/clangd/index/dex/PostingList.cpp
    clang-tools-extra/clangd/support/FileCache.cpp
    clang-tools-extra/clangd/support/FileCache.h
    clang-tools-extra/clangd/support/Threading.cpp
    clang-tools-extra/clangd/support/Threading.h
    clang-tools-extra/clangd/support/Trace.cpp
    clang-tools-extra/clangd/unittests/FuzzyMatchTests.cpp
    clang-tools-extra/clangd/unittests/LSPClient.h
    clang-tools-extra/clangd/unittests/LoggerTests.cpp
    clang-tools-extra/clangd/unittests/PathMappingTests.cpp
    clang-tools-extra/clangd/unittests/support/CancellationTests.cpp
    clang-tools-extra/pseudo/include/clang-pseudo/grammar/Grammar.h
    clang-tools-extra/pseudo/lib/grammar/Grammar.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.h b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
index 6102399d9d387..727c533335c3e 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
@@ -10,7 +10,6 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYOPTIONS_H
 
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/ErrorOr.h"
@@ -232,7 +231,7 @@ class FileOptionsBaseProvider : public DefaultOptionsProvider {
 
   /// Try to read configuration files from \p Directory using registered
   /// \c ConfigHandlers.
-  llvm::Optional<OptionsSource> tryReadConfigFile(llvm::StringRef Directory);
+  std::optional<OptionsSource> tryReadConfigFile(llvm::StringRef Directory);
 
   llvm::StringMap<OptionsSource> CachedOptions;
   ClangTidyOptions OverrideOptions;

diff  --git a/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp b/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp
index 6c5d86a69821b..3a03dc033f802 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp
@@ -11,6 +11,7 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
+#include <optional>
 #include <system_error>
 #include <utility>
 
@@ -74,7 +75,7 @@ void ClangTidyProfiling::storeProfileData() {
   printAsJSON(OS);
 }
 
-ClangTidyProfiling::ClangTidyProfiling(llvm::Optional<StorageParams> Storage)
+ClangTidyProfiling::ClangTidyProfiling(std::optional<StorageParams> Storage)
     : Storage(std::move(Storage)) {}
 
 ClangTidyProfiling::~ClangTidyProfiling() {

diff  --git a/clang-tools-extra/clang-tidy/ClangTidyProfiling.h b/clang-tools-extra/clang-tidy/ClangTidyProfiling.h
index 9487a34620e0a..bf21659a502fb 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyProfiling.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyProfiling.h
@@ -9,10 +9,10 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYPROFILING_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYPROFILING_H
 
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/Chrono.h"
 #include "llvm/Support/Timer.h"
+#include <optional>
 #include <string>
 
 namespace llvm {
@@ -35,9 +35,9 @@ class ClangTidyProfiling {
   };
 
 private:
-  llvm::Optional<llvm::TimerGroup> TG;
+  std::optional<llvm::TimerGroup> TG;
 
-  llvm::Optional<StorageParams> Storage;
+  std::optional<StorageParams> Storage;
 
   void printUserFriendlyTable(llvm::raw_ostream &OS);
   void printAsJSON(llvm::raw_ostream &OS);
@@ -49,7 +49,7 @@ class ClangTidyProfiling {
 
   ClangTidyProfiling() = default;
 
-  ClangTidyProfiling(llvm::Optional<StorageParams> Storage);
+  ClangTidyProfiling(std::optional<StorageParams> Storage);
 
   ~ClangTidyProfiling();
 };

diff  --git a/clang-tools-extra/clangd/ConfigFragment.h b/clang-tools-extra/clangd/ConfigFragment.h
index 98923b516752b..bcd1a05b4a999 100644
--- a/clang-tools-extra/clangd/ConfigFragment.h
+++ b/clang-tools-extra/clangd/ConfigFragment.h
@@ -33,9 +33,9 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CONFIGFRAGMENT_H
 
 #include "ConfigProvider.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/Support/SMLoc.h"
 #include "llvm/Support/SourceMgr.h"
+#include <optional>
 #include <string>
 #include <vector>
 
@@ -140,7 +140,7 @@ struct Fragment {
     ///
     /// (That this simply replaces argv[0], and may mangle commands that use
     /// more complicated drivers like ccache).
-    llvm::Optional<Located<std::string>> Compiler;
+    std::optional<Located<std::string>> Compiler;
 
     /// List of flags to append to the compile command.
     std::vector<Located<std::string>> Add;
@@ -168,7 +168,7 @@ struct Fragment {
     /// - A single path to a directory (absolute, or relative to the fragment)
     /// - Ancestors: search all parent directories (the default)
     /// - None: do not use a compilation database, just default flags.
-    llvm::Optional<Located<std::string>> CompilationDatabase;
+    std::optional<Located<std::string>> CompilationDatabase;
   };
   CompileFlagsBlock CompileFlags;
 
@@ -179,7 +179,7 @@ struct Fragment {
     /// Whether files are built in the background to produce a project index.
     /// This is checked for translation units only, not headers they include.
     /// Legal values are "Build" or "Skip".
-    llvm::Optional<Located<std::string>> Background;
+    std::optional<Located<std::string>> Background;
     /// An external index uses data source outside of clangd itself. This is
     /// usually prepared using clangd-indexer.
     /// Exactly one source (File/Server) should be configured.
@@ -189,19 +189,19 @@ struct Fragment {
       Located<bool> IsNone = false;
       /// Path to an index file generated by clangd-indexer. Relative paths may
       /// be used, if config fragment is associated with a directory.
-      llvm::Optional<Located<std::string>> File;
+      std::optional<Located<std::string>> File;
       /// Address and port number for a clangd-index-server. e.g.
       /// `123.1.1.1:13337`.
-      llvm::Optional<Located<std::string>> Server;
+      std::optional<Located<std::string>> Server;
       /// Source root governed by this index. Default is the directory
       /// associated with the config fragment. Absolute in case of user config
       /// and relative otherwise. Should always use forward-slashes.
-      llvm::Optional<Located<std::string>> MountPoint;
+      std::optional<Located<std::string>> MountPoint;
     };
-    llvm::Optional<Located<ExternalBlock>> External;
+    std::optional<Located<ExternalBlock>> External;
     // Whether the standard library visible from this file should be indexed.
     // This makes all standard library symbols available, included or not.
-    llvm::Optional<Located<bool>> StandardLibrary;
+    std::optional<Located<bool>> StandardLibrary;
   };
   IndexBlock Index;
 
@@ -233,7 +233,7 @@ struct Fragment {
     /// Valid values are:
     /// - Strict
     /// - None
-    llvm::Optional<Located<std::string>> UnusedIncludes;
+    std::optional<Located<std::string>> UnusedIncludes;
 
     /// Controls IncludeCleaner diagnostics.
     struct IncludesBlock {
@@ -283,28 +283,28 @@ struct Fragment {
   struct CompletionBlock {
     /// Whether code completion should include suggestions from scopes that are
     /// not visible. The required scope prefix will be inserted.
-    llvm::Optional<Located<bool>> AllScopes;
+    std::optional<Located<bool>> AllScopes;
   };
   CompletionBlock Completion;
 
   /// Describes hover preferences.
   struct HoverBlock {
     /// Whether hover show a.k.a type.
-    llvm::Optional<Located<bool>> ShowAKA;
+    std::optional<Located<bool>> ShowAKA;
   };
   HoverBlock Hover;
 
   /// Configures labels shown inline with the code.
   struct InlayHintsBlock {
     /// Enables/disables the inlay-hints feature.
-    llvm::Optional<Located<bool>> Enabled;
+    std::optional<Located<bool>> Enabled;
 
     /// Show parameter names before function arguments.
-    llvm::Optional<Located<bool>> ParameterNames;
+    std::optional<Located<bool>> ParameterNames;
     /// Show deduced types for `auto`.
-    llvm::Optional<Located<bool>> DeducedTypes;
+    std::optional<Located<bool>> DeducedTypes;
     /// Show designators in aggregate initialization.
-    llvm::Optional<Located<bool>> Designators;
+    std::optional<Located<bool>> Designators;
   };
   InlayHintsBlock InlayHints;
 };

diff  --git a/clang-tools-extra/clangd/ConfigProvider.cpp b/clang-tools-extra/clangd/ConfigProvider.cpp
index c3f48ac44d14c..ac437ee8b6eb1 100644
--- a/clang-tools-extra/clangd/ConfigProvider.cpp
+++ b/clang-tools-extra/clangd/ConfigProvider.cpp
@@ -19,6 +19,7 @@
 #include "llvm/Support/Path.h"
 #include <chrono>
 #include <mutex>
+#include <optional>
 #include <string>
 
 namespace clang {
@@ -39,7 +40,7 @@ class FileConfigCache : public FileCache {
            std::vector<CompiledFragment> &Out) const {
     read(
         TFS, FreshTime,
-        [&](llvm::Optional<llvm::StringRef> Data) {
+        [&](std::optional<llvm::StringRef> Data) {
           CachedValue.clear();
           if (Data)
             for (auto &Fragment : Fragment::parseYAML(*Data, path(), DC)) {

diff  --git a/clang-tools-extra/clangd/ConfigYAML.cpp b/clang-tools-extra/clangd/ConfigYAML.cpp
index 320f15846e854..ee91753dd88dd 100644
--- a/clang-tools-extra/clangd/ConfigYAML.cpp
+++ b/clang-tools-extra/clangd/ConfigYAML.cpp
@@ -6,13 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 #include "ConfigFragment.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/YAMLParser.h"
+#include <optional>
 #include <string>
 #include <system_error>
 
@@ -26,13 +26,13 @@ using llvm::yaml::Node;
 using llvm::yaml::ScalarNode;
 using llvm::yaml::SequenceNode;
 
-llvm::Optional<llvm::StringRef>
+std::optional<llvm::StringRef>
 bestGuess(llvm::StringRef Search,
           llvm::ArrayRef<llvm::StringRef> AllowedValues) {
   unsigned MaxEdit = (Search.size() + 1) / 3;
   if (!MaxEdit)
     return std::nullopt;
-  llvm::Optional<llvm::StringRef> Result;
+  std::optional<llvm::StringRef> Result;
   for (const auto &AllowedValue : AllowedValues) {
     unsigned EditDistance = Search.edit_distance(AllowedValue, true, MaxEdit);
     // We can't do better than an edit distance of 1, so just return this and
@@ -349,8 +349,8 @@ class Parser {
   };
 
   // Try to parse a single scalar value from the node, warn on failure.
-  llvm::Optional<Located<std::string>> scalarValue(Node &N,
-                                                   llvm::StringRef Desc) {
+  std::optional<Located<std::string>> scalarValue(Node &N,
+                                                  llvm::StringRef Desc) {
     llvm::SmallString<256> Buf;
     if (auto *S = llvm::dyn_cast<ScalarNode>(&N))
       return Located<std::string>(S->getValue(Buf).str(), N.getSourceRange());
@@ -360,7 +360,7 @@ class Parser {
     return std::nullopt;
   }
 
-  llvm::Optional<Located<bool>> boolValue(Node &N, llvm::StringRef Desc) {
+  std::optional<Located<bool>> boolValue(Node &N, llvm::StringRef Desc) {
     if (auto Scalar = scalarValue(N, Desc)) {
       if (auto Bool = llvm::yaml::parseBool(**Scalar))
         return Located<bool>(*Bool, Scalar->Range);
@@ -370,7 +370,7 @@ class Parser {
   }
 
   // Try to parse a list of single scalar values, or just a single value.
-  llvm::Optional<std::vector<Located<std::string>>> scalarValues(Node &N) {
+  std::optional<std::vector<Located<std::string>>> scalarValues(Node &N) {
     std::vector<Located<std::string>> Result;
     if (auto *S = llvm::dyn_cast<ScalarNode>(&N)) {
       llvm::SmallString<256> Buf;

diff  --git a/clang-tools-extra/clangd/FuzzyMatch.cpp b/clang-tools-extra/clangd/FuzzyMatch.cpp
index 0e57de7219b03..82b8ad0f9527d 100644
--- a/clang-tools-extra/clangd/FuzzyMatch.cpp
+++ b/clang-tools-extra/clangd/FuzzyMatch.cpp
@@ -56,8 +56,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "FuzzyMatch.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/Support/Format.h"
+#include <optional>
 
 namespace clang {
 namespace clangd {
@@ -89,7 +89,7 @@ FuzzyMatcher::FuzzyMatcher(llvm::StringRef Pattern)
                               llvm::makeMutableArrayRef(PatRole, PatN));
 }
 
-llvm::Optional<float> FuzzyMatcher::match(llvm::StringRef Word) {
+std::optional<float> FuzzyMatcher::match(llvm::StringRef Word) {
   if (!(WordContainsPattern = init(Word)))
     return std::nullopt;
   if (!PatN)

diff  --git a/clang-tools-extra/clangd/FuzzyMatch.h b/clang-tools-extra/clangd/FuzzyMatch.h
index 81c2edb820eb8..a8621d6ec6545 100644
--- a/clang-tools-extra/clangd/FuzzyMatch.h
+++ b/clang-tools-extra/clangd/FuzzyMatch.h
@@ -16,10 +16,10 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_FUZZYMATCH_H
 
 #include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/raw_ostream.h"
+#include <optional>
 
 namespace clang {
 namespace clangd {
@@ -77,7 +77,7 @@ class FuzzyMatcher {
   // Scores usually fall in a [0,1] range, with 1 being a very good score.
   // "Super" scores in (1,2] are possible if the pattern is the full word.
   // Characters beyond MaxWord are ignored.
-  llvm::Optional<float> match(llvm::StringRef Word);
+  std::optional<float> match(llvm::StringRef Word);
 
   llvm::StringRef pattern() const { return llvm::StringRef(Pat, PatN); }
   bool empty() const { return PatN == 0; }

diff  --git a/clang-tools-extra/clangd/PathMapping.cpp b/clang-tools-extra/clangd/PathMapping.cpp
index 01d3fab5ad33e..2554d34d96b9d 100644
--- a/clang-tools-extra/clangd/PathMapping.cpp
+++ b/clang-tools-extra/clangd/PathMapping.cpp
@@ -12,13 +12,14 @@
 #include "llvm/Support/Error.h"
 #include "llvm/Support/Path.h"
 #include <algorithm>
+#include <optional>
 #include <tuple>
 
 namespace clang {
 namespace clangd {
-llvm::Optional<std::string> doPathMapping(llvm::StringRef S,
-                                          PathMapping::Direction Dir,
-                                          const PathMappings &Mappings) {
+std::optional<std::string> doPathMapping(llvm::StringRef S,
+                                         PathMapping::Direction Dir,
+                                         const PathMappings &Mappings) {
   // Return early to optimize for the common case, wherein S is not a file URI
   if (!S.startswith("file://"))
     return std::nullopt;
@@ -53,7 +54,7 @@ void applyPathMappings(llvm::json::Value &V, PathMapping::Direction Dir,
     llvm::json::Object MappedObj;
     // 1. Map all the Keys
     for (auto &KV : *Obj) {
-      if (llvm::Optional<std::string> MappedKey =
+      if (std::optional<std::string> MappedKey =
               doPathMapping(KV.first.str(), Dir, Mappings)) {
         MappedObj.try_emplace(std::move(*MappedKey), std::move(KV.second));
       } else {
@@ -68,7 +69,7 @@ void applyPathMappings(llvm::json::Value &V, PathMapping::Direction Dir,
     for (llvm::json::Value &Val : *V.getAsArray())
       applyPathMappings(Val, Dir, Mappings);
   } else if (K == Kind::String) {
-    if (llvm::Optional<std::string> Mapped =
+    if (std::optional<std::string> Mapped =
             doPathMapping(*V.getAsString(), Dir, Mappings))
       V = std::move(*Mapped);
   }

diff  --git a/clang-tools-extra/clangd/PathMapping.h b/clang-tools-extra/clangd/PathMapping.h
index 58e42261732ed..1893753392fc3 100644
--- a/clang-tools-extra/clangd/PathMapping.h
+++ b/clang-tools-extra/clangd/PathMapping.h
@@ -9,12 +9,12 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_PATHMAPPING_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_PATHMAPPING_H
 
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/raw_ostream.h"
 #include <memory>
+#include <optional>
 #include <string>
 #include <vector>
 
@@ -50,9 +50,9 @@ llvm::Expected<PathMappings> parsePathMappings(llvm::StringRef RawPathMappings);
 
 /// Returns a modified \p S with the first matching path in \p Mappings
 /// substituted, if applicable
-llvm::Optional<std::string> doPathMapping(llvm::StringRef S,
-                                          PathMapping::Direction Dir,
-                                          const PathMappings &Mappings);
+std::optional<std::string> doPathMapping(llvm::StringRef S,
+                                         PathMapping::Direction Dir,
+                                         const PathMappings &Mappings);
 
 /// Applies the \p Mappings to all the file:// URIs in \p Params.
 /// NOTE: The first matching mapping will be applied, otherwise \p Params will

diff  --git a/clang-tools-extra/clangd/TidyProvider.cpp b/clang-tools-extra/clangd/TidyProvider.cpp
index 936b1ce3edaba..4adc5345c6d9f 100644
--- a/clang-tools-extra/clangd/TidyProvider.cpp
+++ b/clang-tools-extra/clangd/TidyProvider.cpp
@@ -42,7 +42,7 @@ class DotClangTidyCache : private FileCache {
     std::shared_ptr<const tidy::ClangTidyOptions> Result;
     read(
         TFS, FreshTime,
-        [this](llvm::Optional<llvm::StringRef> Data) {
+        [this](std::optional<llvm::StringRef> Data) {
           Value.reset();
           if (Data && !Data->empty()) {
             tidy::DiagCallback Diagnostics = [](const llvm::SMDiagnostic &D) {

diff  --git a/clang-tools-extra/clangd/index/dex/PostingList.cpp b/clang-tools-extra/clangd/index/dex/PostingList.cpp
index 06511cfb43bd5..c02d52734972b 100644
--- a/clang-tools-extra/clangd/index/dex/PostingList.cpp
+++ b/clang-tools-extra/clangd/index/dex/PostingList.cpp
@@ -10,6 +10,7 @@
 #include "index/dex/Iterator.h"
 #include "index/dex/Token.h"
 #include "llvm/Support/MathExtras.h"
+#include <optional>
 
 namespace clang {
 namespace clangd {
@@ -182,7 +183,7 @@ std::vector<Chunk> encodeStream(llvm::ArrayRef<DocID> Documents) {
 
 /// Reads variable length DocID from the buffer and updates the buffer size. If
 /// the stream is terminated, return std::nullopt.
-llvm::Optional<DocID> readVByte(llvm::ArrayRef<uint8_t> &Bytes) {
+std::optional<DocID> readVByte(llvm::ArrayRef<uint8_t> &Bytes) {
   if (Bytes.front() == 0 || Bytes.empty())
     return std::nullopt;
   DocID Result = 0;

diff  --git a/clang-tools-extra/clangd/support/FileCache.cpp b/clang-tools-extra/clangd/support/FileCache.cpp
index 36804113a9bbe..cc59c648b062a 100644
--- a/clang-tools-extra/clangd/support/FileCache.cpp
+++ b/clang-tools-extra/clangd/support/FileCache.cpp
@@ -8,6 +8,7 @@
 
 #include "support/FileCache.h"
 #include "llvm/ADT/ScopeExit.h"
+#include <optional>
 
 namespace clang {
 namespace clangd {
@@ -29,7 +30,7 @@ FileCache::FileCache(llvm::StringRef Path)
 
 void FileCache::read(
     const ThreadsafeFS &TFS, std::chrono::steady_clock::time_point FreshTime,
-    llvm::function_ref<void(llvm::Optional<llvm::StringRef>)> Parse,
+    llvm::function_ref<void(std::optional<llvm::StringRef>)> Parse,
     llvm::function_ref<void()> Read) const {
 
   std::lock_guard<std::mutex> Lock(Mu);

diff  --git a/clang-tools-extra/clangd/support/FileCache.h b/clang-tools-extra/clangd/support/FileCache.h
index 7e28f5b3e4632..edb3498528322 100644
--- a/clang-tools-extra/clangd/support/FileCache.h
+++ b/clang-tools-extra/clangd/support/FileCache.h
@@ -13,6 +13,7 @@
 #include "ThreadsafeFS.h"
 #include "llvm/Support/Chrono.h"
 #include <mutex>
+#include <optional>
 
 namespace clang {
 namespace clangd {
@@ -56,7 +57,7 @@ class FileCache {
   //   - steady_clock::now() + seconds(1) means we accept 1 second of staleness
   void read(const ThreadsafeFS &TFS,
             std::chrono::steady_clock::time_point FreshTime,
-            llvm::function_ref<void(llvm::Optional<llvm::StringRef>)> Parse,
+            llvm::function_ref<void(std::optional<llvm::StringRef>)> Parse,
             llvm::function_ref<void()> Read) const;
 
   PathRef path() const { return Path; }

diff  --git a/clang-tools-extra/clangd/support/Threading.cpp b/clang-tools-extra/clangd/support/Threading.cpp
index be0d84cae3deb..f42db89b483c0 100644
--- a/clang-tools-extra/clangd/support/Threading.cpp
+++ b/clang-tools-extra/clangd/support/Threading.cpp
@@ -12,6 +12,7 @@
 #include "llvm/Support/Threading.h"
 #include "llvm/Support/thread.h"
 #include <atomic>
+#include <optional>
 #include <thread>
 #ifdef __USE_POSIX
 #include <pthread.h>
@@ -109,7 +110,7 @@ void AsyncTaskRunner::runAsync(const llvm::Twine &Name,
   Thread.detach();
 }
 
-Deadline timeoutSeconds(llvm::Optional<double> Seconds) {
+Deadline timeoutSeconds(std::optional<double> Seconds) {
   using namespace std::chrono;
   if (!Seconds)
     return Deadline::infinity();

diff  --git a/clang-tools-extra/clangd/support/Threading.h b/clang-tools-extra/clangd/support/Threading.h
index fb9f6202b0713..1be27820513e5 100644
--- a/clang-tools-extra/clangd/support/Threading.h
+++ b/clang-tools-extra/clangd/support/Threading.h
@@ -18,6 +18,7 @@
 #include <future>
 #include <memory>
 #include <mutex>
+#include <optional>
 #include <thread>
 #include <vector>
 
@@ -70,7 +71,7 @@ class Deadline {
 };
 
 /// Makes a deadline from a timeout in seconds. None means wait forever.
-Deadline timeoutSeconds(llvm::Optional<double> Seconds);
+Deadline timeoutSeconds(std::optional<double> Seconds);
 /// Wait once on CV for the specified duration.
 void wait(std::unique_lock<std::mutex> &Lock, std::condition_variable &CV,
           Deadline D);

diff  --git a/clang-tools-extra/clangd/support/Trace.cpp b/clang-tools-extra/clangd/support/Trace.cpp
index a2bf2dc5103de..419c2eee99ec8 100644
--- a/clang-tools-extra/clangd/support/Trace.cpp
+++ b/clang-tools-extra/clangd/support/Trace.cpp
@@ -9,7 +9,6 @@
 #include "support/Trace.h"
 #include "support/Context.h"
 #include "llvm/ADT/DenseSet.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Chrono.h"
@@ -19,6 +18,7 @@
 #include <chrono>
 #include <memory>
 #include <mutex>
+#include <optional>
 
 namespace clang {
 namespace clangd {
@@ -287,7 +287,7 @@ static std::pair<Context, llvm::json::Object *>
 makeSpanContext(llvm::Twine Name, const Metric &LatencyMetric) {
   if (!T)
     return std::make_pair(Context::current().clone(), nullptr);
-  llvm::Optional<WithContextValue> WithLatency;
+  std::optional<WithContextValue> WithLatency;
   using Clock = std::chrono::high_resolution_clock;
   WithLatency.emplace(llvm::make_scope_exit(
       [StartTime = Clock::now(), Name = Name.str(), &LatencyMetric] {

diff  --git a/clang-tools-extra/clangd/unittests/FuzzyMatchTests.cpp b/clang-tools-extra/clangd/unittests/FuzzyMatchTests.cpp
index 683b9a30e9f9e..9cb668cb7cb16 100644
--- a/clang-tools-extra/clangd/unittests/FuzzyMatchTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FuzzyMatchTests.cpp
@@ -10,6 +10,7 @@
 
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include <optional>
 
 namespace clang {
 namespace clangd {
@@ -39,13 +40,13 @@ struct ExpectedMatch {
   std::string Word;
 
 private:
-  llvm::Optional<llvm::StringRef> Annotated;
+  std::optional<llvm::StringRef> Annotated;
 };
 
 struct MatchesMatcher : public ::testing::MatcherInterface<llvm::StringRef> {
   ExpectedMatch Candidate;
-  llvm::Optional<float> Score;
-  MatchesMatcher(ExpectedMatch Candidate, llvm::Optional<float> Score)
+  std::optional<float> Score;
+  MatchesMatcher(ExpectedMatch Candidate, std::optional<float> Score)
       : Candidate(std::move(Candidate)), Score(Score) {}
 
   void DescribeTo(::std::ostream *OS) const override {
@@ -71,7 +72,7 @@ struct MatchesMatcher : public ::testing::MatcherInterface<llvm::StringRef> {
 // Accepts patterns that match a given word, optionally requiring a score.
 // Dumps the debug tables on match failure.
 ::testing::Matcher<llvm::StringRef> matches(llvm::StringRef M,
-                                            llvm::Optional<float> Score = {}) {
+                                            std::optional<float> Score = {}) {
   return ::testing::MakeMatcher<llvm::StringRef>(new MatchesMatcher(M, Score));
 }
 
@@ -199,7 +200,7 @@ struct RankMatcher : public ::testing::MatcherInterface<llvm::StringRef> {
             : new llvm::raw_null_ostream());
     FuzzyMatcher Matcher(Pattern);
     const ExpectedMatch *LastMatch;
-    llvm::Optional<float> LastScore;
+    std::optional<float> LastScore;
     bool Ok = true;
     for (const auto &Str : RankedStrings) {
       auto Score = Matcher.match(Str.Word);

diff  --git a/clang-tools-extra/clangd/unittests/LSPClient.h b/clang-tools-extra/clangd/unittests/LSPClient.h
index a0f3a31144fb4..be8bd42b84df1 100644
--- a/clang-tools-extra/clangd/unittests/LSPClient.h
+++ b/clang-tools-extra/clangd/unittests/LSPClient.h
@@ -9,12 +9,12 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_LSPCLIENT_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_LSPCLIENT_H
 
-#include <llvm/ADT/Optional.h>
 #include <llvm/Support/Error.h>
 #include <llvm/Support/JSON.h>
 #include <condition_variable>
 #include <deque>
 #include <mutex>
+#include <optional>
 
 namespace clang {
 namespace clangd {
@@ -42,7 +42,7 @@ class LSPClient {
     // Should be called once to provide the value.
     void set(llvm::Expected<llvm::json::Value> V);
 
-    llvm::Optional<llvm::Expected<llvm::json::Value>> Value;
+    std::optional<llvm::Expected<llvm::json::Value>> Value;
     std::mutex Mu;
     std::condition_variable CV;
 
@@ -72,7 +72,7 @@ class LSPClient {
   // Blocks until the server is idle (using the 'sync' protocol extension).
   void sync();
   // sync()s to ensure pending diagnostics arrive, and returns the newest set.
-  llvm::Optional<std::vector<llvm::json::Value>>
+  std::optional<std::vector<llvm::json::Value>>
   diagnostics(llvm::StringRef Path);
 
   // Get the transport used to connect this client to a ClangdLSPServer.

diff  --git a/clang-tools-extra/clangd/unittests/LoggerTests.cpp b/clang-tools-extra/clangd/unittests/LoggerTests.cpp
index 3d2194d79090d..1e28a1499071b 100644
--- a/clang-tools-extra/clangd/unittests/LoggerTests.cpp
+++ b/clang-tools-extra/clangd/unittests/LoggerTests.cpp
@@ -10,6 +10,7 @@
 #include "llvm/Support/Error.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include <optional>
 
 namespace clang {
 namespace clangd {
@@ -40,7 +41,7 @@ TEST(ErrorTest, Overloads) {
 }
 
 TEST(ErrorTest, Lifetimes) {
-  llvm::Optional<llvm::Error> Err;
+  std::optional<llvm::Error> Err;
   {
     // Check the error contains the value when error() was called.
     std::string S = "hello, world";

diff  --git a/clang-tools-extra/clangd/unittests/PathMappingTests.cpp b/clang-tools-extra/clangd/unittests/PathMappingTests.cpp
index 2da38de102767..2e26148495a01 100644
--- a/clang-tools-extra/clangd/unittests/PathMappingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/PathMappingTests.cpp
@@ -10,6 +10,7 @@
 #include "llvm/Support/JSON.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include <optional>
 #include <string>
 namespace clang {
 namespace clangd {
@@ -86,7 +87,7 @@ bool mapsProperly(llvm::StringRef Orig, llvm::StringRef Expected,
   llvm::Expected<PathMappings> Mappings = parsePathMappings(RawMappings);
   if (!Mappings)
     return false;
-  llvm::Optional<std::string> MappedPath = doPathMapping(Orig, Dir, *Mappings);
+  std::optional<std::string> MappedPath = doPathMapping(Orig, Dir, *Mappings);
   std::string Actual = MappedPath ? *MappedPath : Orig.str();
   EXPECT_STREQ(Expected.str().c_str(), Actual.c_str());
   return Expected == Actual;

diff  --git a/clang-tools-extra/clangd/unittests/support/CancellationTests.cpp b/clang-tools-extra/clangd/unittests/support/CancellationTests.cpp
index 074b01b996ae9..ed98d8f307487 100644
--- a/clang-tools-extra/clangd/unittests/support/CancellationTests.cpp
+++ b/clang-tools-extra/clangd/unittests/support/CancellationTests.cpp
@@ -5,6 +5,7 @@
 #include "gtest/gtest.h"
 #include <atomic>
 #include <memory>
+#include <optional>
 #include <thread>
 
 namespace clang {
@@ -20,7 +21,7 @@ TEST(CancellationTest, CancellationTest) {
 }
 
 TEST(CancellationTest, CancelerDiesContextLives) {
-  llvm::Optional<WithContext> ContextWithCancellation;
+  std::optional<WithContext> ContextWithCancellation;
   {
     auto Task = cancelableTask();
     ContextWithCancellation.emplace(std::move(Task.first));

diff  --git a/clang-tools-extra/pseudo/include/clang-pseudo/grammar/Grammar.h b/clang-tools-extra/pseudo/include/clang-pseudo/grammar/Grammar.h
index e13ae0e4ee5a1..a1c779a02d864 100644
--- a/clang-tools-extra/pseudo/include/clang-pseudo/grammar/Grammar.h
+++ b/clang-tools-extra/pseudo/include/clang-pseudo/grammar/Grammar.h
@@ -55,10 +55,10 @@
 #include "clang/Basic/TokenKinds.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseSet.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cstdint>
+#include <optional>
 #include <vector>
 
 namespace clang {
@@ -163,7 +163,7 @@ class Grammar {
   llvm::StringRef symbolName(SymbolID) const;
 
   // Lookup the SymbolID of the nonterminal symbol by Name.
-  llvm::Optional<SymbolID> findNonterminal(llvm::StringRef Name) const;
+  std::optional<SymbolID> findNonterminal(llvm::StringRef Name) const;
 
   // Dumps the whole grammar.
   std::string dump() const;

diff  --git a/clang-tools-extra/pseudo/lib/grammar/Grammar.cpp b/clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
index 8c1338cff0379..6df5565081fa8 100644
--- a/clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
+++ b/clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
@@ -13,6 +13,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/raw_ostream.h"
+#include <optional>
 
 namespace clang {
 namespace pseudo {
@@ -45,7 +46,7 @@ llvm::StringRef Grammar::symbolName(SymbolID SID) const {
   return T->Nonterminals[SID].Name;
 }
 
-llvm::Optional<SymbolID> Grammar::findNonterminal(llvm::StringRef Name) const {
+std::optional<SymbolID> Grammar::findNonterminal(llvm::StringRef Name) const {
   auto It = llvm::partition_point(
       T->Nonterminals,
       [&](const GrammarTable::Nonterminal &X) { return X.Name < Name; });


        


More information about the cfe-commits mailing list