Bug 1628389 - Replace standard library traits classes with _v and _t versions in the GC r=jwalden

Differential Revision: https://phabricator.services.mozilla.com/D70224

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jon Coppeard 2020-04-09 09:49:24 +00:00
parent 7829c32789
commit 11b739d096
6 changed files with 27 additions and 31 deletions

View File

@ -230,15 +230,15 @@ inline T SafelyInitialized() {
// That presumption holds for pointers, where value initialization produces
// a null pointer.
constexpr bool IsPointer = std::is_pointer<T>::value;
constexpr bool IsPointer = std::is_pointer_v<T>;
// For classes and unions we *assume* that if |T|'s default constructor is
// non-trivial it'll initialize correctly. (This is unideal, but C++
// doesn't offer a type trait indicating whether a class's constructor is
// user-defined, which better approximates our desired semantics.)
constexpr bool IsNonTriviallyDefaultConstructibleClassOrUnion =
(std::is_class<T>::value || std::is_union<T>::value) &&
!std::is_trivially_default_constructible<T>::value;
(std::is_class_v<T> ||
std::is_union_v<T>)&&!std::is_trivially_default_constructible_v<T>;
static_assert(IsPointer || IsNonTriviallyDefaultConstructibleClassOrUnion,
"T() must evaluate to a safely-initialized T");
@ -1087,9 +1087,9 @@ class MOZ_RAII Rooted : public js::RootedBase<T, Rooted<T>> {
// If T can be constructed with a cx, then define another constructor for it
// that will be preferred.
template <typename RootingContext,
typename = typename std::enable_if<
std::is_constructible<T, RootingContext>::value>::type>
template <
typename RootingContext,
typename = std::enable_if_t<std::is_constructible_v<T, RootingContext>>>
Rooted(const RootingContext& cx, CtorDispatcher, detail::PreferredOverload)
: Rooted(cx, T(cx)) {}

View File

@ -654,10 +654,10 @@ class CellHeaderWithLengthAndFlags {
// The low bits of the word (see CellFlagBitsReservedForGC) are reserved for GC.
template <class PtrT>
class CellHeaderWithNonGCPointer : public CellHeader {
static_assert(!std::is_pointer<PtrT>::value,
static_assert(!std::is_pointer_v<PtrT>,
"PtrT should be the type of the referent, not of the pointer");
static_assert(
!std::is_base_of<Cell, PtrT>::value,
!std::is_base_of_v<Cell, PtrT>,
"Don't use CellHeaderWithNonGCPointer for pointers to GC things");
public:
@ -704,10 +704,10 @@ class CellHeaderWithTenuredGCPointer : public CellHeader {
// These static asserts are not in class scope because the PtrT may not be
// defined when this class template is instantiated.
static_assert(
!std::is_pointer<PtrT>::value,
!std::is_pointer_v<PtrT>,
"PtrT should be the type of the referent, not of the pointer");
static_assert(
std::is_base_of<Cell, PtrT>::value,
std::is_base_of_v<Cell, PtrT>,
"Only use CellHeaderWithTenuredGCPointer for pointers to GC things");
}

View File

@ -35,7 +35,7 @@ struct TaggedPtr<JS::Value> {
static JS::Value wrap(JS::BigInt* bi) { return JS::BigIntValue(bi); }
template <typename T>
static JS::Value wrap(T* priv) {
static_assert(std::is_base_of<Cell, T>::value,
static_assert(std::is_base_of_v<Cell, T>,
"Type must be a GC thing derived from js::gc::Cell");
return JS::PrivateGCThingValue(priv);
}
@ -59,18 +59,16 @@ struct TaggedPtr<TaggedProto> {
template <typename T>
struct MightBeForwarded {
static_assert(std::is_base_of<Cell, T>::value, "T must derive from Cell");
static_assert(std::is_base_of_v<Cell, T>, "T must derive from Cell");
static_assert(!std::is_same_v<Cell, T> && !std::is_same_v<TenuredCell, T>,
"T must not be Cell or TenuredCell");
static const bool value = std::is_base_of<JSObject, T>::value ||
std::is_base_of<Shape, T>::value ||
std::is_base_of<BaseShape, T>::value ||
std::is_base_of<JSString, T>::value ||
std::is_base_of<JS::BigInt, T>::value ||
std::is_base_of<js::BaseScript, T>::value ||
std::is_base_of<js::Scope, T>::value ||
std::is_base_of<js::RegExpShared, T>::value;
static const bool value =
std::is_base_of_v<JSObject, T> || std::is_base_of_v<Shape, T> ||
std::is_base_of_v<BaseShape, T> || std::is_base_of_v<JSString, T> ||
std::is_base_of_v<JS::BigInt, T> ||
std::is_base_of_v<js::BaseScript, T> || std::is_base_of_v<js::Scope, T> ||
std::is_base_of_v<js::RegExpShared, T>;
};
template <typename T>

View File

@ -199,9 +199,8 @@ void js::CheckTracedThing(JSTracer* trc, T* thing) {
// Check that CellHeader is the first field in the cell.
static_assert(
std::is_base_of<CellHeader,
typename std::remove_const<typename std::remove_reference<
decltype(thing->cellHeader())>::type>::type>::value,
std::is_base_of_v<CellHeader, std::remove_const_t<std::remove_reference_t<
decltype(thing->cellHeader())>>>,
"GC things must provide a cellHeader() method that returns a reference "
"to the cell header");
MOZ_ASSERT(static_cast<const void*>(&thing->cellHeader()) ==
@ -3082,8 +3081,8 @@ void js::gc::StoreBuffer::WholeCellBuffer::trace(TenuringTracer& mover) {
template <typename T>
void js::gc::StoreBuffer::CellPtrEdge<T>::trace(TenuringTracer& mover) const {
static_assert(std::is_base_of<Cell, T>::value, "T must be a Cell type");
static_assert(!std::is_base_of<TenuredCell, T>::value,
static_assert(std::is_base_of_v<Cell, T>, "T must be a Cell type");
static_assert(!std::is_base_of_v<TenuredCell, T>,
"T must not be a tenured Cell type");
if (!*edge) {
@ -3574,9 +3573,9 @@ static inline bool ShouldCheckMarkState(JSRuntime* rt, T** thingp) {
template <typename T>
struct MightBeNurseryAllocated {
static const bool value = std::is_base_of<JSObject, T>::value ||
std::is_base_of<JSString, T>::value ||
std::is_base_of<JS::BigInt, T>::value;
static const bool value = std::is_base_of_v<JSObject, T> ||
std::is_base_of_v<JSString, T> ||
std::is_base_of_v<JS::BigInt, T>;
};
template <typename T>

View File

@ -22,8 +22,7 @@ template <typename T>
struct InternalGCPointerPolicy : public JS::GCPointerPolicy<T> {
using Type = std::remove_pointer_t<T>;
#define IS_BASE_OF_OR(_1, BaseType, _2, _3) \
std::is_base_of<BaseType, Type>::value ||
#define IS_BASE_OF_OR(_1, BaseType, _2, _3) std::is_base_of_v<BaseType, Type> ||
static_assert(
JS_FOR_EACH_TRACEKIND(IS_BASE_OF_OR) false,
"InternalGCPointerPolicy must only be used for GC thing pointers");

View File

@ -68,7 +68,7 @@ template <typename T>
struct BaseGCType {
using type =
typename MapTraceKindToType<JS::MapTypeToTraceKind<T>::kind>::Type;
static_assert(std::is_base_of<type, T>::value, "Failed to find base type");
static_assert(std::is_base_of_v<type, T>, "Failed to find base type");
};
// Our barrier templates are parameterized on the pointer types so that we can