OLD | NEW |
---|---|
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "src/compiler/types.h" | 7 #include "src/compiler/types.h" |
8 #include "src/crankshaft/hydrogen-types.h" | 8 #include "src/crankshaft/hydrogen-types.h" |
9 #include "src/factory.h" | 9 #include "src/factory.h" |
10 #include "src/heap/heap.h" | 10 #include "src/heap/heap.h" |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 CHECK(bits == this->AsBitset(intersect12)); | 184 CHECK(bits == this->AsBitset(intersect12)); |
185 } | 185 } |
186 } | 186 } |
187 } | 187 } |
188 } | 188 } |
189 | 189 |
190 void Constant() { | 190 void Constant() { |
191 // Constructor | 191 // Constructor |
192 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { | 192 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { |
193 Handle<i::Object> value = *vt; | 193 Handle<i::Object> value = *vt; |
194 Type* type = T.Constant(value); | 194 Type* type = T.NewConstant(value); |
195 CHECK(type->IsConstant()); | 195 CHECK(type->IsConstant() || type->IsNumberConstant() || type->IsRange()); |
196 } | 196 } |
197 | 197 |
198 // Value attribute | 198 // Value attribute |
199 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { | 199 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { |
200 Handle<i::Object> value = *vt; | 200 Handle<i::Object> value = *vt; |
201 Type* type = T.Constant(value); | 201 Type* type = T.NewConstant(value); |
202 CHECK(*value == *type->AsConstant()->Value()); | 202 if (type->IsConstant()) { |
203 CHECK(*value == *type->AsConstant()->Value()); | |
204 } else if (type->IsNumberConstant()) { | |
205 double v = value->IsSmi() ? Smi::cast(*value)->value() | |
206 : HeapNumber::cast(*value)->value(); | |
207 CHECK(v == type->AsNumberConstant()->Value()); | |
208 } else { | |
209 CHECK(type->IsRange()); | |
210 double v = value->IsSmi() ? Smi::cast(*value)->value() | |
211 : HeapNumber::cast(*value)->value(); | |
212 CHECK(v == type->AsRange()->Min() && v == type->AsRange()->Max()); | |
213 } | |
203 } | 214 } |
204 | 215 |
205 // Functionality & Injectivity: Constant(V1) = Constant(V2) iff V1 = V2 | 216 // Functionality & Injectivity: Constant(V1) = Constant(V2) iff V1 = V2 |
206 for (ValueIterator vt1 = T.values.begin(); vt1 != T.values.end(); ++vt1) { | 217 for (ValueIterator vt1 = T.values.begin(); vt1 != T.values.end(); ++vt1) { |
207 for (ValueIterator vt2 = T.values.begin(); vt2 != T.values.end(); ++vt2) { | 218 for (ValueIterator vt2 = T.values.begin(); vt2 != T.values.end(); ++vt2) { |
208 Handle<i::Object> value1 = *vt1; | 219 Handle<i::Object> value1 = *vt1; |
209 Handle<i::Object> value2 = *vt2; | 220 Handle<i::Object> value2 = *vt2; |
210 Type* type1 = T.Constant(value1); | 221 Type* type1 = T.NewConstant(value1); |
211 Type* type2 = T.Constant(value2); | 222 Type* type2 = T.NewConstant(value2); |
212 CHECK(Equal(type1, type2) == (*value1 == *value2)); | 223 CHECK(Equal(type1, type2) == (*value1 == *value2)); |
213 } | 224 } |
214 } | 225 } |
215 | 226 |
216 // Typing of numbers | 227 // Typing of numbers |
217 Factory* fac = isolate->factory(); | 228 Factory* fac = isolate->factory(); |
218 CHECK(T.Constant(fac->NewNumber(0))->Is(T.UnsignedSmall)); | 229 CHECK(T.NewConstant(fac->NewNumber(0))->Is(T.UnsignedSmall)); |
219 CHECK(T.Constant(fac->NewNumber(1))->Is(T.UnsignedSmall)); | 230 CHECK(T.NewConstant(fac->NewNumber(1))->Is(T.UnsignedSmall)); |
220 CHECK(T.Constant(fac->NewNumber(0x3fffffff))->Is(T.UnsignedSmall)); | 231 CHECK(T.NewConstant(fac->NewNumber(0x3fffffff))->Is(T.UnsignedSmall)); |
221 CHECK(T.Constant(fac->NewNumber(-1))->Is(T.Negative31)); | 232 CHECK(T.NewConstant(fac->NewNumber(-1))->Is(T.Negative31)); |
222 CHECK(T.Constant(fac->NewNumber(-0x3fffffff))->Is(T.Negative31)); | 233 CHECK(T.NewConstant(fac->NewNumber(-0x3fffffff))->Is(T.Negative31)); |
223 CHECK(T.Constant(fac->NewNumber(-0x40000000))->Is(T.Negative31)); | 234 CHECK(T.NewConstant(fac->NewNumber(-0x40000000))->Is(T.Negative31)); |
224 CHECK(T.Constant(fac->NewNumber(0x40000000))->Is(T.Unsigned31)); | 235 CHECK(T.NewConstant(fac->NewNumber(0x40000000))->Is(T.Unsigned31)); |
225 CHECK(!T.Constant(fac->NewNumber(0x40000000))->Is(T.Unsigned30)); | 236 CHECK(!T.NewConstant(fac->NewNumber(0x40000000))->Is(T.Unsigned30)); |
226 CHECK(T.Constant(fac->NewNumber(0x7fffffff))->Is(T.Unsigned31)); | 237 CHECK(T.NewConstant(fac->NewNumber(0x7fffffff))->Is(T.Unsigned31)); |
227 CHECK(!T.Constant(fac->NewNumber(0x7fffffff))->Is(T.Unsigned30)); | 238 CHECK(!T.NewConstant(fac->NewNumber(0x7fffffff))->Is(T.Unsigned30)); |
228 CHECK(T.Constant(fac->NewNumber(-0x40000001))->Is(T.Negative32)); | 239 CHECK(T.NewConstant(fac->NewNumber(-0x40000001))->Is(T.Negative32)); |
229 CHECK(!T.Constant(fac->NewNumber(-0x40000001))->Is(T.Negative31)); | 240 CHECK(!T.NewConstant(fac->NewNumber(-0x40000001))->Is(T.Negative31)); |
230 CHECK(T.Constant(fac->NewNumber(-0x7fffffff))->Is(T.Negative32)); | 241 CHECK(T.NewConstant(fac->NewNumber(-0x7fffffff))->Is(T.Negative32)); |
231 CHECK(!T.Constant(fac->NewNumber(-0x7fffffff - 1))->Is(T.Negative31)); | 242 CHECK(!T.NewConstant(fac->NewNumber(-0x7fffffff - 1))->Is(T.Negative31)); |
232 if (SmiValuesAre31Bits()) { | 243 if (SmiValuesAre31Bits()) { |
233 CHECK(!T.Constant(fac->NewNumber(0x40000000))->Is(T.UnsignedSmall)); | 244 CHECK(!T.NewConstant(fac->NewNumber(0x40000000))->Is(T.UnsignedSmall)); |
234 CHECK(!T.Constant(fac->NewNumber(0x7fffffff))->Is(T.UnsignedSmall)); | 245 CHECK(!T.NewConstant(fac->NewNumber(0x7fffffff))->Is(T.UnsignedSmall)); |
235 CHECK(!T.Constant(fac->NewNumber(-0x40000001))->Is(T.SignedSmall)); | 246 CHECK(!T.NewConstant(fac->NewNumber(-0x40000001))->Is(T.SignedSmall)); |
236 CHECK(!T.Constant(fac->NewNumber(-0x7fffffff - 1))->Is(T.SignedSmall)); | 247 CHECK(!T.NewConstant(fac->NewNumber(-0x7fffffff - 1))->Is(T.SignedSmall)); |
237 } else { | 248 } else { |
238 CHECK(SmiValuesAre32Bits()); | 249 CHECK(SmiValuesAre32Bits()); |
239 CHECK(T.Constant(fac->NewNumber(0x40000000))->Is(T.UnsignedSmall)); | 250 CHECK(T.NewConstant(fac->NewNumber(0x40000000))->Is(T.UnsignedSmall)); |
240 CHECK(T.Constant(fac->NewNumber(0x7fffffff))->Is(T.UnsignedSmall)); | 251 CHECK(T.NewConstant(fac->NewNumber(0x7fffffff))->Is(T.UnsignedSmall)); |
241 CHECK(T.Constant(fac->NewNumber(-0x40000001))->Is(T.SignedSmall)); | 252 CHECK(T.NewConstant(fac->NewNumber(-0x40000001))->Is(T.SignedSmall)); |
242 CHECK(T.Constant(fac->NewNumber(-0x7fffffff - 1))->Is(T.SignedSmall)); | 253 CHECK(T.NewConstant(fac->NewNumber(-0x7fffffff - 1))->Is(T.SignedSmall)); |
243 } | 254 } |
244 CHECK(T.Constant(fac->NewNumber(0x80000000u))->Is(T.Unsigned32)); | 255 CHECK(T.NewConstant(fac->NewNumber(0x80000000u))->Is(T.Unsigned32)); |
245 CHECK(!T.Constant(fac->NewNumber(0x80000000u))->Is(T.Unsigned31)); | 256 CHECK(!T.NewConstant(fac->NewNumber(0x80000000u))->Is(T.Unsigned31)); |
246 CHECK(T.Constant(fac->NewNumber(0xffffffffu))->Is(T.Unsigned32)); | 257 CHECK(T.NewConstant(fac->NewNumber(0xffffffffu))->Is(T.Unsigned32)); |
247 CHECK(!T.Constant(fac->NewNumber(0xffffffffu))->Is(T.Unsigned31)); | 258 CHECK(!T.NewConstant(fac->NewNumber(0xffffffffu))->Is(T.Unsigned31)); |
248 CHECK(T.Constant(fac->NewNumber(0xffffffffu + 1.0))->Is(T.PlainNumber)); | 259 CHECK(T.NewConstant(fac->NewNumber(0xffffffffu + 1.0))->Is(T.PlainNumber)); |
249 CHECK(!T.Constant(fac->NewNumber(0xffffffffu + 1.0))->Is(T.Integral32)); | 260 CHECK(!T.NewConstant(fac->NewNumber(0xffffffffu + 1.0))->Is(T.Integral32)); |
250 CHECK(T.Constant(fac->NewNumber(-0x7fffffff - 2.0))->Is(T.PlainNumber)); | 261 CHECK(T.NewConstant(fac->NewNumber(-0x7fffffff - 2.0))->Is(T.PlainNumber)); |
251 CHECK(!T.Constant(fac->NewNumber(-0x7fffffff - 2.0))->Is(T.Integral32)); | 262 CHECK(!T.NewConstant(fac->NewNumber(-0x7fffffff - 2.0))->Is(T.Integral32)); |
252 CHECK(T.Constant(fac->NewNumber(0.1))->Is(T.PlainNumber)); | 263 CHECK(T.NewConstant(fac->NewNumber(0.1))->Is(T.PlainNumber)); |
253 CHECK(!T.Constant(fac->NewNumber(0.1))->Is(T.Integral32)); | 264 CHECK(!T.NewConstant(fac->NewNumber(0.1))->Is(T.Integral32)); |
254 CHECK(T.Constant(fac->NewNumber(-10.1))->Is(T.PlainNumber)); | 265 CHECK(T.NewConstant(fac->NewNumber(-10.1))->Is(T.PlainNumber)); |
255 CHECK(!T.Constant(fac->NewNumber(-10.1))->Is(T.Integral32)); | 266 CHECK(!T.NewConstant(fac->NewNumber(-10.1))->Is(T.Integral32)); |
256 CHECK(T.Constant(fac->NewNumber(10e60))->Is(T.PlainNumber)); | 267 CHECK(T.NewConstant(fac->NewNumber(10e60))->Is(T.PlainNumber)); |
257 CHECK(!T.Constant(fac->NewNumber(10e60))->Is(T.Integral32)); | 268 CHECK(!T.NewConstant(fac->NewNumber(10e60))->Is(T.Integral32)); |
258 CHECK(T.Constant(fac->NewNumber(-1.0*0.0))->Is(T.MinusZero)); | 269 CHECK(T.NewConstant(fac->NewNumber(-1.0 * 0.0))->Is(T.MinusZero)); |
259 CHECK(T.Constant(fac->NewNumber(std::numeric_limits<double>::quiet_NaN())) | 270 CHECK( |
260 ->Is(T.NaN)); | 271 T.NewConstant(fac->NewNumber(std::numeric_limits<double>::quiet_NaN())) |
261 CHECK(T.Constant(fac->NewNumber(V8_INFINITY))->Is(T.PlainNumber)); | 272 ->Is(T.NaN)); |
262 CHECK(!T.Constant(fac->NewNumber(V8_INFINITY))->Is(T.Integral32)); | 273 CHECK(T.NewConstant(fac->NewNumber(V8_INFINITY))->Is(T.PlainNumber)); |
263 CHECK(T.Constant(fac->NewNumber(-V8_INFINITY))->Is(T.PlainNumber)); | 274 CHECK(!T.NewConstant(fac->NewNumber(V8_INFINITY))->Is(T.Integral32)); |
264 CHECK(!T.Constant(fac->NewNumber(-V8_INFINITY))->Is(T.Integral32)); | 275 CHECK(T.NewConstant(fac->NewNumber(-V8_INFINITY))->Is(T.PlainNumber)); |
276 CHECK(!T.NewConstant(fac->NewNumber(-V8_INFINITY))->Is(T.Integral32)); | |
265 } | 277 } |
266 | 278 |
267 void Range() { | 279 void Range() { |
268 // Constructor | 280 // Constructor |
269 for (ValueIterator i = T.integers.begin(); i != T.integers.end(); ++i) { | 281 for (ValueIterator i = T.integers.begin(); i != T.integers.end(); ++i) { |
270 for (ValueIterator j = T.integers.begin(); j != T.integers.end(); ++j) { | 282 for (ValueIterator j = T.integers.begin(); j != T.integers.end(); ++j) { |
271 double min = (*i)->Number(); | 283 double min = (*i)->Number(); |
272 double max = (*j)->Number(); | 284 double max = (*j)->Number(); |
273 if (min > max) std::swap(min, max); | 285 if (min > max) std::swap(min, max); |
274 Type* type = T.Range(min, max); | 286 Type* type = T.Range(min, max); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 } | 322 } |
311 } | 323 } |
312 } | 324 } |
313 } | 325 } |
314 } | 326 } |
315 | 327 |
316 void Of() { | 328 void Of() { |
317 // Constant(V)->Is(Of(V)) | 329 // Constant(V)->Is(Of(V)) |
318 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { | 330 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { |
319 Handle<i::Object> value = *vt; | 331 Handle<i::Object> value = *vt; |
320 Type* const_type = T.Constant(value); | 332 Type* const_type = T.NewConstant(value); |
321 Type* of_type = T.Of(value); | 333 Type* of_type = T.Of(value); |
322 CHECK(const_type->Is(of_type)); | 334 CHECK(const_type->Is(of_type)); |
323 } | 335 } |
324 | 336 |
325 // If Of(V)->Is(T), then Constant(V)->Is(T) | 337 // If Of(V)->Is(T), then Constant(V)->Is(T) |
326 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { | 338 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { |
327 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 339 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
328 Handle<i::Object> value = *vt; | 340 Handle<i::Object> value = *vt; |
329 Type* type = *it; | 341 Type* type = *it; |
330 Type* const_type = T.Constant(value); | 342 Type* const_type = T.NewConstant(value); |
331 Type* of_type = T.Of(value); | 343 Type* of_type = T.Of(value); |
332 CHECK(!of_type->Is(type) || const_type->Is(type)); | 344 CHECK(!of_type->Is(type) || const_type->Is(type)); |
333 } | 345 } |
334 } | 346 } |
335 | 347 |
336 // If Constant(V)->Is(T), then Of(V)->Is(T) or T->Maybe(Constant(V)) | 348 // If Constant(V)->Is(T), then Of(V)->Is(T) or T->Maybe(Constant(V)) |
337 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { | 349 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { |
338 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 350 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
339 Handle<i::Object> value = *vt; | 351 Handle<i::Object> value = *vt; |
340 Type* type = *it; | 352 Type* type = *it; |
341 Type* const_type = T.Constant(value); | 353 Type* const_type = T.NewConstant(value); |
342 Type* of_type = T.Of(value); | 354 Type* of_type = T.Of(value); |
343 CHECK(!const_type->Is(type) || | 355 CHECK(!const_type->Is(type) || |
344 of_type->Is(type) || type->Maybe(const_type)); | 356 of_type->Is(type) || type->Maybe(const_type)); |
345 } | 357 } |
346 } | 358 } |
347 } | 359 } |
348 | 360 |
349 void MinMax() { | 361 void MinMax() { |
350 // If b is regular numeric bitset, then Range(b->Min(), b->Max())->Is(b). | 362 // If b is regular numeric bitset, then Range(b->Min(), b->Max())->Is(b). |
351 // TODO(neis): Need to ignore representation for this to be true. | 363 // TODO(neis): Need to ignore representation for this to be true. |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
552 } | 564 } |
553 } | 565 } |
554 } | 566 } |
555 } | 567 } |
556 | 568 |
557 // Constant(V1)->Is(Constant(V2)) iff V1 = V2 | 569 // Constant(V1)->Is(Constant(V2)) iff V1 = V2 |
558 for (ValueIterator vt1 = T.values.begin(); vt1 != T.values.end(); ++vt1) { | 570 for (ValueIterator vt1 = T.values.begin(); vt1 != T.values.end(); ++vt1) { |
559 for (ValueIterator vt2 = T.values.begin(); vt2 != T.values.end(); ++vt2) { | 571 for (ValueIterator vt2 = T.values.begin(); vt2 != T.values.end(); ++vt2) { |
560 Handle<i::Object> value1 = *vt1; | 572 Handle<i::Object> value1 = *vt1; |
561 Handle<i::Object> value2 = *vt2; | 573 Handle<i::Object> value2 = *vt2; |
562 Type* const_type1 = T.Constant(value1); | 574 Type* const_type1 = T.NewConstant(value1); |
563 Type* const_type2 = T.Constant(value2); | 575 Type* const_type2 = T.NewConstant(value2); |
564 CHECK(const_type1->Is(const_type2) == (*value1 == *value2)); | 576 CHECK(const_type1->Is(const_type2) == (*value1 == *value2)); |
565 } | 577 } |
566 } | 578 } |
567 | 579 |
568 // Range-specific subtyping | 580 // Range-specific subtyping |
569 | 581 |
570 // If IsInteger(v) then Constant(v)->Is(Range(v, v)). | 582 // If IsInteger(v) then Constant(v)->Is(Range(v, v)). |
571 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 583 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
572 Type* type = *it; | 584 Type* type = *it; |
573 if (type->IsConstant() && IsInteger(*type->AsConstant()->Value())) { | 585 if (type->IsConstant() && IsInteger(*type->AsConstant()->Value())) { |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
705 CHECK(!(type1->Is(type2) && type1->IsInhabited()) || | 717 CHECK(!(type1->Is(type2) && type1->IsInhabited()) || |
706 type1->Maybe(type2)); | 718 type1->Maybe(type2)); |
707 } | 719 } |
708 } | 720 } |
709 | 721 |
710 // Constant(V1)->Maybe(Constant(V2)) iff V1 = V2 | 722 // Constant(V1)->Maybe(Constant(V2)) iff V1 = V2 |
711 for (ValueIterator vt1 = T.values.begin(); vt1 != T.values.end(); ++vt1) { | 723 for (ValueIterator vt1 = T.values.begin(); vt1 != T.values.end(); ++vt1) { |
712 for (ValueIterator vt2 = T.values.begin(); vt2 != T.values.end(); ++vt2) { | 724 for (ValueIterator vt2 = T.values.begin(); vt2 != T.values.end(); ++vt2) { |
713 Handle<i::Object> value1 = *vt1; | 725 Handle<i::Object> value1 = *vt1; |
714 Handle<i::Object> value2 = *vt2; | 726 Handle<i::Object> value2 = *vt2; |
715 Type* const_type1 = T.Constant(value1); | 727 Type* const_type1 = T.NewConstant(value1); |
716 Type* const_type2 = T.Constant(value2); | 728 Type* const_type2 = T.NewConstant(value2); |
mvstanton
2016/09/28 14:47:44
This and other "rule-enforcement" tests need condi
mvstanton
2016/10/04 11:55:55
Done.
| |
717 CHECK(const_type1->Maybe(const_type2) == (*value1 == *value2)); | 729 CHECK(const_type1->Maybe(const_type2) == (*value1 == *value2)); |
718 } | 730 } |
719 } | 731 } |
720 | 732 |
721 // Basic types | 733 // Basic types |
722 CheckDisjoint(T.Boolean, T.Null); | 734 CheckDisjoint(T.Boolean, T.Null); |
723 CheckDisjoint(T.Undefined, T.Null); | 735 CheckDisjoint(T.Undefined, T.Null); |
724 CheckDisjoint(T.Boolean, T.Undefined); | 736 CheckDisjoint(T.Boolean, T.Undefined); |
725 CheckOverlap(T.SignedSmall, T.Number); | 737 CheckOverlap(T.SignedSmall, T.Number); |
726 CheckOverlap(T.NaN, T.Number); | 738 CheckOverlap(T.NaN, T.Number); |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1101 | 1113 |
1102 TEST(Union3) { Tests().Union3(); } | 1114 TEST(Union3) { Tests().Union3(); } |
1103 | 1115 |
1104 TEST(Union4) { Tests().Union4(); } | 1116 TEST(Union4) { Tests().Union4(); } |
1105 | 1117 |
1106 TEST(Intersect) { Tests().Intersect(); } | 1118 TEST(Intersect) { Tests().Intersect(); } |
1107 | 1119 |
1108 TEST(Distributivity) { Tests().Distributivity(); } | 1120 TEST(Distributivity) { Tests().Distributivity(); } |
1109 | 1121 |
1110 TEST(GetRange) { Tests().GetRange(); } | 1122 TEST(GetRange) { Tests().GetRange(); } |
OLD | NEW |