summaryrefslogtreecommitdiff
path: root/chromium/third_party/dawn/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/dawn/src/common')
-rw-r--r--chromium/third_party/dawn/src/common/BUILD.gn6
-rw-r--r--chromium/third_party/dawn/src/common/BitSetIterator.h6
-rw-r--r--chromium/third_party/dawn/src/common/CMakeLists.txt5
-rw-r--r--chromium/third_party/dawn/src/common/Compiler.h6
-rw-r--r--chromium/third_party/dawn/src/common/HashUtils.h18
-rw-r--r--chromium/third_party/dawn/src/common/SystemUtils.cpp26
-rw-r--r--chromium/third_party/dawn/src/common/SystemUtils.h17
-rw-r--r--chromium/third_party/dawn/src/common/TypedInteger.h212
-rw-r--r--chromium/third_party/dawn/src/common/UnderlyingType.h51
-rw-r--r--chromium/third_party/dawn/src/common/ityp_array.h96
-rw-r--r--chromium/third_party/dawn/src/common/ityp_bitset.h134
-rw-r--r--chromium/third_party/dawn/src/common/ityp_span.h103
-rw-r--r--chromium/third_party/dawn/src/common/windows_with_undefs.h2
13 files changed, 680 insertions, 2 deletions
diff --git a/chromium/third_party/dawn/src/common/BUILD.gn b/chromium/third_party/dawn/src/common/BUILD.gn
index 3f5a09b3782..59a23057224 100644
--- a/chromium/third_party/dawn/src/common/BUILD.gn
+++ b/chromium/third_party/dawn/src/common/BUILD.gn
@@ -96,9 +96,11 @@ config("dawn_internal") {
"-Wc++11-narrowing",
"-Wdeprecated-copy",
"-Wextra-semi-stmt",
+ "-Wimplicit-fallthrough",
"-Winconsistent-missing-destructor-override",
"-Winvalid-offsetof",
"-Wmissing-field-initializers",
+ "-Wnon-c-typedef-for-linkage",
"-Wpessimizing-move",
"-Wreturn-std-move-in-c++11",
"-Wshadow-field",
@@ -166,6 +168,10 @@ if (is_win || is_linux || is_mac || is_fuchsia || is_android) {
"SwapChainUtils.h",
"SystemUtils.cpp",
"SystemUtils.h",
+ "TypedInteger.h",
+ "ityp_array.h",
+ "ityp_bitset.h",
+ "ityp_span.h",
"vulkan_platform.h",
"windows_with_undefs.h",
"xlib_with_undefs.h",
diff --git a/chromium/third_party/dawn/src/common/BitSetIterator.h b/chromium/third_party/dawn/src/common/BitSetIterator.h
index 1a7fd606962..d35bc8a2df0 100644
--- a/chromium/third_party/dawn/src/common/BitSetIterator.h
+++ b/chromium/third_party/dawn/src/common/BitSetIterator.h
@@ -17,6 +17,7 @@
#include "common/Assert.h"
#include "common/Math.h"
+#include "common/UnderlyingType.h"
#include <bitset>
#include <limits>
@@ -44,8 +45,11 @@ class BitSetIterator final {
bool operator==(const Iterator& other) const;
bool operator!=(const Iterator& other) const;
+
T operator*() const {
- return static_cast<T>(mCurrentBit);
+ using U = UnderlyingType<T>;
+ ASSERT(mCurrentBit <= std::numeric_limits<U>::max());
+ return static_cast<T>(static_cast<U>(mCurrentBit));
}
private:
diff --git a/chromium/third_party/dawn/src/common/CMakeLists.txt b/chromium/third_party/dawn/src/common/CMakeLists.txt
index 2e909b33b4e..1ab20234b1f 100644
--- a/chromium/third_party/dawn/src/common/CMakeLists.txt
+++ b/chromium/third_party/dawn/src/common/CMakeLists.txt
@@ -44,6 +44,11 @@ target_sources(dawn_common PRIVATE
"SwapChainUtils.h"
"SystemUtils.cpp"
"SystemUtils.h"
+ "TypedInteger.h"
+ "UnderlyingType.h"
+ "ityp_array.h"
+ "ityp_bitset.h"
+ "ityp_span.h"
"vulkan_platform.h"
"windows_with_undefs.h"
"xlib_with_undefs.h"
diff --git a/chromium/third_party/dawn/src/common/Compiler.h b/chromium/third_party/dawn/src/common/Compiler.h
index 8e425c90588..49e6db4c5e1 100644
--- a/chromium/third_party/dawn/src/common/Compiler.h
+++ b/chromium/third_party/dawn/src/common/Compiler.h
@@ -107,4 +107,10 @@ extern void __cdecl __debugbreak(void);
# define DAWN_FORCE_INLINE inline
#endif
+#if defined(__clang__)
+# define DAWN_FALLTHROUGH [[clang::fallthrough]]
+#else
+# define DAWN_FALLTHROUGH
+#endif
+
#endif // COMMON_COMPILER_H_
diff --git a/chromium/third_party/dawn/src/common/HashUtils.h b/chromium/third_party/dawn/src/common/HashUtils.h
index c42b60e02e7..9d10ca713c2 100644
--- a/chromium/third_party/dawn/src/common/HashUtils.h
+++ b/chromium/third_party/dawn/src/common/HashUtils.h
@@ -16,6 +16,8 @@
#define COMMON_HASHUTILS_H_
#include "common/Platform.h"
+#include "common/TypedInteger.h"
+#include "common/ityp_bitset.h"
#include <bitset>
#include <functional>
@@ -27,6 +29,12 @@ size_t Hash(const T& value) {
return std::hash<T>()(value);
}
+// Add hashing of TypedIntegers
+template <typename Tag, typename T>
+size_t Hash(const TypedInteger<Tag, T>& value) {
+ return Hash(static_cast<T>(value));
+}
+
// When hashing sparse structures we want to iteratively build a hash value with only parts of the
// data. HashCombine "hashes" together an existing hash and hashable values.
//
@@ -80,4 +88,14 @@ size_t Hash(const std::bitset<N>& value) {
}
#endif
+namespace std {
+ template <typename Index, size_t N>
+ class hash<ityp::bitset<Index, N>> {
+ public:
+ size_t operator()(const ityp::bitset<Index, N>& value) const {
+ return Hash(static_cast<const std::bitset<N>&>(value));
+ }
+ };
+} // namespace std
+
#endif // COMMON_HASHUTILS_H_
diff --git a/chromium/third_party/dawn/src/common/SystemUtils.cpp b/chromium/third_party/dawn/src/common/SystemUtils.cpp
index 73aa4ee640d..f8282eb4141 100644
--- a/chromium/third_party/dawn/src/common/SystemUtils.cpp
+++ b/chromium/third_party/dawn/src/common/SystemUtils.cpp
@@ -14,6 +14,8 @@
#include "common/SystemUtils.h"
+#include "common/Assert.h"
+
#if defined(DAWN_PLATFORM_WINDOWS)
# include <Windows.h>
# include <vector>
@@ -115,3 +117,27 @@ std::string GetExecutableDirectory() {
size_t lastPathSepLoc = exePath.find_last_of(GetPathSeparator());
return lastPathSepLoc != std::string::npos ? exePath.substr(0, lastPathSepLoc + 1) : "";
}
+
+// ScopedEnvironmentVar
+
+ScopedEnvironmentVar::ScopedEnvironmentVar(const char* variableName, const char* value)
+ : mName(variableName),
+ mOriginalValue(GetEnvironmentVar(variableName)),
+ mIsSet(SetEnvironmentVar(variableName, value)) {
+}
+
+ScopedEnvironmentVar::~ScopedEnvironmentVar() {
+ if (mIsSet) {
+ bool success = SetEnvironmentVar(mName.c_str(), mOriginalValue.c_str());
+ // If we set the environment variable in the constructor, we should never fail restoring it.
+ ASSERT(success);
+ }
+}
+
+bool ScopedEnvironmentVar::Set(const char* variableName, const char* value) {
+ ASSERT(!mIsSet);
+ mName = variableName;
+ mOriginalValue = GetEnvironmentVar(variableName);
+ mIsSet = SetEnvironmentVar(variableName, value);
+ return mIsSet;
+}
diff --git a/chromium/third_party/dawn/src/common/SystemUtils.h b/chromium/third_party/dawn/src/common/SystemUtils.h
index 2edf1e3a257..ed18c31e661 100644
--- a/chromium/third_party/dawn/src/common/SystemUtils.h
+++ b/chromium/third_party/dawn/src/common/SystemUtils.h
@@ -24,4 +24,21 @@ std::string GetEnvironmentVar(const char* variableName);
bool SetEnvironmentVar(const char* variableName, const char* value);
std::string GetExecutableDirectory();
+class ScopedEnvironmentVar {
+ public:
+ ScopedEnvironmentVar() = default;
+ ScopedEnvironmentVar(const char* variableName, const char* value);
+ ~ScopedEnvironmentVar();
+
+ ScopedEnvironmentVar(const ScopedEnvironmentVar& rhs) = delete;
+ ScopedEnvironmentVar& operator=(const ScopedEnvironmentVar& rhs) = delete;
+
+ bool Set(const char* variableName, const char* value);
+
+ private:
+ std::string mName;
+ std::string mOriginalValue;
+ bool mIsSet = false;
+};
+
#endif // COMMON_SYSTEMUTILS_H_
diff --git a/chromium/third_party/dawn/src/common/TypedInteger.h b/chromium/third_party/dawn/src/common/TypedInteger.h
new file mode 100644
index 00000000000..5474d9a920b
--- /dev/null
+++ b/chromium/third_party/dawn/src/common/TypedInteger.h
@@ -0,0 +1,212 @@
+// Copyright 2020 The Dawn Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef COMMON_TYPEDINTEGER_H_
+#define COMMON_TYPEDINTEGER_H_
+
+#include "common/Assert.h"
+
+#include <limits>
+#include <type_traits>
+
+// TypedInteger is helper class that provides additional type safety in Debug.
+// - Integers of different (Tag, BaseIntegerType) may not be used interoperably
+// - Allows casts only to the underlying type.
+// - Integers of the same (Tag, BaseIntegerType) may be compared or assigned.
+// This class helps ensure that the many types of indices in Dawn aren't mixed up and used
+// interchangably.
+// In Release builds, when DAWN_ENABLE_ASSERTS is not defined, TypedInteger is a passthrough
+// typedef of the underlying type.
+//
+// Example:
+// using UintA = TypedInteger<struct TypeA, uint32_t>;
+// using UintB = TypedInteger<struct TypeB, uint32_t>;
+//
+// in Release:
+// using UintA = uint32_t;
+// using UintB = uint32_t;
+//
+// in Debug:
+// using UintA = detail::TypedIntegerImpl<struct TypeA, uint32_t>;
+// using UintB = detail::TypedIntegerImpl<struct TypeB, uint32_t>;
+//
+// Assignment, construction, comparison, and arithmetic with TypedIntegerImpl are allowed
+// only for typed integers of exactly the same type. Further, they must be
+// created / cast explicitly; there is no implicit conversion.
+//
+// UintA a(2);
+// uint32_t aValue = static_cast<uint32_t>(a);
+//
+namespace detail {
+ template <typename Tag, typename T>
+ class TypedIntegerImpl;
+} // namespace detail
+
+template <typename Tag, typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
+#if defined(DAWN_ENABLE_ASSERTS)
+using TypedInteger = detail::TypedIntegerImpl<Tag, T>;
+#else
+using TypedInteger = T;
+#endif
+
+namespace detail {
+ template <typename Tag, typename T>
+ class alignas(T) TypedIntegerImpl {
+ static_assert(std::is_integral<T>::value, "TypedInteger must be integral");
+ T mValue;
+
+ public:
+ constexpr TypedIntegerImpl() : mValue(0) {
+ static_assert(alignof(TypedIntegerImpl) == alignof(T), "");
+ static_assert(sizeof(TypedIntegerImpl) == sizeof(T), "");
+ }
+
+ // Construction from non-narrowing integral types.
+ template <typename I,
+ typename = std::enable_if_t<
+ std::is_integral<I>::value &&
+ std::numeric_limits<I>::max() <= std::numeric_limits<T>::max() &&
+ std::numeric_limits<I>::min() >= std::numeric_limits<T>::min()>>
+ explicit constexpr TypedIntegerImpl(I rhs) : mValue(static_cast<T>(rhs)) {
+ }
+
+ // Allow explicit casts only to the underlying type. If you're casting out of an
+ // TypedInteger, you should know what what you're doing, and exactly what type you
+ // expect.
+ explicit constexpr operator T() const {
+ return static_cast<T>(this->mValue);
+ }
+
+// Same-tag TypedInteger comparison operators
+#define TYPED_COMPARISON(op) \
+ constexpr bool operator op(const TypedIntegerImpl& rhs) const { \
+ return mValue op rhs.mValue; \
+ }
+ TYPED_COMPARISON(<)
+ TYPED_COMPARISON(<=)
+ TYPED_COMPARISON(>)
+ TYPED_COMPARISON(>=)
+ TYPED_COMPARISON(==)
+ TYPED_COMPARISON(!=)
+#undef TYPED_COMPARISON
+
+ // Increment / decrement operators for for-loop iteration
+ constexpr TypedIntegerImpl& operator++() {
+ ASSERT(this->mValue < std::numeric_limits<T>::max());
+ ++this->mValue;
+ return *this;
+ }
+
+ constexpr TypedIntegerImpl operator++(int) {
+ TypedIntegerImpl ret = *this;
+
+ ASSERT(this->mValue < std::numeric_limits<T>::max());
+ ++this->mValue;
+ return ret;
+ }
+
+ constexpr TypedIntegerImpl& operator--() {
+ assert(this->mValue > std::numeric_limits<T>::min());
+ --this->mValue;
+ return *this;
+ }
+
+ constexpr TypedIntegerImpl operator--(int) {
+ TypedIntegerImpl ret = *this;
+
+ ASSERT(this->mValue > std::numeric_limits<T>::min());
+ --this->mValue;
+ return ret;
+ }
+
+ template <typename T2 = T>
+ constexpr std::enable_if_t<std::is_signed<T2>::value, TypedIntegerImpl> operator-() const {
+ static_assert(std::is_same<T, T2>::value, "");
+ // The negation of the most negative value cannot be represented.
+ ASSERT(this->mValue != std::numeric_limits<T>::min());
+ return TypedIntegerImpl(-this->mValue);
+ }
+
+ template <typename T2 = T>
+ constexpr std::enable_if_t<std::is_unsigned<T2>::value, TypedIntegerImpl> operator+(
+ TypedIntegerImpl rhs) const {
+ static_assert(std::is_same<T, T2>::value, "");
+ // Overflow would wrap around
+ ASSERT(this->mValue + rhs.mValue >= this->mValue);
+
+ return TypedIntegerImpl(this->mValue + rhs.mValue);
+ }
+
+ template <typename T2 = T>
+ constexpr std::enable_if_t<std::is_unsigned<T2>::value, TypedIntegerImpl> operator-(
+ TypedIntegerImpl rhs) const {
+ static_assert(std::is_same<T, T2>::value, "");
+ // Overflow would wrap around
+ ASSERT(this->mValue - rhs.mValue <= this->mValue);
+ return TypedIntegerImpl(this->mValue - rhs.mValue);
+ }
+
+ template <typename T2 = T>
+ constexpr std::enable_if_t<std::is_signed<T2>::value, TypedIntegerImpl> operator+(
+ TypedIntegerImpl rhs) const {
+ static_assert(std::is_same<T, T2>::value, "");
+ if (this->mValue > 0) {
+ // rhs is positive: |rhs| is at most the distance between max and |this|.
+ // rhs is negative: (positive + negative) won't overflow
+ ASSERT(rhs.mValue <= std::numeric_limits<T>::max() - this->mValue);
+ } else {
+ // rhs is postive: (negative + positive) won't underflow
+ // rhs is negative: |rhs| isn't less than the (negative) distance between min
+ // and |this|
+ ASSERT(rhs.mValue >= std::numeric_limits<T>::min() - this->mValue);
+ }
+ return TypedIntegerImpl(this->mValue + rhs.mValue);
+ }
+
+ template <typename T2 = T>
+ constexpr std::enable_if_t<std::is_signed<T2>::value, TypedIntegerImpl> operator-(
+ TypedIntegerImpl rhs) const {
+ static_assert(std::is_same<T, T2>::value, "");
+ if (this->mValue > 0) {
+ // rhs is positive: positive minus positive won't overflow
+ // rhs is negative: |rhs| isn't less than the (negative) distance between |this|
+ // and max.
+ ASSERT(rhs.mValue >= this->mValue - std::numeric_limits<T>::max());
+ } else {
+ // rhs is positive: |rhs| is at most the distance between min and |this|
+ // rhs is negative: negative minus negative won't overflow
+ ASSERT(rhs.mValue <= this->mValue - std::numeric_limits<T>::min());
+ }
+ return TypedIntegerImpl(this->mValue - rhs.mValue);
+ }
+ };
+
+} // namespace detail
+
+namespace std {
+
+ template <typename Tag, typename T>
+ class numeric_limits<detail::TypedIntegerImpl<Tag, T>> : public numeric_limits<T> {
+ public:
+ static detail::TypedIntegerImpl<Tag, T> max() noexcept {
+ return detail::TypedIntegerImpl<Tag, T>(std::numeric_limits<T>::max());
+ }
+ static detail::TypedIntegerImpl<Tag, T> min() noexcept {
+ return detail::TypedIntegerImpl<Tag, T>(std::numeric_limits<T>::min());
+ }
+ };
+
+} // namespace std
+
+#endif // COMMON_TYPEDINTEGER_H_
diff --git a/chromium/third_party/dawn/src/common/UnderlyingType.h b/chromium/third_party/dawn/src/common/UnderlyingType.h
new file mode 100644
index 00000000000..09c72c023f9
--- /dev/null
+++ b/chromium/third_party/dawn/src/common/UnderlyingType.h
@@ -0,0 +1,51 @@
+// Copyright 2020 The Dawn Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef COMMON_UNDERLYINGTYPE_H_
+#define COMMON_UNDERLYINGTYPE_H_
+
+#include <type_traits>
+
+// UnderlyingType is similar to std::underlying_type_t. It is a passthrough for already
+// integer types which simplifies getting the underlying primitive type for an arbitrary
+// template parameter. It includes a specialization for detail::TypedIntegerImpl which yields
+// the wrapped integer type.
+namespace detail {
+ template <typename T, typename Enable = void>
+ struct UnderlyingTypeImpl;
+
+ template <typename I>
+ struct UnderlyingTypeImpl<I, typename std::enable_if_t<std::is_integral<I>::value>> {
+ using type = I;
+ };
+
+ template <typename E>
+ struct UnderlyingTypeImpl<E, typename std::enable_if_t<std::is_enum<E>::value>> {
+ using type = std::underlying_type_t<E>;
+ };
+
+ // Forward declare the TypedInteger impl.
+ template <typename Tag, typename T>
+ class TypedIntegerImpl;
+
+ template <typename Tag, typename I>
+ struct UnderlyingTypeImpl<TypedIntegerImpl<Tag, I>> {
+ using type = typename UnderlyingTypeImpl<I>::type;
+ };
+} // namespace detail
+
+template <typename T>
+using UnderlyingType = typename detail::UnderlyingTypeImpl<T>::type;
+
+#endif // COMMON_UNDERLYINGTYPE_H_
diff --git a/chromium/third_party/dawn/src/common/ityp_array.h b/chromium/third_party/dawn/src/common/ityp_array.h
new file mode 100644
index 00000000000..d413ebc0ba0
--- /dev/null
+++ b/chromium/third_party/dawn/src/common/ityp_array.h
@@ -0,0 +1,96 @@
+// Copyright 2020 The Dawn Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef COMMON_ITYP_ARRAY_H_
+#define COMMON_ITYP_ARRAY_H_
+
+#include "common/TypedInteger.h"
+#include "common/UnderlyingType.h"
+
+#include <array>
+#include <type_traits>
+
+namespace ityp {
+
+ // ityp::array is a helper class that wraps std::array with the restriction that
+ // indices must be a particular type |Index|. Dawn uses multiple flat maps of
+ // index-->data, and this class helps ensure an indices cannot be passed interchangably
+ // to a flat map of a different type.
+ template <typename Index, typename Value, size_t Size>
+ class array : private std::array<Value, Size> {
+ using I = UnderlyingType<Index>;
+ using Base = std::array<Value, Size>;
+
+ static_assert(Size <= std::numeric_limits<I>::max(), "");
+
+ public:
+ constexpr array() = default;
+
+ template <typename... Values>
+ constexpr array(Values&&... values) : Base{std::forward<Values>(values)...} {
+ }
+
+ Value& operator[](Index i) {
+ I index = static_cast<I>(i);
+ ASSERT(index >= 0 && index < Size);
+ return Base::operator[](index);
+ }
+
+ constexpr const Value& operator[](Index i) const {
+ I index = static_cast<I>(i);
+ ASSERT(index >= 0 && index < Size);
+ return Base::operator[](index);
+ }
+
+ Value& at(Index i) {
+ I index = static_cast<I>(i);
+ ASSERT(index >= 0 && index < Size);
+ return Base::at(index);
+ }
+
+ constexpr const Value& at(Index i) const {
+ I index = static_cast<I>(i);
+ ASSERT(index >= 0 && index < Size);
+ return Base::at(index);
+ }
+
+ Value* begin() noexcept {
+ return Base::begin();
+ }
+
+ const Value* begin() const noexcept {
+ return Base::begin();
+ }
+
+ Value* end() noexcept {
+ return Base::end();
+ }
+
+ const Value* end() const noexcept {
+ return Base::end();
+ }
+
+ constexpr Index size() const {
+ return Index(static_cast<I>(Size));
+ }
+
+ using Base::back;
+ using Base::data;
+ using Base::empty;
+ using Base::front;
+ };
+
+} // namespace ityp
+
+#endif // COMMON_ITYP_ARRAY_H_
diff --git a/chromium/third_party/dawn/src/common/ityp_bitset.h b/chromium/third_party/dawn/src/common/ityp_bitset.h
new file mode 100644
index 00000000000..ef351d47d76
--- /dev/null
+++ b/chromium/third_party/dawn/src/common/ityp_bitset.h
@@ -0,0 +1,134 @@
+// Copyright 2020 The Dawn Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef COMMON_ITYP_BITSET_H_
+#define COMMON_ITYP_BITSET_H_
+
+#include "common/BitSetIterator.h"
+#include "common/TypedInteger.h"
+#include "common/UnderlyingType.h"
+
+namespace ityp {
+
+ // ityp::bitset is a helper class that wraps std::bitset with the restriction that
+ // indices must be a particular type |Index|.
+ template <typename Index, size_t N>
+ class bitset : private std::bitset<N> {
+ using I = UnderlyingType<Index>;
+ using Base = std::bitset<N>;
+
+ static_assert(sizeof(I) <= sizeof(size_t), "");
+
+ constexpr bitset(const Base& rhs) : Base(rhs) {
+ }
+
+ public:
+ constexpr bitset() noexcept : Base() {
+ }
+
+ constexpr bitset(unsigned long long value) noexcept : Base(value) {
+ }
+
+ constexpr bool operator[](Index i) const {
+ return Base::operator[](static_cast<I>(i));
+ }
+
+ typename Base::reference operator[](Index i) {
+ return Base::operator[](static_cast<I>(i));
+ }
+
+ bool test(Index i) const {
+ return Base::test(static_cast<I>(i));
+ }
+
+ using Base::all;
+ using Base::any;
+ using Base::count;
+ using Base::none;
+ using Base::size;
+
+ bool operator==(const bitset& other) const noexcept {
+ return Base::operator==(static_cast<const Base&>(other));
+ }
+
+ bool operator!=(const bitset& other) const noexcept {
+ return Base::operator!=(static_cast<const Base&>(other));
+ }
+
+ bitset& operator&=(const bitset& other) noexcept {
+ return static_cast<bitset&>(Base::operator&=(static_cast<const Base&>(other)));
+ }
+
+ bitset& operator|=(const bitset& other) noexcept {
+ return static_cast<bitset&>(Base::operator|=(static_cast<const Base&>(other)));
+ }
+
+ bitset& operator^=(const bitset& other) noexcept {
+ return static_cast<bitset&>(Base::operator^=(static_cast<const Base&>(other)));
+ }
+
+ bitset operator~() const noexcept {
+ return bitset(*this).flip();
+ }
+
+ bitset& set() noexcept {
+ return static_cast<bitset&>(Base::set());
+ }
+
+ bitset& set(Index i, bool value = true) {
+ return static_cast<bitset&>(Base::set(static_cast<I>(i), value));
+ }
+
+ bitset& reset() noexcept {
+ return static_cast<bitset&>(Base::reset());
+ }
+
+ bitset& reset(Index i) {
+ return static_cast<bitset&>(Base::reset(static_cast<I>(i)));
+ }
+
+ bitset& flip() noexcept {
+ return static_cast<bitset&>(Base::flip());
+ }
+
+ bitset& flip(Index i) {
+ return static_cast<bitset&>(Base::flip(static_cast<I>(i)));
+ }
+
+ using Base::to_string;
+ using Base::to_ullong;
+ using Base::to_ulong;
+
+ friend bitset operator&(const bitset& lhs, const bitset& rhs) noexcept {
+ return bitset(static_cast<const Base&>(lhs) & static_cast<const Base&>(rhs));
+ }
+
+ friend bitset operator|(const bitset& lhs, const bitset& rhs) noexcept {
+ return bitset(static_cast<const Base&>(lhs) | static_cast<const Base&>(rhs));
+ }
+
+ friend bitset operator^(const bitset& lhs, const bitset& rhs) noexcept {
+ return bitset(static_cast<const Base&>(lhs) ^ static_cast<const Base&>(rhs));
+ }
+
+ friend BitSetIterator<N, Index> IterateBitSet(const bitset& bitset) {
+ return BitSetIterator<N, Index>(static_cast<const Base&>(bitset));
+ }
+
+ friend class std::hash<bitset>;
+ };
+
+} // namespace ityp
+
+#endif // COMMON_ITYP_BITSET_H_
diff --git a/chromium/third_party/dawn/src/common/ityp_span.h b/chromium/third_party/dawn/src/common/ityp_span.h
new file mode 100644
index 00000000000..00ba93f7503
--- /dev/null
+++ b/chromium/third_party/dawn/src/common/ityp_span.h
@@ -0,0 +1,103 @@
+// Copyright 2020 The Dawn Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef COMMON_ITYP_SPAN_H_
+#define COMMON_ITYP_SPAN_H_
+
+#include "common/TypedInteger.h"
+#include "common/UnderlyingType.h"
+
+#include <type_traits>
+
+namespace ityp {
+
+ // ityp::span is a helper class that wraps an unowned packed array of type |Value|.
+ // It stores the size and pointer to first element. It has the restriction that
+ // indices must be a particular type |Index|. This provides a type-safe way to index
+ // raw pointers.
+ template <typename Index, typename Value>
+ class span {
+ using I = UnderlyingType<Index>;
+
+ public:
+ constexpr span() : mData(nullptr), mSize(0) {
+ }
+ constexpr span(Value* data, Index size) : mData(data), mSize(size) {
+ }
+
+ constexpr Value& operator[](Index i) const {
+ ASSERT(i < mSize);
+ return mData[static_cast<I>(i)];
+ }
+
+ Value* data() noexcept {
+ return mData;
+ }
+
+ const Value* data() const noexcept {
+ return mData;
+ }
+
+ Value* begin() noexcept {
+ return mData;
+ }
+
+ const Value* begin() const noexcept {
+ return mData;
+ }
+
+ Value* end() noexcept {
+ return mData + static_cast<I>(mSize);
+ }
+
+ const Value* end() const noexcept {
+ return mData + static_cast<I>(mSize);
+ }
+
+ Value& front() {
+ ASSERT(mData != nullptr);
+ ASSERT(static_cast<I>(mSize) >= 0);
+ return *mData;
+ }
+
+ const Value& front() const {
+ ASSERT(mData != nullptr);
+ ASSERT(static_cast<I>(mSize) >= 0);
+ return *mData;
+ }
+
+ Value& back() {
+ ASSERT(mData != nullptr);
+ ASSERT(static_cast<I>(mSize) >= 0);
+ return *(mData + static_cast<I>(mSize) - 1);
+ }
+
+ const Value& back() const {
+ ASSERT(mData != nullptr);
+ ASSERT(static_cast<I>(mSize) >= 0);
+ return *(mData + static_cast<I>(mSize) - 1);
+ }
+
+ Index size() const {
+ return mSize;
+ }
+
+ private:
+ Value* mData;
+ Index mSize;
+ };
+
+} // namespace ityp
+
+#endif // COMMON_ITYP_SPAN_H_
diff --git a/chromium/third_party/dawn/src/common/windows_with_undefs.h b/chromium/third_party/dawn/src/common/windows_with_undefs.h
index 381116a0243..6d8649ca8dd 100644
--- a/chromium/third_party/dawn/src/common/windows_with_undefs.h
+++ b/chromium/third_party/dawn/src/common/windows_with_undefs.h
@@ -15,7 +15,7 @@
#ifndef COMMON_WINDOWS_WITH_UNDEFS_H_
#define COMMON_WINDOWS_WITH_UNDEFS_H_
-#include "common/Compiler.h"
+#include "common/Platform.h"
#if !defined(DAWN_PLATFORM_WINDOWS)
# error "windows_with_undefs.h included on non-Windows"