Bug 1626587 - Part 1: Replace mozilla::IsPod in LifoAlloc. r=jwalden
authorAndré Bargull <andre.bargull@gmail.com>
Mon, 27 Apr 2020 10:09:58 +0000
changeset 526236 d49eebe62ba32d22be1b441c51253a94a29e0ccd
parent 526235 eac656992f2b208404135da87fd7d7a8de713c0e
child 526237 1e75beb9d31158b254179ed89bd4ac8ff9cc9cac
push id114141
push userdluca@mozilla.com
push dateMon, 27 Apr 2020 14:18:59 +0000
treeherderautoland@1e75de42137c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalden
bugs1626587
milestone77.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1626587 - Part 1: Replace mozilla::IsPod in LifoAlloc. r=jwalden Replace `mozilla::IsPod` with `std::is_trivial` and `std::is_trivially_destructible`, which should cover the requirements for LifoAlloc. (`std::is_trivial` implies `is_trivially_default_constructible` and `is_trivially_copyable`.) `IsPod<OffsetAndDefIndex>` can then be removed. Differential Revision: https://phabricator.services.mozilla.com/D69198
js/src/ds/LifoAlloc.h
js/src/vm/BytecodeUtil.cpp
--- a/js/src/ds/LifoAlloc.h
+++ b/js/src/ds/LifoAlloc.h
@@ -8,21 +8,21 @@
 #define ds_LifoAlloc_h
 
 #include "mozilla/Attributes.h"
 #include "mozilla/MathAlgorithms.h"
 #include "mozilla/MemoryChecking.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/PodOperations.h"
 #include "mozilla/TemplateLib.h"
-#include "mozilla/TypeTraits.h"
 
 #include <algorithm>
 #include <new>
 #include <stddef.h>  // size_t
+#include <type_traits>
 #include <utility>
 
 // This data structure supports stacky LIFO allocation (mark/release and
 // LifoAllocScope). It does not maintain one contiguous segment; instead, it
 // maintains a bunch of linked memory segments. In order to prevent malloc/free
 // thrashing, unused segments are deallocated when garbage collection occurs.
 
 #include "js/UniquePtr.h"
@@ -738,19 +738,22 @@ class LifoAlloc {
 #else
    public:
     explicit AutoFallibleScope(LifoAlloc*) {}
 #endif
   };
 
   template <typename T>
   T* newArray(size_t count) {
-    static_assert(mozilla::IsPod<T>::value,
-                  "T must be POD so that constructors (and destructors, "
-                  "when the LifoAlloc is freed) need not be called");
+    static_assert(std::is_trivial_v<T>,
+                  "T must be trivially constructible so that constructors need "
+                  "not be called");
+    static_assert(std::is_trivially_destructible_v<T>,
+                  "T must be trivially destructible so destructors don't need "
+                  "to be called when the LifoAlloc is freed");
     return newArrayUninitialized<T>(count);
   }
 
   // Create an array with uninitialized elements of type |T|.
   // The caller is responsible for initialization.
   template <typename T>
   T* newArrayUninitialized(size_t count) {
     size_t bytes;
--- a/js/src/vm/BytecodeUtil.cpp
+++ b/js/src/vm/BytecodeUtil.cpp
@@ -220,20 +220,17 @@ bool js::DumpRealmPCCounts(JSContext* cx
 }
 
 /////////////////////////////////////////////////////////////////////
 // Bytecode Parser
 /////////////////////////////////////////////////////////////////////
 
 // Stores the information about the stack slot, where the value comes from.
 // Elements of BytecodeParser::Bytecode.{offsetStack,offsetStackAfter} arrays.
-struct OffsetAndDefIndex {
-  // To make this struct a POD type, keep these properties public.
-  // Use accessors instead of directly accessing them.
-
+class OffsetAndDefIndex {
   // The offset of the PC that pushed the value for this slot.
   uint32_t offset_;
 
   // The index in `ndefs` for the PC (0-origin)
   uint8_t defIndex_;
 
   enum : uint8_t {
     Normal = 0,
@@ -243,16 +240,17 @@ struct OffsetAndDefIndex {
     Ignored,
 
     // The value in this slot comes from 2 or more paths.
     // offset_ and defIndex_ holds the information for the path that
     // reaches here first.
     Merged,
   } type_;
 
+ public:
   uint32_t offset() const {
     MOZ_ASSERT(!isSpecial());
     return offset_;
   };
   uint32_t specialOffset() const {
     MOZ_ASSERT(isSpecial());
     return offset_;
   };
@@ -284,23 +282,16 @@ struct OffsetAndDefIndex {
     return offset_ == rhs.offset_ && defIndex_ == rhs.defIndex_;
   }
 
   bool operator!=(const OffsetAndDefIndex& rhs) const {
     return !(*this == rhs);
   }
 };
 
-namespace mozilla {
-
-template <>
-struct IsPod<OffsetAndDefIndex> : std::true_type {};
-
-}  // namespace mozilla
-
 namespace {
 
 class BytecodeParser {
  public:
   enum class JumpKind {
     Simple,
     SwitchCase,
     SwitchDefault,