[ORC-RT] Drop __orc_rt::string_view now that we have c++17.

b1356504e63 enabled the use of c++17 features in LLVM, which means that we can
drop the ORC runtime's placeholder string_view implemention in favor of
std::string_view.
GitOrigin-RevId: 1dcff823db9f4dd5c300507f679cdb2494287442
diff --git a/lib/orc/adt.h b/lib/orc/adt.h
index 64afd5d..a76aa5a 100644
--- a/lib/orc/adt.h
+++ b/lib/orc/adt.h
@@ -58,71 +58,10 @@
   size_type Size = 0;
 };
 
-/// A substitue for std::string_view (and llvm::StringRef).
-/// FIXME: Remove in favor of std::string_view once we have c++17.
-class string_view {
-public:
-  typedef char value_type;
-  typedef char *pointer;
-  typedef const char *const_pointer;
-  typedef char &reference;
-  typedef const char &const_reference;
-  typedef std::size_t size_type;
-  typedef std::ptrdiff_t difference_type;
-
-  typedef const_pointer const_iterator;
-  typedef const_iterator iterator;
-
-  constexpr string_view() noexcept = default;
-  constexpr string_view(const char *S, size_type Count)
-      : Data(S), Size(Count) {}
-  string_view(const char *S) : Data(S), Size(strlen(S)) {}
-  string_view(const std::string &S) : Data(S.data()), Size(S.size()) {}
-
-  constexpr const_iterator begin() const noexcept { return Data; }
-  constexpr const_iterator end() const noexcept { return Data + Size; }
-  constexpr const_pointer data() const noexcept { return Data; }
-  constexpr const_reference operator[](size_type idx) { return Data[idx]; }
-  constexpr size_type size() const noexcept { return Size; }
-  constexpr bool empty() const noexcept { return Size == 0; }
-
-  friend bool operator==(const string_view &LHS, const string_view &RHS) {
-    if (LHS.Size != RHS.Size)
-      return false;
-    if (LHS.Data == RHS.Data)
-      return true;
-    for (size_t I = 0; I != LHS.Size; ++I)
-      if (LHS.Data[I] != RHS.Data[I])
-        return false;
-    return true;
-  }
-
-  friend bool operator!=(const string_view &LHS, const string_view &RHS) {
-    return !(LHS == RHS);
-  }
-
-private:
-  const char *Data = nullptr;
-  size_type Size = 0;
-};
-
-inline std::ostream &operator<<(std::ostream &OS, string_view S) {
+inline std::ostream &operator<<(std::ostream &OS, std::string_view S) {
   return OS.write(S.data(), S.size());
 }
 
 } // end namespace __orc_rt
 
-namespace std {
-// Make string_view hashable.
-// FIXME: This can be removed (along with the string_view class) when we move
-// to C++17.
-template <> struct hash<__orc_rt::string_view> {
-  size_t operator()(const __orc_rt::string_view &S) const {
-    std::string Tmp(S.data(), S.size());
-    return hash<std::string>()(Tmp);
-  }
-};
-
-} // namespace std
-
 #endif // ORC_RT_ADT_H
diff --git a/lib/orc/elfnix_platform.cpp b/lib/orc/elfnix_platform.cpp
index 260731e..db692fd 100644
--- a/lib/orc/elfnix_platform.cpp
+++ b/lib/orc/elfnix_platform.cpp
@@ -109,9 +109,9 @@
   Error deregisterObjectSections(ELFNixPerObjectSectionsToRegister POSR);
 
   const char *dlerror();
-  void *dlopen(string_view Name, int Mode);
+  void *dlopen(std::string_view Name, int Mode);
   int dlclose(void *DSOHandle);
-  void *dlsym(void *DSOHandle, string_view Symbol);
+  void *dlsym(void *DSOHandle, std::string_view Symbol);
 
   int registerAtExit(void (*F)(void *), void *Arg, void *DSOHandle);
   void runAtExits(void *DSOHandle);
@@ -124,18 +124,18 @@
 
 private:
   PerJITDylibState *getJITDylibStateByHeaderAddr(void *DSOHandle);
-  PerJITDylibState *getJITDylibStateByName(string_view Path);
+  PerJITDylibState *getJITDylibStateByName(std::string_view Path);
   PerJITDylibState &
   getOrCreateJITDylibState(ELFNixJITDylibInitializers &MOJDIs);
 
   Error registerThreadDataSection(span<const char> ThreadDataSection);
 
   Expected<ExecutorAddr> lookupSymbolInJITDylib(void *DSOHandle,
-                                                string_view Symbol);
+                                                std::string_view Symbol);
 
   Expected<ELFNixJITDylibInitializerSequence>
-  getJITDylibInitializersByName(string_view Path);
-  Expected<void *> dlopenInitialize(string_view Path, int Mode);
+  getJITDylibInitializersByName(std::string_view Path);
+  Expected<void *> dlopenInitialize(std::string_view Path, int Mode);
   Error initializeJITDylib(ELFNixJITDylibInitializers &MOJDIs);
 
   static ELFNixPlatformRuntimeState *MOPS;
@@ -196,7 +196,7 @@
 
 const char *ELFNixPlatformRuntimeState::dlerror() { return DLFcnError.c_str(); }
 
-void *ELFNixPlatformRuntimeState::dlopen(string_view Path, int Mode) {
+void *ELFNixPlatformRuntimeState::dlopen(std::string_view Path, int Mode) {
   std::lock_guard<std::recursive_mutex> Lock(JDStatesMutex);
 
   // Use fast path if all JITDylibs are already loaded and don't require
@@ -222,7 +222,8 @@
   return 0;
 }
 
-void *ELFNixPlatformRuntimeState::dlsym(void *DSOHandle, string_view Symbol) {
+void *ELFNixPlatformRuntimeState::dlsym(void *DSOHandle,
+                                        std::string_view Symbol) {
   auto Addr = lookupSymbolInJITDylib(DSOHandle, Symbol);
   if (!Addr) {
     DLFcnError = toString(Addr.takeError());
@@ -282,7 +283,7 @@
 }
 
 ELFNixPlatformRuntimeState::PerJITDylibState *
-ELFNixPlatformRuntimeState::getJITDylibStateByName(string_view Name) {
+ELFNixPlatformRuntimeState::getJITDylibStateByName(std::string_view Name) {
   // FIXME: Avoid creating string copy here.
   auto I = JDNameToHeader.find(std::string(Name.data(), Name.size()));
   if (I == JDNameToHeader.end())
@@ -328,7 +329,7 @@
 
 Expected<ExecutorAddr>
 ELFNixPlatformRuntimeState::lookupSymbolInJITDylib(void *DSOHandle,
-                                                   string_view Sym) {
+                                                   std::string_view Sym) {
   Expected<ExecutorAddr> Result((ExecutorAddr()));
   if (auto Err = WrapperFunction<SPSExpected<SPSExecutorAddr>(
           SPSExecutorAddr, SPSString)>::call(&__orc_rt_elfnix_symbol_lookup_tag,
@@ -340,7 +341,8 @@
 }
 
 Expected<ELFNixJITDylibInitializerSequence>
-ELFNixPlatformRuntimeState::getJITDylibInitializersByName(string_view Path) {
+ELFNixPlatformRuntimeState::getJITDylibInitializersByName(
+    std::string_view Path) {
   Expected<ELFNixJITDylibInitializerSequence> Result(
       (ELFNixJITDylibInitializerSequence()));
   std::string PathStr(Path.data(), Path.size());
@@ -352,8 +354,8 @@
   return Result;
 }
 
-Expected<void *> ELFNixPlatformRuntimeState::dlopenInitialize(string_view Path,
-                                                              int Mode) {
+Expected<void *>
+ELFNixPlatformRuntimeState::dlopenInitialize(std::string_view Path, int Mode) {
   // Either our JITDylib wasn't loaded, or it or one of its dependencies allows
   // reinitialization. We need to call in to the JIT to see if there's any new
   // work pending.
diff --git a/lib/orc/macho_platform.cpp b/lib/orc/macho_platform.cpp
index a46e38b..7a74320 100644
--- a/lib/orc/macho_platform.cpp
+++ b/lib/orc/macho_platform.cpp
@@ -174,15 +174,15 @@
   Error deregisterThreadDataSection(span<const char> ThreadDataSection);
   Error registerObjectPlatformSections(
       ExecutorAddr HeaderAddr,
-      std::vector<std::pair<string_view, ExecutorAddrRange>> Secs);
+      std::vector<std::pair<std::string_view, ExecutorAddrRange>> Secs);
   Error deregisterObjectPlatformSections(
       ExecutorAddr HeaderAddr,
-      std::vector<std::pair<string_view, ExecutorAddrRange>> Secs);
+      std::vector<std::pair<std::string_view, ExecutorAddrRange>> Secs);
 
   const char *dlerror();
-  void *dlopen(string_view Name, int Mode);
+  void *dlopen(std::string_view Name, int Mode);
   int dlclose(void *DSOHandle);
-  void *dlsym(void *DSOHandle, string_view Symbol);
+  void *dlsym(void *DSOHandle, std::string_view Symbol);
 
   int registerAtExit(void (*F)(void *), void *Arg, void *DSOHandle);
   void runAtExits(JITDylibState &JDS);
@@ -194,10 +194,10 @@
 
 private:
   JITDylibState *getJITDylibStateByHeader(void *DSOHandle);
-  JITDylibState *getJITDylibStateByName(string_view Path);
+  JITDylibState *getJITDylibStateByName(std::string_view Path);
 
   Expected<ExecutorAddr> lookupSymbolInJITDylib(void *DSOHandle,
-                                                string_view Symbol);
+                                                std::string_view Symbol);
 
   static Error registerObjCSelectors(JITDylibState &JDS);
   static Error registerObjCClasses(JITDylibState &JDS);
@@ -206,7 +206,7 @@
   static Error registerSwift5Types(JITDylibState &JDS);
   static Error runModInits(JITDylibState &JDS);
 
-  Expected<void *> dlopenImpl(string_view Path, int Mode);
+  Expected<void *> dlopenImpl(std::string_view Path, int Mode);
   Error dlopenFull(JITDylibState &JDS);
   Error dlopenInitialize(JITDylibState &JDS, MachOJITDylibDepInfoMap &DepInfo);
 
@@ -220,7 +220,7 @@
 
   std::recursive_mutex JDStatesMutex;
   std::unordered_map<void *, JITDylibState> JDStates;
-  std::unordered_map<string_view, void *> JDNameToHeader;
+  std::unordered_map<std::string_view, void *> JDNameToHeader;
 
   std::mutex ThreadDataSectionsMutex;
   std::map<const char *, size_t> ThreadDataSections;
@@ -321,7 +321,7 @@
 
 Error MachOPlatformRuntimeState::registerObjectPlatformSections(
     ExecutorAddr HeaderAddr,
-    std::vector<std::pair<string_view, ExecutorAddrRange>> Secs) {
+    std::vector<std::pair<std::string_view, ExecutorAddrRange>> Secs) {
   ORC_RT_DEBUG({
     printdbg("MachOPlatform: Registering object sections for %p.\n",
              HeaderAddr.toPtr<void *>());
@@ -383,7 +383,7 @@
 
 Error MachOPlatformRuntimeState::deregisterObjectPlatformSections(
     ExecutorAddr HeaderAddr,
-    std::vector<std::pair<string_view, ExecutorAddrRange>> Secs) {
+    std::vector<std::pair<std::string_view, ExecutorAddrRange>> Secs) {
   // TODO: Make this more efficient? (maybe unnecessary if removal is rare?)
   // TODO: Add a JITDylib prepare-for-teardown operation that clears all
   //       registered sections, causing this function to take the fast-path.
@@ -442,7 +442,7 @@
 
 const char *MachOPlatformRuntimeState::dlerror() { return DLFcnError.c_str(); }
 
-void *MachOPlatformRuntimeState::dlopen(string_view Path, int Mode) {
+void *MachOPlatformRuntimeState::dlopen(std::string_view Path, int Mode) {
   ORC_RT_DEBUG({
     std::string S(Path.data(), Path.size());
     printdbg("MachOPlatform::dlopen(\"%s\")\n", S.c_str());
@@ -477,7 +477,8 @@
   return 0;
 }
 
-void *MachOPlatformRuntimeState::dlsym(void *DSOHandle, string_view Symbol) {
+void *MachOPlatformRuntimeState::dlsym(void *DSOHandle,
+                                       std::string_view Symbol) {
   auto Addr = lookupSymbolInJITDylib(DSOHandle, Symbol);
   if (!Addr) {
     DLFcnError = toString(Addr.takeError());
@@ -548,7 +549,7 @@
 }
 
 MachOPlatformRuntimeState::JITDylibState *
-MachOPlatformRuntimeState::getJITDylibStateByName(string_view Name) {
+MachOPlatformRuntimeState::getJITDylibStateByName(std::string_view Name) {
   // FIXME: Avoid creating string once we have C++20.
   auto I = JDNameToHeader.find(std::string(Name.data(), Name.size()));
   if (I != JDNameToHeader.end())
@@ -558,7 +559,7 @@
 
 Expected<ExecutorAddr>
 MachOPlatformRuntimeState::lookupSymbolInJITDylib(void *DSOHandle,
-                                                  string_view Sym) {
+                                                  std::string_view Sym) {
   Expected<ExecutorAddr> Result((ExecutorAddr()));
   if (auto Err = WrapperFunction<SPSExpected<SPSExecutorAddr>(
           SPSExecutorAddr, SPSString)>::call(&__orc_rt_macho_symbol_lookup_tag,
@@ -710,7 +711,7 @@
   return Error::success();
 }
 
-Expected<void *> MachOPlatformRuntimeState::dlopenImpl(string_view Path,
+Expected<void *> MachOPlatformRuntimeState::dlopenImpl(std::string_view Path,
                                                        int Mode) {
   // Try to find JITDylib state by name.
   auto *JDS = getJITDylibStateByName(Path);
@@ -976,7 +977,8 @@
                                   SPSMachOObjectPlatformSectionsMap)>::
       handle(ArgData, ArgSize,
              [](ExecutorAddr HeaderAddr,
-                std::vector<std::pair<string_view, ExecutorAddrRange>> &Secs) {
+                std::vector<std::pair<std::string_view, ExecutorAddrRange>>
+                    &Secs) {
                return MachOPlatformRuntimeState::get()
                    .registerObjectPlatformSections(HeaderAddr, std::move(Secs));
              })
@@ -990,7 +992,8 @@
                                   SPSMachOObjectPlatformSectionsMap)>::
       handle(ArgData, ArgSize,
              [](ExecutorAddr HeaderAddr,
-                std::vector<std::pair<string_view, ExecutorAddrRange>> &Secs) {
+                std::vector<std::pair<std::string_view, ExecutorAddrRange>>
+                    &Secs) {
                return MachOPlatformRuntimeState::get()
                    .deregisterObjectPlatformSections(HeaderAddr,
                                                      std::move(Secs));
diff --git a/lib/orc/run_program_wrapper.cpp b/lib/orc/run_program_wrapper.cpp
index d0f8853..bb4edc5 100644
--- a/lib/orc/run_program_wrapper.cpp
+++ b/lib/orc/run_program_wrapper.cpp
@@ -29,7 +29,7 @@
       handle(ArgData, ArgSize,
              [](const std::string &JITDylibName,
                 const std::string &EntrySymbolName,
-                const std::vector<string_view> &Args) {
+                const std::vector<std::string_view> &Args) {
                std::vector<std::unique_ptr<char[]>> ArgVStorage;
                ArgVStorage.reserve(Args.size());
                for (auto &Arg : Args) {
diff --git a/lib/orc/simple_packed_serialization.h b/lib/orc/simple_packed_serialization.h
index ec43130..33f7303 100644
--- a/lib/orc/simple_packed_serialization.h
+++ b/lib/orc/simple_packed_serialization.h
@@ -399,20 +399,20 @@
 ///
 /// Serialization is as for regular strings. Deserialization points directly
 /// into the blob.
-template <> class SPSSerializationTraits<SPSString, __orc_rt::string_view> {
+template <> class SPSSerializationTraits<SPSString, std::string_view> {
 public:
-  static size_t size(const __orc_rt::string_view &S) {
+  static size_t size(const std::string_view &S) {
     return SPSArgList<uint64_t>::size(static_cast<uint64_t>(S.size())) +
            S.size();
   }
 
-  static bool serialize(SPSOutputBuffer &OB, const __orc_rt::string_view &S) {
+  static bool serialize(SPSOutputBuffer &OB, const std::string_view &S) {
     if (!SPSArgList<uint64_t>::serialize(OB, static_cast<uint64_t>(S.size())))
       return false;
     return OB.write(S.data(), S.size());
   }
 
-  static bool deserialize(SPSInputBuffer &IB, __orc_rt::string_view &S) {
+  static bool deserialize(SPSInputBuffer &IB, std::string_view &S) {
     const char *Data = nullptr;
     uint64_t Size;
     if (!SPSArgList<uint64_t>::deserialize(IB, Size))
diff --git a/lib/orc/unittests/adt_test.cpp b/lib/orc/unittests/adt_test.cpp
index 117f7b5..6625a59 100644
--- a/lib/orc/unittests/adt_test.cpp
+++ b/lib/orc/unittests/adt_test.cpp
@@ -48,83 +48,3 @@
   for (unsigned I = 0; I != S.size(); ++I)
     EXPECT_EQ(S[I], A[I]) << "Unexpected span element value";
 }
-
-TEST(ADTTest, StringViewDefaultConstruction) {
-  string_view S;
-  EXPECT_TRUE(S.empty()) << "Default constructed span not empty";
-  EXPECT_EQ(S.size(), 0U) << "Default constructed span size not zero";
-  EXPECT_EQ(S.begin(), S.end()) << "Default constructed span begin != end";
-}
-
-TEST(ADTTest, StringViewConstructFromCharPtrAndSize) {
-  const char *Str = "abcdefg";
-  string_view S(Str, 5);
-  EXPECT_FALSE(S.empty()) << "string_view should be non-empty";
-  EXPECT_EQ(S.size(), 5U) << "string_view has unexpected size";
-  EXPECT_EQ(std::distance(S.begin(), S.end()), 5U)
-      << "Unexpected iterator range size";
-  EXPECT_EQ(S.data(), &Str[0]) << "string_view data has unexpected value";
-  for (unsigned I = 0; I != S.size(); ++I)
-    EXPECT_EQ(S[I], Str[I]) << "Unexpected string_view element value";
-}
-
-TEST(ADTTest, StringViewConstructFromCharPtr) {
-  const char *Str = "abcdefg";
-  size_t StrLen = strlen(Str);
-  string_view S(Str);
-
-  EXPECT_FALSE(S.empty()) << "string_view should be non-empty";
-  EXPECT_EQ(S.size(), StrLen) << "string_view has unexpected size";
-  EXPECT_EQ(static_cast<size_t>(std::distance(S.begin(), S.end())), StrLen)
-      << "Unexpected iterator range size";
-  EXPECT_EQ(S.data(), &Str[0]) << "string_view data has unexpected value";
-  for (unsigned I = 0; I != S.size(); ++I)
-    EXPECT_EQ(S[I], Str[I]) << "Unexpected string_view element value";
-}
-
-TEST(ADTTest, StringViewConstructFromStdString) {
-  std::string Str("abcdefg");
-  string_view S(Str);
-
-  EXPECT_FALSE(S.empty()) << "string_view should be non-empty";
-  EXPECT_EQ(S.size(), Str.size()) << "string_view has unexpected size";
-  EXPECT_EQ(static_cast<size_t>(std::distance(S.begin(), S.end())), Str.size())
-      << "Unexpected iterator range size";
-  EXPECT_EQ(S.data(), &Str[0]) << "string_view data has unexpected value";
-  for (unsigned I = 0; I != S.size(); ++I)
-    EXPECT_EQ(S[I], Str[I]) << "Unexpected string_view element value";
-}
-
-TEST(ADTTest, StringViewCopyConstructionAndAssignment) {
-  // Check that string_views are copy-constructible and copy-assignable.
-  std::string Str("abcdefg");
-  string_view Orig(Str);
-  string_view CopyConstructed(Orig);
-  string_view CopyAssigned = Orig;
-
-  EXPECT_EQ(Orig, CopyConstructed);
-  EXPECT_EQ(Orig, CopyAssigned);
-}
-
-TEST(ADTTest, StringViewEquality) {
-  EXPECT_EQ("", string_view());
-  EXPECT_FALSE(string_view("aab") == string_view("aac"));
-  EXPECT_FALSE(string_view("aab") != string_view("aab"));
-  EXPECT_NE(string_view("aab"), string_view("aac"));
-}
-
-TEST(ADTTest, StringViewOStreamOperator) {
-  std::string Str("abcdefg");
-  string_view S(Str);
-  std::ostringstream OSS;
-  OSS << S;
-
-  EXPECT_EQ(OSS.str(), Str);
-}
-
-TEST(ADTTest, StringViewHashable) {
-  std::string Str("abcdefg");
-  string_view S(Str);
-
-  EXPECT_EQ(std::hash<std::string>()(Str), std::hash<string_view>()(S));
-}
diff --git a/lib/orc/unittests/simple_packed_serialization_test.cpp b/lib/orc/unittests/simple_packed_serialization_test.cpp
index 92aa58a..3ecc20f 100644
--- a/lib/orc/unittests/simple_packed_serialization_test.cpp
+++ b/lib/orc/unittests/simple_packed_serialization_test.cpp
@@ -127,7 +127,7 @@
 
 TEST(SimplePackedSerializationTest, StringViewCharSequenceSerialization) {
   const char *HW = "Hello, world!";
-  blobSerializationRoundTrip<SPSString, string_view>(string_view(HW));
+  blobSerializationRoundTrip<SPSString, std::string_view>(std::string_view(HW));
 }
 
 TEST(SimplePackedSerializationTest, SpanSerialization) {