Replace base::span with C++20 std::span

Migrate all remaining uses of base::span and base::make_span to C++20
std::span (<span>) and remove src/base/containers/span.h:
- Replace base::span<const Target*> with std::span<const Target* const>
  for read-only target dependency views.
- Use auto iterators and DCHECK(!path.empty()) in base::Value::SetPath
  since std::span::iterator is not guaranteed to be a raw pointer.
- Add missing #include <list> in command_path.cc previously pulled in
  transitively via base/containers/span.h.

Bug: None
Test: ninja -C out run_tests
Change-Id: Ia4f495898a5dd40a910b46d5121d348215eff8a5
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/29643
Reviewed-by: David Turner <digit@google.com>
Commit-Queue: Takuto Ikuta <tikuta@google.com>
diff --git a/src/base/containers/span.h b/src/base/containers/span.h
deleted file mode 100644
index de73fa1..0000000
--- a/src/base/containers/span.h
+++ /dev/null
@@ -1,455 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef BASE_CONTAINERS_SPAN_H_
-#define BASE_CONTAINERS_SPAN_H_
-
-#include <stddef.h>
-#include <stdint.h>
-
-#include <algorithm>
-#include <array>
-#include <iterator>
-#include <string_view>
-#include <type_traits>
-#include <utility>
-
-#include "base/logging.h"
-#include "base/stl_util.h"
-
-namespace base {
-
-// [views.constants]
-constexpr size_t dynamic_extent = static_cast<size_t>(-1);
-
-template <typename T, size_t Extent = dynamic_extent>
-class span;
-
-namespace internal {
-
-template <typename T>
-struct IsSpanImpl : std::false_type {};
-
-template <typename T, size_t Extent>
-struct IsSpanImpl<span<T, Extent>> : std::true_type {};
-
-template <typename T>
-using IsSpan = IsSpanImpl<std::decay_t<T>>;
-
-template <typename T>
-struct IsStdArrayImpl : std::false_type {};
-
-template <typename T, size_t N>
-struct IsStdArrayImpl<std::array<T, N>> : std::true_type {};
-
-template <typename T>
-using IsStdArray = IsStdArrayImpl<std::decay_t<T>>;
-
-template <typename T>
-using IsCArray = std::is_array<std::remove_reference_t<T>>;
-
-template <typename From, typename To>
-using IsLegalDataConversion = std::is_convertible<From (*)[], To (*)[]>;
-
-template <typename Container, typename T>
-using ContainerHasConvertibleData = IsLegalDataConversion<
-    std::remove_pointer_t<decltype(std::data(std::declval<Container>()))>,
-    T>;
-
-template <typename Container>
-using ContainerHasIntegralSize =
-    std::is_integral<decltype(std::size(std::declval<Container>()))>;
-
-template <typename From, size_t FromExtent, typename To, size_t ToExtent>
-using EnableIfLegalSpanConversion =
-    std::enable_if_t<(ToExtent == dynamic_extent || ToExtent == FromExtent) &&
-                     IsLegalDataConversion<From, To>::value>;
-
-// SFINAE check if Array can be converted to a span<T>.
-template <typename Array, size_t N, typename T, size_t Extent>
-using EnableIfSpanCompatibleArray =
-    std::enable_if_t<(Extent == dynamic_extent || Extent == N) &&
-                     ContainerHasConvertibleData<Array, T>::value>;
-
-// SFINAE check if Container can be converted to a span<T>.
-template <typename Container, typename T>
-using EnableIfSpanCompatibleContainer =
-    std::enable_if_t<!internal::IsSpan<Container>::value &&
-                     !internal::IsStdArray<Container>::value &&
-                     !internal::IsCArray<Container>::value &&
-                     ContainerHasConvertibleData<Container, T>::value &&
-                     ContainerHasIntegralSize<Container>::value>;
-
-}  // namespace internal
-
-// A span is a value type that represents an array of elements of type T. Since
-// it only consists of a pointer to memory with an associated size, it is very
-// light-weight. It is cheap to construct, copy, move and use spans, so that
-// users are encouraged to use it as a pass-by-value parameter. A span does not
-// own the underlying memory, so care must be taken to ensure that a span does
-// not outlive the backing store.
-//
-// span is somewhat analogous to std::string_view, but with arbitrary element
-// types, allowing mutation if T is non-const.
-//
-// span is implicitly convertible from C++ arrays, as well as most [1]
-// container-like types that provide a data() and size() method (such as
-// std::vector<T>). A mutable span<T> can also be implicitly converted to an
-// immutable span<const T>.
-//
-// Consider using a span for functions that take a data pointer and size
-// parameter: it allows the function to still act on an array-like type, while
-// allowing the caller code to be a bit more concise.
-//
-// For read-only data access pass a span<const T>: the caller can supply either
-// a span<const T> or a span<T>, while the callee will have a read-only view.
-// For read-write access a mutable span<T> is required.
-//
-// Without span:
-//   Read-Only:
-//     // std::string HexEncode(const uint8_t* data, size_t size);
-//     std::vector<uint8_t> data_buffer = GenerateData();
-//     std::string r = HexEncode(data_buffer.data(), data_buffer.size());
-//
-//  Mutable:
-//     // ssize_t SafeSNPrintf(char* buf, size_t N, const char* fmt, Args...);
-//     char str_buffer[100];
-//     SafeSNPrintf(str_buffer, sizeof(str_buffer), "Pi ~= %lf", 3.14);
-//
-// With span:
-//   Read-Only:
-//     // std::string HexEncode(base::span<const uint8_t> data);
-//     std::vector<uint8_t> data_buffer = GenerateData();
-//     std::string r = HexEncode(data_buffer);
-//
-//  Mutable:
-//     // ssize_t SafeSNPrintf(base::span<char>, const char* fmt, Args...);
-//     char str_buffer[100];
-//     SafeSNPrintf(str_buffer, "Pi ~= %lf", 3.14);
-//
-// Spans with "const" and pointers
-// -------------------------------
-//
-// Const and pointers can get confusing. Here are vectors of pointers and their
-// corresponding spans:
-//
-//   const std::vector<int*>        =>  base::span<int* const>
-//   std::vector<const int*>        =>  base::span<const int*>
-//   const std::vector<const int*>  =>  base::span<const int* const>
-//
-// Differences from the working group proposal
-// -------------------------------------------
-//
-// https://wg21.link/P0122 is the latest working group proposal, Chromium
-// currently implements R7. Differences between the proposal and the
-// implementation are documented in subsections below.
-//
-// Differences from [span.objectrep]:
-// - as_bytes() and as_writable_bytes() return spans of uint8_t instead of
-//   std::byte
-//
-// Differences in constants and types:
-// - index_type is aliased to size_t
-//
-// Differences from [span.sub]:
-// - using size_t instead of ptrdiff_t for indexing
-//
-// Differences from [span.obs]:
-// - using size_t instead of ptrdiff_t to represent size()
-//
-// Differences from [span.elem]:
-// - using size_t instead of ptrdiff_t for indexing
-//
-// Furthermore, all constructors and methods are marked noexcept due to the lack
-// of exceptions in Chromium.
-//
-// Due to the lack of class template argument deduction guides in C++14
-// appropriate make_span() utility functions are provided.
-
-// [span], class template span
-template <typename T, size_t Extent>
-class span {
- public:
-  using element_type = T;
-  using value_type = std::remove_cv_t<T>;
-  using index_type = size_t;
-  using difference_type = ptrdiff_t;
-  using pointer = T*;
-  using reference = T&;
-  using iterator = T*;
-  using const_iterator = const T*;
-  using reverse_iterator = std::reverse_iterator<iterator>;
-  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
-  static constexpr index_type extent = Extent;
-
-  // [span.cons], span constructors, copy, assignment, and destructor
-  constexpr span() noexcept : data_(nullptr), size_(0) {
-    static_assert(Extent == dynamic_extent || Extent == 0, "Invalid Extent");
-  }
-
-  constexpr span(T* data, size_t size) noexcept : data_(data), size_(size) {
-    CHECK(Extent == dynamic_extent || Extent == size);
-  }
-
-  // Artificially templatized to break ambiguity for span(ptr, 0).
-  template <typename = void>
-  constexpr span(T* begin, T* end) noexcept : span(begin, end - begin) {
-    // Note: CHECK_LE is not constexpr, hence regular CHECK must be used.
-    CHECK(begin <= end);
-  }
-
-  template <
-      size_t N,
-      typename = internal::EnableIfSpanCompatibleArray<T (&)[N], N, T, Extent>>
-  constexpr span(T (&array)[N]) noexcept : span(std::data(array), N) {}
-
-  template <
-      size_t N,
-      typename = internal::
-          EnableIfSpanCompatibleArray<std::array<value_type, N>&, N, T, Extent>>
-  constexpr span(std::array<value_type, N>& array) noexcept
-      : span(std::data(array), N) {}
-
-  template <size_t N,
-            typename = internal::EnableIfSpanCompatibleArray<
-                const std::array<value_type, N>&,
-                N,
-                T,
-                Extent>>
-  constexpr span(const std::array<value_type, N>& array) noexcept
-      : span(std::data(array), N) {}
-
-  // Conversion from a container that has compatible std::data() and integral
-  // std::size().
-  template <typename Container,
-            typename = internal::EnableIfSpanCompatibleContainer<Container&, T>>
-  constexpr span(Container& container) noexcept
-      : span(std::data(container), std::size(container)) {}
-
-  template <
-      typename Container,
-      typename = internal::EnableIfSpanCompatibleContainer<const Container&, T>>
-  span(const Container& container) noexcept
-      : span(std::data(container), std::size(container)) {}
-
-  constexpr span(const span& other) noexcept = default;
-
-  // Conversions from spans of compatible types and extents: this allows a
-  // span<T> to be seamlessly used as a span<const T>, but not the other way
-  // around. If extent is not dynamic, OtherExtent has to be equal to Extent.
-  template <
-      typename U,
-      size_t OtherExtent,
-      typename =
-          internal::EnableIfLegalSpanConversion<U, OtherExtent, T, Extent>>
-  constexpr span(const span<U, OtherExtent>& other)
-      : span(other.data(), other.size()) {}
-
-  constexpr span& operator=(const span& other) noexcept = default;
-  ~span() noexcept = default;
-
-  // [span.sub], span subviews
-  template <size_t Count>
-  constexpr span<T, Count> first() const noexcept {
-    static_assert(Extent == dynamic_extent || Count <= Extent,
-                  "Count must not exceed Extent");
-    CHECK(Extent != dynamic_extent || Count <= size());
-    return {data(), Count};
-  }
-
-  template <size_t Count>
-  constexpr span<T, Count> last() const noexcept {
-    static_assert(Extent == dynamic_extent || Count <= Extent,
-                  "Count must not exceed Extent");
-    CHECK(Extent != dynamic_extent || Count <= size());
-    return {data() + (size() - Count), Count};
-  }
-
-  template <size_t Offset, size_t Count = dynamic_extent>
-  constexpr span<T,
-                 (Count != dynamic_extent
-                      ? Count
-                      : (Extent != dynamic_extent ? Extent - Offset
-                                                  : dynamic_extent))>
-  subspan() const noexcept {
-    static_assert(Extent == dynamic_extent || Offset <= Extent,
-                  "Offset must not exceed Extent");
-    static_assert(Extent == dynamic_extent || Count == dynamic_extent ||
-                      Count <= Extent - Offset,
-                  "Count must not exceed Extent - Offset");
-    CHECK(Extent != dynamic_extent || Offset <= size());
-    CHECK(Extent != dynamic_extent || Count == dynamic_extent ||
-          Count <= size() - Offset);
-    return {data() + Offset, Count != dynamic_extent ? Count : size() - Offset};
-  }
-
-  constexpr span<T, dynamic_extent> first(size_t count) const noexcept {
-    // Note: CHECK_LE is not constexpr, hence regular CHECK must be used.
-    CHECK(count <= size());
-    return {data(), count};
-  }
-
-  constexpr span<T, dynamic_extent> last(size_t count) const noexcept {
-    // Note: CHECK_LE is not constexpr, hence regular CHECK must be used.
-    CHECK(count <= size());
-    return {data() + (size() - count), count};
-  }
-
-  constexpr span<T, dynamic_extent> subspan(
-      size_t offset,
-      size_t count = dynamic_extent) const noexcept {
-    // Note: CHECK_LE is not constexpr, hence regular CHECK must be used.
-    CHECK(offset <= size());
-    CHECK(count == dynamic_extent || count <= size() - offset);
-    return {data() + offset, count != dynamic_extent ? count : size() - offset};
-  }
-
-  // [span.obs], span observers
-  constexpr size_t size() const noexcept { return size_; }
-  constexpr size_t size_bytes() const noexcept { return size() * sizeof(T); }
-  constexpr bool empty() const noexcept { return size() == 0; }
-
-  // [span.elem], span element access
-  constexpr T& operator[](size_t idx) const noexcept {
-    // Note: CHECK_LT is not constexpr, hence regular CHECK must be used.
-    CHECK(idx < size());
-    return *(data() + idx);
-  }
-
-  constexpr T& operator()(size_t idx) const noexcept {
-    // Note: CHECK_LT is not constexpr, hence regular CHECK must be used.
-    CHECK(idx < size());
-    return *(data() + idx);
-  }
-
-  constexpr T* data() const noexcept { return data_; }
-
-  // [span.iter], span iterator support
-  constexpr iterator begin() const noexcept { return data(); }
-  constexpr iterator end() const noexcept { return data() + size(); }
-
-  constexpr const_iterator cbegin() const noexcept { return begin(); }
-  constexpr const_iterator cend() const noexcept { return end(); }
-
-  constexpr reverse_iterator rbegin() const noexcept {
-    return reverse_iterator(end());
-  }
-  constexpr reverse_iterator rend() const noexcept {
-    return reverse_iterator(begin());
-  }
-
-  constexpr const_reverse_iterator crbegin() const noexcept {
-    return const_reverse_iterator(cend());
-  }
-  constexpr const_reverse_iterator crend() const noexcept {
-    return const_reverse_iterator(cbegin());
-  }
-
- private:
-  T* data_;
-  size_t size_;
-};
-
-// span<T, Extent>::extent can not be declared inline prior to C++17, hence this
-// definition is required.
-template <class T, size_t Extent>
-constexpr size_t span<T, Extent>::extent;
-
-// [span.comparison], span comparison operators
-// Relational operators. Equality is a element-wise comparison.
-template <typename T, size_t X, typename U, size_t Y>
-constexpr bool operator==(span<T, X> lhs, span<U, Y> rhs) noexcept {
-  return std::equal(lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend());
-}
-
-template <typename T, size_t X, typename U, size_t Y>
-constexpr bool operator!=(span<T, X> lhs, span<U, Y> rhs) noexcept {
-  return !(lhs == rhs);
-}
-
-template <typename T, size_t X, typename U, size_t Y>
-constexpr bool operator<(span<T, X> lhs, span<U, Y> rhs) noexcept {
-  return std::lexicographical_compare(lhs.cbegin(), lhs.cend(), rhs.cbegin(),
-                                      rhs.cend());
-}
-
-template <typename T, size_t X, typename U, size_t Y>
-constexpr bool operator<=(span<T, X> lhs, span<U, Y> rhs) noexcept {
-  return !(rhs < lhs);
-}
-
-template <typename T, size_t X, typename U, size_t Y>
-constexpr bool operator>(span<T, X> lhs, span<U, Y> rhs) noexcept {
-  return rhs < lhs;
-}
-
-template <typename T, size_t X, typename U, size_t Y>
-constexpr bool operator>=(span<T, X> lhs, span<U, Y> rhs) noexcept {
-  return !(lhs < rhs);
-}
-
-// [span.objectrep], views of object representation
-template <typename T, size_t X>
-span<const uint8_t, (X == dynamic_extent ? dynamic_extent : sizeof(T) * X)>
-as_bytes(span<T, X> s) noexcept {
-  return {reinterpret_cast<const uint8_t*>(s.data()), s.size_bytes()};
-}
-
-template <typename T,
-          size_t X,
-          typename = std::enable_if_t<!std::is_const<T>::value>>
-span<uint8_t, (X == dynamic_extent ? dynamic_extent : sizeof(T) * X)>
-as_writable_bytes(span<T, X> s) noexcept {
-  return {reinterpret_cast<uint8_t*>(s.data()), s.size_bytes()};
-}
-
-// Type-deducing helpers for constructing a span.
-template <typename T>
-constexpr span<T> make_span(T* data, size_t size) noexcept {
-  return {data, size};
-}
-
-template <typename T>
-constexpr span<T> make_span(T* begin, T* end) noexcept {
-  return {begin, end};
-}
-
-template <typename T, size_t N>
-constexpr span<T, N> make_span(T (&array)[N]) noexcept {
-  return array;
-}
-
-template <typename T, size_t N>
-constexpr span<T, N> make_span(std::array<T, N>& array) noexcept {
-  return array;
-}
-
-template <typename T, size_t N>
-constexpr span<const T, N> make_span(const std::array<T, N>& array) noexcept {
-  return array;
-}
-
-template <typename Container,
-          typename T = typename Container::value_type,
-          typename = internal::EnableIfSpanCompatibleContainer<Container&, T>>
-constexpr span<T> make_span(Container& container) noexcept {
-  return container;
-}
-
-template <
-    typename Container,
-    typename T = const typename Container::value_type,
-    typename = internal::EnableIfSpanCompatibleContainer<const Container&, T>>
-constexpr span<T> make_span(const Container& container) noexcept {
-  return container;
-}
-
-template <typename T, size_t X>
-constexpr span<T, X> make_span(const span<T, X>& span) noexcept {
-  return span;
-}
-
-}  // namespace base
-
-#endif  // BASE_CONTAINERS_SPAN_H_
diff --git a/src/base/values.cc b/src/base/values.cc
index f3e9e66..132b45a 100644
--- a/src/base/values.cc
+++ b/src/base/values.cc
@@ -299,17 +299,17 @@
   return const_cast<Value*>(const_cast<const Value*>(this)->FindPath(path));
 }
 
-Value* Value::FindPath(span<const std::string_view> path) {
+Value* Value::FindPath(std::span<const std::string_view> path) {
   return const_cast<Value*>(const_cast<const Value*>(this)->FindPath(path));
 }
 
 const Value* Value::FindPath(
     std::initializer_list<std::string_view> path) const {
   DCHECK_GE(path.size(), 2u) << "Use FindKey() for a path of length 1.";
-  return FindPath(make_span(path.begin(), path.size()));
+  return FindPath(std::span<const std::string_view>(path.begin(), path.size()));
 }
 
-const Value* Value::FindPath(span<const std::string_view> path) const {
+const Value* Value::FindPath(std::span<const std::string_view> path) const {
   const Value* cur = this;
   for (const std::string_view& component : path) {
     if (!cur->is_dict() || (cur = cur->FindKey(component)) == nullptr)
@@ -324,7 +324,8 @@
       const_cast<const Value*>(this)->FindPathOfType(path, type));
 }
 
-Value* Value::FindPathOfType(span<const std::string_view> path, Type type) {
+Value* Value::FindPathOfType(std::span<const std::string_view> path,
+                             Type type) {
   return const_cast<Value*>(
       const_cast<const Value*>(this)->FindPathOfType(path, type));
 }
@@ -332,10 +333,11 @@
 const Value* Value::FindPathOfType(std::initializer_list<std::string_view> path,
                                    Type type) const {
   DCHECK_GE(path.size(), 2u) << "Use FindKeyOfType() for a path of length 1.";
-  return FindPathOfType(make_span(path.begin(), path.size()), type);
+  return FindPathOfType(
+      std::span<const std::string_view>(path.begin(), path.size()), type);
 }
 
-const Value* Value::FindPathOfType(span<const std::string_view> path,
+const Value* Value::FindPathOfType(std::span<const std::string_view> path,
                                    Type type) const {
   const Value* result = FindPath(path);
   if (!result || result->type() != type)
@@ -346,16 +348,17 @@
 Value* Value::SetPath(std::initializer_list<std::string_view> path,
                       Value value) {
   DCHECK_GE(path.size(), 2u) << "Use SetKey() for a path of length 1.";
-  return SetPath(make_span(path.begin(), path.size()), std::move(value));
+  return SetPath(std::span<const std::string_view>(path.begin(), path.size()),
+                 std::move(value));
 }
 
-Value* Value::SetPath(span<const std::string_view> path, Value value) {
-  DCHECK_NE(path.begin(), path.end());  // Can't be empty path.
+Value* Value::SetPath(std::span<const std::string_view> path, Value value) {
+  DCHECK(!path.empty());  // Can't be empty path.
 
   // Walk/construct intermediate dictionaries. The last element requires
   // special handling so skip it in this loop.
   Value* cur = this;
-  const std::string_view* cur_path = path.begin();
+  auto cur_path = path.begin();
   for (; (cur_path + 1) < path.end(); ++cur_path) {
     if (!cur->is_dict())
       return nullptr;
@@ -381,10 +384,11 @@
 
 bool Value::RemovePath(std::initializer_list<std::string_view> path) {
   DCHECK_GE(path.size(), 2u) << "Use RemoveKey() for a path of length 1.";
-  return RemovePath(make_span(path.begin(), path.size()));
+  return RemovePath(
+      std::span<const std::string_view>(path.begin(), path.size()));
 }
 
-bool Value::RemovePath(span<const std::string_view> path) {
+bool Value::RemovePath(std::span<const std::string_view> path) {
   if (!is_dict() || path.empty())
     return false;
 
diff --git a/src/base/values.h b/src/base/values.h
index 20a5271..1aa742c 100644
--- a/src/base/values.h
+++ b/src/base/values.h
@@ -26,13 +26,13 @@
 #include <iosfwd>
 #include <map>
 #include <memory>
+#include <span>
 #include <string>
 #include <string_view>
 #include <utility>
 #include <vector>
 
 #include "base/containers/flat_map.h"
-#include "base/containers/span.h"
 #include "base/value_iterators.h"
 
 namespace base {
@@ -226,9 +226,9 @@
   //
   // Note: If there is only one component in the path, use FindKey() instead.
   Value* FindPath(std::initializer_list<std::string_view> path);
-  Value* FindPath(span<const std::string_view> path);
+  Value* FindPath(std::span<const std::string_view> path);
   const Value* FindPath(std::initializer_list<std::string_view> path) const;
-  const Value* FindPath(span<const std::string_view> path) const;
+  const Value* FindPath(std::span<const std::string_view> path) const;
 
   // Like FindPath() but will only return the value if the leaf Value type
   // matches the given type. Will return nullptr otherwise.
@@ -237,10 +237,10 @@
   // instead.
   Value* FindPathOfType(std::initializer_list<std::string_view> path,
                         Type type);
-  Value* FindPathOfType(span<const std::string_view> path, Type type);
+  Value* FindPathOfType(std::span<const std::string_view> path, Type type);
   const Value* FindPathOfType(std::initializer_list<std::string_view> path,
                               Type type) const;
-  const Value* FindPathOfType(span<const std::string_view> path,
+  const Value* FindPathOfType(std::span<const std::string_view> path,
                               Type type) const;
 
   // Sets the given path, expanding and creating dictionary keys as necessary.
@@ -260,7 +260,7 @@
   //
   // Note: If there is only one component in the path, use SetKey() instead.
   Value* SetPath(std::initializer_list<std::string_view> path, Value value);
-  Value* SetPath(span<const std::string_view> path, Value value);
+  Value* SetPath(std::span<const std::string_view> path, Value value);
 
   // Tries to remove a Value at the given path.
   //
@@ -277,7 +277,7 @@
   //
   // Note: If there is only one component in the path, use RemoveKey() instead.
   bool RemovePath(std::initializer_list<std::string_view> path);
-  bool RemovePath(span<const std::string_view> path);
+  bool RemovePath(std::span<const std::string_view> path);
 
   using dict_iterator_proxy = detail::dict_iterator_proxy;
   using const_dict_iterator_proxy = detail::const_dict_iterator_proxy;
diff --git a/src/gn/command_path.cc b/src/gn/command_path.cc
index e3efdd5..14bd532 100644
--- a/src/gn/command_path.cc
+++ b/src/gn/command_path.cc
@@ -5,6 +5,7 @@
 #include <stddef.h>
 
 #include <algorithm>
+#include <list>
 
 #include "base/command_line.h"
 #include "base/strings/stringprintf.h"
diff --git a/src/gn/edit_subcommands.cc b/src/gn/edit_subcommands.cc
index 7232289..d02539d 100644
--- a/src/gn/edit_subcommands.cc
+++ b/src/gn/edit_subcommands.cc
@@ -6,11 +6,11 @@
 
 #include <optional>
 #include <set>
+#include <span>
 #include <string>
 #include <utility>
 #include <vector>
 
-#include "base/containers/span.h"
 #include "base/strings/string_number_conversions.h"
 #include "base/strings/string_util.h"
 #include "gn/build_file_editor.h"
@@ -40,7 +40,7 @@
 }
 
 // Parses multiple string arguments into a vector of GN Values.
-Result<std::vector<Value>> ParseValues(base::span<const std::string> values) {
+Result<std::vector<Value>> ParseValues(std::span<const std::string> values) {
   std::vector<Value> list_elements;
   list_elements.reserve(values.size());
   for (const std::string& val_str : values) {
@@ -64,7 +64,7 @@
 
 Result<ParseNodeGenerator> CreateParseNodeGenerator(
     std::optional<std::string_view> kind,
-    base::span<const std::string> values) {
+    std::span<const std::string> values) {
   CHECK(!values.empty());
 
   if (kind == "expr") {
@@ -582,7 +582,7 @@
                  "Usage: add <attribute> <value(s)>");
     }
     ASSIGN_OR_RETURN(std::vector<Value> values,
-                     ParseValues(base::make_span(args).subspan(2)));
+                     ParseValues(std::span(args).subspan(2)));
     return AddToAttributeCommand(args[1], std::move(values));
   } else if (args[0] == "delete") {
     if (args.size() != 1) {
@@ -595,7 +595,7 @@
                  "Usage: move <from_attribute> <to_attribute> <value(s)>");
     }
     ASSIGN_OR_RETURN(std::vector<Value> values,
-                     ParseValues(base::make_span(args).subspan(3)));
+                     ParseValues(std::span(args).subspan(3)));
     return MoveCommand(args[1], args[2], std::move(values));
   } else if (args[0] == "new") {
     if (args.size() == 2) {
@@ -635,7 +635,7 @@
       return RemoveAttributeCommand(args[1]);
     }
     ASSIGN_OR_RETURN(std::vector<Value> values,
-                     ParseValues(base::make_span(args).subspan(2)));
+                     ParseValues(std::span(args).subspan(2)));
     return RemoveFromAttributeCommand(args[1], std::move(values));
   } else if (args[0] == "rename") {
     if (args.size() != 3) {
@@ -651,9 +651,8 @@
     }
 
     auto [attr, kind] = SplitAttrType(args[1]);
-    ASSIGN_OR_RETURN(
-        auto generator,
-        CreateParseNodeGenerator(kind, base::make_span(args).subspan(2)));
+    ASSIGN_OR_RETURN(auto generator, CreateParseNodeGenerator(
+                                         kind, std::span(args).subspan(2)));
     return SetCommand(std::string(attr), std::move(generator));
   } else if (args[0] == "shard") {
     if (args.size() == 1) {
diff --git a/src/gn/ninja_target_writer.cc b/src/gn/ninja_target_writer.cc
index 0bdcfa5..fc4144b 100644
--- a/src/gn/ninja_target_writer.cc
+++ b/src/gn/ninja_target_writer.cc
@@ -5,6 +5,7 @@
 #include "gn/ninja_target_writer.h"
 
 #include <algorithm>
+#include <span>
 
 #include "base/strings/string_util.h"
 #include "gn/builtin_tool.h"
@@ -294,7 +295,7 @@
 // is added directly; otherwise, if it forwards hard deps, its aggregated hard
 // deps output (at most one file/phony per dep) is appended.
 void AppendHardDepsOutputsForDeps(const Target* target,
-                                  base::span<const Target*> deps,
+                                  std::span<const Target* const> deps,
                                   const ResolvedTargetData& resolved,
                                   std::vector<OutputFile>* outputs) {
   for (const Target* dep : deps) {
diff --git a/src/gn/parse_tree_unittest.cc b/src/gn/parse_tree_unittest.cc
index 7621bc5..e1a14ce 100644
--- a/src/gn/parse_tree_unittest.cc
+++ b/src/gn/parse_tree_unittest.cc
@@ -8,9 +8,9 @@
 
 #include <algorithm>
 #include <memory>
+#include <span>
 #include <utility>
 
-#include "base/containers/span.h"
 #include "gn/input_file.h"
 #include "gn/scope.h"
 #include "gn/test_with_scope.h"
@@ -196,7 +196,7 @@
   ASSERT_EQ(7u, contents.size());
 
   auto all_elements_are_literal_nodes =
-      [](base::span<const std::unique_ptr<ParseNode>> container) -> bool {
+      [](std::span<const std::unique_ptr<ParseNode>> container) -> bool {
     return std::ranges::all_of(container,
                                [](const std::unique_ptr<ParseNode>& element) {
                                  return element->AsLiteral();
diff --git a/src/gn/resolved_target_data.cc b/src/gn/resolved_target_data.cc
index 6f3f522..3faa090 100644
--- a/src/gn/resolved_target_data.cc
+++ b/src/gn/resolved_target_data.cc
@@ -99,9 +99,9 @@
 // Keep in sync with NinjaTargetWriter::WriteHardDepsStampOrPhony().
 void ResolvedTargetData::ComputeHardDeps(TargetInfo* info) const {
   TargetSet all_hard_deps;
-  base::span<const Target*> deps = OnlyForwardsPublicHardDeps(info->target)
-                                       ? info->deps.public_deps()
-                                       : info->deps.linked_deps();
+  std::span<const Target* const> deps = OnlyForwardsPublicHardDeps(info->target)
+                                            ? info->deps.public_deps()
+                                            : info->deps.linked_deps();
   for (const Target* dep : deps) {
     // Direct hard dependencies
     if (info->target->hard_dep() || dep->hard_dep()) {
@@ -131,7 +131,7 @@
 }
 
 void ResolvedTargetData::ComputeInheritedLibsFor(
-    base::span<const Target*> deps,
+    std::span<const Target* const> deps,
     bool is_public,
     TargetPublicPairListBuilder* inherited_libraries) const {
   for (const Target* dep : deps) {
@@ -216,7 +216,7 @@
 }
 
 void ResolvedTargetData::ComputeModuleDepsInformationFor(
-    base::span<const Target*> deps,
+    std::span<const Target* const> deps,
     bool is_public,
     TargetPublicPairListBuilder* module_deps_information) const {
   for (const Target* dep : deps) {
@@ -248,7 +248,7 @@
   info->has_rust_libs = true;
 }
 
-void ResolvedTargetData::ComputeRustLibsFor(base::span<const Target*> deps,
+void ResolvedTargetData::ComputeRustLibsFor(std::span<const Target* const> deps,
                                             bool is_public,
                                             RustLibsBuilder* rust_libs) const {
   for (const Target* dep : deps) {
@@ -334,7 +334,7 @@
   const Target* target = info->target;
 
   if (target->output_type() == Target::GROUP) {
-    auto add_deps = [&](base::span<const Target*> deps) {
+    auto add_deps = [&](std::span<const Target* const> deps) {
       for (const Target* dep : deps) {
         const TargetInfo* dep_info = GetTargetOrderOnlyDeps(dep);
         all_order_only_deps.Append(dep_info->order_only_deps);
diff --git a/src/gn/resolved_target_data.h b/src/gn/resolved_target_data.h
index e498479..ff82a0c 100644
--- a/src/gn/resolved_target_data.h
+++ b/src/gn/resolved_target_data.h
@@ -8,9 +8,9 @@
 #include <atomic>
 #include <memory>
 #include <mutex>
+#include <span>
 #include <vector>
 
-#include "base/containers/span.h"
 #include "gn/lib_file.h"
 #include "gn/output_file.h"
 #include "gn/resolved_target_deps.h"
@@ -53,13 +53,13 @@
 
   // Return the data dependencies of a given target.
   // Convenience shortcut for GetTargetDeps(target).data_deps().
-  base::span<const Target*> GetDataDeps(const Target* target) const {
+  std::span<const Target* const> GetDataDeps(const Target* target) const {
     return GetTargetDeps(target).data_deps();
   }
 
   // Return the public and private dependencies of a given target.
   // Convenience shortcut for GetTargetDeps(target).linked_deps().
-  base::span<const Target*> GetLinkedDeps(const Target* target) const {
+  std::span<const Target* const> GetLinkedDeps(const Target* target) const {
     return GetTargetDeps(target).linked_deps();
   }
 
@@ -139,7 +139,7 @@
   // List of dependent target that generate a .swiftmodule. The current target
   // is assumed to depend on those modules, and will add them to the module
   // search path.
-  base::span<const Target*> GetSwiftModuleDependencies(
+  std::span<const Target* const> GetSwiftModuleDependencies(
       const Target* target) const {
     const TargetInfo* info = GetTargetSwiftValues(target);
     if (!info->swift_values.get())
@@ -297,13 +297,13 @@
 
   // Helper function used by ComputeInheritedLibs().
   void ComputeInheritedLibsFor(
-      base::span<const Target*> deps,
+      std::span<const Target* const> deps,
       bool is_public,
       TargetPublicPairListBuilder* inherited_libraries) const;
 
   // Helper function used by ComputeModuleDepsInformation().
   void ComputeModuleDepsInformationFor(
-      base::span<const Target*> deps,
+      std::span<const Target* const> deps,
       bool is_public,
       TargetPublicPairListBuilder* module_deps_information) const;
 
@@ -313,7 +313,7 @@
     TargetPublicPairListBuilder inheritable;
   };
 
-  void ComputeRustLibsFor(base::span<const Target*> deps,
+  void ComputeRustLibsFor(std::span<const Target* const> deps,
                           bool is_public,
                           RustLibsBuilder* rust_libs) const;
 };
diff --git a/src/gn/resolved_target_deps.h b/src/gn/resolved_target_deps.h
index 069f36e..45b6578 100644
--- a/src/gn/resolved_target_deps.h
+++ b/src/gn/resolved_target_deps.h
@@ -6,8 +6,8 @@
 #define TOOLS_GN_RESOLVED_TARGET_DEPS_H_
 
 #include <memory>
+#include <span>
 
-#include "base/containers/span.h"
 #include "gn/label_ptr.h"
 
 // A class used to record the dependencies of a given Target in
@@ -42,23 +42,23 @@
 
   size_t size() const { return private_count_ + public_count_ + data_count_; }
 
-  base::span<const Target*> public_deps() const {
+  std::span<const Target* const> public_deps() const {
     return {deps_.get(), public_count_};
   }
 
-  base::span<const Target*> private_deps() const {
+  std::span<const Target* const> private_deps() const {
     return {deps_.get() + public_count_, private_count_};
   }
 
-  base::span<const Target*> data_deps() const {
+  std::span<const Target* const> data_deps() const {
     return {deps_.get() + private_count_ + public_count_, data_count_};
   }
 
-  base::span<const Target*> linked_deps() const {
+  std::span<const Target* const> linked_deps() const {
     return {deps_.get(), private_count_ + public_count_};
   }
 
-  base::span<const Target*> all_deps() const {
+  std::span<const Target* const> all_deps() const {
     return {deps_.get(), private_count_ + public_count_ + data_count_};
   }