[dawn] Replace `absl::Span` with C++20 `std::span`

Bug: 343500108
Change-Id: I6ad2363606bb83b470e39a8c162f648c55f41e8b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/239696
Reviewed-by: Loko Kung <lokokung@google.com>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
diff --git a/src/dawn/native/Adapter.cpp b/src/dawn/native/Adapter.cpp
index 69ab98d..8e03d0c 100644
--- a/src/dawn/native/Adapter.cpp
+++ b/src/dawn/native/Adapter.cpp
@@ -29,6 +29,7 @@
 
 #include <algorithm>
 #include <memory>
+#include <span>
 #include <string>
 #include <tuple>
 #include <unordered_set>
@@ -173,10 +174,10 @@
                        mPhysicalDevice->GetArchitectureName().length() +
                        mPhysicalDevice->GetName().length() +
                        mPhysicalDevice->GetDriverDescription().length();
-    absl::Span<char> outBuffer{new char[allocSize], allocSize};
+    std::span<char> outBuffer{new char[allocSize], allocSize};
 
     auto AddString = [&](const std::string& in, StringView* out) {
-        DAWN_ASSERT(in.length() <= outBuffer.length());
+        DAWN_ASSERT(in.length() <= outBuffer.size());
         memcpy(outBuffer.data(), in.data(), in.length());
         *out = {outBuffer.data(), in.length()};
         outBuffer = outBuffer.subspan(in.length());
diff --git a/src/dawn/native/BUILD.gn b/src/dawn/native/BUILD.gn
index 6dd278e..4f981a1 100644
--- a/src/dawn/native/BUILD.gn
+++ b/src/dawn/native/BUILD.gn
@@ -66,7 +66,6 @@
       "${dawn_root}/third_party/gn/abseil-cpp:flat_hash_map",
       "${dawn_root}/third_party/gn/abseil-cpp:flat_hash_set",
       "${dawn_root}/third_party/gn/abseil-cpp:inlined_vector",
-      "${dawn_root}/third_party/gn/abseil-cpp:span",
       "${dawn_root}/third_party/gn/abseil-cpp:str_format",
       "${dawn_root}/third_party/gn/abseil-cpp:strings",
     ]
diff --git a/src/dawn/native/opengl/DisplayEGL.cpp b/src/dawn/native/opengl/DisplayEGL.cpp
index f096e7e..eeebebf 100644
--- a/src/dawn/native/opengl/DisplayEGL.cpp
+++ b/src/dawn/native/opengl/DisplayEGL.cpp
@@ -124,7 +124,7 @@
     return mApiBit;
 }
 
-absl::Span<const wgpu::TextureFormat> DisplayEGL::GetPotentialSurfaceFormats() const {
+std::span<const wgpu::TextureFormat> DisplayEGL::GetPotentialSurfaceFormats() const {
     static constexpr wgpu::TextureFormat kFormatWhenConfigRequired[] = {
         wgpu::TextureFormat::RGBA8Unorm};
     static constexpr wgpu::TextureFormat kFormatsWithNoConfigContext[] = {
diff --git a/src/dawn/native/opengl/DisplayEGL.h b/src/dawn/native/opengl/DisplayEGL.h
index 13faf6f..f48d7c6 100644
--- a/src/dawn/native/opengl/DisplayEGL.h
+++ b/src/dawn/native/opengl/DisplayEGL.h
@@ -29,8 +29,8 @@
 #define SRC_DAWN_NATIVE_OPENGL_DISPLAYEGL_H_
 
 #include <memory>
+#include <span>
 
-#include "absl/types/span.h"  // TODO(343500108): Use std::span when we have C++20.
 #include "dawn/common/DynamicLib.h"
 #include "dawn/common/NonMovable.h"
 #include "dawn/common/Ref.h"
@@ -62,7 +62,7 @@
     EGLint GetAPIEnum() const;
     EGLint GetAPIBit() const;
 
-    absl::Span<const wgpu::TextureFormat> GetPotentialSurfaceFormats() const;
+    std::span<const wgpu::TextureFormat> GetPotentialSurfaceFormats() const;
 
     // Chooses an EGLConfig that works for that surface type and color format.
     EGLConfig ChooseConfig(EGLint surfaceType,
diff --git a/src/dawn/utils/BUILD.gn b/src/dawn/utils/BUILD.gn
index d009127..8628ace 100644
--- a/src/dawn/utils/BUILD.gn
+++ b/src/dawn/utils/BUILD.gn
@@ -141,7 +141,6 @@
   } else {
     public_deps = [
       "${dawn_root}/third_party/gn/abseil-cpp:flat_hash_map",
-      "${dawn_root}/third_party/gn/abseil-cpp:span",
       "${dawn_root}/third_party/gn/abseil-cpp:str_format",
       "${dawn_root}/third_party/gn/abseil-cpp:strings",
     ]
diff --git a/src/dawn/utils/CMakeLists.txt b/src/dawn/utils/CMakeLists.txt
index bc77549..a3befbc 100644
--- a/src/dawn/utils/CMakeLists.txt
+++ b/src/dawn/utils/CMakeLists.txt
@@ -131,7 +131,6 @@
     ${system_sources}
   DEPENDS
     dawn::dawn_common
-    absl::span
   PRIVATE_DEPENDS
     absl::strings
     absl::str_format_internal
diff --git a/src/dawn/utils/CommandLineParser.cpp b/src/dawn/utils/CommandLineParser.cpp
index eca9e03..31fb15b 100644
--- a/src/dawn/utils/CommandLineParser.cpp
+++ b/src/dawn/utils/CommandLineParser.cpp
@@ -64,7 +64,7 @@
 }
 
 CommandLineParser::OptionBase::ParseResult CommandLineParser::OptionBase::Parse(
-    absl::Span<const std::string_view> args) {
+    std::span<const std::string_view> args) {
     auto result = ParseImpl(args);
     if (result.success) {
         mSet = true;
@@ -88,7 +88,7 @@
 }
 
 CommandLineParser::OptionBase::ParseResult CommandLineParser::BoolOption::ParseImpl(
-    absl::Span<const std::string_view> args) {
+    std::span<const std::string_view> args) {
     // Explicit true
     if (!args.empty() && args.front() == "true") {
         if (IsSet()) {
@@ -131,7 +131,7 @@
 }
 
 CommandLineParser::OptionBase::ParseResult CommandLineParser::StringOption::ParseImpl(
-    absl::Span<const std::string_view> args) {
+    std::span<const std::string_view> args) {
     if (IsSet()) {
         return {false, args, "cannot be set multiple times"};
     }
@@ -151,7 +151,7 @@
 
 CommandLineParser::StringListOption::~StringListOption() = default;
 
-absl::Span<const std::string> CommandLineParser::StringListOption::GetValue() const {
+std::span<const std::string> CommandLineParser::StringListOption::GetValue() const {
     return mValue;
 }
 
@@ -164,7 +164,7 @@
 }
 
 CommandLineParser::OptionBase::ParseResult CommandLineParser::StringListOption::ParseImpl(
-    absl::Span<const std::string_view> args) {
+    std::span<const std::string_view> args) {
     if (args.empty()) {
         return {false, args, "expected a value"};
     }
@@ -193,7 +193,7 @@
 }
 
 // static
-std::string CommandLineParser::JoinConversionNames(absl::Span<const std::string_view> names,
+std::string CommandLineParser::JoinConversionNames(std::span<const std::string_view> names,
                                                    std::string_view separator) {
     return absl::StrJoin(names, separator);
 }
@@ -205,7 +205,7 @@
 // static
 const CommandLineParser::ParseOptions CommandLineParser::kDefaultParseOptions = {};
 
-CommandLineParser::ParseResult CommandLineParser::Parse(absl::Span<const std::string_view> args,
+CommandLineParser::ParseResult CommandLineParser::Parse(std::span<const std::string_view> args,
                                                         const ParseOptions& parseOptions) {
     // Build the map of name to option.
     absl::flat_hash_map<std::string, OptionBase*> nameToOption;
diff --git a/src/dawn/utils/CommandLineParser.h b/src/dawn/utils/CommandLineParser.h
index d386e41..30fc577 100644
--- a/src/dawn/utils/CommandLineParser.h
+++ b/src/dawn/utils/CommandLineParser.h
@@ -30,12 +30,12 @@
 
 #include <memory>
 #include <ostream>
+#include <span>
 #include <string>
 #include <string_view>
 #include <utility>
 #include <vector>
 
-#include "absl/types/span.h"  // TODO(343500108): Use std::span when we have C++20.
 #include "dawn/common/Assert.h"
 #include "dawn/common/NonMovable.h"
 
@@ -92,13 +92,13 @@
 
         struct ParseResult {
             bool success;
-            absl::Span<const std::string_view> remainingArgs = {};
+            std::span<const std::string_view> remainingArgs = {};
             std::string errorMessage = {};
         };
-        ParseResult Parse(absl::Span<const std::string_view> args);
+        ParseResult Parse(std::span<const std::string_view> args);
 
       protected:
-        virtual ParseResult ParseImpl(absl::Span<const std::string_view> args) = 0;
+        virtual ParseResult ParseImpl(std::span<const std::string_view> args) = 0;
 
         bool mSet = false;
         std::string mName;
@@ -130,7 +130,7 @@
         std::string GetParameter() const override;
 
       private:
-        ParseResult ParseImpl(absl::Span<const std::string_view> args) override;
+        ParseResult ParseImpl(std::span<const std::string_view> args) override;
         bool mValue = false;
     };
     BoolOption& AddBool(std::string_view name, std::string_view desc = {});
@@ -144,7 +144,7 @@
         std::string GetValue() const;
 
       private:
-        ParseResult ParseImpl(absl::Span<const std::string_view> args) override;
+        ParseResult ParseImpl(std::span<const std::string_view> args) override;
         std::string mValue;
     };
     StringOption& AddString(std::string_view name, std::string_view desc = {});
@@ -156,11 +156,11 @@
         StringListOption(std::string_view name, std::string_view desc);
         ~StringListOption() override;
 
-        absl::Span<const std::string> GetValue() const;
+        std::span<const std::string> GetValue() const;
         std::vector<std::string> GetOwnedValue() const;
 
       private:
-        ParseResult ParseImpl(absl::Span<const std::string_view> args) override;
+        ParseResult ParseImpl(std::span<const std::string_view> args) override;
         std::vector<std::string> mValue;
     };
     StringListOption& AddStringList(std::string_view name, std::string_view desc = {});
@@ -183,12 +183,12 @@
 
       private:
         std::string JoinNames(std::string_view separator) const;
-        OptionBase::ParseResult ParseImpl(absl::Span<const std::string_view> args) override;
+        OptionBase::ParseResult ParseImpl(std::span<const std::string_view> args) override;
         E mValue;
         bool mHasDefault;
         std::vector<std::pair<std::string_view, E>> mConversions;
     };
-    static std::string JoinConversionNames(absl::Span<const std::string_view> names,
+    static std::string JoinConversionNames(std::span<const std::string_view> names,
                                            std::string_view separator);
     template <typename E>
     EnumOption<E>& AddEnum(std::vector<std::pair<std::string_view, E>> conversions,
@@ -212,7 +212,7 @@
     static const ParseOptions kDefaultParseOptions;
 
     // Parse the arguments provided and set the options.
-    ParseResult Parse(absl::Span<const std::string_view> args,
+    ParseResult Parse(std::span<const std::string_view> args,
                       const ParseOptions& parseOptions = kDefaultParseOptions);
 
     // Small wrappers around the previous Parse for ease of use.
@@ -268,7 +268,7 @@
 
 template <typename E>
 CommandLineParser::OptionBase::ParseResult CommandLineParser::EnumOption<E>::ParseImpl(
-    absl::Span<const std::string_view> args) {
+    std::span<const std::string_view> args) {
     if (this->IsSet()) {
         return {false, args, "cannot be set multiple times"};
     }
diff --git a/src/dawn/wire/BUILD.gn b/src/dawn/wire/BUILD.gn
index 3ae02d9..264ba0a 100644
--- a/src/dawn/wire/BUILD.gn
+++ b/src/dawn/wire/BUILD.gn
@@ -72,7 +72,6 @@
     public_deps = [
       "${dawn_root}/third_party/gn/abseil-cpp:flat_hash_map",
       "${dawn_root}/third_party/gn/abseil-cpp:flat_hash_set",
-      "${dawn_root}/third_party/gn/abseil-cpp:span",
     ]
   }
 }
diff --git a/src/dawn/wire/client/Adapter.cpp b/src/dawn/wire/client/Adapter.cpp
index aa9917a..d3266c3 100644
--- a/src/dawn/wire/client/Adapter.cpp
+++ b/src/dawn/wire/client/Adapter.cpp
@@ -31,7 +31,6 @@
 #include <string>
 #include <utility>
 
-#include "absl/types/span.h"  // TODO(343500108): Use std::span when we have C++20.
 #include "dawn/common/Log.h"
 #include "dawn/common/StringViewUtils.h"
 #include "dawn/wire/client/Client.h"
@@ -280,10 +279,10 @@
     // Allocate space for all strings.
     size_t allocSize =
         mVendor.length() + mArchitecture.length() + mDeviceName.length() + mDescription.length();
-    absl::Span<char> outBuffer{new char[allocSize], allocSize};
+    std::span<char> outBuffer{new char[allocSize], allocSize};
 
     auto AddString = [&](const std::string& in, WGPUStringView* out) {
-        DAWN_ASSERT(in.length() <= outBuffer.length());
+        DAWN_ASSERT(in.length() <= outBuffer.size());
         memcpy(outBuffer.data(), in.data(), in.length());
         *out = {outBuffer.data(), in.length()};
         outBuffer = outBuffer.subspan(in.length());
diff --git a/src/dawn/wire/server/ServerAdapter.cpp b/src/dawn/wire/server/ServerAdapter.cpp
index f306409..df38f08 100644
--- a/src/dawn/wire/server/ServerAdapter.cpp
+++ b/src/dawn/wire/server/ServerAdapter.cpp
@@ -25,9 +25,9 @@
 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+#include <span>
 #include <vector>
 
-#include "absl/types/span.h"  // TODO(343500108): Use std::span when we have C++20.
 #include "dawn/common/StringViewUtils.h"
 #include "dawn/wire/SupportedFeatures.h"
 #include "dawn/wire/WireResult.h"
@@ -97,8 +97,8 @@
     // the request to preserve callback ordering.
     FreeMembers<WGPUSupportedFeatures> supportedFeatures(mProcs);
     mProcs.deviceGetFeatures(device, &supportedFeatures);
-    absl::Span<const WGPUFeatureName> features(supportedFeatures.features,
-                                               supportedFeatures.featureCount);
+    std::span<const WGPUFeatureName> features(supportedFeatures.features,
+                                              supportedFeatures.featureCount);
     for (WGPUFeatureName feature : features) {
         if (!IsFeatureSupported(feature)) {
             // Release the device.
diff --git a/src/dawn/wire/server/ServerInstance.cpp b/src/dawn/wire/server/ServerInstance.cpp
index bfd6c61..f272b06 100644
--- a/src/dawn/wire/server/ServerInstance.cpp
+++ b/src/dawn/wire/server/ServerInstance.cpp
@@ -27,7 +27,6 @@
 
 #include <algorithm>
 
-#include "absl/types/span.h"  // TODO(343500108): Use std::span when we have C++20.
 #include "dawn/common/StringViewUtils.h"
 #include "dawn/wire/SupportedFeatures.h"
 #include "dawn/wire/server/ObjectStorage.h"