Bug 1535037 - Use ValueType for TypeSet. r=jandem
authorTom Schuster <evilpies@gmail.com>
Thu, 14 Mar 2019 07:38:00 +0000
changeset 524891 da8f5a9fb9be5f342a13fee9de0b80c853747dff
parent 524890 bd7007ecd0db1868d3ef383746544d187d1ab69d
child 524892 5398aeeb552c26d1433f4219619c1930f49f0577
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1535037
milestone67.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 1535037 - Use ValueType for TypeSet. r=jandem Differential Revision: https://phabricator.services.mozilla.com/D23329
js/src/jit/MacroAssembler.cpp
js/src/vm/ObjectGroup.cpp
js/src/vm/TypeInference-inl.h
js/src/vm/TypeInference.cpp
js/src/vm/TypeSet.h
--- a/js/src/jit/MacroAssembler.cpp
+++ b/js/src/jit/MacroAssembler.cpp
@@ -44,45 +44,46 @@ using mozilla::CheckedUint32;
 template <typename T>
 static void EmitTypeCheck(MacroAssembler& masm, Assembler::Condition cond,
                           const T& src, TypeSet::Type type, Label* label) {
   if (type.isAnyObject()) {
     masm.branchTestObject(cond, src, label);
     return;
   }
   switch (type.primitive()) {
-    case JSVAL_TYPE_DOUBLE:
+    case ValueType::Double:
       // TI double type includes int32.
       masm.branchTestNumber(cond, src, label);
       break;
-    case JSVAL_TYPE_INT32:
+    case ValueType::Int32:
       masm.branchTestInt32(cond, src, label);
       break;
-    case JSVAL_TYPE_BOOLEAN:
+    case ValueType::Boolean:
       masm.branchTestBoolean(cond, src, label);
       break;
-    case JSVAL_TYPE_STRING:
+    case ValueType::String:
       masm.branchTestString(cond, src, label);
       break;
-    case JSVAL_TYPE_SYMBOL:
+    case ValueType::Symbol:
       masm.branchTestSymbol(cond, src, label);
       break;
-    case JSVAL_TYPE_BIGINT:
+    case ValueType::BigInt:
       masm.branchTestBigInt(cond, src, label);
       break;
-    case JSVAL_TYPE_NULL:
+    case ValueType::Null:
       masm.branchTestNull(cond, src, label);
       break;
-    case JSVAL_TYPE_UNDEFINED:
+    case ValueType::Undefined:
       masm.branchTestUndefined(cond, src, label);
       break;
-    case JSVAL_TYPE_MAGIC:
+    case ValueType::Magic:
       masm.branchTestMagic(cond, src, label);
       break;
-    default:
+    case ValueType::PrivateGCThing:
+    case ValueType::Object:
       MOZ_CRASH("Unexpected type");
   }
 }
 
 template <typename Source>
 void MacroAssembler::guardTypeSet(const Source& address, const TypeSet* types,
                                   BarrierKind kind, Register unboxScratch,
                                   Register objScratch,
--- a/js/src/vm/ObjectGroup.cpp
+++ b/js/src/vm/ObjectGroup.cpp
@@ -782,19 +782,19 @@ struct ObjectGroupRealm::ArrayObjectKey 
         type = TypeSet::ObjectType(group);
       }
     }
     return false;
   }
 };
 
 static inline bool NumberTypes(TypeSet::Type a, TypeSet::Type b) {
-  return (a.isPrimitive(JSVAL_TYPE_INT32) ||
-          a.isPrimitive(JSVAL_TYPE_DOUBLE)) &&
-         (b.isPrimitive(JSVAL_TYPE_INT32) || b.isPrimitive(JSVAL_TYPE_DOUBLE));
+  return (a.isPrimitive(ValueType::Int32) ||
+          a.isPrimitive(ValueType::Double)) &&
+         (b.isPrimitive(ValueType::Int32) || b.isPrimitive(ValueType::Double));
 }
 
 /*
  * As for GetValueType, but requires object types to be non-singletons with
  * their default prototype. These are the only values that should appear in
  * arrays and objects whose type can be fixed.
  */
 static inline TypeSet::Type GetValueTypeForTable(const Value& v) {
@@ -1318,22 +1318,22 @@ JSObject* ObjectGroup::newPlainObject(JS
   // this table entry.
   if (!group->unknownProperties(*sweep)) {
     for (size_t i = 0; i < nproperties; i++) {
       TypeSet::Type type = p->value().types[i];
       TypeSet::Type ntype = GetValueTypeForTable(properties[i].value);
       if (ntype == type) {
         continue;
       }
-      if (ntype.isPrimitive(JSVAL_TYPE_INT32) &&
-          type.isPrimitive(JSVAL_TYPE_DOUBLE)) {
+      if (ntype.isPrimitive(ValueType::Int32) &&
+          type.isPrimitive(ValueType::Double)) {
         // The property types already reflect 'int32'.
       } else {
-        if (ntype.isPrimitive(JSVAL_TYPE_DOUBLE) &&
-            type.isPrimitive(JSVAL_TYPE_INT32)) {
+        if (ntype.isPrimitive(ValueType::Double) &&
+            type.isPrimitive(ValueType::Int32)) {
           // Include 'double' in the property types to avoid the update below
           // later.
           p->value().types[i] = TypeSet::DoubleType();
         }
         AddTypePropertyId(cx, group, nullptr, IdToTypeId(properties[i].id),
                           ntype);
       }
     }
--- a/js/src/vm/TypeInference-inl.h
+++ b/js/src/vm/TypeInference-inl.h
@@ -159,39 +159,42 @@ inline bool TypeSet::IsUntrackedValue(co
   return val.isMagic() && (val.whyMagic() == JS_OPTIMIZED_OUT ||
                            val.whyMagic() == JS_UNINITIALIZED_LEXICAL);
 }
 
 inline TypeSet::Type TypeSet::GetMaybeUntrackedValueType(const Value& val) {
   return IsUntrackedValue(val) ? UnknownType() : GetValueType(val);
 }
 
-inline TypeFlags PrimitiveTypeFlag(JSValueType type) {
+inline TypeFlags PrimitiveTypeFlag(ValueType type) {
   switch (type) {
-    case JSVAL_TYPE_UNDEFINED:
+    case ValueType::Undefined:
       return TYPE_FLAG_UNDEFINED;
-    case JSVAL_TYPE_NULL:
+    case ValueType::Null:
       return TYPE_FLAG_NULL;
-    case JSVAL_TYPE_BOOLEAN:
+    case ValueType::Boolean:
       return TYPE_FLAG_BOOLEAN;
-    case JSVAL_TYPE_INT32:
+    case ValueType::Int32:
       return TYPE_FLAG_INT32;
-    case JSVAL_TYPE_DOUBLE:
+    case ValueType::Double:
       return TYPE_FLAG_DOUBLE;
-    case JSVAL_TYPE_STRING:
+    case ValueType::String:
       return TYPE_FLAG_STRING;
-    case JSVAL_TYPE_SYMBOL:
+    case ValueType::Symbol:
       return TYPE_FLAG_SYMBOL;
-    case JSVAL_TYPE_BIGINT:
+    case ValueType::BigInt:
       return TYPE_FLAG_BIGINT;
-    case JSVAL_TYPE_MAGIC:
+    case ValueType::Magic:
       return TYPE_FLAG_LAZYARGS;
-    default:
-      MOZ_CRASH("Bad JSValueType");
+    case ValueType::PrivateGCThing:
+    case ValueType::Object:
+      break;
   }
+
+  MOZ_CRASH("Bad ValueType");
 }
 
 inline JSValueType TypeFlagPrimitive(TypeFlags flags) {
   switch (flags) {
     case TYPE_FLAG_UNDEFINED:
       return JSVAL_TYPE_UNDEFINED;
     case TYPE_FLAG_NULL:
       return JSVAL_TYPE_NULL;
--- a/js/src/vm/TypeInference.cpp
+++ b/js/src/vm/TypeInference.cpp
@@ -88,35 +88,36 @@ const char* js::TypeIdStringImpl(jsid id
 
 /////////////////////////////////////////////////////////////////////
 // Logging
 /////////////////////////////////////////////////////////////////////
 
 /* static */ const char* TypeSet::NonObjectTypeString(TypeSet::Type type) {
   if (type.isPrimitive()) {
     switch (type.primitive()) {
-      case JSVAL_TYPE_UNDEFINED:
+      case ValueType::Undefined:
         return "void";
-      case JSVAL_TYPE_NULL:
+      case ValueType::Null:
         return "null";
-      case JSVAL_TYPE_BOOLEAN:
+      case ValueType::Boolean:
         return "bool";
-      case JSVAL_TYPE_INT32:
+      case ValueType::Int32:
         return "int";
-      case JSVAL_TYPE_DOUBLE:
+      case ValueType::Double:
         return "float";
-      case JSVAL_TYPE_STRING:
+      case ValueType::String:
         return "string";
-      case JSVAL_TYPE_SYMBOL:
+      case ValueType::Symbol:
         return "symbol";
-      case JSVAL_TYPE_BIGINT:
+      case ValueType::BigInt:
         return "BigInt";
-      case JSVAL_TYPE_MAGIC:
+      case ValueType::Magic:
         return "lazyargs";
-      default:
+      case ValueType::PrivateGCThing:
+      case ValueType::Object:
         MOZ_CRASH("Bad type");
     }
   }
   if (type.isUnknown()) {
     return "unknown";
   }
 
   MOZ_ASSERT(type.isAnyObject());
--- a/js/src/vm/TypeSet.h
+++ b/js/src/vm/TypeSet.h
@@ -322,27 +322,27 @@ class TypeSet {
     uintptr_t data;
     explicit Type(uintptr_t data) : data(data) {}
 
    public:
     uintptr_t raw() const { return data; }
 
     bool isPrimitive() const { return data < JSVAL_TYPE_OBJECT; }
 
-    bool isPrimitive(JSValueType type) const {
-      MOZ_ASSERT(type < JSVAL_TYPE_OBJECT);
-      return (uintptr_t)type == data;
+    bool isPrimitive(ValueType type) const {
+      MOZ_ASSERT(type != ValueType::Object);
+      return uintptr_t(type) == data;
     }
 
-    JSValueType primitive() const {
+    ValueType primitive() const {
       MOZ_ASSERT(isPrimitive());
-      return (JSValueType)data;
+      return ValueType(data);
     }
 
-    bool isMagicArguments() const { return primitive() == JSVAL_TYPE_MAGIC; }
+    bool isMagicArguments() const { return primitive() == ValueType::Magic; }
 
     bool isSomeObject() const {
       return data == JSVAL_TYPE_OBJECT || data > JSVAL_TYPE_UNKNOWN;
     }
 
     bool isAnyObject() const { return data == JSVAL_TYPE_OBJECT; }
 
     bool isUnknown() const { return data == JSVAL_TYPE_UNKNOWN; }