Skip to content

Commit

Permalink
Bug 1626570 - Remove obsolete copy enabling machinery. r=froydnj
Browse files Browse the repository at this point in the history
  • Loading branch information
sigiesec committed May 11, 2020
1 parent 2a7be3e commit e6422e2
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 136 deletions.
2 changes: 0 additions & 2 deletions dom/base/nsFocusManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class ContentParent;

struct nsDelayedBlurOrFocusEvent;

MOZ_DECLARE_COPY_CONSTRUCTIBLE(nsDelayedBlurOrFocusEvent)

/**
* The focus manager keeps track of where the focus is, that is, the node
* which receives key events.
Expand Down
1 change: 0 additions & 1 deletion dom/indexedDB/ActorsChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ struct CloneInfo;
} // namespace mozilla

MOZ_DECLARE_RELOCATE_USING_MOVE_CONSTRUCTOR(mozilla::dom::indexedDB::CloneInfo)
MOZ_DECLARE_NON_COPY_CONSTRUCTIBLE(mozilla::dom::indexedDB::CloneInfo)

namespace mozilla {
namespace dom {
Expand Down
2 changes: 0 additions & 2 deletions dom/security/nsCSPContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ class nsINetworkInterceptController;
class nsIEventTarget;
struct ConsoleMsgQueueElem;

MOZ_DECLARE_COPY_CONSTRUCTIBLE(ConsoleMsgQueueElem)

namespace mozilla {
namespace dom {
class Element;
Expand Down
2 changes: 0 additions & 2 deletions storage/mozStorageAsyncStatementExecution.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ class StatementData;
} // namespace storage
} // namespace mozilla

MOZ_DECLARE_COPY_CONSTRUCTIBLE(mozilla::storage::StatementData)

namespace mozilla::storage {
class AsyncExecuteStatements final : public nsIRunnable,
public mozIStoragePendingStatement {
Expand Down
2 changes: 0 additions & 2 deletions widget/MouseEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ class PBrowserBridgeParent;
class WidgetPointerEvent;
} // namespace mozilla

MOZ_DECLARE_COPY_CONSTRUCTIBLE(mozilla::WidgetPointerEvent)

namespace mozilla {
class WidgetPointerEventHolder final {
public:
Expand Down
155 changes: 28 additions & 127 deletions xpcom/ds/nsTArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,83 +268,21 @@ extern nsTArrayHeader sEmptyTArrayHeader;
}

namespace detail {
// SpecializableIsCopyConstructible is a wrapper around
// std::is_copy_constructible, which explicitly disallows defining
// specializations of it. However, we need to specialize it to allow
// instantiating nsTArray for incomplete value types, for which it must be known
// whether the value type is copy-constructible. Specialization should always be
// done using the MOZ_DECLARE_COPY_CONSTRUCTIBLE or
// MOZ_DECLARE_NON_COPY_CONSTRUCTIBLE macros.
template <typename E>
struct SpecializableIsCopyConstructible {
static constexpr bool Value = std::is_copy_constructible_v<E>;
};

#define MOZ_DECLARE_COPY_CONSTRUCTIBLE(E) \
namespace detail { \
template <> \
struct SpecializableIsCopyConstructible<E> { \
static constexpr bool Value = true; \
}; \
}
#define MOZ_DECLARE_NON_COPY_CONSTRUCTIBLE(E) \
namespace detail { \
template <> \
struct SpecializableIsCopyConstructible<E> { \
static constexpr bool Value = false; \
}; \
}

template <typename E>
constexpr bool SpecializableIsCopyConstructibleValue =
SpecializableIsCopyConstructible<E>::Value;

// nsTArray_CopyEnabler is used as a base class of nsTArray_Impl to ensure
// nsTArray_Impl only is copy-constructible and copy-assignable if E is
// copy-constructible. nsTArray_Impl never makes use of E's copy assignment
// operator, so the decision is made solely based on E's copy-constructibility.
template <typename E, typename Impl, typename Alloc,
bool IsCopyConstructible = false>
class nsTArray_CopyEnabler;

template <typename E, typename Impl, typename Alloc>
class nsTArray_CopyEnabler<E, Impl, Alloc, false> {
public:
nsTArray_CopyEnabler() = default;

nsTArray_CopyEnabler(const nsTArray_CopyEnabler&) = delete;
nsTArray_CopyEnabler& operator=(const nsTArray_CopyEnabler&) = delete;
};

template <typename E, typename Impl, typename Alloc>
class nsTArray_CopyEnabler<E, Impl, Alloc, true> {
// nsTArray_CopyDisabler disables copy operations.
class nsTArray_CopyDisabler {
public:
nsTArray_CopyEnabler() = default;

nsTArray_CopyEnabler(const nsTArray_CopyEnabler& aOther) {
static_cast<Impl*>(this)->template AppendElementsInternal<Alloc>(
static_cast<const Impl&>(aOther).Elements(),
static_cast<const Impl&>(aOther).Length());
}
nsTArray_CopyDisabler() = default;

nsTArray_CopyEnabler& operator=(const nsTArray_CopyEnabler& aOther) {
if (this != &aOther) {
static_cast<Impl*>(this)->template ReplaceElementsAtInternal<Alloc>(
0, static_cast<Impl*>(this)->Length(),
static_cast<const Impl&>(aOther).Elements(),
static_cast<const Impl&>(aOther).Length());
}
return *this;
}
nsTArray_CopyDisabler(const nsTArray_CopyDisabler&) = delete;
nsTArray_CopyDisabler& operator=(const nsTArray_CopyDisabler&) = delete;
};

} // namespace detail

// This class provides a SafeElementAt method to nsTArray<T*> which does
// not take a second default value parameter.
template <class E, class Derived, typename Alloc>
struct nsTArray_SafeElementAtHelper
: public ::detail::nsTArray_CopyEnabler<E, Derived, Alloc> {
template <class E, class Derived>
struct nsTArray_SafeElementAtHelper : public ::detail::nsTArray_CopyDisabler {
typedef E* elem_type;
typedef size_t index_type;

Expand All @@ -355,9 +293,9 @@ struct nsTArray_SafeElementAtHelper
const elem_type& SafeElementAt(index_type aIndex) const;
};

template <class E, class Derived, typename Alloc>
struct nsTArray_SafeElementAtHelper<E*, Derived, Alloc>
: public ::detail::nsTArray_CopyEnabler<E*, Derived, Alloc> {
template <class E, class Derived>
struct nsTArray_SafeElementAtHelper<E*, Derived>
: public ::detail::nsTArray_CopyDisabler {
typedef E* elem_type;
// typedef const E* const_elem_type; XXX: see below
typedef size_t index_type;
Expand All @@ -377,9 +315,9 @@ struct nsTArray_SafeElementAtHelper<E*, Derived, Alloc>

// E is a smart pointer type; the
// smart pointer can act as its element_type*.
template <class E, class Derived, typename Alloc>
template <class E, class Derived>
struct nsTArray_SafeElementAtSmartPtrHelper
: public ::detail::nsTArray_CopyEnabler<E, Derived, Alloc> {
: public ::detail::nsTArray_CopyDisabler {
typedef typename E::element_type* elem_type;
typedef const typename E::element_type* const_elem_type;
typedef size_t index_type;
Expand All @@ -405,24 +343,23 @@ struct nsTArray_SafeElementAtSmartPtrHelper
template <class T>
class nsCOMPtr;

template <class E, class Derived, typename Alloc>
struct nsTArray_SafeElementAtHelper<nsCOMPtr<E>, Derived, Alloc>
: public nsTArray_SafeElementAtSmartPtrHelper<nsCOMPtr<E>, Derived, Alloc> {
};
template <class E, class Derived>
struct nsTArray_SafeElementAtHelper<nsCOMPtr<E>, Derived>
: public nsTArray_SafeElementAtSmartPtrHelper<nsCOMPtr<E>, Derived> {};

template <class E, class Derived, typename Alloc>
struct nsTArray_SafeElementAtHelper<RefPtr<E>, Derived, Alloc>
: public nsTArray_SafeElementAtSmartPtrHelper<RefPtr<E>, Derived, Alloc> {};
template <class E, class Derived>
struct nsTArray_SafeElementAtHelper<RefPtr<E>, Derived>
: public nsTArray_SafeElementAtSmartPtrHelper<RefPtr<E>, Derived> {};

namespace mozilla {
template <class T>
class OwningNonNull;
} // namespace mozilla

template <class E, class Derived, typename Alloc>
struct nsTArray_SafeElementAtHelper<mozilla::OwningNonNull<E>, Derived, Alloc>
template <class E, class Derived>
struct nsTArray_SafeElementAtHelper<mozilla::OwningNonNull<E>, Derived>
: public nsTArray_SafeElementAtSmartPtrHelper<mozilla::OwningNonNull<E>,
Derived, Alloc> {};
Derived> {};

// Servo bindings.
extern "C" void Gecko_EnsureTArrayCapacity(void* aArray, size_t aCapacity,
Expand Down Expand Up @@ -839,33 +776,8 @@ struct MOZ_NEEDS_MEMMOVABLE_TYPE nsTArray_RelocationStrategy {
using Type = nsTArray_RelocateUsingMoveConstructor<T<S>>; \
};

MOZ_DECLARE_COPY_CONSTRUCTIBLE(nsTString<char>)
MOZ_DECLARE_COPY_CONSTRUCTIBLE(nsTString<char16_t>)

MOZ_DECLARE_COPY_CONSTRUCTIBLE(mozilla::a11y::BatchData)

// TODO mozilla::ipc::AutoIPCStream is not even movable, so memmovable use with
// nsTArray (in StructuredCloneData) seems at least quirky
MOZ_DECLARE_NON_COPY_CONSTRUCTIBLE(mozilla::ipc::AutoIPCStream)
MOZ_DECLARE_COPY_CONSTRUCTIBLE(mozilla::ipc::ContentSecurityPolicy)
MOZ_DECLARE_COPY_CONSTRUCTIBLE(mozilla::layers::Animation)
MOZ_DECLARE_COPY_CONSTRUCTIBLE(mozilla::layers::FrameStats)
MOZ_DECLARE_COPY_CONSTRUCTIBLE(mozilla::layers::PropertyAnimationGroup)
#define MOZ_NSTARRAY_COMMA ,
MOZ_DECLARE_COPY_CONSTRUCTIBLE(
mozilla::dom::binding_detail::RecordEntry<
nsTString<char> MOZ_NSTARRAY_COMMA
mozilla::dom::Nullable<mozilla::dom::OwningUTF8StringOrDouble>>)
MOZ_DECLARE_COPY_CONSTRUCTIBLE(mozilla::dom::binding_detail::RecordEntry<
nsTString<char16_t> MOZ_NSTARRAY_COMMA
mozilla::dom::OwningStringOrBooleanOrObject>)
#undef MOZ_NSTARRAY_COMMA
MOZ_DECLARE_COPY_CONSTRUCTIBLE(mozilla::dom::MessagePortIdentifier)
MOZ_DECLARE_COPY_CONSTRUCTIBLE(mozilla::dom::MozPluginParameter)
MOZ_DECLARE_COPY_CONSTRUCTIBLE(mozilla::dom::OwningFileOrDirectory)
MOZ_DECLARE_COPY_CONSTRUCTIBLE(mozilla::dom::Pref)
MOZ_DECLARE_COPY_CONSTRUCTIBLE(mozilla::dom::ResponsiveImageCandidate)
MOZ_DECLARE_COPY_CONSTRUCTIBLE(mozilla::dom::ServiceWorkerRegistrationData)

MOZ_DECLARE_RELOCATE_USING_MOVE_CONSTRUCTOR_FOR_TEMPLATE(JS::Heap)
MOZ_DECLARE_RELOCATE_USING_MOVE_CONSTRUCTOR_FOR_TEMPLATE(std::function)
Expand Down Expand Up @@ -898,9 +810,8 @@ MOZ_DECLARE_RELOCATE_USING_MOVE_CONSTRUCTOR(mozilla::SourceBufferTask)
// nsTArray_Impl class, to allow extra conversions to be added for specific
// types.
//
template <class E, class Derived, typename Alloc>
struct nsTArray_TypedBase
: public nsTArray_SafeElementAtHelper<E, Derived, Alloc> {};
template <class E, class Derived>
struct nsTArray_TypedBase : public nsTArray_SafeElementAtHelper<E, Derived> {};

//
// Specialization of nsTArray_TypedBase for arrays containing JS::Heap<E>
Expand All @@ -913,9 +824,9 @@ struct nsTArray_TypedBase
// The static_cast is necessary to obtain the correct address for the derived
// class since we are a base class used in multiple inheritance.
//
template <class E, class Derived, typename Alloc>
struct nsTArray_TypedBase<JS::Heap<E>, Derived, Alloc>
: public nsTArray_SafeElementAtHelper<JS::Heap<E>, Derived, Alloc> {
template <class E, class Derived>
struct nsTArray_TypedBase<JS::Heap<E>, Derived>
: public nsTArray_SafeElementAtHelper<JS::Heap<E>, Derived> {
operator const nsTArray<E>&() {
static_assert(sizeof(E) == sizeof(JS::Heap<E>),
"JS::Heap<E> must be binary compatible with E.");
Expand Down Expand Up @@ -1037,17 +948,8 @@ template <class E, class Alloc>
class nsTArray_Impl
: public nsTArray_base<Alloc,
typename nsTArray_RelocationStrategy<E>::Type>,
public nsTArray_TypedBase<E, nsTArray_Impl<E, Alloc>,
Alloc> // This must come last to ensure the
// members from nsTArray_base are
// initialized before the delegated
// constructor calls from
// nsTArray_CopyEnabler are executed.
{
public nsTArray_TypedBase<E, nsTArray_Impl<E, Alloc>> {
private:
friend class ::detail::nsTArray_CopyEnabler<E, nsTArray_Impl<E, Alloc>,
Alloc>;

friend class nsTArray<E>;

typedef nsTArrayFallibleAllocator FallibleAlloc;
Expand All @@ -1061,8 +963,7 @@ class nsTArray_Impl
typedef E elem_type;
typedef nsTArray_Impl<E, Alloc> self_type;
typedef nsTArrayElementTraits<E> elem_traits;
typedef nsTArray_SafeElementAtHelper<E, self_type, Alloc>
safeelementat_helper_type;
typedef nsTArray_SafeElementAtHelper<E, self_type> safeelementat_helper_type;
typedef mozilla::ArrayIterator<elem_type&, nsTArray<E>> iterator;
typedef mozilla::ArrayIterator<const elem_type&, nsTArray<E>> const_iterator;
typedef mozilla::ReverseIterator<iterator> reverse_iterator;
Expand Down

0 comments on commit e6422e2

Please sign in to comment.