Reviewers: Toon Verwaest,

Description:
Introduce Type::IsCurrently

[email protected]
BUG=

Please review this at https://codereview.chromium.org/83003003/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+18, -5 lines):
  M src/ic.cc
  M src/types.h
  M src/types.cc


Index: src/ic.cc
diff --git a/src/ic.cc b/src/ic.cc
index 53c103a89989074790fd0a839d978763d4202825..96f1804f57b58cae3d707c85bcbbc615cd03ccaa 100644
--- a/src/ic.cc
+++ b/src/ic.cc
@@ -783,7 +783,7 @@ void CallICBase::UpdateCaches(LookupResult* lookup,
       : Handle<JSObject>(JSObject::cast(object->GetPrototype(isolate())),
                          isolate());

-  PatchCache(handle(Type::CurrentOf(cache_object), isolate()), name, code);
+ PatchCache(handle(Type::OfCurrently(cache_object), isolate()), name, code);
   TRACE_IC("CallIC", name);
 }

@@ -1148,7 +1148,7 @@ void LoadIC::UpdateCaches(LookupResult* lookup,
     code = ComputeHandler(lookup, object, name);
   }

-  PatchCache(handle(Type::CurrentOf(object), isolate()), name, code);
+  PatchCache(handle(Type::OfCurrently(object), isolate()), name, code);
   TRACE_IC("LoadIC", name);
 }

@@ -1609,7 +1609,7 @@ void StoreIC::UpdateCaches(LookupResult* lookup,

   Handle<Code> code = ComputeHandler(lookup, receiver, name, value);

-  PatchCache(handle(Type::CurrentOf(receiver), isolate()), name, code);
+  PatchCache(handle(Type::OfCurrently(receiver), isolate()), name, code);
   TRACE_IC("StoreIC", name);
 }

Index: src/types.cc
diff --git a/src/types.cc b/src/types.cc
index 7c54d4fb27e7db94b06c1726a9e07678bc8ead80..485ba885187364ed2b99098865eec3197b2c47dc 100644
--- a/src/types.cc
+++ b/src/types.cc
@@ -244,7 +244,7 @@ int Type::GlbBitset() {


 // Most precise _current_ type of a value (usually its class).
-Type* Type::CurrentOf(Handle<i::Object> value) {
+Type* Type::OfCurrently(Handle<i::Object> value) {
   if (value->IsSmi()) return Smi();
   i::Map* map = i::HeapObject::cast(*value)->map();
   if (map->instance_type() == HEAP_NUMBER_TYPE ||
@@ -297,6 +297,14 @@ bool Type::SlowIs(Type* that) {
 }


+bool Type::IsCurrently(Type* that) {
+  return this->Is(that) ||
+      (this->is_constant() && that->is_class() &&
+       this->as_constant()->IsHeapObject() &&
+ i::HeapObject::cast(*this->as_constant())->map() == *that->as_class());
+}
+
+
 // Check this overlaps that.
 bool Type::Maybe(Type* that) {
   // Fast path for bitsets.
Index: src/types.h
diff --git a/src/types.h b/src/types.h
index eab78c2760a2109c84f56b3f026efb6088b6f6c4..d9d11f077e9f196d8f42cf1da97987bfceeaf598 100644
--- a/src/types.h
+++ b/src/types.h
@@ -153,13 +153,18 @@ class Type : public Object {
   static Type* Of(Handle<i::Object> value) {
     return from_bitset(LubBitset(*value));
   }
-  static Type* CurrentOf(Handle<i::Object> value);

   bool Is(Type* that) { return (this == that) ? true : SlowIs(that); }
   bool Is(Handle<Type> that) { return this->Is(*that); }
   bool Maybe(Type* that);
   bool Maybe(Handle<Type> that) { return this->Maybe(*that); }

+  // State-dependent versions of Of and Is that consider subtyping between
+  // a constant and its map class.
+  static Type* OfCurrently(Handle<i::Object> value);
+  bool IsCurrently(Type* that);
+  bool IsCurrently(Handle<Type> that)  { return this->IsCurrently(*that); }
+
   bool IsClass() { return is_class(); }
   bool IsConstant() { return is_constant(); }
   Handle<i::Map> AsClass() { return as_class(); }


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to