From 1a05ece305ce9eef0351d63347f342d7efd25fcc Mon Sep 17 00:00:00 2001 From: Benedikt Meurer Date: Mon, 8 Dec 2014 09:28:10 +0100 Subject: [PATCH] [turbofan] Improve typing of JSToNumber. R=jarin@chromium.org Review URL: https://codereview.chromium.org/786703002 Cr-Commit-Position: refs/heads/master@{#25698} --- src/compiler/typer.cc | 18 ++++++++++++++++-- src/compiler/typer.h | 4 +++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/compiler/typer.cc b/src/compiler/typer.cc index e5b7b83..7104871 100644 --- a/src/compiler/typer.cc +++ b/src/compiler/typer.cc @@ -162,11 +162,13 @@ Typer::Typer(Graph* graph, MaybeHandle context) Type::Constant(minusinfinity, zone), zone), nan_or_minuszero, zone); + boolean_or_number = Type::Union(Type::Boolean(), Type::Number(), zone); + undefined_or_null = Type::Union(Type::Undefined(), Type::Null(), zone); + undefined_or_number = Type::Union(Type::Undefined(), Type::Number(), zone); negative_signed32 = Type::Union( Type::SignedSmall(), Type::OtherSigned32(), zone); non_negative_signed32 = Type::Union( Type::UnsignedSmall(), Type::OtherUnsigned31(), zone); - undefined_or_null = Type::Union(Type::Undefined(), Type::Null(), zone); singleton_false = Type::Constant(f->false_value(), zone); singleton_true = Type::Constant(f->true_value(), zone); singleton_zero = Type::Range(zero, zero, zone); @@ -520,10 +522,22 @@ Type* Typer::Visitor::ToBoolean(Type* type, Typer* t) { Type* Typer::Visitor::ToNumber(Type* type, Typer* t) { if (type->Is(Type::Number())) return type; + if (type->Is(Type::Null())) return t->singleton_zero; if (type->Is(Type::Undefined())) return Type::NaN(); + if (type->Is(t->undefined_or_null)) { + return Type::Union(Type::NaN(), t->singleton_zero, t->zone()); + } + if (type->Is(t->undefined_or_number)) { + return Type::Union(Type::Intersect(type, Type::Number(), t->zone()), + Type::NaN(), t->zone()); + } if (type->Is(t->singleton_false)) return t->singleton_zero; if (type->Is(t->singleton_true)) return t->singleton_one; if (type->Is(Type::Boolean())) return t->zero_or_one; + if (type->Is(t->boolean_or_number)) { + return Type::Union(Type::Intersect(type, Type::Number(), t->zone()), + t->zero_or_one, t->zone()); + } return Type::Number(); } @@ -1172,7 +1186,7 @@ Bounds Typer::Visitor::TypeJSToBoolean(Node* node) { Bounds Typer::Visitor::TypeJSToNumber(Node* node) { - return Bounds(Type::None(zone()), Type::Number(zone())); + return TypeUnaryOp(node, ToNumber); } diff --git a/src/compiler/typer.h b/src/compiler/typer.h index 7b740e1..a3e00ca 100644 --- a/src/compiler/typer.h +++ b/src/compiler/typer.h @@ -38,9 +38,11 @@ class Typer { Decorator* decorator_; Zone* zone_; + Type* boolean_or_number; + Type* undefined_or_null; + Type* undefined_or_number; Type* negative_signed32; Type* non_negative_signed32; - Type* undefined_or_null; Type* singleton_false; Type* singleton_true; Type* singleton_zero; -- 2.7.4