[turbofan] Improve typing of ToBoolean.
authorBenedikt Meurer <bmeurer@chromium.org>
Mon, 22 Dec 2014 07:21:30 +0000 (08:21 +0100)
committerBenedikt Meurer <bmeurer@chromium.org>
Mon, 22 Dec 2014 07:21:51 +0000 (07:21 +0000)
According to ES6 draft, revision 29 (2014-12-06), section 7.1.2,
ToBoolean yields true for true, detectable receivers (the ES6 Object
type), symbols and numbers except -0, +0 and NaN.

R=hpayer@chromium.org

Review URL: https://codereview.chromium.org/807663006

Cr-Commit-Position: refs/heads/master@{#25915}

src/compiler/typer.cc
src/compiler/typer.h

index 58e6c37..b33ee0c 100644 (file)
@@ -187,6 +187,9 @@ Typer::Typer(Graph* graph, MaybeHandle<Context> context)
                         Type::Union(Type::Union(singleton_false, zeroish, zone),
                                     undefined_or_null, zone),
                         zone);
+  truish = Type::Union(
+      singleton_true,
+      Type::Union(Type::DetectableReceiver(), Type::Symbol(), zone), zone);
   integer = Type::Range(minusinfinity, infinity, zone);
   weakint = Type::Union(integer, nan_or_minuszero, zone);
 
@@ -513,8 +516,8 @@ Type* Typer::Visitor::ToPrimitive(Type* type, Typer* t) {
 Type* Typer::Visitor::ToBoolean(Type* type, Typer* t) {
   if (type->Is(Type::Boolean())) return type;
   if (type->Is(t->falsish)) return t->singleton_false;
-  if (type->Is(Type::DetectableReceiver())) return t->singleton_true;
-  if (type->Is(Type::OrderedNumber()) && (type->Max() < 0 || 0 < type->Min())) {
+  if (type->Is(t->truish)) return t->singleton_true;
+  if (type->Is(Type::PlainNumber()) && (type->Max() < 0 || 0 < type->Min())) {
     return t->singleton_true;  // Ruled out nan, -0 and +0.
   }
   return Type::Boolean();
index 45d3a32..b65a9a5 100644 (file)
@@ -54,6 +54,7 @@ class Typer {
   Type* signed32ish;
   Type* unsigned32ish;
   Type* falsish;
+  Type* truish;
   Type* integer;
   Type* weakint;
   Type* number_fun0_;