[llvm] 1da3a79 - JSON: llvm::Optional => std::optional

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 15 23:56:59 PST 2022


Author: Fangrui Song
Date: 2022-12-16T07:56:52Z
New Revision: 1da3a795fcf61a2c931d9320738db7d5c0444ce2

URL: https://github.com/llvm/llvm-project/commit/1da3a795fcf61a2c931d9320738db7d5c0444ce2
DIFF: https://github.com/llvm/llvm-project/commit/1da3a795fcf61a2c931d9320738db7d5c0444ce2.diff

LOG: JSON: llvm::Optional => std::optional

Many files are from language servers.

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 
    

Modified: 
    clang-tools-extra/clangd/ClangdLSPServer.cpp
    clang-tools-extra/clangd/ClangdLSPServer.h
    clang-tools-extra/clangd/ClangdServer.cpp
    clang-tools-extra/clangd/ClangdServer.h
    clang-tools-extra/clangd/Config.h
    clang-tools-extra/clangd/ConfigCompile.cpp
    clang-tools-extra/clangd/GlobalCompilationDatabase.h
    clang-tools-extra/clangd/Hover.cpp
    clang-tools-extra/clangd/Hover.h
    clang-tools-extra/clangd/InlayHints.cpp
    clang-tools-extra/clangd/InlayHints.h
    clang-tools-extra/clangd/Protocol.h
    clang-tools-extra/clangd/XRefs.cpp
    clang-tools-extra/clangd/XRefs.h
    clang-tools-extra/clangd/index/Index.h
    clang-tools-extra/clangd/tool/Check.cpp
    clang/lib/Basic/Sarif.cpp
    lldb/include/lldb/Target/TraceCursor.h
    lldb/include/lldb/Target/TraceDumper.h
    lldb/include/lldb/Utility/TraceGDBRemotePackets.h
    lldb/include/lldb/Utility/TraceIntelPTGDBRemotePackets.h
    lldb/source/Plugins/Process/Linux/IntelPTSingleBufferTrace.cpp
    lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
    lldb/source/Target/TraceDumper.cpp
    lldb/source/Utility/TraceGDBRemotePackets.cpp
    lldb/source/Utility/TraceIntelPTGDBRemotePackets.cpp
    lldb/tools/lldb-vscode/JSONUtils.cpp
    lldb/tools/lldb-vscode/RunInTerminal.cpp
    llvm/include/llvm/Support/JSON.h
    llvm/lib/Support/JSON.cpp
    llvm/unittests/Support/JSONTest.cpp
    mlir/lib/Tools/lsp-server-support/Protocol.cpp
    mlir/lib/Tools/lsp-server-support/Protocol.h
    mlir/lib/Tools/lsp-server-support/Transport.cpp
    mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp
    mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp
    mlir/lib/Tools/mlir-lsp-server/MLIRServer.h
    mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.cpp
    mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.cpp
    mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.h
    mlir/lib/Tools/mlir-pdll-lsp-server/Protocol.cpp
    mlir/lib/Tools/tblgen-lsp-server/LSPServer.cpp
    mlir/lib/Tools/tblgen-lsp-server/TableGenServer.cpp
    mlir/lib/Tools/tblgen-lsp-server/TableGenServer.h
    polly/lib/Exchange/JSONExporter.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 7159a694dad79..306ff3bcec925 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -57,10 +57,10 @@ constexpr trace::Metric LSPLatency("lsp_latency", trace::Metric::Distribution,
 
 // LSP defines file versions as numbers that increase.
 // ClangdServer treats them as opaque and therefore uses strings instead.
-std::string encodeVersion(llvm::Optional<int64_t> LSPVersion) {
+std::string encodeVersion(std::optional<int64_t> LSPVersion) {
   return LSPVersion ? llvm::to_string(*LSPVersion) : "";
 }
-llvm::Optional<int64_t> decodeVersion(llvm::StringRef Encoded) {
+std::optional<int64_t> decodeVersion(llvm::StringRef Encoded) {
   int64_t Result;
   if (llvm::to_integer(Encoded, Result, 10))
     return Result;
@@ -805,7 +805,7 @@ void ClangdLSPServer::onWorkspaceSymbol(
 }
 
 void ClangdLSPServer::onPrepareRename(const TextDocumentPositionParams &Params,
-                                      Callback<llvm::Optional<Range>> Reply) {
+                                      Callback<std::optional<Range>> Reply) {
   Server->prepareRename(
       Params.textDocument.uri.file(), Params.position, /*NewName*/ std::nullopt,
       Opts.Rename,
@@ -1143,7 +1143,7 @@ void ClangdLSPServer::onGoToDeclaration(
 
 void ClangdLSPServer::onSwitchSourceHeader(
     const TextDocumentIdentifier &Params,
-    Callback<llvm::Optional<URIForFile>> Reply) {
+    Callback<std::optional<URIForFile>> Reply) {
   Server->switchSourceHeader(
       Params.uri.file(),
       [Reply = std::move(Reply),
@@ -1164,10 +1164,10 @@ void ClangdLSPServer::onDocumentHighlight(
 }
 
 void ClangdLSPServer::onHover(const TextDocumentPositionParams &Params,
-                              Callback<llvm::Optional<Hover>> Reply) {
+                              Callback<std::optional<Hover>> Reply) {
   Server->findHover(Params.textDocument.uri.file(), Params.position,
-                    [Reply = std::move(Reply), this](
-                        llvm::Expected<llvm::Optional<HoverInfo>> H) mutable {
+                    [Reply = std::move(Reply),
+                     this](llvm::Expected<std::optional<HoverInfo>> H) mutable {
                       if (!H)
                         return Reply(H.takeError());
                       if (!*H)
@@ -1244,7 +1244,7 @@ void ClangdLSPServer::onResolveTypeHierarchy(
     Callback<llvm::json::Value> Reply) {
   auto Serialize =
       [Reply = std::move(Reply)](
-          llvm::Expected<llvm::Optional<TypeHierarchyItem>> Resp) mutable {
+          llvm::Expected<std::optional<TypeHierarchyItem>> Resp) mutable {
         if (!Resp) {
           Reply(Resp.takeError());
           return;
@@ -1268,7 +1268,7 @@ void ClangdLSPServer::onPrepareTypeHierarchy(
 
 void ClangdLSPServer::onSuperTypes(
     const ResolveTypeHierarchyItemParams &Params,
-    Callback<llvm::Optional<std::vector<TypeHierarchyItem>>> Reply) {
+    Callback<std::optional<std::vector<TypeHierarchyItem>>> Reply) {
   Server->superTypes(Params.item, std::move(Reply));
 }
 
@@ -1545,7 +1545,7 @@ void ClangdLSPServer::onMemoryUsage(const NoParams &,
 }
 
 void ClangdLSPServer::onAST(const ASTParams &Params,
-                            Callback<llvm::Optional<ASTNode>> CB) {
+                            Callback<std::optional<ASTNode>> CB) {
   Server->getAST(Params.textDocument.uri.file(), Params.range, std::move(CB));
 }
 

diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.h b/clang-tools-extra/clangd/ClangdLSPServer.h
index c942848f769d5..bbf72d8a54c76 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.h
+++ b/clang-tools-extra/clangd/ClangdLSPServer.h
@@ -94,7 +94,7 @@ class ClangdLSPServer : private ClangdServer::Callbacks,
   void onDocumentDidChange(const DidChangeTextDocumentParams &);
   void onDocumentDidClose(const DidCloseTextDocumentParams &);
   void onDocumentDidSave(const DidSaveTextDocumentParams &);
-  void onAST(const ASTParams &, Callback<llvm::Optional<ASTNode>>);
+  void onAST(const ASTParams &, Callback<std::optional<ASTNode>>);
   void onDocumentOnTypeFormatting(const DocumentOnTypeFormattingParams &,
                                   Callback<std::vector<TextEdit>>);
   void onDocumentRangeFormatting(const DocumentRangeFormattingParams &,
@@ -122,21 +122,21 @@ class ClangdLSPServer : private ClangdServer::Callbacks,
                             Callback<std::vector<Location>>);
   void onReference(const ReferenceParams &, Callback<std::vector<Location>>);
   void onSwitchSourceHeader(const TextDocumentIdentifier &,
-                            Callback<llvm::Optional<URIForFile>>);
+                            Callback<std::optional<URIForFile>>);
   void onDocumentHighlight(const TextDocumentPositionParams &,
                            Callback<std::vector<DocumentHighlight>>);
   void onFileEvent(const DidChangeWatchedFilesParams &);
   void onWorkspaceSymbol(const WorkspaceSymbolParams &,
                          Callback<std::vector<SymbolInformation>>);
   void onPrepareRename(const TextDocumentPositionParams &,
-                       Callback<llvm::Optional<Range>>);
+                       Callback<std::optional<Range>>);
   void onRename(const RenameParams &, Callback<WorkspaceEdit>);
   void onHover(const TextDocumentPositionParams &,
-               Callback<llvm::Optional<Hover>>);
+               Callback<std::optional<Hover>>);
   void onPrepareTypeHierarchy(const TypeHierarchyPrepareParams &,
                               Callback<std::vector<TypeHierarchyItem>>);
   void onSuperTypes(const ResolveTypeHierarchyItemParams &,
-                    Callback<llvm::Optional<std::vector<TypeHierarchyItem>>>);
+                    Callback<std::optional<std::vector<TypeHierarchyItem>>>);
   void onSubTypes(const ResolveTypeHierarchyItemParams &,
                   Callback<std::vector<TypeHierarchyItem>>);
   void onTypeHierarchy(const TypeHierarchyPrepareParams &,

diff  --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp
index 356d904c2a4af..b2b6c44744765 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -737,7 +737,7 @@ void ClangdServer::findDocumentHighlights(
 }
 
 void ClangdServer::findHover(PathRef File, Position Pos,
-                             Callback<llvm::Optional<HoverInfo>> CB) {
+                             Callback<std::optional<HoverInfo>> CB) {
   auto Action = [File = File.str(), Pos, CB = std::move(CB),
                  this](llvm::Expected<InputsAndAST> InpAST) mutable {
     if (!InpAST)
@@ -766,7 +766,7 @@ void ClangdServer::typeHierarchy(PathRef File, Position Pos, int Resolve,
 
 void ClangdServer::superTypes(
     const TypeHierarchyItem &Item,
-    Callback<llvm::Optional<std::vector<TypeHierarchyItem>>> CB) {
+    Callback<std::optional<std::vector<TypeHierarchyItem>>> CB) {
   WorkScheduler->run("typeHierarchy/superTypes", /*Path=*/"",
                      [=, CB = std::move(CB)]() mutable {
                        CB(clangd::superTypes(Item, Index));
@@ -782,7 +782,7 @@ void ClangdServer::subTypes(const TypeHierarchyItem &Item,
 
 void ClangdServer::resolveTypeHierarchy(
     TypeHierarchyItem Item, int Resolve, TypeHierarchyDirection Direction,
-    Callback<llvm::Optional<TypeHierarchyItem>> CB) {
+    Callback<std::optional<TypeHierarchyItem>> CB) {
   WorkScheduler->run(
       "Resolve Type Hierarchy", "", [=, CB = std::move(CB)]() mutable {
         clangd::resolveTypeHierarchy(Item, Resolve, Direction, Index);
@@ -810,7 +810,7 @@ void ClangdServer::incomingCalls(
                      });
 }
 
-void ClangdServer::inlayHints(PathRef File, llvm::Optional<Range> RestrictRange,
+void ClangdServer::inlayHints(PathRef File, std::optional<Range> RestrictRange,
                               Callback<std::vector<InlayHint>> CB) {
   auto Action = [RestrictRange(std::move(RestrictRange)),
                  CB = std::move(CB)](Expected<InputsAndAST> InpAST) mutable {
@@ -955,8 +955,8 @@ void ClangdServer::semanticHighlights(
                             Transient);
 }
 
-void ClangdServer::getAST(PathRef File, llvm::Optional<Range> R,
-                          Callback<llvm::Optional<ASTNode>> CB) {
+void ClangdServer::getAST(PathRef File, std::optional<Range> R,
+                          Callback<std::optional<ASTNode>> CB) {
   auto Action =
       [R, CB(std::move(CB))](llvm::Expected<InputsAndAST> Inputs) mutable {
         if (!Inputs)

diff  --git a/clang-tools-extra/clangd/ClangdServer.h b/clang-tools-extra/clangd/ClangdServer.h
index 11f952fd2c7b1..8ad6300ec294d 100644
--- a/clang-tools-extra/clangd/ClangdServer.h
+++ b/clang-tools-extra/clangd/ClangdServer.h
@@ -248,7 +248,7 @@ class ClangdServer {
 
   /// Get code hover for a given position.
   void findHover(PathRef File, Position Pos,
-                 Callback<llvm::Optional<HoverInfo>> CB);
+                 Callback<std::optional<HoverInfo>> CB);
 
   /// Get information about type hierarchy for a given position.
   void typeHierarchy(PathRef File, Position Pos, int Resolve,
@@ -256,7 +256,7 @@ class ClangdServer {
                      Callback<std::vector<TypeHierarchyItem>> CB);
   /// Get direct parents of a type hierarchy item.
   void superTypes(const TypeHierarchyItem &Item,
-                  Callback<llvm::Optional<std::vector<TypeHierarchyItem>>> CB);
+                  Callback<std::optional<std::vector<TypeHierarchyItem>>> CB);
   /// Get direct children of a type hierarchy item.
   void subTypes(const TypeHierarchyItem &Item,
                 Callback<std::vector<TypeHierarchyItem>> CB);
@@ -264,7 +264,7 @@ class ClangdServer {
   /// Resolve type hierarchy item in the given direction.
   void resolveTypeHierarchy(TypeHierarchyItem Item, int Resolve,
                             TypeHierarchyDirection Direction,
-                            Callback<llvm::Optional<TypeHierarchyItem>> CB);
+                            Callback<std::optional<TypeHierarchyItem>> CB);
 
   /// Get information about call hierarchy for a given position.
   void prepareCallHierarchy(PathRef File, Position Pos,
@@ -275,7 +275,7 @@ class ClangdServer {
                      Callback<std::vector<CallHierarchyIncomingCall>>);
 
   /// Resolve inlay hints for a given document.
-  void inlayHints(PathRef File, llvm::Optional<Range> RestrictRange,
+  void inlayHints(PathRef File, std::optional<Range> RestrictRange,
                   Callback<std::vector<InlayHint>>);
 
   /// Retrieve the top symbols from the workspace matching a query.
@@ -361,8 +361,8 @@ class ClangdServer {
                           Callback<std::vector<HighlightingToken>>);
 
   /// Describe the AST subtree for a piece of code.
-  void getAST(PathRef File, llvm::Optional<Range> R,
-              Callback<llvm::Optional<ASTNode>> CB);
+  void getAST(PathRef File, std::optional<Range> R,
+              Callback<std::optional<ASTNode>> CB);
 
   /// Runs an arbitrary action that has access to the AST of the specified file.
   /// The action will execute on one of ClangdServer's internal threads.

diff  --git a/clang-tools-extra/clangd/Config.h b/clang-tools-extra/clangd/Config.h
index 7de8a7af1373f..7123a900f4175 100644
--- a/clang-tools-extra/clangd/Config.h
+++ b/clang-tools-extra/clangd/Config.h
@@ -56,7 +56,7 @@ struct Config {
   struct CDBSearchSpec {
     enum { Ancestors, FixedDir, NoCDBSearch } Policy = Ancestors;
     // Absolute, native slashes, no trailing slash.
-    llvm::Optional<std::string> FixedCDBPath;
+    std::optional<std::string> FixedCDBPath;
   };
 
   /// Controls how the compile command for the current file is determined.

diff  --git a/clang-tools-extra/clangd/ConfigCompile.cpp b/clang-tools-extra/clangd/ConfigCompile.cpp
index d5a1ec74b0a00..84243409760dd 100644
--- a/clang-tools-extra/clangd/ConfigCompile.cpp
+++ b/clang-tools-extra/clangd/ConfigCompile.cpp
@@ -115,9 +115,9 @@ struct FragmentCompiler {
     return Result;
   }
 
-  llvm::Optional<std::string> makeAbsolute(Located<std::string> Path,
-                                           llvm::StringLiteral Description,
-                                           llvm::sys::path::Style Style) {
+  std::optional<std::string> makeAbsolute(Located<std::string> Path,
+                                          llvm::StringLiteral Description,
+                                          llvm::sys::path::Style Style) {
     if (llvm::sys::path::is_absolute(*Path))
       return *Path;
     if (FragmentDirectory.empty()) {

diff  --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.h b/clang-tools-extra/clangd/GlobalCompilationDatabase.h
index 5d1b20f562d7a..511fa6cb20142 100644
--- a/clang-tools-extra/clangd/GlobalCompilationDatabase.h
+++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.h
@@ -106,7 +106,7 @@ class DirectoryBasedGlobalCompilationDatabase
     std::function<Context(llvm::StringRef)> ContextProvider;
     // Only look for a compilation database in this one fixed directory.
     // FIXME: fold this into config/context mechanism.
-    llvm::Optional<Path> CompileCommandsDir;
+    std::optional<Path> CompileCommandsDir;
   };
 
   DirectoryBasedGlobalCompilationDatabase(const Options &Opts);

diff  --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp
index d08760f1cda3e..72c0841d34c64 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -642,7 +642,7 @@ HoverInfo getHoverContents(const NamedDecl *D, const PrintingPolicy &PP,
 }
 
 /// The standard defines __func__ as a "predefined variable".
-llvm::Optional<HoverInfo>
+std::optional<HoverInfo>
 getPredefinedExprHoverContents(const PredefinedExpr &PE, ASTContext &Ctx,
                                const PrintingPolicy &PP) {
   HoverInfo HI;
@@ -733,9 +733,9 @@ std::string typeAsDefinition(const HoverInfo::PrintedType &PType) {
   return Result;
 }
 
-llvm::Optional<HoverInfo> getThisExprHoverContents(const CXXThisExpr *CTE,
-                                                   ASTContext &ASTCtx,
-                                                   const PrintingPolicy &PP) {
+std::optional<HoverInfo> getThisExprHoverContents(const CXXThisExpr *CTE,
+                                                  ASTContext &ASTCtx,
+                                                  const PrintingPolicy &PP) {
   QualType OriginThisType = CTE->getType()->getPointeeType();
   QualType ClassType = declaredType(OriginThisType->getAsTagDecl());
   // For partial specialization class, origin `this` pointee type will be
@@ -811,9 +811,9 @@ llvm::StringLiteral getNameForExpr(const Expr *E) {
 
 // Generates hover info for `this` and evaluatable expressions.
 // FIXME: Support hover for literals (esp user-defined)
-llvm::Optional<HoverInfo> getHoverContents(const Expr *E, ParsedAST &AST,
-                                           const PrintingPolicy &PP,
-                                           const SymbolIndex *Index) {
+std::optional<HoverInfo> getHoverContents(const Expr *E, ParsedAST &AST,
+                                          const PrintingPolicy &PP,
+                                          const SymbolIndex *Index) {
   // There's not much value in hovering over "42" and getting a hover card
   // saying "42 is an int", similar for other literals.
   if (isLiteral(E))
@@ -840,7 +840,7 @@ llvm::Optional<HoverInfo> getHoverContents(const Expr *E, ParsedAST &AST,
 }
 
 // Generates hover info for attributes.
-llvm::Optional<HoverInfo> getHoverContents(const Attr *A, ParsedAST &AST) {
+std::optional<HoverInfo> getHoverContents(const Attr *A, ParsedAST &AST) {
   HoverInfo HI;
   HI.Name = A->getSpelling();
   if (A->hasScope())
@@ -1052,9 +1052,9 @@ const NamedDecl *pickDeclToUse(llvm::ArrayRef<const NamedDecl *> Candidates) {
 
 } // namespace
 
-llvm::Optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
-                                   const format::FormatStyle &Style,
-                                   const SymbolIndex *Index) {
+std::optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
+                                  const format::FormatStyle &Style,
+                                  const SymbolIndex *Index) {
   PrintingPolicy PP =
       getPrintingPolicy(AST.getASTContext().getPrintingPolicy());
   const SourceManager &SM = AST.getSourceManager();
@@ -1087,7 +1087,7 @@ llvm::Optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
   // for the left of the hovered token).
   CharSourceRange HighlightRange =
       TokensTouchingCursor.back().range(SM).toCharRange(SM);
-  llvm::Optional<HoverInfo> HI;
+  std::optional<HoverInfo> HI;
   // Macros and deducedtype only works on identifiers and auto/decltype keywords
   // respectively. Therefore they are only trggered on whichever works for them,
   // similar to SelectionTree::create().

diff  --git a/clang-tools-extra/clangd/Hover.h b/clang-tools-extra/clangd/Hover.h
index f9d83f64f142b..4f9950d7bd061 100644
--- a/clang-tools-extra/clangd/Hover.h
+++ b/clang-tools-extra/clangd/Hover.h
@@ -136,9 +136,9 @@ inline bool operator==(const HoverInfo::Param &LHS,
 }
 
 /// Get the hover information when hovering at \p Pos.
-llvm::Optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
-                                   const format::FormatStyle &Style,
-                                   const SymbolIndex *Index);
+std::optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
+                                  const format::FormatStyle &Style,
+                                  const SymbolIndex *Index);
 
 } // namespace clangd
 } // namespace clang

diff  --git a/clang-tools-extra/clangd/InlayHints.cpp b/clang-tools-extra/clangd/InlayHints.cpp
index b4c48f387f97b..07328b62e1fb3 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -192,7 +192,7 @@ getDesignators(const InitListExpr *Syn) {
 class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
 public:
   InlayHintVisitor(std::vector<InlayHint> &Results, ParsedAST &AST,
-                   const Config &Cfg, llvm::Optional<Range> RestrictRange)
+                   const Config &Cfg, std::optional<Range> RestrictRange)
       : Results(Results), AST(AST.getASTContext()), Tokens(AST.getTokens()),
         Cfg(Cfg), RestrictRange(std::move(RestrictRange)),
         MainFileID(AST.getSourceManager().getMainFileID()),
@@ -679,7 +679,7 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
   ASTContext &AST;
   const syntax::TokenBuffer &Tokens;
   const Config &Cfg;
-  llvm::Optional<Range> RestrictRange;
+  std::optional<Range> RestrictRange;
   FileID MainFileID;
   StringRef MainFileBuf;
   const HeuristicResolver *Resolver;
@@ -698,7 +698,7 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
 } // namespace
 
 std::vector<InlayHint> inlayHints(ParsedAST &AST,
-                                  llvm::Optional<Range> RestrictRange) {
+                                  std::optional<Range> RestrictRange) {
   std::vector<InlayHint> Results;
   const auto &Cfg = Config::current();
   if (!Cfg.InlayHints.Enabled)

diff  --git a/clang-tools-extra/clangd/InlayHints.h b/clang-tools-extra/clangd/InlayHints.h
index a3c16788435d1..6a0236a0ab08a 100644
--- a/clang-tools-extra/clangd/InlayHints.h
+++ b/clang-tools-extra/clangd/InlayHints.h
@@ -25,7 +25,7 @@ class ParsedAST;
 /// Compute and return inlay hints for a file.
 /// If RestrictRange is set, return only hints whose location is in that range.
 std::vector<InlayHint> inlayHints(ParsedAST &AST,
-                                  llvm::Optional<Range> RestrictRange);
+                                  std::optional<Range> RestrictRange);
 
 } // namespace clangd
 } // namespace clang

diff  --git a/clang-tools-extra/clangd/Protocol.h b/clang-tools-extra/clangd/Protocol.h
index c4ce97f7ff581..96815b7011cb1 100644
--- a/clang-tools-extra/clangd/Protocol.h
+++ b/clang-tools-extra/clangd/Protocol.h
@@ -147,7 +147,7 @@ struct VersionedTextDocumentIdentifier : public TextDocumentIdentifier {
   /// including undo/redo. The number doesn't need to be consecutive.
   ///
   /// clangd extension: versions are optional, and synthesized if missing.
-  llvm::Optional<std::int64_t> version;
+  std::optional<std::int64_t> version;
 };
 llvm::json::Value toJSON(const VersionedTextDocumentIdentifier &);
 bool fromJSON(const llvm::json::Value &, VersionedTextDocumentIdentifier &,
@@ -255,7 +255,7 @@ struct TextDocumentItem {
   /// change, including undo/redo.
   ///
   /// clangd extension: versions are optional, and synthesized if missing.
-  llvm::Optional<int64_t> version;
+  std::optional<int64_t> version;
 
   /// The content of the opened text document.
   std::string text;
@@ -534,7 +534,7 @@ struct InitializationOptions {
   // also set through the initialize request (initializationOptions field).
   ConfigurationSettings ConfigSettings;
 
-  llvm::Optional<std::string> compilationDatabasePath;
+  std::optional<std::string> compilationDatabasePath;
   // Additional flags to be included in the "fallback command" used when
   // the compilation database doesn't describe an opened file.
   // The command used will be approximately `clang $FILE $fallbackFlags`.
@@ -551,18 +551,18 @@ struct InitializeParams {
   /// the server. Is null if the process has not been started by another
   /// process. If the parent process is not alive then the server should exit
   /// (see exit notification) its process.
-  llvm::Optional<int> processId;
+  std::optional<int> processId;
 
   /// The rootPath of the workspace. Is null
   /// if no folder is open.
   ///
   /// @deprecated in favour of rootUri.
-  llvm::Optional<std::string> rootPath;
+  std::optional<std::string> rootPath;
 
   /// The rootUri of the workspace. Is null if no
   /// folder is open. If both `rootPath` and `rootUri` are set
   /// `rootUri` wins.
-  llvm::Optional<URIForFile> rootUri;
+  std::optional<URIForFile> rootUri;
 
   // User provided initialization options.
   // initializationOptions?: any;
@@ -573,7 +573,7 @@ struct InitializeParams {
   llvm::json::Object rawCapabilities;
 
   /// The initial trace setting. If omitted trace is disabled ('off').
-  llvm::Optional<TraceLevel> trace;
+  std::optional<TraceLevel> trace;
 
   /// User-provided initialization options.
   InitializationOptions initializationOptions;
@@ -708,10 +708,10 @@ bool fromJSON(const llvm::json::Value &, DidSaveTextDocumentParams &,
 
 struct TextDocumentContentChangeEvent {
   /// The range of the document that changed.
-  llvm::Optional<Range> range;
+  std::optional<Range> range;
 
   /// The length of the range that got replaced.
-  llvm::Optional<int> rangeLength;
+  std::optional<int> rangeLength;
 
   /// The new text of the range/document.
   std::string text;
@@ -732,7 +732,7 @@ struct DidChangeTextDocumentParams {
   /// version of the file. If not set, diagnostics are eventually consistent:
   /// either they will be provided for this version or some subsequent one.
   /// This is a clangd extension.
-  llvm::Optional<bool> wantDiagnostics;
+  std::optional<bool> wantDiagnostics;
 
   /// Force a complete rebuild of the file, ignoring all cached state. Slow!
   /// This is useful to defeat clangd's assumption that missing headers will
@@ -878,18 +878,18 @@ struct Diagnostic {
 
   /// An array of related diagnostic information, e.g. when symbol-names within
   /// a scope collide all definitions can be marked via this property.
-  llvm::Optional<std::vector<DiagnosticRelatedInformation>> relatedInformation;
+  std::optional<std::vector<DiagnosticRelatedInformation>> relatedInformation;
 
   /// The diagnostic's category. Can be omitted.
   /// An LSP extension that's used to send the name of the category over to the
   /// client. The category typically describes the compilation stage during
   /// which the issue was produced, e.g. "Semantic Issue" or "Parse Issue".
-  llvm::Optional<std::string> category;
+  std::optional<std::string> category;
 
   /// Clangd extension: code actions related to this diagnostic.
   /// Only with capability textDocument.publishDiagnostics.codeActionsInline.
   /// (These actions can also be obtained using textDocument/codeAction).
-  llvm::Optional<std::vector<CodeAction>> codeActions;
+  std::optional<std::vector<CodeAction>> codeActions;
 
   /// A data entry field that is preserved between a
   /// `textDocument/publishDiagnostics` notification
@@ -919,7 +919,7 @@ struct PublishDiagnosticsParams {
   /// An array of diagnostic information items.
   std::vector<Diagnostic> diagnostics;
   /// The version number of the document the diagnostics are published for.
-  llvm::Optional<int64_t> version;
+  std::optional<int64_t> version;
 };
 llvm::json::Value toJSON(const PublishDiagnosticsParams &);
 
@@ -1119,7 +1119,7 @@ struct WorkspaceSymbolParams {
 
   /// Max results to return, overriding global default. 0 means no limit.
   /// Clangd extension.
-  llvm::Optional<int> limit;
+  std::optional<int> limit;
 };
 bool fromJSON(const llvm::json::Value &, WorkspaceSymbolParams &,
               llvm::json::Path);
@@ -1131,7 +1131,7 @@ llvm::json::Value toJSON(const ApplyWorkspaceEditParams &);
 
 struct ApplyWorkspaceEditResponse {
   bool applied = true;
-  llvm::Optional<std::string> failureReason;
+  std::optional<std::string> failureReason;
 };
 bool fromJSON(const llvm::json::Value &, ApplyWorkspaceEditResponse &,
               llvm::json::Path);
@@ -1171,7 +1171,7 @@ struct CompletionParams : TextDocumentPositionParams {
 
   /// Max results to return, overriding global default. 0 means no limit.
   /// Clangd extension.
-  llvm::Optional<int> limit;
+  std::optional<int> limit;
 };
 bool fromJSON(const llvm::json::Value &, CompletionParams &, llvm::json::Path);
 
@@ -1223,7 +1223,7 @@ struct CompletionItem {
   std::string detail;
 
   /// A human-readable string that represents a doc-comment.
-  llvm::Optional<MarkupContent> documentation;
+  std::optional<MarkupContent> documentation;
 
   /// A string that should be used when comparing this item with other items.
   /// When `falsy` the label is used.
@@ -1408,7 +1408,7 @@ struct TypeHierarchyItem {
   SymbolKind kind;
 
   /// More detail for this item, e.g. the signature of a function.
-  llvm::Optional<std::string> detail;
+  std::optional<std::string> detail;
 
   /// The resource identifier of this item.
   URIForFile uri;
@@ -1425,7 +1425,7 @@ struct TypeHierarchyItem {
   struct ResolveParams {
     SymbolID symbolID;
     /// None means parents aren't resolved and empty is no parents.
-    llvm::Optional<std::vector<ResolveParams>> parents;
+    std::optional<std::vector<ResolveParams>> parents;
   };
   /// A data entry field that is preserved between a type hierarchy prepare and
   /// supertypes or subtypes requests. It could also be used to identify the
@@ -1438,13 +1438,13 @@ struct TypeHierarchyItem {
   bool deprecated = false;
 
   /// This is a clangd exntesion.
-  llvm::Optional<std::vector<TypeHierarchyItem>> parents;
+  std::optional<std::vector<TypeHierarchyItem>> parents;
 
   /// If this type hierarchy item is resolved, it contains the direct children
   /// of the current item. Could be empty if the item does not have any
   /// descendants. If not defined, the children have not been resolved.
   /// This is a clangd exntesion.
-  llvm::Optional<std::vector<TypeHierarchyItem>> children;
+  std::optional<std::vector<TypeHierarchyItem>> children;
 };
 llvm::json::Value toJSON(const TypeHierarchyItem::ResolveParams &);
 bool fromJSON(const TypeHierarchyItem::ResolveParams &);
@@ -1552,7 +1552,7 @@ struct InlayHintsParams {
   ///
   /// None is a clangd extension, which hints for computing hints on the whole
   /// file.
-  llvm::Optional<Range> range;
+  std::optional<Range> range;
 };
 bool fromJSON(const llvm::json::Value &, InlayHintsParams &, llvm::json::Path);
 
@@ -1831,7 +1831,7 @@ struct ASTParams {
   /// The position of the node to be dumped.
   /// The highest-level node that entirely contains the range will be returned.
   /// If no range is given, the root translation unit node will be returned.
-  llvm::Optional<Range> range;
+  std::optional<Range> range;
 };
 bool fromJSON(const llvm::json::Value &, ASTParams &, llvm::json::Path);
 

diff  --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp
index e06170500efe6..df82d8d9fa738 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -2060,7 +2060,7 @@ getTypeHierarchy(ParsedAST &AST, Position Pos, int ResolveLevels,
   return Results;
 }
 
-llvm::Optional<std::vector<TypeHierarchyItem>>
+std::optional<std::vector<TypeHierarchyItem>>
 superTypes(const TypeHierarchyItem &Item, const SymbolIndex *Index) {
   std::vector<TypeHierarchyItem> Results;
   if (!Item.data.parents)

diff  --git a/clang-tools-extra/clangd/XRefs.h b/clang-tools-extra/clangd/XRefs.h
index 7667bbd558326..c854b85a233ad 100644
--- a/clang-tools-extra/clangd/XRefs.h
+++ b/clang-tools-extra/clangd/XRefs.h
@@ -131,7 +131,7 @@ std::vector<TypeHierarchyItem> getTypeHierarchy(
 
 /// Returns direct parents of a TypeHierarchyItem using SymbolIDs stored inside
 /// the item.
-llvm::Optional<std::vector<TypeHierarchyItem>>
+std::optional<std::vector<TypeHierarchyItem>>
 superTypes(const TypeHierarchyItem &Item, const SymbolIndex *Index);
 /// Returns direct children of a TypeHierarchyItem.
 std::vector<TypeHierarchyItem> subTypes(const TypeHierarchyItem &Item,

diff  --git a/clang-tools-extra/clangd/index/Index.h b/clang-tools-extra/clangd/index/Index.h
index 3c032a5caeb57..5406b95eae04a 100644
--- a/clang-tools-extra/clangd/index/Index.h
+++ b/clang-tools-extra/clangd/index/Index.h
@@ -39,7 +39,7 @@ struct FuzzyFindRequest {
   bool AnyScope = false;
   /// The number of top candidates to return. The index may choose to
   /// return more than this, e.g. if it doesn't know which candidates are best.
-  llvm::Optional<uint32_t> Limit;
+  std::optional<uint32_t> Limit;
   /// If set to true, only symbols for completion support will be considered.
   bool RestrictForCodeCompletion = false;
   /// Contextually relevant files (e.g. the file we're code-completing in).

diff  --git a/clang-tools-extra/clangd/tool/Check.cpp b/clang-tools-extra/clangd/tool/Check.cpp
index ccd2ac2baa582..f2677d378ffcc 100644
--- a/clang-tools-extra/clangd/tool/Check.cpp
+++ b/clang-tools-extra/clangd/tool/Check.cpp
@@ -333,7 +333,7 @@ class Checker {
   }
 
   // Build Inlay Hints for the entire AST or the specified range
-  void buildInlayHints(llvm::Optional<Range> LineRange) {
+  void buildInlayHints(std::optional<Range> LineRange) {
     log("Building inlay hints");
     auto Hints = inlayHints(*AST, LineRange);
 
@@ -342,7 +342,7 @@ class Checker {
     }
   }
 
-  void buildSemanticHighlighting(llvm::Optional<Range> LineRange) {
+  void buildSemanticHighlighting(std::optional<Range> LineRange) {
     log("Building semantic highlighting");
     auto Highlights = getSemanticHighlightings(*AST);
     for (const auto HL : Highlights)
@@ -351,7 +351,7 @@ class Checker {
   }
 
   // Run AST-based features at each token in the file.
-  void testLocationFeatures(llvm::Optional<Range> LineRange) {
+  void testLocationFeatures(std::optional<Range> LineRange) {
     trace::Span Trace("testLocationFeatures");
     log("Testing features at each token (may be slow in large files)");
     auto &SM = AST->getSourceManager();
@@ -417,7 +417,7 @@ class Checker {
 
 bool check(llvm::StringRef File, const ThreadsafeFS &TFS,
            const ClangdLSPServer::Options &Opts) {
-  llvm::Optional<Range> LineRange;
+  std::optional<Range> LineRange;
   if (!CheckFileLines.empty()) {
     uint32_t Begin = 0, End = std::numeric_limits<uint32_t>::max();
     StringRef RangeStr(CheckFileLines);

diff  --git a/clang/lib/Basic/Sarif.cpp b/clang/lib/Basic/Sarif.cpp
index b3bee674225d2..a2f0faf2e38fa 100644
--- a/clang/lib/Basic/Sarif.cpp
+++ b/clang/lib/Basic/Sarif.cpp
@@ -307,7 +307,7 @@ void SarifDocumentWriter::endRun() {
     if (!A.MimeType.empty())
       Artifact["mimeType"] = A.MimeType;
     if (A.Offset.has_value())
-      Artifact["offset"] = A.Offset;
+      Artifact["offset"] = *A.Offset;
     Artifacts->push_back(json::Value(std::move(Artifact)));
   }
 

diff  --git a/lldb/include/lldb/Target/TraceCursor.h b/lldb/include/lldb/Target/TraceCursor.h
index dfb113fa8b900..87d5eed773aef 100644
--- a/lldb/include/lldb/Target/TraceCursor.h
+++ b/lldb/include/lldb/Target/TraceCursor.h
@@ -261,7 +261,7 @@ class TraceCursor {
   /// \return
   ///     The requested HW clock value, or \a std::nullopt if this information
   ///     is not available for the current item.
-  virtual llvm::Optional<uint64_t> GetHWClock() const = 0;
+  virtual std::optional<uint64_t> GetHWClock() const = 0;
 
   /// Get the approximate wall clock time in nanoseconds at which the current
   /// trace item was executed. Each trace plug-in has a 
diff erent definition for
@@ -280,7 +280,7 @@ class TraceCursor {
   ///     A string representing some metadata associated with a
   ///     \a eTraceEventSyncPoint event. \b std::nullopt if no metadata is
   ///     available.
-  virtual llvm::Optional<std::string> GetSyncPointMetadata() const = 0;
+  virtual std::optional<std::string> GetSyncPointMetadata() const = 0;
   /// \}
 
 protected:

diff  --git a/lldb/include/lldb/Target/TraceDumper.h b/lldb/include/lldb/Target/TraceDumper.h
index e5fdaaf2877e5..4a8fbf8fc7430 100644
--- a/lldb/include/lldb/Target/TraceDumper.h
+++ b/lldb/include/lldb/Target/TraceDumper.h
@@ -64,13 +64,13 @@ class TraceDumper {
     lldb::user_id_t id;
     lldb::addr_t load_address;
     llvm::Optional<double> timestamp;
-    llvm::Optional<uint64_t> hw_clock;
-    llvm::Optional<std::string> sync_point_metadata;
+    std::optional<uint64_t> hw_clock;
+    std::optional<std::string> sync_point_metadata;
     llvm::Optional<llvm::StringRef> error;
     llvm::Optional<lldb::TraceEvent> event;
     llvm::Optional<SymbolInfo> symbol_info;
     llvm::Optional<SymbolInfo> prev_symbol_info;
-    llvm::Optional<lldb::cpu_id_t> cpu_id;
+    std::optional<lldb::cpu_id_t> cpu_id;
   };
 
   /// An object representing a traced function call.

diff  --git a/lldb/include/lldb/Utility/TraceGDBRemotePackets.h b/lldb/include/lldb/Utility/TraceGDBRemotePackets.h
index 1b35b051e438e..96d3f70f4b5f9 100644
--- a/lldb/include/lldb/Utility/TraceGDBRemotePackets.h
+++ b/lldb/include/lldb/Utility/TraceGDBRemotePackets.h
@@ -46,7 +46,7 @@ struct TraceStartRequest {
 
   /// If \a std::nullopt, then this starts tracing the whole process. Otherwise,
   /// only tracing for the specified threads is enabled.
-  llvm::Optional<std::vector<lldb::tid_t>> tids;
+  std::optional<std::vector<lldb::tid_t>> tids;
 
   /// \return
   ///     \b true if \a tids is \a std::nullopt, i.e. whole process tracing.
@@ -74,7 +74,7 @@ struct TraceStopRequest {
   std::string type;
   /// If \a std::nullopt, then this stops tracing the whole process. Otherwise,
   /// only tracing for the specified threads is stopped.
-  llvm::Optional<std::vector<lldb::tid_t>> tids;
+  std::optional<std::vector<lldb::tid_t>> tids;
 };
 
 bool fromJSON(const llvm::json::Value &value, TraceStopRequest &packet,
@@ -132,8 +132,8 @@ llvm::json::Value toJSON(const TraceCpuState &packet);
 struct TraceGetStateResponse {
   std::vector<TraceThreadState> traced_threads;
   std::vector<TraceBinaryData> process_binary_data;
-  llvm::Optional<std::vector<TraceCpuState>> cpus;
-  llvm::Optional<std::vector<std::string>> warnings;
+  std::optional<std::vector<TraceCpuState>> cpus;
+  std::optional<std::vector<std::string>> warnings;
 
   void AddWarning(llvm::StringRef warning);
 };
@@ -152,9 +152,9 @@ struct TraceGetBinaryDataRequest {
   /// Identifier for the data.
   std::string kind;
   /// Optional tid if the data is related to a thread.
-  llvm::Optional<lldb::tid_t> tid;
+  std::optional<lldb::tid_t> tid;
   /// Optional core id if the data is related to a cpu core.
-  llvm::Optional<lldb::cpu_id_t> cpu_id;
+  std::optional<lldb::cpu_id_t> cpu_id;
 };
 
 bool fromJSON(const llvm::json::Value &value,

diff  --git a/lldb/include/lldb/Utility/TraceIntelPTGDBRemotePackets.h b/lldb/include/lldb/Utility/TraceIntelPTGDBRemotePackets.h
index 5930cd9970e76..dd3dddadd0d33 100644
--- a/lldb/include/lldb/Utility/TraceIntelPTGDBRemotePackets.h
+++ b/lldb/include/lldb/Utility/TraceIntelPTGDBRemotePackets.h
@@ -14,6 +14,7 @@
 #include "llvm/Support/JSON.h"
 
 #include <chrono>
+#include <optional>
 
 /// See docs/lldb-gdb-remote.txt for more information.
 ///
@@ -38,21 +39,21 @@ struct TraceIntelPTStartRequest : TraceStartRequest {
   bool enable_tsc;
 
   /// PSB packet period
-  llvm::Optional<uint64_t> psb_period;
+  std::optional<uint64_t> psb_period;
 
   /// Required when doing "process tracing".
   ///
   /// Limit in bytes on all the thread traces started by this "process trace"
   /// instance. When a thread is about to be traced and the limit would be hit,
   /// then a "tracing" stop event is triggered.
-  llvm::Optional<uint64_t> process_buffer_size_limit;
+  std::optional<uint64_t> process_buffer_size_limit;
 
   /// Whether to have a trace buffer per thread or per cpu cpu.
-  llvm::Optional<bool> per_cpu_tracing;
+  std::optional<bool> per_cpu_tracing;
 
   /// Disable the cgroup filtering that is automatically applied in per cpu
   /// mode.
-  llvm::Optional<bool> disable_cgroup_filtering;
+  std::optional<bool> disable_cgroup_filtering;
 
   bool IsPerCpuTracing() const;
 };
@@ -110,7 +111,7 @@ struct LinuxPerfZeroTscConversion {
 
 struct TraceIntelPTGetStateResponse : TraceGetStateResponse {
   /// The TSC to wall time conversion if it exists, otherwise \b nullptr.
-  llvm::Optional<LinuxPerfZeroTscConversion> tsc_perf_zero_conversion;
+  std::optional<LinuxPerfZeroTscConversion> tsc_perf_zero_conversion;
   bool using_cgroup_filtering = false;
 };
 

diff  --git a/lldb/source/Plugins/Process/Linux/IntelPTSingleBufferTrace.cpp b/lldb/source/Plugins/Process/Linux/IntelPTSingleBufferTrace.cpp
index a33108dbdb12b..269b7ca9dee9f 100644
--- a/lldb/source/Plugins/Process/Linux/IntelPTSingleBufferTrace.cpp
+++ b/lldb/source/Plugins/Process/Linux/IntelPTSingleBufferTrace.cpp
@@ -143,7 +143,8 @@ static Error CheckPsbPeriod(size_t psb_period) {
 
 #ifdef PERF_ATTR_SIZE_VER5
 static Expected<uint64_t>
-GeneratePerfEventConfigValue(bool enable_tsc, Optional<uint64_t> psb_period) {
+GeneratePerfEventConfigValue(bool enable_tsc,
+                             std::optional<uint64_t> psb_period) {
   uint64_t config = 0;
   // tsc is always supported
   if (enable_tsc) {
@@ -174,7 +175,7 @@ GeneratePerfEventConfigValue(bool enable_tsc, Optional<uint64_t> psb_period) {
 ///   or an \a llvm::Error otherwise.
 static Expected<perf_event_attr>
 CreateIntelPTPerfEventConfiguration(bool enable_tsc,
-                                    llvm::Optional<uint64_t> psb_period) {
+                                    std::optional<uint64_t> psb_period) {
   perf_event_attr attr;
   memset(&attr, 0, sizeof(attr));
   attr.size = sizeof(attr);

diff  --git a/lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp b/lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
index d50a738888eac..0d650aba4e6d3 100644
--- a/lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
+++ b/lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
@@ -102,7 +102,7 @@ lldb::addr_t TraceCursorIntelPT::GetLoadAddress() const {
   return m_decoded_thread_sp->GetInstructionLoadAddress(m_pos);
 }
 
-Optional<uint64_t> TraceCursorIntelPT::GetHWClock() const {
+std::optional<uint64_t> TraceCursorIntelPT::GetHWClock() const {
   if (const Optional<DecodedThread::TSCRange> &range = GetTSCRange())
     return range->tsc;
   return std::nullopt;
@@ -138,7 +138,7 @@ bool TraceCursorIntelPT::HasId(lldb::user_id_t id) const {
 
 user_id_t TraceCursorIntelPT::GetId() const { return m_pos; }
 
-Optional<std::string> TraceCursorIntelPT::GetSyncPointMetadata() const {
+std::optional<std::string> TraceCursorIntelPT::GetSyncPointMetadata() const {
   return formatv("offset = 0x{0:x}",
                  m_decoded_thread_sp->GetSyncPointOffsetByIndex(m_pos))
       .str();

diff  --git a/lldb/source/Target/TraceDumper.cpp b/lldb/source/Target/TraceDumper.cpp
index 1f581011959e0..6aa35e75911b8 100644
--- a/lldb/source/Target/TraceDumper.cpp
+++ b/lldb/source/Target/TraceDumper.cpp
@@ -20,7 +20,7 @@ using namespace llvm;
 
 /// \return
 ///   The given string or \b std::nullopt if it's empty.
-static Optional<const char *> ToOptionalString(const char *s) {
+static std::optional<const char *> ToOptionalString(const char *s) {
   if (!s)
     return std::nullopt;
   return s;
@@ -407,7 +407,7 @@ class OutputWriterJSON : public TraceDumper::OutputWriter {
       m_j.attribute("id", item.id);
       if (m_options.show_timestamps)
         m_j.attribute("timestamp_ns", item.timestamp
-                                          ? Optional<std::string>(
+                                          ? std::optional<std::string>(
                                                 std::to_string(*item.timestamp))
                                           : std::nullopt);
 

diff  --git a/lldb/source/Utility/TraceGDBRemotePackets.cpp b/lldb/source/Utility/TraceGDBRemotePackets.cpp
index 9879b7b2cb797..387c7ef9f876a 100644
--- a/lldb/source/Utility/TraceGDBRemotePackets.cpp
+++ b/lldb/source/Utility/TraceGDBRemotePackets.cpp
@@ -144,7 +144,7 @@ json::Value toJSON(const TraceGetBinaryDataRequest &packet) {
 bool fromJSON(const json::Value &value, TraceGetBinaryDataRequest &packet,
               Path path) {
   ObjectMapper o(value, path);
-  Optional<uint64_t> cpu_id;
+  std::optional<uint64_t> cpu_id;
   if (!(o && o.map("type", packet.type) && o.map("kind", packet.kind) &&
         o.map("tid", packet.tid) && o.map("cpuId", cpu_id)))
     return false;

diff  --git a/lldb/source/Utility/TraceIntelPTGDBRemotePackets.cpp b/lldb/source/Utility/TraceIntelPTGDBRemotePackets.cpp
index 7a0ed9c53c658..20e16b8ed3a6a 100644
--- a/lldb/source/Utility/TraceIntelPTGDBRemotePackets.cpp
+++ b/lldb/source/Utility/TraceIntelPTGDBRemotePackets.cpp
@@ -30,10 +30,10 @@ json::Value toJSON(const JSONUINT64 &uint64, bool hex) {
 }
 
 bool fromJSON(const json::Value &value, JSONUINT64 &uint64, Path path) {
-  if (Optional<uint64_t> val = value.getAsUINT64()) {
+  if (std::optional<uint64_t> val = value.getAsUINT64()) {
     uint64.value = *val;
     return true;
-  } else if (Optional<StringRef> val = value.getAsString()) {
+  } else if (std::optional<StringRef> val = value.getAsString()) {
     if (!val->getAsInteger(/*radix=*/0, uint64.value))
       return true;
     path.report("invalid string number");

diff  --git a/lldb/tools/lldb-vscode/JSONUtils.cpp b/lldb/tools/lldb-vscode/JSONUtils.cpp
index 53f1d509d08bd..5593d7be3b660 100644
--- a/lldb/tools/lldb-vscode/JSONUtils.cpp
+++ b/lldb/tools/lldb-vscode/JSONUtils.cpp
@@ -47,7 +47,7 @@ llvm::StringRef GetAsString(const llvm::json::Value &value) {
 
 // Gets a string from a JSON object using the key, or returns an empty string.
 llvm::StringRef GetString(const llvm::json::Object &obj, llvm::StringRef key) {
-  if (llvm::Optional<llvm::StringRef> value = obj.getString(key))
+  if (std::optional<llvm::StringRef> value = obj.getString(key))
     return *value;
   return llvm::StringRef();
 }

diff  --git a/lldb/tools/lldb-vscode/RunInTerminal.cpp b/lldb/tools/lldb-vscode/RunInTerminal.cpp
index 2126563d9e961..25260afa64be3 100644
--- a/lldb/tools/lldb-vscode/RunInTerminal.cpp
+++ b/lldb/tools/lldb-vscode/RunInTerminal.cpp
@@ -63,13 +63,13 @@ json::Value RunInTerminalMessageDidAttach::ToJSON() const {
 static Expected<RunInTerminalMessageUP>
 ParseJSONMessage(const json::Value &json) {
   if (const json::Object *obj = json.getAsObject()) {
-    if (Optional<StringRef> kind = obj->getString("kind")) {
+    if (std::optional<StringRef> kind = obj->getString("kind")) {
       if (*kind == "pid") {
-        if (Optional<int64_t> pid = obj->getInteger("pid"))
+        if (std::optional<int64_t> pid = obj->getInteger("pid"))
           return std::make_unique<RunInTerminalMessagePid>(
               static_cast<lldb::pid_t>(*pid));
       } else if (*kind == "error") {
-        if (Optional<StringRef> error = obj->getString("error"))
+        if (std::optional<StringRef> error = obj->getString("error"))
           return std::make_unique<RunInTerminalMessageError>(*error);
       } else if (*kind == "didAttach") {
         return std::make_unique<RunInTerminalMessageDidAttach>();

diff  --git a/llvm/include/llvm/Support/JSON.h b/llvm/include/llvm/Support/JSON.h
index 47b2a2fbe0823..9a5025360b9fd 100644
--- a/llvm/include/llvm/Support/JSON.h
+++ b/llvm/include/llvm/Support/JSON.h
@@ -85,7 +85,7 @@ std::string fixUTF8(llvm::StringRef S);
 class Array;
 class ObjectKey;
 class Value;
-template <typename T> Value toJSON(const llvm::Optional<T> &Opt);
+template <typename T> Value toJSON(const std::optional<T> &Opt);
 
 /// An Object is a JSON object, which maps strings to heterogenous JSON values.
 /// It simulates DenseMap<ObjectKey, Value>. ObjectKey is a maybe-owned string.
@@ -138,11 +138,11 @@ class Object {
   // Typed accessors return std::nullopt/nullptr if
   //   - the property doesn't exist
   //   - or it has the wrong type
-  llvm::Optional<std::nullptr_t> getNull(StringRef K) const;
-  llvm::Optional<bool> getBoolean(StringRef K) const;
-  llvm::Optional<double> getNumber(StringRef K) const;
-  llvm::Optional<int64_t> getInteger(StringRef K) const;
-  llvm::Optional<llvm::StringRef> getString(StringRef K) const;
+  std::optional<std::nullptr_t> getNull(StringRef K) const;
+  std::optional<bool> getBoolean(StringRef K) const;
+  std::optional<double> getNumber(StringRef K) const;
+  std::optional<int64_t> getInteger(StringRef K) const;
+  std::optional<llvm::StringRef> getString(StringRef K) const;
   const json::Object *getObject(StringRef K) const;
   json::Object *getObject(StringRef K);
   const json::Array *getArray(StringRef K) const;
@@ -234,14 +234,14 @@ inline bool operator!=(const Array &L, const Array &R) { return !(L == R); }
 ///   object  (json::Object)
 ///
 /// The kind can be queried directly, or implicitly via the typed accessors:
-///   if (Optional<StringRef> S = E.getAsString()
+///   if (std::optional<StringRef> S = E.getAsString()
 ///     assert(E.kind() == Value::String);
 ///
 /// Array and Object also have typed indexing accessors for easy traversal:
 ///   Expected<Value> E = parse(R"( {"options": {"font": "sans-serif"}} )");
 ///   if (Object* O = E->getAsObject())
 ///     if (Object* Opts = O->getObject("options"))
-///       if (Optional<StringRef> Font = Opts->getString("font"))
+///       if (std::optional<StringRef> Font = Opts->getString("font"))
 ///         assert(Opts->at("font").kind() == Value::String);
 ///
 /// === Converting JSON values to C++ types ===
@@ -262,13 +262,13 @@ inline bool operator!=(const Array &L, const Array &R) { return !(L == R); }
 ///   - std::string
 ///   - vector<T>, where T is deserializable
 ///   - map<string, T>, where T is deserializable
-///   - Optional<T>, where T is deserializable
+///   - std::optional<T>, where T is deserializable
 /// ObjectMapper can help writing fromJSON() functions for object types.
 ///
 /// For conversion in the other direction, the serializer function is:
 ///    toJSON(const T&) -> json::Value
 /// If this exists, then it also allows constructing Value from T, and can
-/// be used to serialize vector<T>, map<string, T>, and Optional<T>.
+/// be used to serialize vector<T>, map<string, T>, and std::optional<T>.
 ///
 /// === Serialization ===
 ///
@@ -402,17 +402,17 @@ class Value {
 
   // Typed accessors return std::nullopt/nullptr if the Value is not of this
   // type.
-  llvm::Optional<std::nullptr_t> getAsNull() const {
+  std::optional<std::nullptr_t> getAsNull() const {
     if (LLVM_LIKELY(Type == T_Null))
       return nullptr;
     return std::nullopt;
   }
-  llvm::Optional<bool> getAsBoolean() const {
+  std::optional<bool> getAsBoolean() const {
     if (LLVM_LIKELY(Type == T_Boolean))
       return as<bool>();
     return std::nullopt;
   }
-  llvm::Optional<double> getAsNumber() const {
+  std::optional<double> getAsNumber() const {
     if (LLVM_LIKELY(Type == T_Double))
       return as<double>();
     if (LLVM_LIKELY(Type == T_Integer))
@@ -422,7 +422,7 @@ class Value {
     return std::nullopt;
   }
   // Succeeds if the Value is a Number, and exactly representable as int64_t.
-  llvm::Optional<int64_t> getAsInteger() const {
+  std::optional<int64_t> getAsInteger() const {
     if (LLVM_LIKELY(Type == T_Integer))
       return as<int64_t>();
     if (LLVM_LIKELY(Type == T_Double)) {
@@ -434,7 +434,7 @@ class Value {
     }
     return std::nullopt;
   }
-  llvm::Optional<uint64_t> getAsUINT64() const {
+  std::optional<uint64_t> getAsUINT64() const {
     if (Type == T_UINT64)
       return as<uint64_t>();
     else if (Type == T_Integer) {
@@ -444,7 +444,7 @@ class Value {
     }
     return std::nullopt;
   }
-  llvm::Optional<llvm::StringRef> getAsString() const {
+  std::optional<llvm::StringRef> getAsString() const {
     if (Type == T_String)
       return llvm::StringRef(as<std::string>());
     if (LLVM_LIKELY(Type == T_StringRef))
@@ -763,7 +763,7 @@ inline bool fromJSON(const Value &E, std::nullptr_t &Out, Path P) {
   return false;
 }
 template <typename T>
-bool fromJSON(const Value &E, llvm::Optional<T> &Out, Path P) {
+bool fromJSON(const Value &E, std::optional<T> &Out, Path P) {
   if (E.getAsNull()) {
     Out = std::nullopt;
     return true;
@@ -801,8 +801,8 @@ bool fromJSON(const Value &E, std::map<std::string, T> &Out, Path P) {
   return false;
 }
 
-// Allow serialization of Optional<T> for supported T.
-template <typename T> Value toJSON(const llvm::Optional<T> &Opt) {
+// Allow serialization of std::optional<T> for supported T.
+template <typename T> Value toJSON(const std::optional<T> &Opt) {
   return Opt ? Value(*Opt) : Value(nullptr);
 }
 
@@ -842,7 +842,7 @@ class ObjectMapper {
   /// Maps a property to a field, if it exists.
   /// If the property exists and is invalid, reports an error.
   /// (Optional requires special handling, because missing keys are OK).
-  template <typename T> bool map(StringLiteral Prop, llvm::Optional<T> &Out) {
+  template <typename T> bool map(StringLiteral Prop, std::optional<T> &Out) {
     assert(*this && "Must check this is an object before calling map()");
     if (const Value *E = O->get(Prop))
       return fromJSON(*E, Out, P.field(Prop));

diff  --git a/llvm/lib/Support/JSON.cpp b/llvm/lib/Support/JSON.cpp
index 22219ac384218..0e7f7bf1d9990 100644
--- a/llvm/lib/Support/JSON.cpp
+++ b/llvm/lib/Support/JSON.cpp
@@ -37,27 +37,27 @@ const Value *Object::get(StringRef K) const {
     return nullptr;
   return &I->second;
 }
-llvm::Optional<std::nullptr_t> Object::getNull(StringRef K) const {
+std::optional<std::nullptr_t> Object::getNull(StringRef K) const {
   if (auto *V = get(K))
     return V->getAsNull();
   return std::nullopt;
 }
-llvm::Optional<bool> Object::getBoolean(StringRef K) const {
+std::optional<bool> Object::getBoolean(StringRef K) const {
   if (auto *V = get(K))
     return V->getAsBoolean();
   return std::nullopt;
 }
-llvm::Optional<double> Object::getNumber(StringRef K) const {
+std::optional<double> Object::getNumber(StringRef K) const {
   if (auto *V = get(K))
     return V->getAsNumber();
   return std::nullopt;
 }
-llvm::Optional<int64_t> Object::getInteger(StringRef K) const {
+std::optional<int64_t> Object::getInteger(StringRef K) const {
   if (auto *V = get(K))
     return V->getAsInteger();
   return std::nullopt;
 }
-llvm::Optional<llvm::StringRef> Object::getString(StringRef K) const {
+std::optional<llvm::StringRef> Object::getString(StringRef K) const {
   if (auto *V = get(K))
     return V->getAsString();
   return std::nullopt;

diff  --git a/llvm/unittests/Support/JSONTest.cpp b/llvm/unittests/Support/JSONTest.cpp
index bbd69f51112a4..ff425a0c20f3a 100644
--- a/llvm/unittests/Support/JSONTest.cpp
+++ b/llvm/unittests/Support/JSONTest.cpp
@@ -46,9 +46,9 @@ TEST(JSONTest, Constructors) {
   EXPECT_EQ(R"({"A":{"B":{}}})", s(Object{{"A", Object{{"B", Object{}}}}}));
   EXPECT_EQ(R"({"A":{"B":{"X":"Y"}}})",
             s(Object{{"A", Object{{"B", Object{{"X", "Y"}}}}}}));
-  EXPECT_EQ("null", s(llvm::Optional<double>()));
-  EXPECT_EQ("2.5", s(llvm::Optional<double>(2.5)));
-  EXPECT_EQ("[[2.5,null]]", s(std::vector<std::vector<llvm::Optional<double>>>{
+  EXPECT_EQ("null", s(std::optional<double>()));
+  EXPECT_EQ("2.5", s(std::optional<double>(2.5)));
+  EXPECT_EQ("[[2.5,null]]", s(std::vector<std::vector<std::optional<double>>>{
                                 {2.5, std::nullopt}}));
 }
 
@@ -266,9 +266,9 @@ TEST(JSONTest, Inspection) {
   EXPECT_FALSE(O->getNull("boolean"));
   EXPECT_TRUE(O->getNull("null"));
 
-  EXPECT_EQ(O->getNumber("number"), llvm::Optional<double>(2.78));
+  EXPECT_EQ(O->getNumber("number"), std::optional<double>(2.78));
   EXPECT_FALSE(O->getInteger("number"));
-  EXPECT_EQ(O->getString("string"), llvm::Optional<llvm::StringRef>("json"));
+  EXPECT_EQ(O->getString("string"), std::optional<llvm::StringRef>("json"));
   ASSERT_FALSE(O->getObject("missing"));
   ASSERT_FALSE(O->getObject("array"));
   ASSERT_TRUE(O->getObject("object"));
@@ -276,17 +276,17 @@ TEST(JSONTest, Inspection) {
 
   Array *A = O->getArray("array");
   ASSERT_TRUE(A);
-  EXPECT_EQ((*A)[1].getAsBoolean(), llvm::Optional<bool>(true));
+  EXPECT_EQ((*A)[1].getAsBoolean(), std::optional<bool>(true));
   ASSERT_TRUE((*A)[4].getAsArray());
   EXPECT_EQ(*(*A)[4].getAsArray(), (Array{1, 2, 3}));
   EXPECT_EQ((*(*A)[4].getAsArray())[1].getAsInteger(),
-            llvm::Optional<int64_t>(2));
+            std::optional<int64_t>(2));
   int I = 0;
   for (Value &E : *A) {
     if (I++ == 5) {
       ASSERT_TRUE(E.getAsObject());
       EXPECT_EQ(E.getAsObject()->getString("time"),
-                llvm::Optional<llvm::StringRef>("arrow"));
+                std::optional<llvm::StringRef>("arrow"));
     } else
       EXPECT_FALSE(E.getAsObject());
   }
@@ -298,8 +298,8 @@ TEST(JSONTest, Integers) {
     const char *Desc;
     Value Val;
     const char *Str;
-    llvm::Optional<int64_t> AsInt;
-    llvm::Optional<double> AsNumber;
+    std::optional<int64_t> AsInt;
+    std::optional<double> AsNumber;
   } TestCases[] = {
     {
         "Non-integer. Stored as double, not convertible.",
@@ -441,10 +441,10 @@ TEST(JSONTest, U64Integers) {
 // Sample struct with typical JSON-mapping rules.
 struct CustomStruct {
   CustomStruct() : B(false) {}
-  CustomStruct(std::string S, llvm::Optional<int> I, bool B)
+  CustomStruct(std::string S, std::optional<int> I, bool B)
       : S(S), I(I), B(B) {}
   std::string S;
-  llvm::Optional<int> I;
+  std::optional<int> I;
   bool B;
 };
 inline bool operator==(const CustomStruct &L, const CustomStruct &R) {
@@ -513,7 +513,7 @@ TEST(JSONTest, Deserialize) {
   EXPECT_FALSE(fromJSON(Object{{"str", 1}}, V, Root));
   EXPECT_EQ("expected string at CustomStruct.str", toString(Root.getError()));
 
-  // Optional<T> must parse as the correct type if present.
+  // std::optional<T> must parse as the correct type if present.
   EXPECT_FALSE(fromJSON(Object{{"str", "1"}, {"int", "string"}}, V, Root));
   EXPECT_EQ("expected integer at CustomStruct.int", toString(Root.getError()));
 

diff  --git a/mlir/lib/Tools/lsp-server-support/Protocol.cpp b/mlir/lib/Tools/lsp-server-support/Protocol.cpp
index 862afd4351c81..3fdb95a4c56d6 100644
--- a/mlir/lib/Tools/lsp-server-support/Protocol.cpp
+++ b/mlir/lib/Tools/lsp-server-support/Protocol.cpp
@@ -246,7 +246,7 @@ void URIForFile::registerSupportedScheme(StringRef scheme) {
 
 bool mlir::lsp::fromJSON(const llvm::json::Value &value, URIForFile &result,
                          llvm::json::Path path) {
-  if (Optional<StringRef> str = value.getAsString()) {
+  if (std::optional<StringRef> str = value.getAsString()) {
     llvm::Expected<URIForFile> expectedURI = URIForFile::fromURI(*str);
     if (!expectedURI) {
       path.report("unresolvable URI");
@@ -281,7 +281,7 @@ bool mlir::lsp::fromJSON(const llvm::json::Value &value,
   if (const llvm::json::Object *textDocument = o->getObject("textDocument")) {
     if (const llvm::json::Object *documentSymbol =
             textDocument->getObject("documentSymbol")) {
-      if (Optional<bool> hierarchicalSupport =
+      if (std::optional<bool> hierarchicalSupport =
               documentSymbol->getBoolean("hierarchicalDocumentSymbolSupport"))
         result.hierarchicalDocumentSymbol = *hierarchicalSupport;
     }
@@ -299,7 +299,7 @@ bool mlir::lsp::fromJSON(const llvm::json::Value &value,
 
 bool mlir::lsp::fromJSON(const llvm::json::Value &value, TraceLevel &result,
                          llvm::json::Path path) {
-  if (Optional<StringRef> str = value.getAsString()) {
+  if (std::optional<StringRef> str = value.getAsString()) {
     if (*str == "off") {
       result = TraceLevel::Off;
       return true;
@@ -701,7 +701,7 @@ raw_ostream &mlir::lsp::operator<<(raw_ostream &os, const TextEdit &value) {
 
 bool mlir::lsp::fromJSON(const llvm::json::Value &value,
                          CompletionItemKind &result, llvm::json::Path path) {
-  if (Optional<int64_t> intValue = value.getAsInteger()) {
+  if (std::optional<int64_t> intValue = value.getAsInteger()) {
     if (*intValue < static_cast<int>(CompletionItemKind::Text) ||
         *intValue > static_cast<int>(CompletionItemKind::TypeParameter))
       return false;

diff  --git a/mlir/lib/Tools/lsp-server-support/Protocol.h b/mlir/lib/Tools/lsp-server-support/Protocol.h
index 1fec0984a4f45..14e8ae3f8382c 100644
--- a/mlir/lib/Tools/lsp-server-support/Protocol.h
+++ b/mlir/lib/Tools/lsp-server-support/Protocol.h
@@ -186,7 +186,7 @@ struct InitializeParams {
   ClientCapabilities capabilities;
 
   /// The initial trace setting. If omitted trace is disabled ('off').
-  Optional<TraceLevel> trace;
+  std::optional<TraceLevel> trace;
 };
 
 /// Add support for JSON serialization.
@@ -469,10 +469,10 @@ struct TextDocumentContentChangeEvent {
                                std::string &contents);
 
   /// The range of the document that changed.
-  Optional<Range> range;
+  std::optional<Range> range;
 
   /// The length of the range that got replaced.
-  Optional<int> rangeLength;
+  std::optional<int> rangeLength;
 
   /// The new text of the range/document.
   std::string text;
@@ -675,13 +675,13 @@ struct Diagnostic {
 
   /// An array of related diagnostic information, e.g. when symbol-names within
   /// a scope collide all definitions can be marked via this property.
-  Optional<std::vector<DiagnosticRelatedInformation>> relatedInformation;
+  std::optional<std::vector<DiagnosticRelatedInformation>> relatedInformation;
 
   /// The diagnostic's category. Can be omitted.
   /// An LSP extension that's used to send the name of the category over to the
   /// client. The category typically describes the compilation stage during
   /// which the issue was produced, e.g. "Semantic Issue" or "Parse Issue".
-  Optional<std::string> category;
+  std::optional<std::string> category;
 };
 
 /// Add support for JSON serialization.
@@ -821,7 +821,7 @@ struct CompletionItem {
   std::string detail;
 
   /// A human-readable string that represents a doc-comment.
-  Optional<MarkupContent> documentation;
+  std::optional<MarkupContent> documentation;
 
   /// A string that should be used when comparing this item with other items.
   /// When `falsy` the label is used.
@@ -844,7 +844,7 @@ struct CompletionItem {
   ///
   /// Note: The range of the edit must be a single line range and it must
   /// contain the position at which completion has been requested.
-  Optional<TextEdit> textEdit;
+  std::optional<TextEdit> textEdit;
 
   /// An optional array of additional text edits that are applied when selecting
   /// this completion. Edits must not overlap with the main edit nor with

diff  --git a/mlir/lib/Tools/lsp-server-support/Transport.cpp b/mlir/lib/Tools/lsp-server-support/Transport.cpp
index b400e75555a46..ddb7622347f85 100644
--- a/mlir/lib/Tools/lsp-server-support/Transport.cpp
+++ b/mlir/lib/Tools/lsp-server-support/Transport.cpp
@@ -154,7 +154,7 @@ static llvm::json::Object encodeError(llvm::Error error) {
 /// Decode the given JSON object into an error.
 llvm::Error decodeError(const llvm::json::Object &o) {
   StringRef msg = o.getString("message").value_or("Unspecified error");
-  if (Optional<int64_t> code = o.getInteger("code"))
+  if (std::optional<int64_t> code = o.getInteger("code"))
     return llvm::make_error<LSPError>(msg.str(), ErrorCode(*code));
   return llvm::make_error<llvm::StringError>(llvm::inconvertibleErrorCode(),
                                              msg.str());
@@ -235,7 +235,7 @@ bool JSONTransport::handleMessage(llvm::json::Value msg,
   llvm::Optional<llvm::json::Value> id;
   if (llvm::json::Value *i = object->get("id"))
     id = std::move(*i);
-  Optional<StringRef> method = object->getString("method");
+  std::optional<StringRef> method = object->getString("method");
 
   // This is a response.
   if (!method) {

diff  --git a/mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp b/mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp
index da0ddf20e71c9..3deff0f2b6b5f 100644
--- a/mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp
+++ b/mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp
@@ -54,7 +54,7 @@ struct LSPServer {
   // Hover
 
   void onHover(const TextDocumentPositionParams &params,
-               Callback<Optional<Hover>> reply);
+               Callback<std::optional<Hover>> reply);
 
   //===--------------------------------------------------------------------===//
   // Document Symbols
@@ -217,7 +217,7 @@ void LSPServer::onReference(const ReferenceParams &params,
 // Hover
 
 void LSPServer::onHover(const TextDocumentPositionParams &params,
-                        Callback<Optional<Hover>> reply) {
+                        Callback<std::optional<Hover>> reply) {
   reply(server.findHover(params.textDocument.uri, params.position));
 }
 

diff  --git a/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp b/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp
index f93861e064457..7a679d844920c 100644
--- a/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp
+++ b/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp
@@ -263,9 +263,9 @@ struct MLIRDocument {
   // Hover
   //===--------------------------------------------------------------------===//
 
-  Optional<lsp::Hover> findHover(const lsp::URIForFile &uri,
-                                 const lsp::Position &hoverPos);
-  Optional<lsp::Hover>
+  std::optional<lsp::Hover> findHover(const lsp::URIForFile &uri,
+                                      const lsp::Position &hoverPos);
+  std::optional<lsp::Hover>
   buildHoverForOperation(SMRange hoverRange,
                          const AsmParserState::OperationDefinition &op);
   lsp::Hover buildHoverForOperationResult(SMRange hoverRange, Operation *op,
@@ -446,8 +446,9 @@ void MLIRDocument::findReferencesOf(const lsp::URIForFile &uri,
 // MLIRDocument: Hover
 //===----------------------------------------------------------------------===//
 
-Optional<lsp::Hover> MLIRDocument::findHover(const lsp::URIForFile &uri,
-                                             const lsp::Position &hoverPos) {
+std::optional<lsp::Hover>
+MLIRDocument::findHover(const lsp::URIForFile &uri,
+                        const lsp::Position &hoverPos) {
   SMLoc posLoc = hoverPos.getAsSMLoc(sourceMgr);
   SMRange hoverRange;
 
@@ -493,7 +494,7 @@ Optional<lsp::Hover> MLIRDocument::findHover(const lsp::URIForFile &uri,
   return std::nullopt;
 }
 
-Optional<lsp::Hover> MLIRDocument::buildHoverForOperation(
+std::optional<lsp::Hover> MLIRDocument::buildHoverForOperation(
     SMRange hoverRange, const AsmParserState::OperationDefinition &op) {
   lsp::Hover hover(lsp::Range(sourceMgr, hoverRange));
   llvm::raw_string_ostream os(hover.contents.value);
@@ -944,8 +945,8 @@ class MLIRTextFile {
                       std::vector<lsp::Location> &locations);
   void findReferencesOf(const lsp::URIForFile &uri, lsp::Position pos,
                         std::vector<lsp::Location> &references);
-  Optional<lsp::Hover> findHover(const lsp::URIForFile &uri,
-                                 lsp::Position hoverPos);
+  std::optional<lsp::Hover> findHover(const lsp::URIForFile &uri,
+                                      lsp::Position hoverPos);
   void findDocumentSymbols(std::vector<lsp::DocumentSymbol> &symbols);
   lsp::CompletionList getCodeCompletion(const lsp::URIForFile &uri,
                                         lsp::Position completePos);
@@ -1046,10 +1047,10 @@ void MLIRTextFile::findReferencesOf(const lsp::URIForFile &uri,
       chunk.adjustLocForChunkOffset(loc.range);
 }
 
-Optional<lsp::Hover> MLIRTextFile::findHover(const lsp::URIForFile &uri,
-                                             lsp::Position hoverPos) {
+std::optional<lsp::Hover> MLIRTextFile::findHover(const lsp::URIForFile &uri,
+                                                  lsp::Position hoverPos) {
   MLIRTextFileChunk &chunk = getChunkFor(hoverPos);
-  Optional<lsp::Hover> hoverInfo = chunk.document.findHover(uri, hoverPos);
+  std::optional<lsp::Hover> hoverInfo = chunk.document.findHover(uri, hoverPos);
 
   // Adjust any locations within this file for the offset of this chunk.
   if (chunk.lineOffset != 0 && hoverInfo && hoverInfo->range)
@@ -1250,8 +1251,8 @@ void lsp::MLIRServer::findReferencesOf(const URIForFile &uri,
     fileIt->second->findReferencesOf(uri, pos, references);
 }
 
-Optional<lsp::Hover> lsp::MLIRServer::findHover(const URIForFile &uri,
-                                                const Position &hoverPos) {
+std::optional<lsp::Hover> lsp::MLIRServer::findHover(const URIForFile &uri,
+                                                     const Position &hoverPos) {
   auto fileIt = impl->files.find(uri.file());
   if (fileIt != impl->files.end())
     return fileIt->second->findHover(uri, hoverPos);

diff  --git a/mlir/lib/Tools/mlir-lsp-server/MLIRServer.h b/mlir/lib/Tools/mlir-lsp-server/MLIRServer.h
index f7978708385c1..e9e7541466226 100644
--- a/mlir/lib/Tools/mlir-lsp-server/MLIRServer.h
+++ b/mlir/lib/Tools/mlir-lsp-server/MLIRServer.h
@@ -60,7 +60,8 @@ class MLIRServer {
 
   /// Find a hover description for the given hover position, or std::nullopt if
   /// one couldn't be found.
-  Optional<Hover> findHover(const URIForFile &uri, const Position &hoverPos);
+  std::optional<Hover> findHover(const URIForFile &uri,
+                                 const Position &hoverPos);
 
   /// Find all of the document symbols within the given file.
   void findDocumentSymbols(const URIForFile &uri,

diff  --git a/mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.cpp b/mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.cpp
index 8eeb55ff1b8bc..9b525cd53fc21 100644
--- a/mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.cpp
+++ b/mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.cpp
@@ -62,7 +62,7 @@ struct LSPServer {
   // Hover
 
   void onHover(const TextDocumentPositionParams &params,
-               Callback<Optional<Hover>> reply);
+               Callback<std::optional<Hover>> reply);
 
   //===--------------------------------------------------------------------===//
   // Document Symbols
@@ -92,7 +92,7 @@ struct LSPServer {
   // PDLL View Output
 
   void onPDLLViewOutput(const PDLLViewOutputParams &params,
-                        Callback<Optional<PDLLViewOutputResult>> reply);
+                        Callback<std::optional<PDLLViewOutputResult>> reply);
 
   //===--------------------------------------------------------------------===//
   // Fields
@@ -225,7 +225,7 @@ void LSPServer::onDocumentLink(const DocumentLinkParams &params,
 // Hover
 
 void LSPServer::onHover(const TextDocumentPositionParams &params,
-                        Callback<Optional<Hover>> reply) {
+                        Callback<std::optional<Hover>> reply) {
   reply(server.findHover(params.textDocument.uri, params.position));
 }
 
@@ -270,7 +270,7 @@ void LSPServer::onInlayHint(const InlayHintsParams &params,
 
 void LSPServer::onPDLLViewOutput(
     const PDLLViewOutputParams &params,
-    Callback<Optional<PDLLViewOutputResult>> reply) {
+    Callback<std::optional<PDLLViewOutputResult>> reply) {
   reply(server.getPDLLViewOutput(params.uri, params.kind));
 }
 

diff  --git a/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.cpp b/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.cpp
index b22c7c8eec053..84759aa084f6a 100644
--- a/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.cpp
+++ b/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.cpp
@@ -282,10 +282,10 @@ struct PDLDocument {
   // Hover
   //===--------------------------------------------------------------------===//
 
-  Optional<lsp::Hover> findHover(const lsp::URIForFile &uri,
-                                 const lsp::Position &hoverPos);
-  Optional<lsp::Hover> findHover(const ast::Decl *decl,
-                                 const SMRange &hoverRange);
+  std::optional<lsp::Hover> findHover(const lsp::URIForFile &uri,
+                                      const lsp::Position &hoverPos);
+  std::optional<lsp::Hover> findHover(const ast::Decl *decl,
+                                      const SMRange &hoverRange);
   lsp::Hover buildHoverForOpName(const ods::Operation *op,
                                  const SMRange &hoverRange);
   lsp::Hover buildHoverForVariable(const ast::VariableDecl *varDecl,
@@ -447,8 +447,9 @@ void PDLDocument::getDocumentLinks(const lsp::URIForFile &uri,
 // PDLDocument: Hover
 //===----------------------------------------------------------------------===//
 
-Optional<lsp::Hover> PDLDocument::findHover(const lsp::URIForFile &uri,
-                                            const lsp::Position &hoverPos) {
+std::optional<lsp::Hover>
+PDLDocument::findHover(const lsp::URIForFile &uri,
+                       const lsp::Position &hoverPos) {
   SMLoc posLoc = hoverPos.getAsSMLoc(sourceMgr);
 
   // Check for a reference to an include.
@@ -469,8 +470,8 @@ Optional<lsp::Hover> PDLDocument::findHover(const lsp::URIForFile &uri,
   return findHover(decl, hoverRange);
 }
 
-Optional<lsp::Hover> PDLDocument::findHover(const ast::Decl *decl,
-                                            const SMRange &hoverRange) {
+std::optional<lsp::Hover> PDLDocument::findHover(const ast::Decl *decl,
+                                                 const SMRange &hoverRange) {
   // Add hover for variables.
   if (const auto *varDecl = dyn_cast<ast::VariableDecl>(decl))
     return buildHoverForVariable(varDecl, hoverRange);
@@ -1388,8 +1389,8 @@ class PDLTextFile {
                         std::vector<lsp::Location> &references);
   void getDocumentLinks(const lsp::URIForFile &uri,
                         std::vector<lsp::DocumentLink> &links);
-  Optional<lsp::Hover> findHover(const lsp::URIForFile &uri,
-                                 lsp::Position hoverPos);
+  std::optional<lsp::Hover> findHover(const lsp::URIForFile &uri,
+                                      lsp::Position hoverPos);
   void findDocumentSymbols(std::vector<lsp::DocumentSymbol> &symbols);
   lsp::CompletionList getCodeCompletion(const lsp::URIForFile &uri,
                                         lsp::Position completePos);
@@ -1497,10 +1498,10 @@ void PDLTextFile::getDocumentLinks(const lsp::URIForFile &uri,
   }
 }
 
-Optional<lsp::Hover> PDLTextFile::findHover(const lsp::URIForFile &uri,
-                                            lsp::Position hoverPos) {
+std::optional<lsp::Hover> PDLTextFile::findHover(const lsp::URIForFile &uri,
+                                                 lsp::Position hoverPos) {
   PDLTextFileChunk &chunk = getChunkFor(hoverPos);
-  Optional<lsp::Hover> hoverInfo = chunk.document.findHover(uri, hoverPos);
+  std::optional<lsp::Hover> hoverInfo = chunk.document.findHover(uri, hoverPos);
 
   // Adjust any locations within this file for the offset of this chunk.
   if (chunk.lineOffset != 0 && hoverInfo && hoverInfo->range)
@@ -1762,8 +1763,8 @@ void lsp::PDLLServer::getDocumentLinks(
     return fileIt->second->getDocumentLinks(uri, documentLinks);
 }
 
-Optional<lsp::Hover> lsp::PDLLServer::findHover(const URIForFile &uri,
-                                                const Position &hoverPos) {
+std::optional<lsp::Hover> lsp::PDLLServer::findHover(const URIForFile &uri,
+                                                     const Position &hoverPos) {
   auto fileIt = impl->files.find(uri.file());
   if (fileIt != impl->files.end())
     return fileIt->second->findHover(uri, hoverPos);
@@ -1807,7 +1808,7 @@ void lsp::PDLLServer::getInlayHints(const URIForFile &uri, const Range &range,
                    inlayHints.end());
 }
 
-Optional<lsp::PDLLViewOutputResult>
+std::optional<lsp::PDLLViewOutputResult>
 lsp::PDLLServer::getPDLLViewOutput(const URIForFile &uri,
                                    PDLLViewOutputKind kind) {
   auto fileIt = impl->files.find(uri.file());

diff  --git a/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.h b/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.h
index 2542354d0e2ca..f77a68aa8681c 100644
--- a/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.h
+++ b/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.h
@@ -83,7 +83,8 @@ class PDLLServer {
 
   /// Find a hover description for the given hover position, or std::nullopt if
   /// one couldn't be found.
-  Optional<Hover> findHover(const URIForFile &uri, const Position &hoverPos);
+  std::optional<Hover> findHover(const URIForFile &uri,
+                                 const Position &hoverPos);
 
   /// Find all of the document symbols within the given file.
   void findDocumentSymbols(const URIForFile &uri,
@@ -103,8 +104,8 @@ class PDLLServer {
 
   /// Get the output of the given PDLL file, or std::nullopt if there is no
   /// valid output.
-  Optional<PDLLViewOutputResult> getPDLLViewOutput(const URIForFile &uri,
-                                                   PDLLViewOutputKind kind);
+  std::optional<PDLLViewOutputResult>
+  getPDLLViewOutput(const URIForFile &uri, PDLLViewOutputKind kind);
 
 private:
   struct Impl;

diff  --git a/mlir/lib/Tools/mlir-pdll-lsp-server/Protocol.cpp b/mlir/lib/Tools/mlir-pdll-lsp-server/Protocol.cpp
index ea0b77a022e84..27a1b712ae801 100644
--- a/mlir/lib/Tools/mlir-pdll-lsp-server/Protocol.cpp
+++ b/mlir/lib/Tools/mlir-pdll-lsp-server/Protocol.cpp
@@ -44,7 +44,7 @@ static bool mapOptOrNull(const llvm::json::Value &params,
 
 bool mlir::lsp::fromJSON(const llvm::json::Value &value,
                          PDLLViewOutputKind &result, llvm::json::Path path) {
-  if (Optional<StringRef> str = value.getAsString()) {
+  if (std::optional<StringRef> str = value.getAsString()) {
     if (*str == "ast") {
       result = PDLLViewOutputKind::AST;
       return true;

diff  --git a/mlir/lib/Tools/tblgen-lsp-server/LSPServer.cpp b/mlir/lib/Tools/tblgen-lsp-server/LSPServer.cpp
index 4995978259932..e51a2245077c5 100644
--- a/mlir/lib/Tools/tblgen-lsp-server/LSPServer.cpp
+++ b/mlir/lib/Tools/tblgen-lsp-server/LSPServer.cpp
@@ -60,7 +60,7 @@ struct LSPServer {
   // Hover
 
   void onHover(const TextDocumentPositionParams &params,
-               Callback<Optional<Hover>> reply);
+               Callback<std::optional<Hover>> reply);
 
   //===--------------------------------------------------------------------===//
   // Fields
@@ -177,7 +177,7 @@ void LSPServer::onDocumentLink(const DocumentLinkParams &params,
 // Hover
 
 void LSPServer::onHover(const TextDocumentPositionParams &params,
-                        Callback<Optional<Hover>> reply) {
+                        Callback<std::optional<Hover>> reply) {
   reply(server.findHover(params.textDocument.uri, params.position));
 }
 

diff  --git a/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.cpp b/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.cpp
index 5b7fea1fb3bd8..4bfee8435db43 100644
--- a/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.cpp
+++ b/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.cpp
@@ -354,8 +354,8 @@ class TableGenTextFile {
   // Hover
   //===--------------------------------------------------------------------===//
 
-  Optional<lsp::Hover> findHover(const lsp::URIForFile &uri,
-                                 const lsp::Position &hoverPos);
+  std::optional<lsp::Hover> findHover(const lsp::URIForFile &uri,
+                                      const lsp::Position &hoverPos);
   lsp::Hover buildHoverForRecord(const llvm::Record *record,
                                  const SMRange &hoverRange);
   lsp::Hover buildHoverForTemplateArg(const llvm::Record *record,
@@ -518,7 +518,7 @@ void TableGenTextFile::getDocumentLinks(const lsp::URIForFile &uri,
 // TableGenTextFile: Hover
 //===----------------------------------------------------------------------===//
 
-Optional<lsp::Hover>
+std::optional<lsp::Hover>
 TableGenTextFile::findHover(const lsp::URIForFile &uri,
                             const lsp::Position &hoverPos) {
   // Check for a reference to an include.
@@ -723,8 +723,9 @@ void lsp::TableGenServer::getDocumentLinks(
     return fileIt->second->getDocumentLinks(uri, documentLinks);
 }
 
-Optional<lsp::Hover> lsp::TableGenServer::findHover(const URIForFile &uri,
-                                                    const Position &hoverPos) {
+std::optional<lsp::Hover>
+lsp::TableGenServer::findHover(const URIForFile &uri,
+                               const Position &hoverPos) {
   auto fileIt = impl->files.find(uri.file());
   if (fileIt != impl->files.end())
     return fileIt->second->findHover(uri, hoverPos);

diff  --git a/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.h b/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.h
index 0565c27ef6ca0..dd994a3ddefb9 100644
--- a/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.h
+++ b/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.h
@@ -75,7 +75,8 @@ class TableGenServer {
 
   /// Find a hover description for the given hover position, or std::nullopt if
   /// one couldn't be found.
-  Optional<Hover> findHover(const URIForFile &uri, const Position &hoverPos);
+  std::optional<Hover> findHover(const URIForFile &uri,
+                                 const Position &hoverPos);
 
 private:
   struct Impl;

diff  --git a/polly/lib/Exchange/JSONExporter.cpp b/polly/lib/Exchange/JSONExporter.cpp
index 995af209035bb..6eafa5b10f0c2 100644
--- a/polly/lib/Exchange/JSONExporter.cpp
+++ b/polly/lib/Exchange/JSONExporter.cpp
@@ -288,7 +288,7 @@ static bool importSchedule(Scop &S, const json::Object &JScop,
       errs() << "Statement " << Index << " has no 'schedule' key.\n";
       return false;
     }
-    Optional<StringRef> Schedule =
+    std::optional<StringRef> Schedule =
         statements[Index].getAsObject()->getString("schedule");
     assert(Schedule.has_value() &&
            "Schedules that contain extension nodes require special handling.");


        


More information about the llvm-commits mailing list