[VM] Decouple compile_type.h from runtime by making it only use runtime_api.h

Issue https://github.com/dart-lang/sdk/issues/31709

Change-Id: I36ae58a4d4f4540433cdb6de2aa370d025142863
Reviewed-on: https://dart-review.googlesource.com/c/93942
Auto-Submit: Martin Kustermann <kustermann@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
diff --git a/runtime/vm/compiler/backend/compile_type.h b/runtime/vm/compiler/backend/compile_type.h
index ded5fa6..e659dbd 100644
--- a/runtime/vm/compiler/backend/compile_type.h
+++ b/runtime/vm/compiler/backend/compile_type.h
@@ -5,11 +5,13 @@
 #ifndef RUNTIME_VM_COMPILER_BACKEND_COMPILE_TYPE_H_
 #define RUNTIME_VM_COMPILER_BACKEND_COMPILE_TYPE_H_
 
-#include "vm/object.h"
-#include "vm/thread.h"
+#include "vm/allocation.h"
+#include "vm/class_id.h"
+#include "vm/compiler/runtime_api.h"
 
 namespace dart {
 
+class AbstractType;
 class BufferFormatter;
 
 // CompileType describes type of a value produced by a definition.
@@ -91,7 +93,7 @@
   }
 
   static CompileType CreateNullable(bool is_nullable, intptr_t cid) {
-    return CompileType(is_nullable, cid, NULL);
+    return CompileType(is_nullable, cid, nullptr);
   }
 
   // Create a new CompileType representing given abstract type. By default
@@ -106,7 +108,7 @@
   // Create None CompileType. It is the bottom of the lattice and is used to
   // represent type of the phi that was not yet inferred.
   static CompileType None() {
-    return CompileType(kNullable, kIllegalCid, NULL);
+    return CompileType(kNullable, kIllegalCid, nullptr);
   }
 
   // Create Dynamic CompileType. It is the top of the lattice and is used to
@@ -159,10 +161,10 @@
   bool IsEqualTo(CompileType* other) {
     return (is_nullable_ == other->is_nullable_) &&
            (ToNullableCid() == other->ToNullableCid()) &&
-           (ToAbstractType()->Equals(*other->ToAbstractType()));
+           (compiler::IsEqualType(*ToAbstractType(), *other->ToAbstractType()));
   }
 
-  bool IsNone() const { return (cid_ == kIllegalCid) && (type_ == NULL); }
+  bool IsNone() const { return (cid_ == kIllegalCid) && (type_ == nullptr); }
 
   // Return true if value of this type is a non-nullable int.
   bool IsInt() { return !is_nullable() && IsNullableInt(); }
@@ -172,11 +174,12 @@
 
   // Return true if value of this type is either int or null.
   bool IsNullableInt() {
-    if ((cid_ == kSmiCid) || (cid_ == kMintCid)) {
+    if (cid_ == kSmiCid || cid_ == kMintCid) {
       return true;
     }
-    if ((cid_ == kIllegalCid) || (cid_ == kDynamicCid)) {
-      return (type_ != NULL) && ((type_->IsIntType() || type_->IsSmiType()));
+    if (cid_ == kIllegalCid || cid_ == kDynamicCid) {
+      return type_ != nullptr &&
+             (compiler::IsIntType(*type_) || compiler::IsSmiType(*type_));
     }
     return false;
   }
@@ -186,8 +189,8 @@
     if (cid_ == kSmiCid) {
       return true;
     }
-    if ((cid_ == kIllegalCid) || (cid_ == kDynamicCid)) {
-      return type_ != nullptr && type_->IsSmiType();
+    if (cid_ == kIllegalCid || cid_ == kDynamicCid) {
+      return type_ != nullptr && compiler::IsSmiType(*type_);
     }
     return false;
   }
@@ -198,7 +201,7 @@
       return true;
     }
     if ((cid_ == kIllegalCid) || (cid_ == kDynamicCid)) {
-      return (type_ != NULL) && type_->IsDoubleType();
+      return type_ != nullptr && compiler::IsDoubleType(*type_);
     }
     return false;
   }
diff --git a/runtime/vm/compiler/runtime_api.cc b/runtime/vm/compiler/runtime_api.cc
index aca31eb..d89816b 100644
--- a/runtime/vm/compiler/runtime_api.cc
+++ b/runtime/vm/compiler/runtime_api.cc
@@ -23,6 +23,22 @@
   return a.raw() == b.raw();
 }
 
+bool IsEqualType(const AbstractType& a, const AbstractType& b) {
+  return a.Equals(b);
+}
+
+bool IsDoubleType(const AbstractType& type) {
+  return type.IsDoubleType();
+}
+
+bool IsIntType(const AbstractType& type) {
+  return type.IsIntType();
+}
+
+bool IsSmiType(const AbstractType& type) {
+  return type.IsSmiType();
+}
+
 bool IsNotTemporaryScopedHandle(const Object& obj) {
   return obj.IsNotTemporaryScopedHandle();
 }
diff --git a/runtime/vm/compiler/runtime_api.h b/runtime/vm/compiler/runtime_api.h
index 853fac0..8df8767 100644
--- a/runtime/vm/compiler/runtime_api.h
+++ b/runtime/vm/compiler/runtime_api.h
@@ -36,7 +36,9 @@
 class RuntimeEntry;
 class Zone;
 
-#define DO(clazz) class clazz;
+#define DO(clazz)                                                              \
+  class Raw##clazz;                                                            \
+  class clazz;
 CLASS_LIST_FOR_HANDLES(DO)
 #undef DO
 
@@ -106,6 +108,18 @@
 // Returns true if [a] and [b] are the same object.
 bool IsSameObject(const Object& a, const Object& b);
 
+// Returns true if [a] and [b] represent the same type (are equal).
+bool IsEqualType(const AbstractType& a, const AbstractType& b);
+
+// Returns true if [type] is the "int" type.
+bool IsIntType(const AbstractType& type);
+
+// Returns true if [type] is the "double" type.
+bool IsDoubleType(const AbstractType& type);
+
+// Returns true if [type] is the "_Smi" type.
+bool IsSmiType(const AbstractType& type);
+
 // Returns true if the given handle is a zone handle or one of the global
 // cached handles.
 bool IsNotTemporaryScopedHandle(const Object& obj);