Commit 356c8834 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

Reland "wtf: Build traits based on cppgc for when using Oilpan library"

This is a reland of d22a4cef

Fixes:
- Add :wtf_support target for mojo targets, even when only requiring
  headers.
- Slim down :wtf target by only requiring //v8:cppgc_headers when
  using the Oilpan library.

Original change's description:
> wtf: Build traits based on cppgc for when using Oilpan library
>
> Currently WTF uses forward declarations to define basic GC traits that
> are used throughout WTF and Blink globally, i.e., without any specific
> context or other traits being available. This is an implicit
> dependency on blink.
>
> With Oilpan throuhg V8, we make this dependency a header-only
> dependency that is explicit which allows to re-use existing traits
> from the library to define the WTF equivalents.
>
> Change-Id: I3995c0d587424299ed880adcd5ac848a635e4f1e
> Bug: chromium:1056170
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2532236
> Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
> Reviewed-by: Kentaro Hara <haraken@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#826397}

Cq-Include-Trybots: luci.chromium.try:linux-chromeos-rel
Bug: chromium:1056170
Change-Id: Ic9594e7d4824d12cd06273854c9391ee97503fca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2532222Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826936}
parent af0b7ed2
......@@ -1346,6 +1346,10 @@ template("mojom") {
full_name = get_label_info("$d", "label_no_toolchain")
public_deps += [ "${full_name}${variant_suffix}_headers" ]
}
if (defined(bindings_configuration.for_blink) &&
bindings_configuration.for_blink) {
public_deps += [ "//mojo/public/cpp/bindings:wtf_support" ]
}
}
if (!force_source_set && defined(invoker.component_macro_prefix)) {
......
......@@ -342,11 +342,6 @@ namespace internal {
template <typename T>
constexpr bool IsMember = WTF::IsSubclassOfTemplate<T, Member>::value;
template <typename T>
constexpr bool IsMemberOrWeakMemberType =
WTF::IsSubclassOfTemplate<T, Member>::value ||
WTF::IsSubclassOfTemplate<T, WeakMember>::value;
} // namespace internal
template <typename KeyArg,
......@@ -376,11 +371,11 @@ class HeapHashMap : public HashMap<KeyArg,
WTF::IsTraceable<KeyArg>::value || WTF::IsTraceable<MappedArg>::value,
"For hash maps without traceable elements, use HashMap<> "
"instead of HeapHashMap<>.");
static_assert(internal::IsMemberOrWeakMemberType<KeyArg> ||
static_assert(WTF::IsMemberOrWeakMemberType<KeyArg>::value ||
!WTF::IsTraceable<KeyArg>::value,
"HeapHashMap supports only Member, WeakMember and "
"non-traceable types as keys.");
static_assert(internal::IsMemberOrWeakMemberType<MappedArg> ||
static_assert(WTF::IsMemberOrWeakMemberType<MappedArg>::value ||
!WTF::IsTraceable<MappedArg>::value ||
WTF::IsSubclassOfTemplate<MappedArg,
TraceWrapperV8Reference>::value,
......@@ -413,7 +408,7 @@ class HeapHashSet
DISALLOW_NEW();
static void CheckType() {
static_assert(internal::IsMemberOrWeakMemberType<ValueArg>,
static_assert(WTF::IsMemberOrWeakMemberType<ValueArg>::value,
"HeapHashSet supports only Member and WeakMember.");
static_assert(std::is_trivially_destructible<HeapHashSet>::value,
"HeapHashSet must be trivially destructible.");
......@@ -446,7 +441,7 @@ class HeapLinkedHashSet
DISALLOW_NEW();
static void CheckType() {
static_assert(internal::IsMemberOrWeakMemberType<ValueArg>,
static_assert(WTF::IsMemberOrWeakMemberType<ValueArg>::value,
"HeapLinkedHashSet supports only Member and WeakMember.");
// If not trivially destructible, we have to add a destructor which will
// hinder performance.
......@@ -486,7 +481,7 @@ class HeapListHashSet
DISALLOW_NEW();
static void CheckType() {
static_assert(internal::IsMemberOrWeakMemberType<ValueArg>,
static_assert(WTF::IsMemberOrWeakMemberType<ValueArg>::value,
"HeapListHashSet supports only Member and WeakMember.");
static_assert(std::is_trivially_destructible<HeapListHashSet>::value,
"HeapListHashSet must be trivially destructible.");
......@@ -525,7 +520,7 @@ class HeapHashCountedSet
DISALLOW_NEW();
static void CheckType() {
static_assert(internal::IsMemberOrWeakMemberType<Value>,
static_assert(WTF::IsMemberOrWeakMemberType<Value>::value,
"HeapHashCountedSet supports only Member and WeakMember.");
static_assert(std::is_trivially_destructible<HeapHashCountedSet>::value,
"HeapHashCountedSet must be trivially destructible.");
......
......@@ -4,10 +4,19 @@
assert(!is_ios)
import("//build/buildflag_header.gni")
import("//build/config/compiler/compiler.gni")
import("//testing/test.gni")
import("//third_party/blink/public/public_features.gni")
import("//third_party/blink/renderer/config.gni")
buildflag_header("buildflags") {
header = "buildflags.h"
header_dir = "third_party/blink/renderer/platform/wtf"
flags = [ "USE_V8_OILPAN=$enable_blink_heap_use_v8_oilpan" ]
}
visibility = [
":*",
"//mojo/public/cpp/bindings/*",
......@@ -201,8 +210,12 @@ component("wtf") {
"//third_party/blink/renderer:features",
]
# TODO(tkent): WTF should not depend on it.
deps = [ "//third_party/blink/public/common:headers" ]
deps = [
":buildflags",
# TODO(tkent): WTF should not depend on it.
"//third_party/blink/public/common:headers",
]
public_deps = [
"//base",
......@@ -211,6 +224,10 @@ component("wtf") {
"//third_party/icu",
]
if (enable_blink_heap_use_v8_oilpan) {
public_deps += [ "//v8:cppgc_headers" ]
}
# Rules changing the |sources| list are temporarily commented out, until
# those files are actually moved to here.
......
......@@ -32,4 +32,6 @@ include_rules = [
"-third_party/blink/renderer/platform",
"+third_party/blink/renderer/platform/wtf",
"-v8",
# Allow pulling in cppgc for Oilpan use.
"+v8/include/cppgc",
]
......@@ -36,13 +36,6 @@
#include "third_party/blink/renderer/platform/wtf/thread_safe_ref_counted.h"
#include "third_party/blink/renderer/platform/wtf/type_traits.h"
namespace blink {
template <typename T>
class Member;
template <typename T>
class WeakMember;
}
namespace WTF {
// Functional.h provides a very simple way to bind a function pointer and
......@@ -200,8 +193,7 @@ struct CheckGCedTypeRestriction {
"it with either WrapPersistent, WrapWeakPersistent, "
"WrapCrossThreadPersistent, WrapCrossThreadWeakPersistent, "
"RefPtr or unretained.");
static_assert(!IsSubclassOfTemplate<T, blink::Member>::value &&
!IsSubclassOfTemplate<T, blink::WeakMember>::value,
static_assert(!WTF::IsMemberOrWeakMemberType<T>::value,
"Member and WeakMember are not allowed to bind into "
"WTF::Function. Wrap it with either WrapPersistent, "
"WrapWeakPersistent, WrapCrossThreadPersistent or "
......
......@@ -28,6 +28,19 @@
#include "base/compiler_specific.h"
#include "base/template_util.h"
#include "build/build_config.h"
#include "third_party/blink/renderer/platform/wtf/buildflags.h"
#if BUILDFLAG(USE_V8_OILPAN)
#include "v8/include/cppgc/type-traits.h" // nogncheck
#else
namespace blink {
template <typename T>
class Member;
class Visitor;
template <typename T>
class WeakMember;
} // namespace blink
#endif // BUILDFLAG(BLINK_HEAP_USE_V8_OILPAN)
namespace WTF {
......@@ -37,24 +50,6 @@ inline const char* GetStringWithTypeName() {
return PRETTY_FUNCTION;
}
// Specifies whether a type should be treated weakly by the memory management
// system. Only supported by the garbage collector and not by PartitionAlloc.
// Requires garbage collection support, so it is only safe to override in sync
// with changing garbage collection semantics.
template <typename T>
struct IsWeak : std::false_type {};
enum WeakHandlingFlag {
kNoWeakHandling,
kWeakHandling,
};
template <typename T>
struct WeakHandlingTrait
: std::integral_constant<WeakHandlingFlag,
IsWeak<T>::value ? kWeakHandling
: kNoWeakHandling> {};
template <typename T, typename U>
struct IsSubclass {
private:
......@@ -122,15 +117,24 @@ struct IsSubclassOfTemplateTypenameSizeTypename {
static const bool value = sizeof(SubclassCheck(t_)) == sizeof(YesType);
};
} // namespace WTF
#if BUILDFLAG(USE_V8_OILPAN)
namespace blink {
template <typename T>
struct IsTraceable : cppgc::internal::IsTraceable<T> {};
class Visitor;
template <typename T>
struct IsGarbageCollectedType : cppgc::internal::IsGarbageCollectedType<T> {};
} // namespace blink
template <typename T>
struct IsWeak : cppgc::internal::IsWeak<T> {};
namespace WTF {
template <typename T>
struct IsMemberOrWeakMemberType
: std::integral_constant<bool,
cppgc::IsMemberTypeV<T> ||
cppgc::IsWeakMemberTypeV<T>> {};
#else // !USE_V8_OILPAN
namespace internal {
// IsTraceMethodConst is used to verify that all Trace methods are marked as
......@@ -168,33 +172,6 @@ struct IsTraceable<std::pair<T, U>>
: std::integral_constant<bool,
IsTraceable<T>::value || IsTraceable<U>::value> {};
// Convenience template wrapping the IsTraceableInCollection template in
// Collection Traits. It helps make the code more readable.
template <typename Traits>
struct IsTraceableInCollectionTrait
: std::integral_constant<
bool,
Traits::template IsTraceableInCollection<>::value> {};
// This is used to check that DISALLOW_NEW objects are not
// stored in off-heap Vectors, HashTables etc.
template <typename T>
struct IsDisallowNew {
private:
using YesType = char;
struct NoType {
char padding[8];
};
template <typename U>
static YesType CheckMarker(typename U::IsDisallowNewMarker*);
template <typename U>
static NoType CheckMarker(...);
public:
static const bool value = sizeof(CheckMarker<T>(nullptr)) == sizeof(YesType);
};
template <typename T>
class IsGarbageCollectedTypeInternal {
typedef char YesType;
......@@ -235,6 +212,60 @@ class IsGarbageCollectedType : public IsGarbageCollectedTypeInternal<T> {
static_assert(sizeof(T), "T must be fully defined");
};
// Specifies whether a type should be treated weakly by the memory management
// system. Only supported by the garbage collector and not by PartitionAlloc.
// Requires garbage collection support, so it is only safe to override in sync
// with changing garbage collection semantics.
template <typename T>
struct IsWeak : std::false_type {};
template <typename T>
struct IsMemberOrWeakMemberType
: std::integral_constant<
bool,
WTF::IsSubclassOfTemplate<T, blink::Member>::value ||
WTF::IsSubclassOfTemplate<T, blink::WeakMember>::value> {};
#endif // !USE_V8_OILPAN
// Convenience template wrapping the IsTraceableInCollection template in
// Collection Traits. It helps make the code more readable.
template <typename Traits>
struct IsTraceableInCollectionTrait
: std::integral_constant<
bool,
Traits::template IsTraceableInCollection<>::value> {};
enum WeakHandlingFlag {
kNoWeakHandling,
kWeakHandling,
};
template <typename T>
struct WeakHandlingTrait
: std::integral_constant<WeakHandlingFlag,
IsWeak<T>::value ? kWeakHandling
: kNoWeakHandling> {};
// This is used to check that DISALLOW_NEW objects are not
// stored in off-heap Vectors, HashTables etc.
template <typename T>
struct IsDisallowNew {
private:
using YesType = char;
struct NoType {
char padding[8];
};
template <typename U>
static YesType CheckMarker(typename U::IsDisallowNewMarker*);
template <typename U>
static NoType CheckMarker(...);
public:
static const bool value = sizeof(CheckMarker<T>(nullptr)) == sizeof(YesType);
};
template <>
class IsGarbageCollectedType<void> {
public:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment