Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(451)

Side by Side Diff: src/types.h

Issue 1328193003: Construct Range rather than Constant when typing integers. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix typo. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/typer.cc ('k') | src/types.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef V8_TYPES_H_ 5 #ifndef V8_TYPES_H_
6 #define V8_TYPES_H_ 6 #define V8_TYPES_H_
7 7
8 #include "src/conversions.h" 8 #include "src/conversions.h"
9 #include "src/handles.h" 9 #include "src/handles.h"
10 #include "src/objects.h" 10 #include "src/objects.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // representation types initially include all semantic ranges. Representations 88 // representation types initially include all semantic ranges. Representations
89 // can then e.g. be narrowed for a given semantic type using intersection: 89 // can then e.g. be narrowed for a given semantic type using intersection:
90 // 90 //
91 // SignedSmall /\ TaggedInt (a 'smi') 91 // SignedSmall /\ TaggedInt (a 'smi')
92 // Number /\ TaggedPtr (a heap number) 92 // Number /\ TaggedPtr (a heap number)
93 // 93 //
94 // 94 //
95 // RANGE TYPES 95 // RANGE TYPES
96 // 96 //
97 // A range type represents a continuous integer interval by its minimum and 97 // A range type represents a continuous integer interval by its minimum and
98 // maximum value. Either value might be an infinity. 98 // maximum value. Either value may be an infinity, in which case that infinity
99 // itself is also included in the range. A range never contains NaN or -0.
99 // 100 //
100 // Constant(v) is considered a subtype of Range(x..y) if v happens to be an 101 // If a value v happens to be an integer n, then Constant(v) is considered a
101 // integer between x and y. 102 // subtype of Range(n, n) (and therefore also a subtype of any larger range).
103 // In order to avoid large unions, however, it is usually a good idea to use
104 // Range rather than Constant.
102 // 105 //
103 // 106 //
104 // PREDICATES 107 // PREDICATES
105 // 108 //
106 // There are two main functions for testing types: 109 // There are two main functions for testing types:
107 // 110 //
108 // T1->Is(T2) -- tests whether T1 is included in T2 (i.e., T1 <= T2) 111 // T1->Is(T2) -- tests whether T1 is included in T2 (i.e., T1 <= T2)
109 // T1->Maybe(T2) -- tests whether T1 and T2 overlap (i.e., T1 /\ T2 =/= 0) 112 // T1->Maybe(T2) -- tests whether T1 and T2 overlap (i.e., T1 /\ T2 =/= 0)
110 // 113 //
111 // Typically, the former is to be used to select representations (e.g., via 114 // Typically, the former is to be used to select representations (e.g., via
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 ArrayType* AsArray() { return ArrayType::cast(this); } 509 ArrayType* AsArray() { return ArrayType::cast(this); }
507 FunctionType* AsFunction() { return FunctionType::cast(this); } 510 FunctionType* AsFunction() { return FunctionType::cast(this); }
508 511
509 // Minimum and maximum of a numeric type. 512 // Minimum and maximum of a numeric type.
510 // These functions do not distinguish between -0 and +0. If the type equals 513 // These functions do not distinguish between -0 and +0. If the type equals
511 // kNaN, they return NaN; otherwise kNaN is ignored. Only call these 514 // kNaN, they return NaN; otherwise kNaN is ignored. Only call these
512 // functions on subtypes of Number. 515 // functions on subtypes of Number.
513 double Min(); 516 double Min();
514 double Max(); 517 double Max();
515 518
516 // Extracts a range from the type. If the type is a range, it just 519 // Extracts a range from the type: if the type is a range or a union
517 // returns it; if it is a union, it returns the range component. 520 // containing a range, that range is returned; otherwise, NULL is returned.
518 // Note that it does not contain range for constants.
519 RangeType* GetRange(); 521 RangeType* GetRange();
520 522
523 static bool IsInteger(double x) {
524 return nearbyint(x) == x && !i::IsMinusZero(x); // Allows for infinities.
525 }
526 static bool IsInteger(i::Object* x) {
527 return x->IsNumber() && IsInteger(x->Number());
528 }
529
521 int NumClasses(); 530 int NumClasses();
522 int NumConstants(); 531 int NumConstants();
523 532
524 template<class T> class Iterator; 533 template<class T> class Iterator;
525 Iterator<i::Map> Classes() { 534 Iterator<i::Map> Classes() {
526 if (this->IsBitset()) return Iterator<i::Map>(); 535 if (this->IsBitset()) return Iterator<i::Map>();
527 return Iterator<i::Map>(Config::handle(this)); 536 return Iterator<i::Map>(Config::handle(this));
528 } 537 }
529 Iterator<i::Object> Constants() { 538 Iterator<i::Object> Constants() {
530 if (this->IsBitset()) return Iterator<i::Object>(); 539 if (this->IsBitset()) return Iterator<i::Object>();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 591
583 // Auxiliary functions. 592 // Auxiliary functions.
584 bool SemanticMaybe(TypeImpl* that); 593 bool SemanticMaybe(TypeImpl* that);
585 594
586 bitset BitsetGlb() { return BitsetType::Glb(this); } 595 bitset BitsetGlb() { return BitsetType::Glb(this); }
587 bitset BitsetLub() { return BitsetType::Lub(this); } 596 bitset BitsetLub() { return BitsetType::Lub(this); }
588 597
589 bool SlowIs(TypeImpl* that); 598 bool SlowIs(TypeImpl* that);
590 bool SemanticIs(TypeImpl* that); 599 bool SemanticIs(TypeImpl* that);
591 600
592 static bool IsInteger(double x) {
593 return nearbyint(x) == x && !i::IsMinusZero(x); // Allows for infinities.
594 }
595 static bool IsInteger(i::Object* x) {
596 return x->IsNumber() && IsInteger(x->Number());
597 }
598
599 struct Limits { 601 struct Limits {
600 double min; 602 double min;
601 double max; 603 double max;
602 Limits(double min, double max) : min(min), max(max) {} 604 Limits(double min, double max) : min(min), max(max) {}
603 explicit Limits(RangeType* range) : min(range->Min()), max(range->Max()) {} 605 explicit Limits(RangeType* range) : min(range->Min()), max(range->Max()) {}
604 static Limits Empty(Region* region) { return Limits(1, 0); } 606 static Limits Empty(Region* region) { return Limits(1, 0); }
605 }; 607 };
606 608
607 static bool IsEmpty(Limits lim); 609 static bool IsEmpty(Limits lim);
608 static Limits Intersect(Limits lhs, Limits rhs); 610 static Limits Intersect(Limits lhs, Limits rhs);
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 bool Narrows(BoundsImpl that) { 1167 bool Narrows(BoundsImpl that) {
1166 return that.lower->Is(this->lower) && this->upper->Is(that.upper); 1168 return that.lower->Is(this->lower) && this->upper->Is(that.upper);
1167 } 1169 }
1168 }; 1170 };
1169 1171
1170 typedef BoundsImpl<ZoneTypeConfig> Bounds; 1172 typedef BoundsImpl<ZoneTypeConfig> Bounds;
1171 1173
1172 } } // namespace v8::internal 1174 } } // namespace v8::internal
1173 1175
1174 #endif // V8_TYPES_H_ 1176 #endif // V8_TYPES_H_
OLDNEW
« no previous file with comments | « src/compiler/typer.cc ('k') | src/types.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698