OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/typer.h" | 5 #include "src/compiler/typer.h" |
6 | 6 |
7 #include <iomanip> | 7 #include <iomanip> |
8 | 8 |
9 #include "src/base/flags.h" | 9 #include "src/base/flags.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 Typer::Typer(Isolate* isolate, Flags flags, Graph* graph) | 36 Typer::Typer(Isolate* isolate, Flags flags, Graph* graph) |
37 : isolate_(isolate), | 37 : isolate_(isolate), |
38 flags_(flags), | 38 flags_(flags), |
39 graph_(graph), | 39 graph_(graph), |
40 decorator_(nullptr), | 40 decorator_(nullptr), |
41 cache_(TypeCache::Get()), | 41 cache_(TypeCache::Get()), |
42 operation_typer_(isolate, zone()) { | 42 operation_typer_(isolate, zone()) { |
43 Zone* zone = this->zone(); | 43 Zone* zone = this->zone(); |
44 Factory* const factory = isolate->factory(); | 44 Factory* const factory = isolate->factory(); |
45 | 45 |
46 singleton_false_ = Type::HeapConstant(factory->false_value(), zone); | 46 singleton_empty_string_ = Type::HeapConstant(factory->empty_string(), zone); |
47 singleton_true_ = Type::HeapConstant(factory->true_value(), zone); | 47 singleton_false_ = operation_typer_.singleton_false(); |
48 singleton_the_hole_ = Type::HeapConstant(factory->the_hole_value(), zone); | 48 singleton_true_ = operation_typer_.singleton_true(); |
49 falsish_ = Type::Union( | 49 falsish_ = Type::Union( |
50 Type::Undetectable(), | 50 Type::Undetectable(), |
51 Type::Union(Type::Union(singleton_false_, cache_.kZeroish, zone), | 51 Type::Union(Type::Union(singleton_false_, cache_.kZeroish, zone), |
52 singleton_the_hole_, zone), | 52 Type::Union(singleton_empty_string_, Type::Hole(), zone), |
| 53 zone), |
53 zone); | 54 zone); |
54 truish_ = Type::Union( | 55 truish_ = Type::Union( |
55 singleton_true_, | 56 singleton_true_, |
56 Type::Union(Type::DetectableReceiver(), Type::Symbol(), zone), zone); | 57 Type::Union(Type::DetectableReceiver(), Type::Symbol(), zone), zone); |
57 | 58 |
58 decorator_ = new (zone) Decorator(this); | 59 decorator_ = new (zone) Decorator(this); |
59 graph_->AddDecorator(decorator_); | 60 graph_->AddDecorator(decorator_); |
60 } | 61 } |
61 | 62 |
62 | 63 |
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 } | 902 } |
902 | 903 |
903 | 904 |
904 Type* Typer::Visitor::JSStrictEqualTyper(Type* lhs, Type* rhs, Typer* t) { | 905 Type* Typer::Visitor::JSStrictEqualTyper(Type* lhs, Type* rhs, Typer* t) { |
905 if (!JSType(lhs)->Maybe(JSType(rhs))) return t->singleton_false_; | 906 if (!JSType(lhs)->Maybe(JSType(rhs))) return t->singleton_false_; |
906 if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) return t->singleton_false_; | 907 if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) return t->singleton_false_; |
907 if (lhs->Is(Type::Number()) && rhs->Is(Type::Number()) && | 908 if (lhs->Is(Type::Number()) && rhs->Is(Type::Number()) && |
908 (lhs->Max() < rhs->Min() || lhs->Min() > rhs->Max())) { | 909 (lhs->Max() < rhs->Min() || lhs->Min() > rhs->Max())) { |
909 return t->singleton_false_; | 910 return t->singleton_false_; |
910 } | 911 } |
911 if ((lhs->Is(t->singleton_the_hole_) || rhs->Is(t->singleton_the_hole_)) && | 912 if ((lhs->Is(Type::Hole()) || rhs->Is(Type::Hole())) && !lhs->Maybe(rhs)) { |
912 !lhs->Maybe(rhs)) { | |
913 return t->singleton_false_; | 913 return t->singleton_false_; |
914 } | 914 } |
915 if (lhs->IsHeapConstant() && rhs->Is(lhs)) { | 915 if (lhs->IsHeapConstant() && rhs->Is(lhs)) { |
916 // Types are equal and are inhabited only by a single semantic value, | 916 // Types are equal and are inhabited only by a single semantic value, |
917 // which is not nan due to the earlier check. | 917 // which is not nan due to the earlier check. |
918 return t->singleton_true_; | 918 return t->singleton_true_; |
919 } | 919 } |
920 return Type::Boolean(); | 920 return Type::Boolean(); |
921 } | 921 } |
922 | 922 |
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1943 Type* Typer::Visitor::TypeConstant(Handle<Object> value) { | 1943 Type* Typer::Visitor::TypeConstant(Handle<Object> value) { |
1944 if (Type::IsInteger(*value)) { | 1944 if (Type::IsInteger(*value)) { |
1945 return Type::Range(value->Number(), value->Number(), zone()); | 1945 return Type::Range(value->Number(), value->Number(), zone()); |
1946 } | 1946 } |
1947 return Type::NewConstant(value, zone()); | 1947 return Type::NewConstant(value, zone()); |
1948 } | 1948 } |
1949 | 1949 |
1950 } // namespace compiler | 1950 } // namespace compiler |
1951 } // namespace internal | 1951 } // namespace internal |
1952 } // namespace v8 | 1952 } // namespace v8 |
OLD | NEW |