Diff
Modified: trunk/Source/WTF/ChangeLog (264273 => 264274)
--- trunk/Source/WTF/ChangeLog 2020-07-12 02:51:02 UTC (rev 264273)
+++ trunk/Source/WTF/ChangeLog 2020-07-12 04:39:31 UTC (rev 264274)
@@ -1,3 +1,16 @@
+2020-07-11 Commit Queue <[email protected]>
+
+ Unreviewed, reverting r264270.
+ https://bugs.webkit.org/show_bug.cgi?id=214228
+
+ Broke the build
+
+ Reverted changeset:
+
+ "Make hasher work with tuple-like classes"
+ https://bugs.webkit.org/show_bug.cgi?id=214224
+ https://trac.webkit.org/changeset/264270
+
2020-07-11 Darin Adler <[email protected]>
Remove live ranges from AccessibilityObject.h, AccessibilityObjectInterface.h, AccessibilityRenderObject.h, AXIsolatedObject.h
Modified: trunk/Source/WTF/wtf/Hasher.h (264273 => 264274)
--- trunk/Source/WTF/wtf/Hasher.h 2020-07-12 02:51:02 UTC (rev 264273)
+++ trunk/Source/WTF/wtf/Hasher.h 2020-07-12 04:39:31 UTC (rev 264274)
@@ -106,10 +106,11 @@
add(hasher, static_cast<std::underlying_type_t<Enumeration>>(value));
}
-template<typename, typename = void> constexpr bool HasBeginFunctionMember = false;
-template<typename T> constexpr bool HasBeginFunctionMember<T, std::void_t<decltype(std::declval<T>().begin())>> = true;
+template<typename> struct TypeCheckHelper { };
+template<typename, typename = void> struct HasBeginFunctionMember : std::false_type { };
+template<typename Container> struct HasBeginFunctionMember<Container, std::conditional_t<false, TypeCheckHelper<decltype(std::declval<Container>().begin())>, void>> : std::true_type { };
-template<typename Container> std::enable_if_t<HasBeginFunctionMember<Container> && !IsTypeComplete<std::tuple_size<Container>>, void> add(Hasher& hasher, const Container& container)
+template<typename Container> std::enable_if_t<HasBeginFunctionMember<Container>::value, void> add(Hasher& hasher, const Container& container)
{
for (const auto& value : container)
add(hasher, value);
@@ -125,22 +126,20 @@
addArgs(hasher, args...);
}
-template<typename, typename = void> constexpr bool HasGetFunctionMember = false;
-template<typename T> constexpr bool HasGetFunctionMember<T, std::void_t<decltype(std::declval<T>().template get<0>())>> = true;
+template<typename Tuple, std::size_t ...i> void addTupleHelper(Hasher& hasher, const Tuple& values, std::index_sequence<i...>)
+{
+ addArgs(hasher, std::get<i>(values)...);
+}
-template<typename TupleLike, std::size_t ...I> void addTupleLikeHelper(Hasher& hasher, const TupleLike& tupleLike, std::index_sequence<I...>)
+template<typename... Types> void add(Hasher& hasher, const std::tuple<Types...>& tuple)
{
- if constexpr (HasGetFunctionMember<TupleLike>)
- addArgs(hasher, tupleLike.template get<I>()...);
- else {
- using std::get;
- addArgs(hasher, get<I>(tupleLike)...);
- }
+ addTupleHelper(hasher, tuple, std::make_index_sequence<std::tuple_size<std::tuple<Types...>>::value> { });
}
-template<typename TupleLike> std::enable_if_t<IsTypeComplete<std::tuple_size<TupleLike>>, void> add(Hasher& hasher, const TupleLike& tuple)
+template<typename T1, typename T2> void add(Hasher& hasher, const std::pair<T1, T2>& pair)
{
- addTupleLikeHelper(hasher, tuple, std::make_index_sequence<std::tuple_size<TupleLike>::value> { });
+ add(hasher, pair.first);
+ add(hasher, pair.second);
}
template<typename T> void add(Hasher& hasher, const Optional<T>& optional)
Modified: trunk/Source/WTF/wtf/OptionSet.h (264273 => 264274)
--- trunk/Source/WTF/wtf/OptionSet.h 2020-07-12 02:51:02 UTC (rev 264273)
+++ trunk/Source/WTF/wtf/OptionSet.h 2020-07-12 04:39:31 UTC (rev 264274)
@@ -32,10 +32,18 @@
#include <wtf/EnumTraits.h>
#include <wtf/MathExtras.h>
#include <wtf/Optional.h>
-#include <wtf/StdLibExtras.h>
namespace WTF {
+// Detecting in C++ whether a type is defined, part 3: SFINAE and incomplete types
+// <https://devblogs.microsoft.com/oldnewthing/20190710-00/?p=102678>
+template<typename, typename = void>
+constexpr bool is_type_complete_v = false;
+
+template<typename T>
+constexpr bool is_type_complete_v<T, std::void_t<decltype(sizeof(T))>> = true;
+
+
template<typename E> class OptionSet;
@@ -68,13 +76,13 @@
};
-template<typename E, std::enable_if_t<std::is_enum<E>::value && IsTypeComplete<EnumTraits<E>>>* = nullptr>
+template<typename E, std::enable_if_t<std::is_enum<E>::value && is_type_complete_v<EnumTraits<E>>>* = nullptr>
constexpr bool isValidOptionSetEnum(E e)
{
return OptionSetValueChecker<std::underlying_type_t<E>, typename EnumTraits<E>::values>::isValidOptionSetEnum(static_cast<std::underlying_type_t<E>>(e));
}
-template<typename E, std::enable_if_t<std::is_enum<E>::value && !IsTypeComplete<EnumTraits<E>>>* = nullptr>
+template<typename E, std::enable_if_t<std::is_enum<E>::value && !is_type_complete_v<EnumTraits<E>>>* = nullptr>
constexpr bool isValidOptionSetEnum(E e)
{
// FIXME: Remove once all OptionSet<> enums have EnumTraits<> defined.
@@ -82,7 +90,7 @@
}
-template<typename E, std::enable_if_t<std::is_enum<E>::value && IsTypeComplete<EnumTraits<E>>>* = nullptr>
+template<typename E, std::enable_if_t<std::is_enum<E>::value && is_type_complete_v<EnumTraits<E>>>* = nullptr>
constexpr typename OptionSet<E>::StorageType maskRawValue(typename OptionSet<E>::StorageType rawValue)
{
auto allValidBitsValue = OptionSetValueChecker<std::underlying_type_t<E>, typename EnumTraits<E>::values>::allValidBits();
@@ -89,7 +97,7 @@
return rawValue & allValidBitsValue;
}
-template<typename E, std::enable_if_t<std::is_enum<E>::value && !IsTypeComplete<EnumTraits<E>>>* = nullptr>
+template<typename E, std::enable_if_t<std::is_enum<E>::value && !is_type_complete_v<EnumTraits<E>>>* = nullptr>
constexpr typename OptionSet<E>::StorageType maskRawValue(typename OptionSet<E>::StorageType rawValue)
{
// FIXME: Remove once all OptionSet<> enums have EnumTraits<> defined.
Modified: trunk/Source/WTF/wtf/StdLibExtras.h (264273 => 264274)
--- trunk/Source/WTF/wtf/StdLibExtras.h 2020-07-12 02:51:02 UTC (rev 264273)
+++ trunk/Source/WTF/wtf/StdLibExtras.h 2020-07-12 04:39:31 UTC (rev 264274)
@@ -418,11 +418,6 @@
template <template <typename...> class Base, typename Derived>
struct IsBaseOfTemplate : public std::integral_constant<bool, Detail::IsBaseOfTemplateImpl<Base, Derived>::value> {};
-// Based on 'Detecting in C++ whether a type is defined, part 3: SFINAE and incomplete types'
-// <https://devblogs.microsoft.com/oldnewthing/20190710-00/?p=102678>
-template<typename, typename = void> constexpr bool IsTypeComplete = false;
-template<typename T> constexpr bool IsTypeComplete<T, std::void_t<decltype(sizeof(T))>> = true;
-
template <class T>
struct RemoveCVAndReference {
typedef typename std::remove_cv<typename std::remove_reference<T>::type>::type type;
Modified: trunk/Tools/ChangeLog (264273 => 264274)
--- trunk/Tools/ChangeLog 2020-07-12 02:51:02 UTC (rev 264273)
+++ trunk/Tools/ChangeLog 2020-07-12 04:39:31 UTC (rev 264274)
@@ -1,3 +1,16 @@
+2020-07-11 Commit Queue <[email protected]>
+
+ Unreviewed, reverting r264270.
+ https://bugs.webkit.org/show_bug.cgi?id=214228
+
+ Broke the build
+
+ Reverted changeset:
+
+ "Make hasher work with tuple-like classes"
+ https://bugs.webkit.org/show_bug.cgi?id=214224
+ https://trac.webkit.org/changeset/264270
+
2020-07-11 Sam Weinig <[email protected]>
Reduce surface area of the ExtendedColor class to a bare minimum
Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/Hasher.cpp (264273 => 264274)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/Hasher.cpp 2020-07-12 02:51:02 UTC (rev 264273)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/Hasher.cpp 2020-07-12 04:39:31 UTC (rev 264274)
@@ -208,6 +208,8 @@
EXPECT_EQ(1652352321U, computeHash(HasherAddCustom2 { }));
}
+#if 0 // FIXME: Add support for tuple-like classes.
+
struct HasherAddTupleLikeClass1 {
std::array<int, 4> array { { 1, 2, 3, 4 } };
template<size_t i> int get() const { return std::get<i>(array); }
@@ -217,46 +219,34 @@
std::array<int, 4> array { { 1, 2, 3, 4 } };
};
-template<size_t i> int get(const HasherAddTupleLikeClass2& object)
-{
- return object.array[i];
}
-struct HasherAddTupleLikeClass3 {
- int a = 1;
- double b = 2;
-
- template<size_t i> decltype(auto) get() const
- {
- if constexpr (!i)
- return a;
- if constexpr (i == 1)
- return b;
- }
-};
-
-}
-
namespace std {
-template<> class tuple_size<TestWebKitAPI::HasherAddTupleLikeClass1> : public integral_constant<size_t, 4> { };
-template<size_t I> class tuple_element<I, TestWebKitAPI::HasherAddTupleLikeClass1> { public: using type = int; };
+// FIXME: Documentation at cppreference.cpp says std::tuple_size is a struct, but it's a class in current macOS tools.
+// FIXME: It's inelegant to inject this into the std namespace. Is that really how a tuple-like class needs to be defined?
+// FIXME: This is so inconvenient that I am not sure it's something we want to do for lots of classes in WebKit.
+template<> class std::tuple_size<TestWebKitAPI::HasherAddTupleLikeClass1> : public std::integral_constant<size_t, std::tuple_size<decltype(TestWebKitAPI::HasherAddTupleLikeClass1::array)>::value> { };
-template<> class tuple_size<TestWebKitAPI::HasherAddTupleLikeClass2> : public integral_constant<size_t, 4> { };
-template<size_t I> class tuple_element<I, TestWebKitAPI::HasherAddTupleLikeClass2> { public: using type = int; };
+template<> class std::tuple_size<TestWebKitAPI::HasherAddTupleLikeClass2> : public std::integral_constant<size_t, std::tuple_size<decltype(TestWebKitAPI::HasherAddTupleLikeClass2::array)>::value> { };
-template<> class tuple_size<TestWebKitAPI::HasherAddTupleLikeClass3> : public integral_constant<size_t, 2> { };
-template<size_t I> class tuple_element<I, TestWebKitAPI::HasherAddTupleLikeClass3> { public: using type = decltype(declval<TestWebKitAPI::HasherAddTupleLikeClass3>().template get<I>()); };
-
}
namespace TestWebKitAPI {
+// FIXME: Is it OK for the get to be in the class's namespace and rely on argument-dependent lookup?
+// Or does this function template need to be moved into the std namespace like the tuple_size specialization?
+template<size_t i> int get(const HasherAddTupleLikeClass2& object)
+{
+ return get<i>(object.array);
+}
+
TEST(WTF, Hasher_tupleLike)
{
EXPECT_EQ(1652352321U, computeHash(HasherAddTupleLikeClass1 { }));
EXPECT_EQ(1652352321U, computeHash(HasherAddTupleLikeClass2 { }));
- EXPECT_EQ(3489601216U, computeHash(HasherAddTupleLikeClass3 { }));
}
+#endif
+
} // namespace TestWebKitAPI