Chromium Code Reviews

Side by Side Diff: test/cctest/test-types.cc

Issue 558193003: Redesign of the internal type system. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
« src/types.cc ('K') | « src/types.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/hydrogen-types.h" 7 #include "src/hydrogen-types.h"
8 #include "src/isolate-inl.h" 8 #include "src/isolate-inl.h"
9 #include "src/types.h" 9 #include "src/types.h"
10 #include "test/cctest/cctest.h" 10 #include "test/cctest/cctest.h"
(...skipping 22 matching lines...)
33 static int Length(Struct* structured) { 33 static int Length(Struct* structured) {
34 return static_cast<int>(reinterpret_cast<intptr_t>(structured[1])); 34 return static_cast<int>(reinterpret_cast<intptr_t>(structured[1]));
35 } 35 }
36 36
37 static Zone* ToRegion(Zone* zone, Isolate* isolate) { return zone; } 37 static Zone* ToRegion(Zone* zone, Isolate* isolate) { return zone; }
38 38
39 struct BitsetType : Type::BitsetType { 39 struct BitsetType : Type::BitsetType {
40 using Type::BitsetType::New; 40 using Type::BitsetType::New;
41 using Type::BitsetType::Glb; 41 using Type::BitsetType::Glb;
42 using Type::BitsetType::Lub; 42 using Type::BitsetType::Lub;
43 using Type::BitsetType::InherentLub; 43 using Type::BitsetType::IsInhabited;
44 }; 44 };
45 }; 45 };
46 46
47 47
48 struct HeapRep { 48 struct HeapRep {
49 typedef FixedArray Struct; 49 typedef FixedArray Struct;
50 50
51 static bool IsStruct(Handle<HeapType> t, int tag) { 51 static bool IsStruct(Handle<HeapType> t, int tag) {
52 return t->IsFixedArray() && Smi::cast(AsStruct(t)->get(0))->value() == tag; 52 return t->IsFixedArray() && Smi::cast(AsStruct(t)->get(0))->value() == tag;
53 } 53 }
54 static bool IsBitset(Handle<HeapType> t) { return t->IsSmi(); } 54 static bool IsBitset(Handle<HeapType> t) { return t->IsSmi(); }
55 static bool IsUnion(Handle<HeapType> t) { return IsStruct(t, 6); } 55 static bool IsUnion(Handle<HeapType> t) { return IsStruct(t, 6); }
56 56
57 static Struct* AsStruct(Handle<HeapType> t) { return FixedArray::cast(*t); } 57 static Struct* AsStruct(Handle<HeapType> t) { return FixedArray::cast(*t); }
58 static int AsBitset(Handle<HeapType> t) { return Smi::cast(*t)->value(); } 58 static int AsBitset(Handle<HeapType> t) { return Smi::cast(*t)->value(); }
59 static Struct* AsUnion(Handle<HeapType> t) { return AsStruct(t); } 59 static Struct* AsUnion(Handle<HeapType> t) { return AsStruct(t); }
60 static int Length(Struct* structured) { return structured->length() - 1; } 60 static int Length(Struct* structured) { return structured->length() - 1; }
61 61
62 static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; } 62 static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; }
63 63
64 struct BitsetType : HeapType::BitsetType { 64 struct BitsetType : HeapType::BitsetType {
65 using HeapType::BitsetType::New; 65 using HeapType::BitsetType::New;
66 using HeapType::BitsetType::Glb; 66 using HeapType::BitsetType::Glb;
67 using HeapType::BitsetType::Lub; 67 using HeapType::BitsetType::Lub;
68 using HeapType::BitsetType::InherentLub; 68 using HeapType::BitsetType::IsInhabited;
69 static int Glb(Handle<HeapType> type) { return Glb(*type); } 69 static int Glb(Handle<HeapType> type) { return Glb(*type); }
70 static int Lub(Handle<HeapType> type) { return Lub(*type); } 70 static int Lub(Handle<HeapType> type) { return Lub(*type); }
71 static int InherentLub(Handle<HeapType> type) { return InherentLub(*type); }
72 }; 71 };
73 }; 72 };
74 73
75 74
76 template<class Type, class TypeHandle, class Region> 75 template<class Type, class TypeHandle, class Region>
77 class Types { 76 class Types {
78 public: 77 public:
79 Types(Region* region, Isolate* isolate) 78 Types(Region* region, Isolate* isolate)
80 : region_(region), rng_(isolate->random_number_generator()) { 79 : region_(region), rng_(isolate->random_number_generator()) {
81 #define DECLARE_TYPE(name, value) \ 80 #define DECLARE_TYPE(name, value) \
82 name = Type::name(region); \ 81 name = Type::name(region); \
83 types.push_back(name); 82 types.push_back(name);
84 BITSET_TYPE_LIST(DECLARE_TYPE) 83 PROPER_BITSET_TYPE_LIST(DECLARE_TYPE)
85 #undef DECLARE_TYPE 84 #undef DECLARE_TYPE
86 85
87 object_map = isolate->factory()->NewMap(JS_OBJECT_TYPE, 3 * kPointerSize); 86 object_map = isolate->factory()->NewMap(JS_OBJECT_TYPE, 3 * kPointerSize);
88 array_map = isolate->factory()->NewMap(JS_ARRAY_TYPE, 4 * kPointerSize); 87 array_map = isolate->factory()->NewMap(JS_ARRAY_TYPE, 4 * kPointerSize);
89 uninitialized_map = isolate->factory()->uninitialized_map(); 88 uninitialized_map = isolate->factory()->uninitialized_map();
90 ObjectClass = Type::Class(object_map, region); 89 ObjectClass = Type::Class(object_map, region);
91 ArrayClass = Type::Class(array_map, region); 90 ArrayClass = Type::Class(array_map, region);
92 UninitializedClass = Type::Class(uninitialized_map, region); 91 UninitializedClass = Type::Class(uninitialized_map, region);
93 92
94 maps.push_back(object_map); 93 maps.push_back(object_map);
(...skipping 19 matching lines...)
114 values.push_back(smi); 113 values.push_back(smi);
115 values.push_back(signed32); 114 values.push_back(signed32);
116 values.push_back(object1); 115 values.push_back(object1);
117 values.push_back(object2); 116 values.push_back(object2);
118 values.push_back(array); 117 values.push_back(array);
119 values.push_back(uninitialized); 118 values.push_back(uninitialized);
120 for (ValueVector::iterator it = values.begin(); it != values.end(); ++it) { 119 for (ValueVector::iterator it = values.begin(); it != values.end(); ++it) {
121 types.push_back(Type::Constant(*it, region)); 120 types.push_back(Type::Constant(*it, region));
122 } 121 }
123 122
124 doubles.push_back(-0.0); 123 integers.push_back(isolate->factory()->NewNumber(-V8_INFINITY));
125 doubles.push_back(+0.0); 124 integers.push_back(isolate->factory()->NewNumber(+V8_INFINITY));
126 doubles.push_back(-std::numeric_limits<double>::infinity()); 125 integers.push_back(isolate->factory()->NewNumber(-rng_->NextInt(10)));
127 doubles.push_back(+std::numeric_limits<double>::infinity()); 126 integers.push_back(isolate->factory()->NewNumber(+rng_->NextInt(10)));
128 for (int i = 0; i < 10; ++i) { 127 for (int i = 0; i < 10; ++i) {
129 doubles.push_back(rng_->NextInt()); 128 double x = rng_->NextInt();
130 doubles.push_back(rng_->NextDouble() * rng_->NextInt()); 129 integers.push_back(isolate->factory()->NewNumber(x));
130 x *= rng_->NextInt();
131 if (!IsMinusZero(x)) integers.push_back(isolate->factory()->NewNumber(x));
131 } 132 }
132 133
133 NumberArray = Type::Array(Number, region); 134 NumberArray = Type::Array(Number, region);
134 StringArray = Type::Array(String, region); 135 StringArray = Type::Array(String, region);
135 AnyArray = Type::Array(Any, region); 136 AnyArray = Type::Array(Any, region);
136 137
137 SignedFunction1 = Type::Function(SignedSmall, SignedSmall, region); 138 SignedFunction1 = Type::Function(SignedSmall, SignedSmall, region);
138 NumberFunction1 = Type::Function(Number, Number, region); 139 NumberFunction1 = Type::Function(Number, Number, region);
139 NumberFunction2 = Type::Function(Number, Number, Number, region); 140 NumberFunction2 = Type::Function(Number, Number, Number, region);
140 MethodFunction = Type::Function(String, Object, 0, region); 141 MethodFunction = Type::Function(String, Object, 0, region);
(...skipping 34 matching lines...)
175 TypeHandle AnyArray; 176 TypeHandle AnyArray;
176 177
177 TypeHandle SignedFunction1; 178 TypeHandle SignedFunction1;
178 TypeHandle NumberFunction1; 179 TypeHandle NumberFunction1;
179 TypeHandle NumberFunction2; 180 TypeHandle NumberFunction2;
180 TypeHandle MethodFunction; 181 TypeHandle MethodFunction;
181 182
182 typedef std::vector<TypeHandle> TypeVector; 183 typedef std::vector<TypeHandle> TypeVector;
183 typedef std::vector<Handle<i::Map> > MapVector; 184 typedef std::vector<Handle<i::Map> > MapVector;
184 typedef std::vector<Handle<i::Object> > ValueVector; 185 typedef std::vector<Handle<i::Object> > ValueVector;
185 typedef std::vector<double> DoubleVector;
186 186
187 TypeVector types; 187 TypeVector types;
188 MapVector maps; 188 MapVector maps;
189 ValueVector values; 189 ValueVector values;
190 DoubleVector doubles; // Some floating-point values, excluding NaN. 190 ValueVector integers; // "Integer" values used as range limits.
191
192 // Range type helper functions, partially copied from types.cc.
193 // Note: dle(dmin(x,y), dmax(x,y)) holds iff neither x nor y is NaN.
194 bool dle(double x, double y) {
195 return x <= y && (x != 0 || IsMinusZero(x) || !IsMinusZero(y));
196 }
197 bool deq(double x, double y) {
198 return dle(x, y) && dle(y, x);
199 }
200 double dmin(double x, double y) {
201 return dle(x, y) ? x : y;
202 }
203 double dmax(double x, double y) {
204 return dle(x, y) ? y : x;
205 }
206 191
207 TypeHandle Of(Handle<i::Object> value) { 192 TypeHandle Of(Handle<i::Object> value) {
208 return Type::Of(value, region_); 193 return Type::Of(value, region_);
209 } 194 }
210 195
211 TypeHandle NowOf(Handle<i::Object> value) { 196 TypeHandle NowOf(Handle<i::Object> value) {
212 return Type::NowOf(value, region_); 197 return Type::NowOf(value, region_);
213 } 198 }
214 199
200 TypeHandle Class(Handle<i::Map> map) {
201 return Type::Class(map, region_);
202 }
203
215 TypeHandle Constant(Handle<i::Object> value) { 204 TypeHandle Constant(Handle<i::Object> value) {
216 return Type::Constant(value, region_); 205 return Type::Constant(value, region_);
217 } 206 }
218 207
219 TypeHandle Range(double min, double max) { 208 TypeHandle Range(Handle<i::Object> min, Handle<i::Object> max) {
220 return Type::Range(min, max, region_); 209 return Type::Range(min, max, region_);
221 } 210 }
222 211
223 TypeHandle Class(Handle<i::Map> map) { 212 TypeHandle Context(TypeHandle outer) {
224 return Type::Class(map, region_); 213 return Type::Context(outer, region_);
225 } 214 }
226 215
227 TypeHandle Array1(TypeHandle element) { 216 TypeHandle Array1(TypeHandle element) {
228 return Type::Array(element, region_); 217 return Type::Array(element, region_);
229 } 218 }
230 219
231 TypeHandle Function0(TypeHandle result, TypeHandle receiver) { 220 TypeHandle Function0(TypeHandle result, TypeHandle receiver) {
232 return Type::Function(result, receiver, 0, region_); 221 return Type::Function(result, receiver, 0, region_);
233 } 222 }
234 223
(...skipping 16 matching lines...)
251 240
252 template<class Type2, class TypeHandle2> 241 template<class Type2, class TypeHandle2>
253 TypeHandle Convert(TypeHandle2 t) { 242 TypeHandle Convert(TypeHandle2 t) {
254 return Type::template Convert<Type2>(t, region_); 243 return Type::template Convert<Type2>(t, region_);
255 } 244 }
256 245
257 TypeHandle Random() { 246 TypeHandle Random() {
258 return types[rng_->NextInt(static_cast<int>(types.size()))]; 247 return types[rng_->NextInt(static_cast<int>(types.size()))];
259 } 248 }
260 249
261 TypeHandle Fuzz(int depth = 5) { 250 TypeHandle Fuzz(int depth = 4) {
262 switch (rng_->NextInt(depth == 0 ? 3 : 20)) { 251 switch (rng_->NextInt(depth == 0 ? 3 : 20)) {
263 case 0: { // bitset 252 case 0: { // bitset
264 int n = 0 253 int n = 0
265 #define COUNT_BITSET_TYPES(type, value) + 1 254 #define COUNT_BITSET_TYPES(type, value) + 1
266 BITSET_TYPE_LIST(COUNT_BITSET_TYPES) 255 PROPER_BITSET_TYPE_LIST(COUNT_BITSET_TYPES)
267 #undef COUNT_BITSET_TYPES 256 #undef COUNT_BITSET_TYPES
268 ; 257 ;
269 int i = rng_->NextInt(n); 258 int i = rng_->NextInt(n);
270 #define PICK_BITSET_TYPE(type, value) \ 259 #define PICK_BITSET_TYPE(type, value) \
271 if (i-- == 0) return Type::type(region_); 260 if (i-- == 0) return Type::type(region_);
272 BITSET_TYPE_LIST(PICK_BITSET_TYPE) 261 PROPER_BITSET_TYPE_LIST(PICK_BITSET_TYPE)
273 #undef PICK_BITSET_TYPE 262 #undef PICK_BITSET_TYPE
274 UNREACHABLE(); 263 UNREACHABLE();
275 } 264 }
276 case 1: { // class 265 case 1: { // class
277 int i = rng_->NextInt(static_cast<int>(maps.size())); 266 int i = rng_->NextInt(static_cast<int>(maps.size()));
278 return Type::Class(maps[i], region_); 267 return Type::Class(maps[i], region_);
279 } 268 }
280 case 2: { // constant 269 case 2: { // constant
281 int i = rng_->NextInt(static_cast<int>(values.size())); 270 int i = rng_->NextInt(static_cast<int>(values.size()));
282 return Type::Constant(values[i], region_); 271 return Type::Constant(values[i], region_);
283 } 272 }
284 case 3: { // context 273 case 3: { // range
274 int i = rng_->NextInt(static_cast<int>(integers.size()));
275 int j = rng_->NextInt(static_cast<int>(integers.size()));
276 i::Handle<i::Object> min = integers[i];
277 i::Handle<i::Object> max = integers[j];
278 if (min->Number() > max->Number()) std::swap(min, max);
rossberg 2014/09/10 15:44:15 Oh you nasty imperative programmer...
279 return Type::Range(min, max, region_);
280 }
281 case 4: { // context
285 int depth = rng_->NextInt(3); 282 int depth = rng_->NextInt(3);
286 TypeHandle type = Type::Internal(region_); 283 TypeHandle type = Type::Internal(region_);
287 for (int i = 0; i < depth; ++i) type = Type::Context(type, region_); 284 for (int i = 0; i < depth; ++i) type = Type::Context(type, region_);
288 return type; 285 return type;
289 } 286 }
290 case 4: { // array 287 case 5: { // array
291 TypeHandle element = Fuzz(depth / 2); 288 TypeHandle element = Fuzz(depth / 2);
292 return Type::Array(element, region_); 289 return Type::Array(element, region_);
293 } 290 }
294 case 5: 291 case 6:
295 case 6: { // function 292 case 7: { // function
296 TypeHandle result = Fuzz(depth / 2); 293 TypeHandle result = Fuzz(depth / 2);
297 TypeHandle receiver = Fuzz(depth / 2); 294 TypeHandle receiver = Fuzz(depth / 2);
298 int arity = rng_->NextInt(3); 295 int arity = rng_->NextInt(3);
299 TypeHandle type = Type::Function(result, receiver, arity, region_); 296 TypeHandle type = Type::Function(result, receiver, arity, region_);
300 for (int i = 0; i < type->AsFunction()->Arity(); ++i) { 297 for (int i = 0; i < type->AsFunction()->Arity(); ++i) {
301 TypeHandle parameter = Fuzz(depth / 2); 298 TypeHandle parameter = Fuzz(depth / 2);
302 type->AsFunction()->InitParameter(i, parameter); 299 type->AsFunction()->InitParameter(i, parameter);
303 } 300 }
304 return type; 301 return type;
305 } 302 }
(...skipping 17 matching lines...)
323 v8::base::RandomNumberGenerator* rng_; 320 v8::base::RandomNumberGenerator* rng_;
324 }; 321 };
325 322
326 323
327 template<class Type, class TypeHandle, class Region, class Rep> 324 template<class Type, class TypeHandle, class Region, class Rep>
328 struct Tests : Rep { 325 struct Tests : Rep {
329 typedef Types<Type, TypeHandle, Region> TypesInstance; 326 typedef Types<Type, TypeHandle, Region> TypesInstance;
330 typedef typename TypesInstance::TypeVector::iterator TypeIterator; 327 typedef typename TypesInstance::TypeVector::iterator TypeIterator;
331 typedef typename TypesInstance::MapVector::iterator MapIterator; 328 typedef typename TypesInstance::MapVector::iterator MapIterator;
332 typedef typename TypesInstance::ValueVector::iterator ValueIterator; 329 typedef typename TypesInstance::ValueVector::iterator ValueIterator;
333 typedef typename TypesInstance::DoubleVector::iterator DoubleIterator;
334 330
335 Isolate* isolate; 331 Isolate* isolate;
336 HandleScope scope; 332 HandleScope scope;
337 Zone zone; 333 Zone zone;
338 TypesInstance T; 334 TypesInstance T;
339 335
340 Tests() : 336 Tests() :
341 isolate(CcTest::i_isolate()), 337 isolate(CcTest::i_isolate()),
342 scope(isolate), 338 scope(isolate),
343 zone(isolate), 339 zone(isolate),
344 T(Rep::ToRegion(&zone, isolate), isolate) { 340 T(Rep::ToRegion(&zone, isolate), isolate) {
345 } 341 }
346 342
347 bool Equal(TypeHandle type1, TypeHandle type2) { 343 bool Equal(TypeHandle type1, TypeHandle type2) {
348 return 344 return
349 type1->Equals(type2) && 345 type1->Equals(type2) &&
350 Rep::IsBitset(type1) == Rep::IsBitset(type2) && 346 this->IsBitset(type1) == this->IsBitset(type2) &&
351 Rep::IsUnion(type1) == Rep::IsUnion(type2) && 347 this->IsUnion(type1) == this->IsUnion(type2) &&
352 type1->NumClasses() == type2->NumClasses() && 348 type1->NumClasses() == type2->NumClasses() &&
353 type1->NumConstants() == type2->NumConstants() && 349 type1->NumConstants() == type2->NumConstants() &&
354 (!Rep::IsBitset(type1) || 350 (!this->IsBitset(type1) ||
355 Rep::AsBitset(type1) == Rep::AsBitset(type2)) && 351 this->AsBitset(type1) == this->AsBitset(type2)) &&
356 (!Rep::IsUnion(type1) || 352 (!this->IsUnion(type1) ||
357 Rep::Length(Rep::AsUnion(type1)) == Rep::Length(Rep::AsUnion(type2))); 353 this->Length(this->AsUnion(type1)) ==
354 this->Length(this->AsUnion(type2)));
358 } 355 }
359 356
360 void CheckEqual(TypeHandle type1, TypeHandle type2) { 357 void CheckEqual(TypeHandle type1, TypeHandle type2) {
361 CHECK(Equal(type1, type2)); 358 CHECK(Equal(type1, type2));
362 } 359 }
363 360
364 void CheckSub(TypeHandle type1, TypeHandle type2) { 361 void CheckSub(TypeHandle type1, TypeHandle type2) {
365 CHECK(type1->Is(type2)); 362 CHECK(type1->Is(type2));
366 CHECK(!type2->Is(type1)); 363 CHECK(!type2->Is(type1));
367 if (Rep::IsBitset(type1) && Rep::IsBitset(type2)) { 364 if (this->IsBitset(type1) && this->IsBitset(type2)) {
368 CHECK_NE(Rep::AsBitset(type1), Rep::AsBitset(type2)); 365 CHECK_NE(this->AsBitset(type1), this->AsBitset(type2));
369 } 366 }
370 } 367 }
371 368
372 void CheckUnordered(TypeHandle type1, TypeHandle type2) { 369 void CheckUnordered(TypeHandle type1, TypeHandle type2) {
373 CHECK(!type1->Is(type2)); 370 CHECK(!type1->Is(type2));
374 CHECK(!type2->Is(type1)); 371 CHECK(!type2->Is(type1));
375 if (Rep::IsBitset(type1) && Rep::IsBitset(type2)) { 372 if (this->IsBitset(type1) && this->IsBitset(type2)) {
376 CHECK_NE(Rep::AsBitset(type1), Rep::AsBitset(type2)); 373 CHECK_NE(this->AsBitset(type1), this->AsBitset(type2));
377 } 374 }
378 } 375 }
379 376
380 void CheckOverlap(TypeHandle type1, TypeHandle type2, TypeHandle mask) { 377 void CheckOverlap(TypeHandle type1, TypeHandle type2) {
381 CHECK(type1->Maybe(type2)); 378 CHECK(type1->Maybe(type2));
382 CHECK(type2->Maybe(type1)); 379 CHECK(type2->Maybe(type1));
383 if (Rep::IsBitset(type1) && Rep::IsBitset(type2)) {
384 CHECK_NE(0,
385 Rep::AsBitset(type1) & Rep::AsBitset(type2) & Rep::AsBitset(mask));
386 }
387 } 380 }
388 381
389 void CheckDisjoint(TypeHandle type1, TypeHandle type2, TypeHandle mask) { 382 void CheckDisjoint(TypeHandle type1, TypeHandle type2) {
390 CHECK(!type1->Is(type2)); 383 CHECK(!type1->Is(type2));
391 CHECK(!type2->Is(type1)); 384 CHECK(!type2->Is(type1));
392 CHECK(!type1->Maybe(type2)); 385 CHECK(!type1->Maybe(type2));
393 CHECK(!type2->Maybe(type1)); 386 CHECK(!type2->Maybe(type1));
394 if (Rep::IsBitset(type1) && Rep::IsBitset(type2)) { 387 }
395 CHECK_EQ(0, 388
396 Rep::AsBitset(type1) & Rep::AsBitset(type2) & Rep::AsBitset(mask)); 389 void IsSomeType() {
390 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
391 TypeHandle t = *it;
392 CHECK(1 ==
393 this->IsBitset(t) + t->IsClass() + t->IsConstant() + t->IsRange() +
394 this->IsUnion(t) + t->IsArray() + t->IsFunction() + t->IsContext());
397 } 395 }
398 } 396 }
399 397
400 void Bitset() { 398 void Bitset() {
401 // None and Any are bitsets. 399 // None and Any are bitsets.
402 CHECK(this->IsBitset(T.None)); 400 CHECK(this->IsBitset(T.None));
403 CHECK(this->IsBitset(T.Any)); 401 CHECK(this->IsBitset(T.Any));
404 402
405 CHECK_EQ(0, this->AsBitset(T.None)); 403 CHECK_EQ(0, this->AsBitset(T.None));
406 CHECK_EQ(-1, this->AsBitset(T.Any)); 404 CHECK_EQ(-1, this->AsBitset(T.Any));
(...skipping 38 matching lines...)
445 TypeHandle type2 = *it2; 443 TypeHandle type2 = *it2;
446 TypeHandle union12 = T.Union(type1, type2); 444 TypeHandle union12 = T.Union(type1, type2);
447 if (this->IsBitset(type1) && this->IsBitset(type2)) { 445 if (this->IsBitset(type1) && this->IsBitset(type2)) {
448 CHECK_EQ( 446 CHECK_EQ(
449 this->AsBitset(type1) | this->AsBitset(type2), 447 this->AsBitset(type1) | this->AsBitset(type2),
450 this->AsBitset(union12)); 448 this->AsBitset(union12));
451 } 449 }
452 } 450 }
453 } 451 }
454 452
455 // Intersect(T1, T2) is bitwise conjunction for bitsets T1,T2 453 // Intersect(T1, T2) is almost bitwise conjunction for bitsets T1,T2
rossberg 2014/09/10 15:44:15 Can't harm to be more precise. :) "is ... upto uni
neis1 2014/09/11 12:58:12 Acknowledged.
456 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { 454 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
457 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { 455 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
458 TypeHandle type1 = *it1; 456 TypeHandle type1 = *it1;
459 TypeHandle type2 = *it2; 457 TypeHandle type2 = *it2;
460 TypeHandle intersect12 = T.Intersect(type1, type2); 458 TypeHandle intersect12 = T.Intersect(type1, type2);
461 if (this->IsBitset(type1) && this->IsBitset(type2)) { 459 if (this->IsBitset(type1) && this->IsBitset(type2)) {
460 int bitset = this->AsBitset(type1) & this->AsBitset(type2);
462 CHECK_EQ( 461 CHECK_EQ(
463 this->AsBitset(type1) & this->AsBitset(type2), 462 Rep::BitsetType::IsInhabited(bitset) ? bitset : 0,
464 this->AsBitset(intersect12)); 463 this->AsBitset(intersect12));
465 } 464 }
466 } 465 }
467 } 466 }
468 } 467 }
469 468
470 void Class() { 469 void Class() {
471 // Constructor 470 // Constructor
472 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) { 471 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) {
473 Handle<i::Map> map = *mt; 472 Handle<i::Map> map = *mt;
(...skipping 81 matching lines...)
555 CHECK(T.Constant(fac->NewNumber(-10.1))->Is(T.OtherNumber)); 554 CHECK(T.Constant(fac->NewNumber(-10.1))->Is(T.OtherNumber));
556 CHECK(T.Constant(fac->NewNumber(10e60))->Is(T.OtherNumber)); 555 CHECK(T.Constant(fac->NewNumber(10e60))->Is(T.OtherNumber));
557 CHECK(T.Constant(fac->NewNumber(-1.0*0.0))->Is(T.MinusZero)); 556 CHECK(T.Constant(fac->NewNumber(-1.0*0.0))->Is(T.MinusZero));
558 CHECK(T.Constant(fac->NewNumber(v8::base::OS::nan_value()))->Is(T.NaN)); 557 CHECK(T.Constant(fac->NewNumber(v8::base::OS::nan_value()))->Is(T.NaN));
559 CHECK(T.Constant(fac->NewNumber(V8_INFINITY))->Is(T.OtherNumber)); 558 CHECK(T.Constant(fac->NewNumber(V8_INFINITY))->Is(T.OtherNumber));
560 CHECK(T.Constant(fac->NewNumber(-V8_INFINITY))->Is(T.OtherNumber)); 559 CHECK(T.Constant(fac->NewNumber(-V8_INFINITY))->Is(T.OtherNumber));
561 } 560 }
562 561
563 void Range() { 562 void Range() {
564 // Constructor 563 // Constructor
565 for (DoubleIterator i = T.doubles.begin(); i != T.doubles.end(); ++i) { 564 for (ValueIterator i = T.integers.begin(); i != T.integers.end(); ++i) {
566 for (DoubleIterator j = T.doubles.begin(); j != T.doubles.end(); ++j) { 565 for (ValueIterator j = T.integers.begin(); j != T.integers.end(); ++j) {
567 double min = T.dmin(*i, *j); 566 i::Handle<i::Object> min = *i;
568 double max = T.dmax(*i, *j); 567 i::Handle<i::Object> max = *j;
568 if (min->Number() > max->Number()) std::swap(min, max);
569 TypeHandle type = T.Range(min, max); 569 TypeHandle type = T.Range(min, max);
570 CHECK(type->IsRange()); 570 CHECK(type->IsRange());
571 } 571 }
572 } 572 }
573 573
574 // Range attributes 574 // Range attributes
575 for (DoubleIterator i = T.doubles.begin(); i != T.doubles.end(); ++i) { 575 for (ValueIterator i = T.integers.begin(); i != T.integers.end(); ++i) {
576 for (DoubleIterator j = T.doubles.begin(); j != T.doubles.end(); ++j) { 576 for (ValueIterator j = T.integers.begin(); j != T.integers.end(); ++j) {
577 double min = T.dmin(*i, *j); 577 i::Handle<i::Object> min = *i;
578 double max = T.dmax(*i, *j); 578 i::Handle<i::Object> max = *j;
579 printf("RangeType: min, max = %f, %f\n", min, max); 579 if (min->Number() > max->Number()) std::swap(min, max);
580 TypeHandle type = T.Range(min, max); 580 TypeHandle type = T.Range(min, max);
581 printf("RangeType: Min, Max = %f, %f\n", 581 CHECK(*min == *type->AsRange()->MinV());
582 type->AsRange()->Min(), type->AsRange()->Max()); 582 CHECK(*max == *type->AsRange()->MaxV());
583 CHECK(min == type->AsRange()->Min());
584 CHECK(max == type->AsRange()->Max());
585 } 583 }
586 } 584 }
587 585
588 // TODO(neis): enable once subtyping is updated. 586 // Functionality & Injectivity: Range(min1, max1) = Range(min2, max2) <=>
589 // // Functionality & Injectivity: Range(min1, max1) = Range(min2, max2) <=> 587 // min1 = min2 /\ max1 = max2
590 // // min1 = min2 /\ max1 = max2 588 for (ValueIterator i1 = T.integers.begin();
591 // for (DoubleIterator i1 = T.doubles.begin(); i1 != T.doubles.end(); ++i1) { 589 i1 != T.integers.end(); ++i1) {
592 // for (DoubleIterator j1 = T.doubles.begin(); j1 != T.doubles.end(); ++j1) { 590 for (ValueIterator j1 = T.integers.begin();
593 // for (DoubleIterator i2 = T.doubles.begin(); 591 j1 != T.integers.end(); ++j1) {
594 // i2 != T.doubles.end(); ++i2) { 592 for (ValueIterator i2 = T.integers.begin();
595 // for (DoubleIterator j2 = T.doubles.begin(); 593 i2 != T.integers.end(); ++i2) {
596 // j2 != T.doubles.end(); ++j2) { 594 for (ValueIterator j2 = T.integers.begin();
597 // double min1 = T.dmin(*i1, *j1); 595 j2 != T.integers.end(); ++j2) {
598 // double max1 = T.dmax(*i1, *j1); 596 i::Handle<i::Object> min1 = *i1;
599 // double min2 = T.dmin(*i2, *j2); 597 i::Handle<i::Object> max1 = *j1;
600 // double max2 = T.dmax(*i2, *j2); 598 i::Handle<i::Object> min2 = *i2;
601 // TypeHandle type1 = T.Range(min1, max1); 599 i::Handle<i::Object> max2 = *j2;
602 // TypeHandle type2 = T.Range(min2, max2); 600 if (min1->Number() > max1->Number()) std::swap(min1, max1);
603 // CHECK(Equal(type1, type2) == 601 if (min2->Number() > max2->Number()) std::swap(min2, max2);
604 // (T.deq(min1, min2) && T.deq(max1, max2))); 602 TypeHandle type1 = T.Range(min1, max1);
605 // } 603 TypeHandle type2 = T.Range(min2, max2);
606 // } 604 CHECK(Equal(type1, type2) == (*min1 == *min2 && *max1 == *max2));
607 // } 605 }
608 // } 606 }
607 }
608 }
609 } 609 }
610 610
611 void Array() { 611 void Array() {
612 // Constructor 612 // Constructor
613 for (int i = 0; i < 20; ++i) { 613 for (int i = 0; i < 20; ++i) {
614 TypeHandle type = T.Random(); 614 TypeHandle type = T.Random();
615 TypeHandle array = T.Array1(type); 615 TypeHandle array = T.Array1(type);
616 CHECK(array->IsArray()); 616 CHECK(array->IsArray());
617 } 617 }
618 618
(...skipping 87 matching lines...)
706 706
707 void Of() { 707 void Of() {
708 // Constant(V)->Is(Of(V)) 708 // Constant(V)->Is(Of(V))
709 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { 709 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
710 Handle<i::Object> value = *vt; 710 Handle<i::Object> value = *vt;
711 TypeHandle const_type = T.Constant(value); 711 TypeHandle const_type = T.Constant(value);
712 TypeHandle of_type = T.Of(value); 712 TypeHandle of_type = T.Of(value);
713 CHECK(const_type->Is(of_type)); 713 CHECK(const_type->Is(of_type));
714 } 714 }
715 715
716 // Constant(V)->Is(T) iff Of(V)->Is(T) or T->Maybe(Constant(V)) 716 // If Of(V)->Is(T), then Constant(V)->Is(T)
717 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { 717 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
718 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 718 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
719 Handle<i::Object> value = *vt; 719 Handle<i::Object> value = *vt;
720 TypeHandle type = *it; 720 TypeHandle type = *it;
721 TypeHandle const_type = T.Constant(value); 721 TypeHandle const_type = T.Constant(value);
722 TypeHandle of_type = T.Of(value); 722 TypeHandle of_type = T.Of(value);
723 CHECK(const_type->Is(type) == 723 CHECK(!of_type->Is(type) || const_type->Is(type));
724 (of_type->Is(type) || type->Maybe(const_type))); 724 }
725 }
726
727 // If Constant(V)->Is(T), then Of(V)->Is(T) or T->Maybe(Constant(V))
728 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
729 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
730 Handle<i::Object> value = *vt;
731 TypeHandle type = *it;
732 TypeHandle const_type = T.Constant(value);
733 TypeHandle of_type = T.Of(value);
734 CHECK(!const_type->Is(type) ||
735 of_type->Is(type) || type->Maybe(const_type));
725 } 736 }
726 } 737 }
727 } 738 }
728 739
729 void NowOf() { 740 void NowOf() {
730 // Constant(V)->NowIs(NowOf(V)) 741 // Constant(V)->NowIs(NowOf(V))
731 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { 742 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
732 Handle<i::Object> value = *vt; 743 Handle<i::Object> value = *vt;
733 TypeHandle const_type = T.Constant(value); 744 TypeHandle const_type = T.Constant(value);
734 TypeHandle nowof_type = T.NowOf(value); 745 TypeHandle nowof_type = T.NowOf(value);
735 CHECK(const_type->NowIs(nowof_type)); 746 CHECK(const_type->NowIs(nowof_type));
736 } 747 }
737 748
738 // NowOf(V)->Is(Of(V)) 749 // NowOf(V)->Is(Of(V))
739 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { 750 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
740 Handle<i::Object> value = *vt; 751 Handle<i::Object> value = *vt;
741 TypeHandle nowof_type = T.NowOf(value); 752 TypeHandle nowof_type = T.NowOf(value);
742 TypeHandle of_type = T.Of(value); 753 TypeHandle of_type = T.Of(value);
743 CHECK(nowof_type->Is(of_type)); 754 CHECK(nowof_type->Is(of_type));
744 } 755 }
745 756
746 // Constant(V)->NowIs(T) iff NowOf(V)->NowIs(T) or T->Maybe(Constant(V)) 757 // If NowOf(V)->NowIs(T), then Constant(V)->NowIs(T)
747 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { 758 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
748 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 759 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
749 Handle<i::Object> value = *vt; 760 Handle<i::Object> value = *vt;
750 TypeHandle type = *it; 761 TypeHandle type = *it;
751 TypeHandle const_type = T.Constant(value); 762 TypeHandle const_type = T.Constant(value);
752 TypeHandle nowof_type = T.NowOf(value); 763 TypeHandle nowof_type = T.NowOf(value);
753 CHECK(const_type->NowIs(type) == 764 CHECK(!nowof_type->NowIs(type) || const_type->NowIs(type));
754 (nowof_type->NowIs(type) || type->Maybe(const_type)));
755 } 765 }
756 } 766 }
757 767
758 // Constant(V)->Is(T) implies NowOf(V)->Is(T) or T->Maybe(Constant(V)) 768 // If Constant(V)->NowIs(T),
769 // then NowOf(V)->NowIs(T) or T->Maybe(Constant(V))
759 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { 770 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
760 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 771 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
761 Handle<i::Object> value = *vt; 772 Handle<i::Object> value = *vt;
773 TypeHandle type = *it;
774 TypeHandle const_type = T.Constant(value);
775 TypeHandle nowof_type = T.NowOf(value);
776 CHECK(!const_type->NowIs(type) ||
777 nowof_type->NowIs(type) || type->Maybe(const_type));
778 }
779 }
780
781 // If Constant(V)->Is(T),
782 // then NowOf(V)->Is(T) or T->Maybe(Constant(V))
783 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
784 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
785 Handle<i::Object> value = *vt;
762 TypeHandle type = *it; 786 TypeHandle type = *it;
763 TypeHandle const_type = T.Constant(value); 787 TypeHandle const_type = T.Constant(value);
764 TypeHandle nowof_type = T.NowOf(value); 788 TypeHandle nowof_type = T.NowOf(value);
765 CHECK(!const_type->Is(type) || 789 CHECK(!const_type->Is(type) ||
766 (nowof_type->Is(type) || type->Maybe(const_type))); 790 nowof_type->Is(type) || type->Maybe(const_type));
767 } 791 }
768 } 792 }
769 } 793 }
770 794
771 void Bounds() { 795 void BitsetGlb() {
772 // Ordering: (T->BitsetGlb())->Is(T->BitsetLub()) 796 // Lower: (T->BitsetGlb())->Is(T)
773 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
774 TypeHandle type = *it;
775 TypeHandle glb =
776 Rep::BitsetType::New(Rep::BitsetType::Glb(type), T.region());
777 TypeHandle lub =
778 Rep::BitsetType::New(Rep::BitsetType::Lub(type), T.region());
779 CHECK(glb->Is(lub));
780 }
781
782 // Lower bound: (T->BitsetGlb())->Is(T)
783 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 797 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
784 TypeHandle type = *it; 798 TypeHandle type = *it;
785 TypeHandle glb = 799 TypeHandle glb =
786 Rep::BitsetType::New(Rep::BitsetType::Glb(type), T.region()); 800 Rep::BitsetType::New(Rep::BitsetType::Glb(type), T.region());
787 CHECK(glb->Is(type)); 801 CHECK(glb->Is(type));
788 } 802 }
789 803
790 // Upper bound: T->Is(T->BitsetLub()) 804 // Greatest: If T1->IsBitset() and T1->Is(T2), then T1->Is(T2->BitsetGlb())
805 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
806 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
807 TypeHandle type1 = *it1;
808 TypeHandle type2 = *it2;
809 TypeHandle glb2 =
810 Rep::BitsetType::New(Rep::BitsetType::Glb(type2), T.region());
811 CHECK(!this->IsBitset(type1) || !type1->Is(type2) || type1->Is(glb2));
812 }
813 }
814
815 // Monotonicity: T1->Is(T2) implies (T1->BitsetGlb())->Is(T2->BitsetGlb())
816 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
817 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
818 TypeHandle type1 = *it1;
819 TypeHandle type2 = *it2;
820 TypeHandle glb1 =
821 Rep::BitsetType::New(Rep::BitsetType::Glb(type1), T.region());
822 TypeHandle glb2 =
823 Rep::BitsetType::New(Rep::BitsetType::Glb(type2), T.region());
824 CHECK(!type1->Is(type2) || glb1->Is(glb2));
825 }
826 }
827 }
828
829 void BitsetLub() {
830 // Upper: T->Is(T->BitsetLub())
791 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 831 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
792 TypeHandle type = *it; 832 TypeHandle type = *it;
793 TypeHandle lub = 833 TypeHandle lub =
794 Rep::BitsetType::New(Rep::BitsetType::Lub(type), T.region()); 834 Rep::BitsetType::New(Rep::BitsetType::Lub(type), T.region());
795 CHECK(type->Is(lub)); 835 CHECK(type->Is(lub));
796 } 836 }
797 837
798 // Inherent bound: (T->BitsetLub())->Is(T->InherentBitsetLub()) 838 // Least: If T2->IsBitset() and T1->Is(T2), then (T1->BitsetLub())->Is(T2)
799 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 839 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
800 TypeHandle type = *it; 840 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
801 TypeHandle lub = 841 TypeHandle type1 = *it1;
802 Rep::BitsetType::New(Rep::BitsetType::Lub(type), T.region()); 842 TypeHandle type2 = *it2;
803 TypeHandle inherent = 843 TypeHandle lub1 =
804 Rep::BitsetType::New(Rep::BitsetType::InherentLub(type), T.region()); 844 Rep::BitsetType::New(Rep::BitsetType::Lub(type1), T.region());
805 CHECK(lub->Is(inherent)); 845 CHECK(!this->IsBitset(type2) || !type1->Is(type2) || lub1->Is(type2));
846 }
847 }
848
849 // Monotonicity: T1->Is(T2) implies (T1->BitsetLub())->Is(T2->BitsetLub())
850 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
851 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
852 TypeHandle type1 = *it1;
853 TypeHandle type2 = *it2;
854 TypeHandle lub1 =
855 Rep::BitsetType::New(Rep::BitsetType::Lub(type1), T.region());
856 TypeHandle lub2 =
857 Rep::BitsetType::New(Rep::BitsetType::Lub(type2), T.region());
858 CHECK(!type1->Is(type2) || lub1->Is(lub2));
859 }
806 } 860 }
807 } 861 }
808 862
809 void Is() { 863 void Is() {
810 // Least Element (Bottom): None->Is(T) 864 // Least Element (Bottom): None->Is(T)
811 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 865 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
812 TypeHandle type = *it; 866 TypeHandle type = *it;
813 CHECK(T.None->Is(type)); 867 CHECK(T.None->Is(type));
814 } 868 }
815 869
(...skipping 35 matching lines...)
851 905
852 // Antisymmetry: T1->Is(T2) and T2->Is(T1) iff T1 = T2 906 // Antisymmetry: T1->Is(T2) and T2->Is(T1) iff T1 = T2
853 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { 907 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
854 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { 908 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
855 TypeHandle type1 = *it1; 909 TypeHandle type1 = *it1;
856 TypeHandle type2 = *it2; 910 TypeHandle type2 = *it2;
857 CHECK((type1->Is(type2) && type2->Is(type1)) == Equal(type1, type2)); 911 CHECK((type1->Is(type2) && type2->Is(type1)) == Equal(type1, type2));
858 } 912 }
859 } 913 }
860 914
915 // Class(M1)->Is(Class(M2)) iff M1 = M2
916 for (MapIterator mt1 = T.maps.begin(); mt1 != T.maps.end(); ++mt1) {
917 for (MapIterator mt2 = T.maps.begin(); mt2 != T.maps.end(); ++mt2) {
918 Handle<i::Map> map1 = *mt1;
919 Handle<i::Map> map2 = *mt2;
920 TypeHandle class_type1 = T.Class(map1);
921 TypeHandle class_type2 = T.Class(map2);
922 CHECK(class_type1->Is(class_type2) == (*map1 == *map2));
923 }
924 }
925
861 // Constant(V1)->Is(Constant(V2)) iff V1 = V2 926 // Constant(V1)->Is(Constant(V2)) iff V1 = V2
862 for (ValueIterator vt1 = T.values.begin(); vt1 != T.values.end(); ++vt1) { 927 for (ValueIterator vt1 = T.values.begin(); vt1 != T.values.end(); ++vt1) {
863 for (ValueIterator vt2 = T.values.begin(); vt2 != T.values.end(); ++vt2) { 928 for (ValueIterator vt2 = T.values.begin(); vt2 != T.values.end(); ++vt2) {
864 Handle<i::Object> value1 = *vt1; 929 Handle<i::Object> value1 = *vt1;
865 Handle<i::Object> value2 = *vt2; 930 Handle<i::Object> value2 = *vt2;
866 TypeHandle const_type1 = T.Constant(value1); 931 TypeHandle const_type1 = T.Constant(value1);
867 TypeHandle const_type2 = T.Constant(value2); 932 TypeHandle const_type2 = T.Constant(value2);
868 CHECK(const_type1->Is(const_type2) == (*value1 == *value2)); 933 CHECK(const_type1->Is(const_type2) == (*value1 == *value2));
869 } 934 }
870 } 935 }
871 936
872 // Class(M1)->Is(Class(M2)) iff M1 = M2 937 // Range(min1, max1)->Is(Range(min2, max2)) iff
873 for (MapIterator mt1 = T.maps.begin(); mt1 != T.maps.end(); ++mt1) { 938 // min1 >= min2 /\ max1 <= max2
874 for (MapIterator mt2 = T.maps.begin(); mt2 != T.maps.end(); ++mt2) { 939 for (ValueIterator i1 = T.integers.begin();
875 Handle<i::Map> map1 = *mt1; 940 i1 != T.integers.end(); ++i1) {
876 Handle<i::Map> map2 = *mt2; 941 for (ValueIterator j1 = T.integers.begin();
877 TypeHandle class_type1 = T.Class(map1); 942 j1 != T.integers.end(); ++j1) {
878 TypeHandle class_type2 = T.Class(map2); 943 for (ValueIterator i2 = T.integers.begin();
879 CHECK(class_type1->Is(class_type2) == (*map1 == *map2)); 944 i2 != T.integers.end(); ++i2) {
945 for (ValueIterator j2 = T.integers.begin();
946 j2 != T.integers.end(); ++j2) {
947 i::Handle<i::Object> min1 = *i1;
948 i::Handle<i::Object> max1 = *j1;
949 i::Handle<i::Object> min2 = *i2;
950 i::Handle<i::Object> max2 = *j2;
951 if (min1->Number() > max1->Number()) std::swap(min1, max1);
952 if (min2->Number() > max2->Number()) std::swap(min2, max2);
953 TypeHandle type1 = T.Range(min1, max1);
954 TypeHandle type2 = T.Range(min2, max2);
955 CHECK(type1->Is(type2) ==
956 (min2->Number() <= min1->Number() &&
957 max1->Number() <= max2->Number()));
958 }
959 }
880 } 960 }
881 } 961 }
882 962
883 // Constant(V)->Is(Class(M)) never 963 // Context(T1)->Is(Context(T2)) iff T1 = T2
884 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) { 964 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
885 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { 965 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
886 Handle<i::Map> map = *mt; 966 TypeHandle outer1 = *it1;
887 Handle<i::Object> value = *vt; 967 TypeHandle outer2 = *it2;
888 TypeHandle constant_type = T.Constant(value); 968 TypeHandle type1 = T.Context(outer1);
889 TypeHandle class_type = T.Class(map); 969 TypeHandle type2 = T.Context(outer2);
890 CHECK(!constant_type->Is(class_type)); 970 CHECK(type1->Is(type2) == outer1->Equals(outer2));
891 } 971 }
892 } 972 }
893 973
894 // Class(M)->Is(Constant(V)) never 974 // Array(T1)->Is(Array(T2)) iff T1 = T2
895 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) { 975 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
896 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { 976 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
897 Handle<i::Map> map = *mt; 977 TypeHandle element1 = *it1;
898 Handle<i::Object> value = *vt; 978 TypeHandle element2 = *it2;
899 TypeHandle constant_type = T.Constant(value); 979 TypeHandle type1 = T.Array1(element1);
900 TypeHandle class_type = T.Class(map); 980 TypeHandle type2 = T.Array1(element2);
901 CHECK(!class_type->Is(constant_type)); 981 CHECK(type1->Is(type2) == element1->Equals(element2));
902 } 982 }
903 } 983 }
904 984
985 // Function0(S1, T1)->Is(Function0(S2, T2)) iff S1 = S2 and T1 = T2
986 for (TypeIterator i = T.types.begin(); i != T.types.end(); ++i) {
987 for (TypeIterator j = T.types.begin(); j != T.types.end(); ++j) {
988 TypeHandle result1 = *i;
989 TypeHandle receiver1 = *j;
990 TypeHandle type1 = T.Function0(result1, receiver1);
991 TypeHandle result2 = T.Random();
992 TypeHandle receiver2 = T.Random();
993 TypeHandle type2 = T.Function0(result2, receiver2);
994 CHECK(type1->Is(type2) ==
995 (result1->Equals(result2) && receiver1->Equals(receiver2)));
996 }
997 }
998
999 // (In-)Compatibilities.
1000 for (TypeIterator i = T.types.begin(); i != T.types.end(); ++i) {
1001 for (TypeIterator j = T.types.begin(); j != T.types.end(); ++j) {
1002 TypeHandle type1 = *i;
1003 TypeHandle type2 = *j;
1004 CHECK(!type1->Is(type2) || this->IsBitset(type2) ||
1005 this->IsUnion(type2) || this->IsUnion(type1) ||
1006 (type1->IsClass() && type2->IsClass()) ||
1007 (type1->IsConstant() && type2->IsConstant()) ||
1008 (type1->IsConstant() && type2->IsRange()) ||
1009 (type1->IsRange() && type2->IsRange()) ||
1010 (type1->IsContext() && type2->IsContext()) ||
1011 (type1->IsArray() && type2->IsArray()) ||
1012 (type1->IsFunction() && type2->IsFunction()) ||
1013 type1->Equals(T.None));
1014 }
1015 }
1016
905 // Basic types 1017 // Basic types
906 CheckUnordered(T.Boolean, T.Null); 1018 CheckUnordered(T.Boolean, T.Null);
907 CheckUnordered(T.Undefined, T.Null); 1019 CheckUnordered(T.Undefined, T.Null);
908 CheckUnordered(T.Boolean, T.Undefined); 1020 CheckUnordered(T.Boolean, T.Undefined);
909 1021
910 CheckSub(T.SignedSmall, T.Number); 1022 CheckSub(T.SignedSmall, T.Number);
911 CheckSub(T.Signed32, T.Number); 1023 CheckSub(T.Signed32, T.Number);
912 CheckSub(T.SignedSmall, T.Signed32); 1024 CheckSub(T.SignedSmall, T.Signed32);
913 CheckUnordered(T.SignedSmall, T.MinusZero); 1025 CheckUnordered(T.SignedSmall, T.MinusZero);
914 CheckUnordered(T.Signed32, T.Unsigned32); 1026 CheckUnordered(T.Signed32, T.Unsigned32);
(...skipping 167 matching lines...)
1082 void Contains() { 1194 void Contains() {
1083 // T->Contains(V) iff Constant(V)->Is(T) 1195 // T->Contains(V) iff Constant(V)->Is(T)
1084 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 1196 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
1085 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { 1197 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
1086 TypeHandle type = *it; 1198 TypeHandle type = *it;
1087 Handle<i::Object> value = *vt; 1199 Handle<i::Object> value = *vt;
1088 TypeHandle const_type = T.Constant(value); 1200 TypeHandle const_type = T.Constant(value);
1089 CHECK(type->Contains(value) == const_type->Is(type)); 1201 CHECK(type->Contains(value) == const_type->Is(type));
1090 } 1202 }
1091 } 1203 }
1092
1093 // Of(V)->Is(T) implies T->Contains(V)
1094 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
1095 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
1096 TypeHandle type = *it;
1097 Handle<i::Object> value = *vt;
1098 TypeHandle of_type = T.Of(value);
1099 CHECK(!of_type->Is(type) || type->Contains(value));
1100 }
1101 }
1102 } 1204 }
1103 1205
1104 void NowContains() { 1206 void NowContains() {
1105 // T->NowContains(V) iff Constant(V)->NowIs(T) 1207 // T->NowContains(V) iff Constant(V)->NowIs(T)
1106 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 1208 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
1107 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { 1209 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
1108 TypeHandle type = *it; 1210 TypeHandle type = *it;
1109 Handle<i::Object> value = *vt; 1211 Handle<i::Object> value = *vt;
1110 TypeHandle const_type = T.Constant(value); 1212 TypeHandle const_type = T.Constant(value);
1111 CHECK(type->NowContains(value) == const_type->NowIs(type)); 1213 CHECK(type->NowContains(value) == const_type->NowIs(type));
(...skipping 11 matching lines...)
1123 1225
1124 // NowOf(V)->Is(T) implies T->NowContains(V) 1226 // NowOf(V)->Is(T) implies T->NowContains(V)
1125 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 1227 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
1126 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { 1228 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
1127 TypeHandle type = *it; 1229 TypeHandle type = *it;
1128 Handle<i::Object> value = *vt; 1230 Handle<i::Object> value = *vt;
1129 TypeHandle nowof_type = T.Of(value); 1231 TypeHandle nowof_type = T.Of(value);
1130 CHECK(!nowof_type->NowIs(type) || type->NowContains(value)); 1232 CHECK(!nowof_type->NowIs(type) || type->NowContains(value));
1131 } 1233 }
1132 } 1234 }
1133
1134 // NowOf(V)->NowIs(T) implies T->NowContains(V)
1135 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
1136 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
1137 TypeHandle type = *it;
1138 Handle<i::Object> value = *vt;
1139 TypeHandle nowof_type = T.Of(value);
1140 CHECK(!nowof_type->NowIs(type) || type->NowContains(value));
1141 }
1142 }
1143 } 1235 }
1144 1236
1145 void Maybe() { 1237 void Maybe() {
1146 // T->Maybe(Any) iff T inhabited 1238 // T->Maybe(Any) iff T inhabited
1147 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 1239 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
1148 TypeHandle type = *it; 1240 TypeHandle type = *it;
1149 CHECK(type->Maybe(T.Any) == type->IsInhabited()); 1241 CHECK(type->Maybe(T.Any) == type->IsInhabited());
1150 } 1242 }
1151 1243
1152 // T->Maybe(None) never 1244 // T->Maybe(None) never
(...skipping 62 matching lines...)
1215 for (MapIterator mt1 = T.maps.begin(); mt1 != T.maps.end(); ++mt1) { 1307 for (MapIterator mt1 = T.maps.begin(); mt1 != T.maps.end(); ++mt1) {
1216 for (MapIterator mt2 = T.maps.begin(); mt2 != T.maps.end(); ++mt2) { 1308 for (MapIterator mt2 = T.maps.begin(); mt2 != T.maps.end(); ++mt2) {
1217 Handle<i::Map> map1 = *mt1; 1309 Handle<i::Map> map1 = *mt1;
1218 Handle<i::Map> map2 = *mt2; 1310 Handle<i::Map> map2 = *mt2;
1219 TypeHandle class_type1 = T.Class(map1); 1311 TypeHandle class_type1 = T.Class(map1);
1220 TypeHandle class_type2 = T.Class(map2); 1312 TypeHandle class_type2 = T.Class(map2);
1221 CHECK(class_type1->Maybe(class_type2) == (*map1 == *map2)); 1313 CHECK(class_type1->Maybe(class_type2) == (*map1 == *map2));
1222 } 1314 }
1223 } 1315 }
1224 1316
1225 // Constant(V)->Maybe(Class(M)) never
1226 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) {
1227 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
1228 Handle<i::Map> map = *mt;
1229 Handle<i::Object> value = *vt;
1230 TypeHandle const_type = T.Constant(value);
1231 TypeHandle class_type = T.Class(map);
1232 CHECK(!const_type->Maybe(class_type));
1233 }
1234 }
1235
1236 // Class(M)->Maybe(Constant(V)) never
1237 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) {
1238 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) {
1239 Handle<i::Map> map = *mt;
1240 Handle<i::Object> value = *vt;
1241 TypeHandle const_type = T.Constant(value);
1242 TypeHandle class_type = T.Class(map);
1243 CHECK(!class_type->Maybe(const_type));
1244 }
1245 }
1246
1247 // Basic types 1317 // Basic types
1248 CheckDisjoint(T.Boolean, T.Null, T.Semantic); 1318 CheckDisjoint(T.Boolean, T.Null);
1249 CheckDisjoint(T.Undefined, T.Null, T.Semantic); 1319 CheckDisjoint(T.Undefined, T.Null);
1250 CheckDisjoint(T.Boolean, T.Undefined, T.Semantic); 1320 CheckDisjoint(T.Boolean, T.Undefined);
1251 1321 CheckOverlap(T.SignedSmall, T.Number);
1252 CheckOverlap(T.SignedSmall, T.Number, T.Semantic); 1322 CheckOverlap(T.NaN, T.Number);
1253 CheckOverlap(T.NaN, T.Number, T.Semantic); 1323 CheckDisjoint(T.Signed32, T.NaN);
1254 CheckDisjoint(T.Signed32, T.NaN, T.Semantic); 1324 CheckOverlap(T.UniqueName, T.Name);
1255 1325 CheckOverlap(T.String, T.Name);
1256 CheckOverlap(T.UniqueName, T.Name, T.Semantic); 1326 CheckOverlap(T.InternalizedString, T.String);
1257 CheckOverlap(T.String, T.Name, T.Semantic); 1327 CheckOverlap(T.InternalizedString, T.UniqueName);
1258 CheckOverlap(T.InternalizedString, T.String, T.Semantic); 1328 CheckOverlap(T.InternalizedString, T.Name);
1259 CheckOverlap(T.InternalizedString, T.UniqueName, T.Semantic); 1329 CheckOverlap(T.Symbol, T.UniqueName);
1260 CheckOverlap(T.InternalizedString, T.Name, T.Semantic); 1330 CheckOverlap(T.Symbol, T.Name);
1261 CheckOverlap(T.Symbol, T.UniqueName, T.Semantic); 1331 CheckOverlap(T.String, T.UniqueName);
1262 CheckOverlap(T.Symbol, T.Name, T.Semantic); 1332 CheckDisjoint(T.String, T.Symbol);
1263 CheckOverlap(T.String, T.UniqueName, T.Semantic); 1333 CheckDisjoint(T.InternalizedString, T.Symbol);
1264 CheckDisjoint(T.String, T.Symbol, T.Semantic); 1334 CheckOverlap(T.Object, T.Receiver);
1265 CheckDisjoint(T.InternalizedString, T.Symbol, T.Semantic); 1335 CheckOverlap(T.Array, T.Object);
1266 1336 CheckOverlap(T.Function, T.Object);
1267 CheckOverlap(T.Object, T.Receiver, T.Semantic); 1337 CheckOverlap(T.Proxy, T.Receiver);
1268 CheckOverlap(T.Array, T.Object, T.Semantic); 1338 CheckDisjoint(T.Object, T.Proxy);
1269 CheckOverlap(T.Function, T.Object, T.Semantic); 1339 CheckDisjoint(T.Array, T.Function);
1270 CheckOverlap(T.Proxy, T.Receiver, T.Semantic);
1271 CheckDisjoint(T.Object, T.Proxy, T.Semantic);
1272 CheckDisjoint(T.Array, T.Function, T.Semantic);
1273 1340
1274 // Structural types 1341 // Structural types
1275 CheckOverlap(T.ObjectClass, T.Object, T.Semantic); 1342 CheckOverlap(T.ObjectClass, T.Object);
1276 CheckOverlap(T.ArrayClass, T.Object, T.Semantic); 1343 CheckOverlap(T.ArrayClass, T.Object);
1277 CheckOverlap(T.ObjectClass, T.ObjectClass, T.Semantic); 1344 CheckOverlap(T.ObjectClass, T.ObjectClass);
1278 CheckOverlap(T.ArrayClass, T.ArrayClass, T.Semantic); 1345 CheckOverlap(T.ArrayClass, T.ArrayClass);
1279 CheckDisjoint(T.ObjectClass, T.ArrayClass, T.Semantic); 1346 CheckDisjoint(T.ObjectClass, T.ArrayClass);
1280 1347 CheckOverlap(T.SmiConstant, T.SignedSmall);
1281 CheckOverlap(T.SmiConstant, T.SignedSmall, T.Semantic); 1348 CheckOverlap(T.SmiConstant, T.Signed32);
1282 CheckOverlap(T.SmiConstant, T.Signed32, T.Semantic); 1349 CheckOverlap(T.SmiConstant, T.Number);
1283 CheckOverlap(T.SmiConstant, T.Number, T.Semantic); 1350 CheckOverlap(T.ObjectConstant1, T.Object);
1284 CheckOverlap(T.ObjectConstant1, T.Object, T.Semantic); 1351 CheckOverlap(T.ObjectConstant2, T.Object);
1285 CheckOverlap(T.ObjectConstant2, T.Object, T.Semantic); 1352 CheckOverlap(T.ArrayConstant, T.Object);
1286 CheckOverlap(T.ArrayConstant, T.Object, T.Semantic); 1353 CheckOverlap(T.ArrayConstant, T.Array);
1287 CheckOverlap(T.ArrayConstant, T.Array, T.Semantic); 1354 CheckOverlap(T.ObjectConstant1, T.ObjectConstant1);
1288 CheckOverlap(T.ObjectConstant1, T.ObjectConstant1, T.Semantic); 1355 CheckDisjoint(T.ObjectConstant1, T.ObjectConstant2);
1289 CheckDisjoint(T.ObjectConstant1, T.ObjectConstant2, T.Semantic); 1356 CheckDisjoint(T.ObjectConstant1, T.ArrayConstant);
1290 CheckDisjoint(T.ObjectConstant1, T.ArrayConstant, T.Semantic); 1357 CheckDisjoint(T.ObjectConstant1, T.ArrayClass);
1291 1358 CheckDisjoint(T.ObjectConstant2, T.ArrayClass);
1292 CheckDisjoint(T.ObjectConstant1, T.ObjectClass, T.Semantic); 1359 CheckDisjoint(T.ArrayConstant, T.ObjectClass);
1293 CheckDisjoint(T.ObjectConstant2, T.ObjectClass, T.Semantic); 1360 CheckOverlap(T.NumberArray, T.Array);
1294 CheckDisjoint(T.ObjectConstant1, T.ArrayClass, T.Semantic); 1361 CheckDisjoint(T.NumberArray, T.AnyArray);
1295 CheckDisjoint(T.ObjectConstant2, T.ArrayClass, T.Semantic); 1362 CheckDisjoint(T.NumberArray, T.StringArray);
1296 CheckDisjoint(T.ArrayConstant, T.ObjectClass, T.Semantic); 1363 CheckOverlap(T.MethodFunction, T.Function);
1297 1364 CheckDisjoint(T.SignedFunction1, T.NumberFunction1);
1298 CheckOverlap(T.NumberArray, T.Array, T.Semantic); 1365 CheckDisjoint(T.SignedFunction1, T.NumberFunction2);
1299 CheckDisjoint(T.NumberArray, T.AnyArray, T.Semantic); 1366 CheckDisjoint(T.NumberFunction1, T.NumberFunction2);
1300 CheckDisjoint(T.NumberArray, T.StringArray, T.Semantic); 1367 CheckDisjoint(T.SignedFunction1, T.MethodFunction);
1301 1368 CheckOverlap(T.ObjectConstant1, T.ObjectClass); // !!!
1302 CheckOverlap(T.MethodFunction, T.Function, T.Semantic); 1369 CheckOverlap(T.ObjectConstant2, T.ObjectClass); // !!!
1303 CheckDisjoint(T.SignedFunction1, T.NumberFunction1, T.Semantic);
1304 CheckDisjoint(T.SignedFunction1, T.NumberFunction2, T.Semantic);
1305 CheckDisjoint(T.NumberFunction1, T.NumberFunction2, T.Semantic);
1306 CheckDisjoint(T.SignedFunction1, T.MethodFunction, T.Semantic);
1307 } 1370 }
1308 1371
1309 void Union1() { 1372 void Union1() {
1310 // Identity: Union(T, None) = T 1373 // Identity: Union(T, None) = T
1311 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 1374 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
1312 TypeHandle type = *it; 1375 TypeHandle type = *it;
1313 TypeHandle union_type = T.Union(type, T.None); 1376 TypeHandle union_type = T.Union(type, T.None);
1314 CheckEqual(union_type, type); 1377 CheckEqual(union_type, type);
1315 } 1378 }
1316 1379
(...skipping 16 matching lines...)
1333 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { 1396 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
1334 TypeHandle type1 = *it1; 1397 TypeHandle type1 = *it1;
1335 TypeHandle type2 = *it2; 1398 TypeHandle type2 = *it2;
1336 TypeHandle union12 = T.Union(type1, type2); 1399 TypeHandle union12 = T.Union(type1, type2);
1337 TypeHandle union21 = T.Union(type2, type1); 1400 TypeHandle union21 = T.Union(type2, type1);
1338 CheckEqual(union12, union21); 1401 CheckEqual(union12, union21);
1339 } 1402 }
1340 } 1403 }
1341 1404
1342 // Associativity: Union(T1, Union(T2, T3)) = Union(Union(T1, T2), T3) 1405 // Associativity: Union(T1, Union(T2, T3)) = Union(Union(T1, T2), T3)
1406 // This does NOT hold!
1407 /*
1343 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { 1408 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
1344 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { 1409 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
1345 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { 1410 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) {
1346 TypeHandle type1 = *it1; 1411 TypeHandle type1 = *it1;
1347 TypeHandle type2 = *it2; 1412 TypeHandle type2 = *it2;
1348 TypeHandle type3 = *it3; 1413 TypeHandle type3 = *it3;
1349 TypeHandle union12 = T.Union(type1, type2); 1414 TypeHandle union12 = T.Union(type1, type2);
1350 TypeHandle union23 = T.Union(type2, type3); 1415 TypeHandle union23 = T.Union(type2, type3);
1351 TypeHandle union1_23 = T.Union(type1, union23); 1416 TypeHandle union1_23 = T.Union(type1, union23);
1352 TypeHandle union12_3 = T.Union(union12, type3); 1417 TypeHandle union12_3 = T.Union(union12, type3);
1353 CheckEqual(union1_23, union12_3); 1418 CheckEqual(union1_23, union12_3);
1354 } 1419 }
1355 } 1420 }
1356 } 1421 }
1422 */
1357 1423
1358 // Meet: T1->Is(Union(T1, T2)) and T2->Is(Union(T1, T2)) 1424 // Meet: T1->Is(Union(T1, T2)) and T2->Is(Union(T1, T2))
1359 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { 1425 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
1360 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { 1426 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
1361 TypeHandle type1 = *it1; 1427 TypeHandle type1 = *it1;
1362 TypeHandle type2 = *it2; 1428 TypeHandle type2 = *it2;
1363 TypeHandle union12 = T.Union(type1, type2); 1429 TypeHandle union12 = T.Union(type1, type2);
1364 CHECK(type1->Is(union12)); 1430 CHECK(type1->Is(union12));
1365 CHECK(type2->Is(union12)); 1431 CHECK(type2->Is(union12));
1366 } 1432 }
1367 } 1433 }
1368 1434
1369 // Upper Boundedness: T1->Is(T2) implies Union(T1, T2) = T2 1435 // Upper Boundedness: T1->Is(T2) implies Union(T1, T2) = T2
1370 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { 1436 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
1371 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { 1437 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
1372 TypeHandle type1 = *it1; 1438 TypeHandle type1 = *it1;
1373 TypeHandle type2 = *it2; 1439 TypeHandle type2 = *it2;
1374 TypeHandle union12 = T.Union(type1, type2); 1440 TypeHandle union12 = T.Union(type1, type2);
1375 if (type1->Is(type2)) CheckEqual(union12, type2); 1441 if (type1->Is(type2)) CheckEqual(union12, type2);
1376 } 1442 }
1377 } 1443 }
1378 }
1379 1444
1380 void Union2() {
1381 // Monotonicity: T1->Is(T2) implies Union(T1, T3)->Is(Union(T2, T3)) 1445 // Monotonicity: T1->Is(T2) implies Union(T1, T3)->Is(Union(T2, T3))
1446 // This does NOT hold.
1447 /*
1382 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { 1448 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
1383 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { 1449 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
1384 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { 1450 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) {
1385 TypeHandle type1 = *it1; 1451 TypeHandle type1 = *it1;
1386 TypeHandle type2 = *it2; 1452 TypeHandle type2 = *it2;
1387 TypeHandle type3 = *it3; 1453 TypeHandle type3 = *it3;
1388 TypeHandle union13 = T.Union(type1, type3); 1454 TypeHandle union13 = T.Union(type1, type3);
1389 TypeHandle union23 = T.Union(type2, type3); 1455 TypeHandle union23 = T.Union(type2, type3);
1390 CHECK(!type1->Is(type2) || union13->Is(union23)); 1456 CHECK(!type1->Is(type2) || union13->Is(union23));
1391 } 1457 }
1392 } 1458 }
1393 } 1459 }
1460 */
1461 }
1394 1462
1463 void Union2() {
1395 // Monotonicity: T1->Is(T3) and T2->Is(T3) implies Union(T1, T2)->Is(T3) 1464 // Monotonicity: T1->Is(T3) and T2->Is(T3) implies Union(T1, T2)->Is(T3)
1465 // This does NOT hold. TODO(neis): Could fix this by splitting
1466 // OtherNumber into a negative and a positive part.
1467 /*
1396 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { 1468 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
1397 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { 1469 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
1398 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { 1470 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) {
1399 TypeHandle type1 = *it1; 1471 TypeHandle type1 = *it1;
1400 TypeHandle type2 = *it2; 1472 TypeHandle type2 = *it2;
1401 TypeHandle type3 = *it3; 1473 TypeHandle type3 = *it3;
1402 TypeHandle union12 = T.Union(type1, type2); 1474 TypeHandle union12 = T.Union(type1, type2);
1403 CHECK(!(type1->Is(type3) && type2->Is(type3)) || union12->Is(type3)); 1475 CHECK(!(type1->Is(type3) && type2->Is(type3)) || union12->Is(type3));
1404 } 1476 }
1405 } 1477 }
1406 } 1478 }
1479 */
1480 }
1407 1481
1482 void Union3() {
1408 // Monotonicity: T1->Is(T2) or T1->Is(T3) implies T1->Is(Union(T2, T3)) 1483 // Monotonicity: T1->Is(T2) or T1->Is(T3) implies T1->Is(Union(T2, T3))
1409 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { 1484 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
1410 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { 1485 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
1411 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { 1486 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) {
1412 TypeHandle type1 = *it1; 1487 TypeHandle type1 = *it1;
1413 TypeHandle type2 = *it2; 1488 TypeHandle type2 = *it2;
1414 TypeHandle type3 = *it3; 1489 TypeHandle type3 = *it3;
1415 TypeHandle union23 = T.Union(type2, type3); 1490 TypeHandle union23 = T.Union(type2, type3);
1416 CHECK(!(type1->Is(type2) || type1->Is(type3)) || type1->Is(union23)); 1491 CHECK(!(type1->Is(type2) || type1->Is(type3)) || type1->Is(union23));
1417 } 1492 }
1418 } 1493 }
1419 } 1494 }
1495 }
1420 1496
1497 void Union4() {
1421 // Class-class 1498 // Class-class
1422 CheckSub(T.Union(T.ObjectClass, T.ArrayClass), T.Object); 1499 CheckSub(T.Union(T.ObjectClass, T.ArrayClass), T.Object);
1423 CheckUnordered(T.Union(T.ObjectClass, T.ArrayClass), T.Array); 1500 CheckUnordered(T.Union(T.ObjectClass, T.ArrayClass), T.Array);
1424 CheckOverlap(T.Union(T.ObjectClass, T.ArrayClass), T.Array, T.Semantic); 1501 CheckOverlap(T.Union(T.ObjectClass, T.ArrayClass), T.Array);
1425 CheckDisjoint(T.Union(T.ObjectClass, T.ArrayClass), T.Number, T.Semantic); 1502 CheckDisjoint(T.Union(T.ObjectClass, T.ArrayClass), T.Number);
1426 1503
1427 // Constant-constant 1504 // Constant-constant
1428 CheckSub(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.Object); 1505 CheckSub(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.Object);
1429 CheckUnordered(T.Union(T.ObjectConstant1, T.ArrayConstant), T.Array); 1506 CheckUnordered(T.Union(T.ObjectConstant1, T.ArrayConstant), T.Array);
1430 CheckUnordered( 1507 CheckUnordered(
1431 T.Union(T.ObjectConstant1, T.ObjectConstant2), T.ObjectClass); 1508 T.Union(T.ObjectConstant1, T.ObjectConstant2), T.ObjectClass);
1432 CheckOverlap( 1509 CheckOverlap(
1433 T.Union(T.ObjectConstant1, T.ArrayConstant), T.Array, T.Semantic); 1510 T.Union(T.ObjectConstant1, T.ArrayConstant), T.Array);
1434 CheckDisjoint( 1511 CheckDisjoint(
1435 T.Union(T.ObjectConstant1, T.ArrayConstant), T.Number, T.Semantic); 1512 T.Union(T.ObjectConstant1, T.ArrayConstant), T.Number);
1436 CheckDisjoint( 1513 CheckOverlap(
1437 T.Union(T.ObjectConstant1, T.ArrayConstant), T.ObjectClass, T.Semantic); 1514 T.Union(T.ObjectConstant1, T.ArrayConstant), T.ObjectClass); // !!!
1438 1515
1439 // Bitset-array 1516 // Bitset-array
1440 CHECK(this->IsBitset(T.Union(T.AnyArray, T.Array))); 1517 CHECK(this->IsBitset(T.Union(T.AnyArray, T.Array)));
1441 CHECK(this->IsUnion(T.Union(T.NumberArray, T.Number))); 1518 CHECK(this->IsUnion(T.Union(T.NumberArray, T.Number)));
1442 1519
1443 CheckEqual(T.Union(T.AnyArray, T.Array), T.Array); 1520 CheckEqual(T.Union(T.AnyArray, T.Array), T.Array);
1444 CheckUnordered(T.Union(T.AnyArray, T.String), T.Array); 1521 CheckUnordered(T.Union(T.AnyArray, T.String), T.Array);
1445 CheckOverlap(T.Union(T.NumberArray, T.String), T.Object, T.Semantic); 1522 CheckOverlap(T.Union(T.NumberArray, T.String), T.Object);
1446 CheckDisjoint(T.Union(T.NumberArray, T.String), T.Number, T.Semantic); 1523 CheckDisjoint(T.Union(T.NumberArray, T.String), T.Number);
1447 1524
1448 // Bitset-function 1525 // Bitset-function
1449 CHECK(this->IsBitset(T.Union(T.MethodFunction, T.Function))); 1526 CHECK(this->IsBitset(T.Union(T.MethodFunction, T.Function)));
1450 CHECK(this->IsUnion(T.Union(T.NumberFunction1, T.Number))); 1527 CHECK(this->IsUnion(T.Union(T.NumberFunction1, T.Number)));
1451 1528
1452 CheckEqual(T.Union(T.MethodFunction, T.Function), T.Function); 1529 CheckEqual(T.Union(T.MethodFunction, T.Function), T.Function);
1453 CheckUnordered(T.Union(T.NumberFunction1, T.String), T.Function); 1530 CheckUnordered(T.Union(T.NumberFunction1, T.String), T.Function);
1454 CheckOverlap(T.Union(T.NumberFunction2, T.String), T.Object, T.Semantic); 1531 CheckOverlap(T.Union(T.NumberFunction2, T.String), T.Object);
1455 CheckDisjoint(T.Union(T.NumberFunction1, T.String), T.Number, T.Semantic); 1532 CheckDisjoint(T.Union(T.NumberFunction1, T.String), T.Number);
1456 1533
1457 // Bitset-class 1534 // Bitset-class
1458 CheckSub( 1535 CheckSub(
1459 T.Union(T.ObjectClass, T.SignedSmall), T.Union(T.Object, T.Number)); 1536 T.Union(T.ObjectClass, T.SignedSmall), T.Union(T.Object, T.Number));
1460 CheckSub(T.Union(T.ObjectClass, T.Array), T.Object); 1537 CheckSub(T.Union(T.ObjectClass, T.Array), T.Object);
1461 CheckUnordered(T.Union(T.ObjectClass, T.String), T.Array); 1538 CheckUnordered(T.Union(T.ObjectClass, T.String), T.Array);
1462 CheckOverlap(T.Union(T.ObjectClass, T.String), T.Object, T.Semantic); 1539 CheckOverlap(T.Union(T.ObjectClass, T.String), T.Object);
1463 CheckDisjoint(T.Union(T.ObjectClass, T.String), T.Number, T.Semantic); 1540 CheckDisjoint(T.Union(T.ObjectClass, T.String), T.Number);
1464 1541
1465 // Bitset-constant 1542 // Bitset-constant
1466 CheckSub( 1543 CheckSub(
1467 T.Union(T.ObjectConstant1, T.Signed32), T.Union(T.Object, T.Number)); 1544 T.Union(T.ObjectConstant1, T.Signed32), T.Union(T.Object, T.Number));
1468 CheckSub(T.Union(T.ObjectConstant1, T.Array), T.Object); 1545 CheckSub(T.Union(T.ObjectConstant1, T.Array), T.Object);
1469 CheckUnordered(T.Union(T.ObjectConstant1, T.String), T.Array); 1546 CheckUnordered(T.Union(T.ObjectConstant1, T.String), T.Array);
1470 CheckOverlap(T.Union(T.ObjectConstant1, T.String), T.Object, T.Semantic); 1547 CheckOverlap(T.Union(T.ObjectConstant1, T.String), T.Object);
1471 CheckDisjoint(T.Union(T.ObjectConstant1, T.String), T.Number, T.Semantic); 1548 CheckDisjoint(T.Union(T.ObjectConstant1, T.String), T.Number);
1472 1549
1473 // Class-constant 1550 // Class-constant
1474 CheckSub(T.Union(T.ObjectConstant1, T.ArrayClass), T.Object); 1551 CheckSub(T.Union(T.ObjectConstant1, T.ArrayClass), T.Object);
1475 CheckUnordered(T.ObjectClass, T.Union(T.ObjectConstant1, T.ArrayClass)); 1552 CheckUnordered(T.ObjectClass, T.Union(T.ObjectConstant1, T.ArrayClass));
1476 CheckSub( 1553 CheckSub(
1477 T.Union(T.ObjectConstant1, T.ArrayClass), T.Union(T.Array, T.Object)); 1554 T.Union(T.ObjectConstant1, T.ArrayClass), T.Union(T.Array, T.Object));
1478 CheckUnordered(T.Union(T.ObjectConstant1, T.ArrayClass), T.ArrayConstant); 1555 CheckUnordered(T.Union(T.ObjectConstant1, T.ArrayClass), T.ArrayConstant);
1479 CheckDisjoint( 1556 CheckDisjoint(
1480 T.Union(T.ObjectConstant1, T.ArrayClass), T.ObjectConstant2, 1557 T.Union(T.ObjectConstant1, T.ArrayClass), T.ObjectConstant2);
1481 T.Semantic); 1558 CheckOverlap(
1482 CheckDisjoint( 1559 T.Union(T.ObjectConstant1, T.ArrayClass), T.ObjectClass); // !!!
1483 T.Union(T.ObjectConstant1, T.ArrayClass), T.ObjectClass, T.Semantic);
1484 1560
1485 // Bitset-union 1561 // Bitset-union
1486 CheckSub( 1562 CheckSub(
1487 T.NaN, 1563 T.NaN,
1488 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Number)); 1564 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Number));
1489 CheckSub( 1565 CheckSub(
1490 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Signed32), 1566 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Signed32),
1491 T.Union(T.ObjectConstant1, T.Union(T.Number, T.ArrayClass))); 1567 T.Union(T.ObjectConstant1, T.Union(T.Number, T.ArrayClass)));
1492 1568
1493 // Class-union 1569 // Class-union
(...skipping 33 matching lines...)
1527 T.Union(T.ObjectConstant2, T.ObjectConstant1), 1603 T.Union(T.ObjectConstant2, T.ObjectConstant1),
1528 T.Union(T.ObjectConstant1, T.ObjectConstant2)), 1604 T.Union(T.ObjectConstant1, T.ObjectConstant2)),
1529 T.Union(T.ObjectConstant2, T.ObjectConstant1)); 1605 T.Union(T.ObjectConstant2, T.ObjectConstant1));
1530 CheckEqual( 1606 CheckEqual(
1531 T.Union( 1607 T.Union(
1532 T.Union(T.Number, T.ArrayClass), 1608 T.Union(T.Number, T.ArrayClass),
1533 T.Union(T.SignedSmall, T.Array)), 1609 T.Union(T.SignedSmall, T.Array)),
1534 T.Union(T.Number, T.Array)); 1610 T.Union(T.Number, T.Array));
1535 } 1611 }
1536 1612
1537 void Intersect1() { 1613 void Intersect() {
1538 // Identity: Intersect(T, Any) = T 1614 // Identity: Intersect(T, Any) = T
1539 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 1615 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
1540 TypeHandle type = *it; 1616 TypeHandle type = *it;
1541 TypeHandle intersect_type = T.Intersect(type, T.Any); 1617 TypeHandle intersect_type = T.Intersect(type, T.Any);
1542 CheckEqual(intersect_type, type); 1618 CheckEqual(intersect_type, type);
1543 } 1619 }
1544 1620
1545 // Domination: Intersect(T, None) = None 1621 // Domination: Intersect(T, None) = None
1546 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 1622 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
1547 TypeHandle type = *it; 1623 TypeHandle type = *it;
(...skipping 14 matching lines...)
1562 TypeHandle type1 = *it1; 1638 TypeHandle type1 = *it1;
1563 TypeHandle type2 = *it2; 1639 TypeHandle type2 = *it2;
1564 TypeHandle intersect12 = T.Intersect(type1, type2); 1640 TypeHandle intersect12 = T.Intersect(type1, type2);
1565 TypeHandle intersect21 = T.Intersect(type2, type1); 1641 TypeHandle intersect21 = T.Intersect(type2, type1);
1566 CheckEqual(intersect12, intersect21); 1642 CheckEqual(intersect12, intersect21);
1567 } 1643 }
1568 } 1644 }
1569 1645
1570 // Associativity: 1646 // Associativity:
1571 // Intersect(T1, Intersect(T2, T3)) = Intersect(Intersect(T1, T2), T3) 1647 // Intersect(T1, Intersect(T2, T3)) = Intersect(Intersect(T1, T2), T3)
1648 // This does NOT hold.
1649 /*
1572 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { 1650 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
1573 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { 1651 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
1574 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { 1652 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) {
1575 TypeHandle type1 = *it1; 1653 TypeHandle type1 = *it1;
1576 TypeHandle type2 = *it2; 1654 TypeHandle type2 = *it2;
1577 TypeHandle type3 = *it3; 1655 TypeHandle type3 = *it3;
1578 TypeHandle intersect12 = T.Intersect(type1, type2); 1656 TypeHandle intersect12 = T.Intersect(type1, type2);
1579 TypeHandle intersect23 = T.Intersect(type2, type3); 1657 TypeHandle intersect23 = T.Intersect(type2, type3);
1580 TypeHandle intersect1_23 = T.Intersect(type1, intersect23); 1658 TypeHandle intersect1_23 = T.Intersect(type1, intersect23);
1581 TypeHandle intersect12_3 = T.Intersect(intersect12, type3); 1659 TypeHandle intersect12_3 = T.Intersect(intersect12, type3);
1582 CheckEqual(intersect1_23, intersect12_3); 1660 CheckEqual(intersect1_23, intersect12_3);
1583 } 1661 }
1584 } 1662 }
1585 } 1663 }
1664 */
1586 1665
1587 // Join: Intersect(T1, T2)->Is(T1) and Intersect(T1, T2)->Is(T2) 1666 // Join: Intersect(T1, T2)->Is(T1) and Intersect(T1, T2)->Is(T2)
1667 // This does NOT hold.
1668 /*
1588 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { 1669 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
1589 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { 1670 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
1590 TypeHandle type1 = *it1; 1671 TypeHandle type1 = *it1;
1591 TypeHandle type2 = *it2; 1672 TypeHandle type2 = *it2;
1592 TypeHandle intersect12 = T.Intersect(type1, type2); 1673 TypeHandle intersect12 = T.Intersect(type1, type2);
1593 CHECK(intersect12->Is(type1)); 1674 CHECK(intersect12->Is(type1));
1594 CHECK(intersect12->Is(type2)); 1675 CHECK(intersect12->Is(type2));
1595 } 1676 }
1596 } 1677 }
1678 */
1597 1679
1598 // Lower Boundedness: T1->Is(T2) implies Intersect(T1, T2) = T1 1680 // Lower Boundedness: T1->Is(T2) implies Intersect(T1, T2) = T1
1599 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { 1681 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
1600 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { 1682 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
1601 TypeHandle type1 = *it1; 1683 TypeHandle type1 = *it1;
1602 TypeHandle type2 = *it2; 1684 TypeHandle type2 = *it2;
1603 TypeHandle intersect12 = T.Intersect(type1, type2); 1685 TypeHandle intersect12 = T.Intersect(type1, type2);
1604 if (type1->Is(type2)) CheckEqual(intersect12, type1); 1686 if (type1->Is(type2)) CheckEqual(intersect12, type1);
1605 } 1687 }
1606 } 1688 }
1607 }
1608 1689
1609 void Intersect2() {
1610 // Monotonicity: T1->Is(T2) implies Intersect(T1, T3)->Is(Intersect(T2, T3)) 1690 // Monotonicity: T1->Is(T2) implies Intersect(T1, T3)->Is(Intersect(T2, T3))
1691 // This does NOT hold.
1692 /*
1611 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { 1693 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
1612 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { 1694 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
1613 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { 1695 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) {
1614 TypeHandle type1 = *it1; 1696 TypeHandle type1 = *it1;
1615 TypeHandle type2 = *it2; 1697 TypeHandle type2 = *it2;
1616 TypeHandle type3 = *it3; 1698 TypeHandle type3 = *it3;
1617 TypeHandle intersect13 = T.Intersect(type1, type3); 1699 TypeHandle intersect13 = T.Intersect(type1, type3);
1618 TypeHandle intersect23 = T.Intersect(type2, type3); 1700 TypeHandle intersect23 = T.Intersect(type2, type3);
1619 CHECK(!type1->Is(type2) || intersect13->Is(intersect23)); 1701 CHECK(!type1->Is(type2) || intersect13->Is(intersect23));
1620 } 1702 }
1621 } 1703 }
1622 } 1704 }
1705 */
1623 1706
1624 // Monotonicity: T1->Is(T3) or T2->Is(T3) implies Intersect(T1, T2)->Is(T3) 1707 // Monotonicity: T1->Is(T3) or T2->Is(T3) implies Intersect(T1, T2)->Is(T3)
1708 // This does NOT hold.
1709 /*
1625 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { 1710 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
1626 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { 1711 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
1627 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { 1712 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) {
1628 TypeHandle type1 = *it1; 1713 TypeHandle type1 = *it1;
1629 TypeHandle type2 = *it2; 1714 TypeHandle type2 = *it2;
1630 TypeHandle type3 = *it3; 1715 TypeHandle type3 = *it3;
1631 TypeHandle intersect12 = T.Intersect(type1, type2); 1716 TypeHandle intersect12 = T.Intersect(type1, type2);
1632 CHECK(!(type1->Is(type3) || type2->Is(type3)) || 1717 CHECK(!(type1->Is(type3) || type2->Is(type3)) ||
1633 intersect12->Is(type3)); 1718 intersect12->Is(type3));
1634 } 1719 }
1635 } 1720 }
1636 } 1721 }
1722 */
1637 1723
1638 // Monotonicity: T1->Is(T2) and T1->Is(T3) implies T1->Is(Intersect(T2, T3)) 1724 // Monotonicity: T1->Is(T2) and T1->Is(T3) implies T1->Is(Intersect(T2, T3))
1725 // This does NOT hold.
1726 /*
1639 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { 1727 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
1640 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { 1728 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
1641 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { 1729 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) {
1642 TypeHandle type1 = *it1; 1730 TypeHandle type1 = *it1;
1643 TypeHandle type2 = *it2; 1731 TypeHandle type2 = *it2;
1644 TypeHandle type3 = *it3; 1732 TypeHandle type3 = *it3;
1645 TypeHandle intersect23 = T.Intersect(type2, type3); 1733 TypeHandle intersect23 = T.Intersect(type2, type3);
1646 CHECK(!(type1->Is(type2) && type1->Is(type3)) || 1734 CHECK(!(type1->Is(type2) && type1->Is(type3)) ||
1647 type1->Is(intersect23)); 1735 type1->Is(intersect23));
1648 } 1736 }
1649 } 1737 }
1650 } 1738 }
1739 */
1651 1740
1652 // Bitset-class 1741 // Bitset-class
1653 CheckEqual(T.Intersect(T.ObjectClass, T.Object), T.ObjectClass); 1742 CheckEqual(T.Intersect(T.ObjectClass, T.Object), T.ObjectClass);
1654 CheckSub(T.Intersect(T.ObjectClass, T.Array), T.Representation); 1743 CheckEqual(T.Intersect(T.ObjectClass, T.Array), T.None);
1655 CheckSub(T.Intersect(T.ObjectClass, T.Number), T.Representation); 1744 CheckEqual(T.Intersect(T.ObjectClass, T.Number), T.None);
1656 1745
1657 // Bitset-array 1746 // Bitset-array
1658 CheckEqual(T.Intersect(T.NumberArray, T.Object), T.NumberArray); 1747 CheckEqual(T.Intersect(T.NumberArray, T.Object), T.NumberArray);
1659 CheckSub(T.Intersect(T.AnyArray, T.Function), T.Representation); 1748 CheckEqual(T.Intersect(T.AnyArray, T.Function), T.None);
1660 1749
1661 // Bitset-function 1750 // Bitset-function
1662 CheckEqual(T.Intersect(T.MethodFunction, T.Object), T.MethodFunction); 1751 CheckEqual(T.Intersect(T.MethodFunction, T.Object), T.MethodFunction);
1663 CheckSub(T.Intersect(T.NumberFunction1, T.Array), T.Representation); 1752 CheckEqual(T.Intersect(T.NumberFunction1, T.Array), T.None);
1664 1753
1665 // Bitset-union 1754 // Bitset-union
1666 CheckEqual( 1755 CheckEqual(
1667 T.Intersect(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)), 1756 T.Intersect(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)),
1668 T.Union(T.ObjectConstant1, T.ObjectClass)); 1757 T.Union(T.ObjectConstant1, T.ObjectClass));
1669 CHECK( 1758 CHECK(
1670 !T.Intersect(T.Union(T.ArrayClass, T.ObjectConstant1), T.Number) 1759 !T.Intersect(T.Union(T.ArrayClass, T.ObjectConstant1), T.Number)
1671 ->IsInhabited()); 1760 ->IsInhabited());
1672 1761
1673 // Class-constant 1762 // Class-constant
1674 CHECK(!T.Intersect(T.ObjectConstant1, T.ObjectClass)->IsInhabited()); 1763 CHECK(T.Intersect(T.ObjectConstant1, T.ObjectClass)->IsInhabited()); // !!!
1675 CHECK(!T.Intersect(T.ArrayClass, T.ObjectConstant2)->IsInhabited()); 1764 CHECK(!T.Intersect(T.ArrayClass, T.ObjectConstant2)->IsInhabited());
1676 1765
1677 // Array-union 1766 // Array-union
1678 CheckEqual( 1767 CheckEqual(
1679 T.Intersect(T.NumberArray, T.Union(T.NumberArray, T.ArrayClass)), 1768 T.Intersect(T.NumberArray, T.Union(T.NumberArray, T.ArrayClass)),
1680 T.NumberArray); 1769 T.NumberArray);
1681 CheckEqual( 1770 CheckEqual(
1682 T.Intersect(T.AnyArray, T.Union(T.Object, T.SmiConstant)), 1771 T.Intersect(T.AnyArray, T.Union(T.Object, T.SmiConstant)),
1683 T.AnyArray); 1772 T.AnyArray);
1684 CHECK( 1773 CHECK(
(...skipping 12 matching lines...)
1697 ->IsInhabited()); 1786 ->IsInhabited());
1698 1787
1699 // Class-union 1788 // Class-union
1700 CheckEqual( 1789 CheckEqual(
1701 T.Intersect(T.ArrayClass, T.Union(T.ObjectConstant2, T.ArrayClass)), 1790 T.Intersect(T.ArrayClass, T.Union(T.ObjectConstant2, T.ArrayClass)),
1702 T.ArrayClass); 1791 T.ArrayClass);
1703 CheckEqual( 1792 CheckEqual(
1704 T.Intersect(T.ArrayClass, T.Union(T.Object, T.SmiConstant)), 1793 T.Intersect(T.ArrayClass, T.Union(T.Object, T.SmiConstant)),
1705 T.ArrayClass); 1794 T.ArrayClass);
1706 CHECK( 1795 CHECK(
1707 !T.Intersect(T.Union(T.ObjectClass, T.ArrayConstant), T.ArrayClass) 1796 T.Intersect(T.Union(T.ObjectClass, T.ArrayConstant), T.ArrayClass)
1708 ->IsInhabited()); 1797 ->IsInhabited()); // !!!
1709 1798
1710 // Constant-union 1799 // Constant-union
1711 CheckEqual( 1800 CheckEqual(
1712 T.Intersect( 1801 T.Intersect(
1713 T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)), 1802 T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)),
1714 T.ObjectConstant1); 1803 T.ObjectConstant1);
1715 CheckEqual( 1804 CheckEqual(
1716 T.Intersect(T.SmiConstant, T.Union(T.Number, T.ObjectConstant2)), 1805 T.Intersect(T.SmiConstant, T.Union(T.Number, T.ObjectConstant2)),
1717 T.SmiConstant); 1806 T.SmiConstant);
1718 CHECK( 1807 CHECK(
1719 !T.Intersect( 1808 T.Intersect(
1720 T.Union(T.ArrayConstant, T.ObjectClass), T.ObjectConstant1) 1809 T.Union(T.ArrayConstant, T.ObjectClass), T.ObjectConstant1)
1721 ->IsInhabited()); 1810 ->IsInhabited()); // !!!
1722 1811
1723 // Union-union 1812 // Union-union
1724 CheckEqual( 1813 CheckEqual(
1725 T.Intersect( 1814 T.Intersect(
1726 T.Union(T.Number, T.ArrayClass), 1815 T.Union(T.Number, T.ArrayClass),
1727 T.Union(T.SignedSmall, T.Array)), 1816 T.Union(T.SignedSmall, T.Array)),
1728 T.Union(T.SignedSmall, T.ArrayClass)); 1817 T.Union(T.SignedSmall, T.ArrayClass));
1729 CheckEqual( 1818 CheckEqual(
1730 T.Intersect( 1819 T.Intersect(
1731 T.Union(T.Number, T.ObjectClass), 1820 T.Union(T.Number, T.ObjectClass),
1732 T.Union(T.Signed32, T.Array)), 1821 T.Union(T.Signed32, T.Array)),
1733 T.Signed32); 1822 T.Signed32);
1734 CheckEqual( 1823 CheckEqual(
1735 T.Intersect( 1824 T.Intersect(
1736 T.Union(T.ObjectConstant2, T.ObjectConstant1), 1825 T.Union(T.ObjectConstant2, T.ObjectConstant1),
1737 T.Union(T.ObjectConstant1, T.ObjectConstant2)), 1826 T.Union(T.ObjectConstant1, T.ObjectConstant2)),
1738 T.Union(T.ObjectConstant2, T.ObjectConstant1)); 1827 T.Union(T.ObjectConstant2, T.ObjectConstant1));
1739 CheckEqual( 1828 CheckEqual(
1740 T.Intersect( 1829 T.Intersect(
1741 T.Union( 1830 T.Union(
1742 T.Union(T.ObjectConstant2, T.ObjectConstant1), T.ArrayClass), 1831 T.ArrayClass,
1832 T.Union(T.ObjectConstant2, T.ObjectConstant1)),
1743 T.Union( 1833 T.Union(
1744 T.ObjectConstant1, 1834 T.ObjectConstant1,
1745 T.Union(T.ArrayConstant, T.ObjectConstant2))), 1835 T.Union(T.ArrayConstant, T.ObjectConstant2))),
1746 T.Union(T.ObjectConstant2, T.ObjectConstant1)); 1836 T.Union(
1837 T.ArrayConstant,
1838 T.Union(T.ObjectConstant2, T.ObjectConstant1))); // !!!
1747 } 1839 }
1748 1840
1749 void Distributivity1() { 1841 void Distributivity() {
1750 // Distributivity:
1751 // Union(T1, Intersect(T2, T3)) = Intersect(Union(T1, T2), Union(T1, T3)) 1842 // Union(T1, Intersect(T2, T3)) = Intersect(Union(T1, T2), Union(T1, T3))
1843 // This does NOT hold.
1844 /*
1752 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { 1845 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
1753 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { 1846 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
1754 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { 1847 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) {
1755 TypeHandle type1 = *it1; 1848 TypeHandle type1 = *it1;
1756 TypeHandle type2 = *it2; 1849 TypeHandle type2 = *it2;
1757 TypeHandle type3 = *it3; 1850 TypeHandle type3 = *it3;
1758 TypeHandle union12 = T.Union(type1, type2); 1851 TypeHandle union12 = T.Union(type1, type2);
1759 TypeHandle union13 = T.Union(type1, type3); 1852 TypeHandle union13 = T.Union(type1, type3);
1760 TypeHandle intersect23 = T.Intersect(type2, type3); 1853 TypeHandle intersect23 = T.Intersect(type2, type3);
1761 TypeHandle union1_23 = T.Union(type1, intersect23); 1854 TypeHandle union1_23 = T.Union(type1, intersect23);
1762 TypeHandle intersect12_13 = T.Intersect(union12, union13); 1855 TypeHandle intersect12_13 = T.Intersect(union12, union13);
1763 CHECK(Equal(union1_23, intersect12_13)); 1856 CHECK(Equal(union1_23, intersect12_13));
1764 } 1857 }
1765 } 1858 }
1766 } 1859 }
1767 } 1860 */
1768 1861
1769 void Distributivity2() {
1770 // Distributivity:
1771 // Intersect(T1, Union(T2, T3)) = Union(Intersect(T1, T2), Intersect(T1,T3)) 1862 // Intersect(T1, Union(T2, T3)) = Union(Intersect(T1, T2), Intersect(T1,T3))
1863 // This does NOT hold.
1864 /*
1772 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { 1865 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
1773 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { 1866 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
1774 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { 1867 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) {
1775 TypeHandle type1 = *it1; 1868 TypeHandle type1 = *it1;
1776 TypeHandle type2 = *it2; 1869 TypeHandle type2 = *it2;
1777 TypeHandle type3 = *it3; 1870 TypeHandle type3 = *it3;
1778 TypeHandle intersect12 = T.Intersect(type1, type2); 1871 TypeHandle intersect12 = T.Intersect(type1, type2);
1779 TypeHandle intersect13 = T.Intersect(type1, type3); 1872 TypeHandle intersect13 = T.Intersect(type1, type3);
1780 TypeHandle union23 = T.Union(type2, type3); 1873 TypeHandle union23 = T.Union(type2, type3);
1781 TypeHandle intersect1_23 = T.Intersect(type1, union23); 1874 TypeHandle intersect1_23 = T.Intersect(type1, union23);
1782 TypeHandle union12_13 = T.Union(intersect12, intersect13); 1875 TypeHandle union12_13 = T.Union(intersect12, intersect13);
1783 CHECK(Equal(intersect1_23, union12_13)); 1876 CHECK(Equal(intersect1_23, union12_13));
1784 } 1877 }
1785 } 1878 }
1786 } 1879 }
1880 */
1787 } 1881 }
1788 1882
1789 template<class Type2, class TypeHandle2, class Region2, class Rep2> 1883 template<class Type2, class TypeHandle2, class Region2, class Rep2>
1790 void Convert() { 1884 void Convert() {
1791 Types<Type2, TypeHandle2, Region2> T2( 1885 Types<Type2, TypeHandle2, Region2> T2(
1792 Rep2::ToRegion(&zone, isolate), isolate); 1886 Rep2::ToRegion(&zone, isolate), isolate);
1793 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { 1887 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) {
1794 TypeHandle type1 = *it; 1888 TypeHandle type1 = *it;
1795 TypeHandle2 type2 = T2.template Convert<Type>(type1); 1889 TypeHandle2 type2 = T2.template Convert<Type>(type1);
1796 TypeHandle type3 = T.template Convert<Type2>(type2); 1890 TypeHandle type3 = T.template Convert<Type2>(type2);
(...skipping 11 matching lines...)
1808 CHECK(!type1->Is(type2) || htype1.IsSubtypeOf(htype2)); 1902 CHECK(!type1->Is(type2) || htype1.IsSubtypeOf(htype2));
1809 } 1903 }
1810 } 1904 }
1811 } 1905 }
1812 }; 1906 };
1813 1907
1814 typedef Tests<Type, Type*, Zone, ZoneRep> ZoneTests; 1908 typedef Tests<Type, Type*, Zone, ZoneRep> ZoneTests;
1815 typedef Tests<HeapType, Handle<HeapType>, Isolate, HeapRep> HeapTests; 1909 typedef Tests<HeapType, Handle<HeapType>, Isolate, HeapRep> HeapTests;
1816 1910
1817 1911
1912 TEST(IsSomeType) {
1913 CcTest::InitializeVM();
1914 ZoneTests().IsSomeType();
1915 HeapTests().IsSomeType();
1916 }
1917
1918
1818 TEST(BitsetType) { 1919 TEST(BitsetType) {
1819 CcTest::InitializeVM(); 1920 CcTest::InitializeVM();
1820 ZoneTests().Bitset(); 1921 ZoneTests().Bitset();
1821 HeapTests().Bitset(); 1922 HeapTests().Bitset();
1822 } 1923 }
1823 1924
1824 1925
1825 TEST(ClassType) { 1926 TEST(ClassType) {
1826 CcTest::InitializeVM(); 1927 CcTest::InitializeVM();
1827 ZoneTests().Class(); 1928 ZoneTests().Class();
(...skipping 36 matching lines...)
1864 } 1965 }
1865 1966
1866 1967
1867 TEST(NowOf) { 1968 TEST(NowOf) {
1868 CcTest::InitializeVM(); 1969 CcTest::InitializeVM();
1869 ZoneTests().NowOf(); 1970 ZoneTests().NowOf();
1870 HeapTests().NowOf(); 1971 HeapTests().NowOf();
1871 } 1972 }
1872 1973
1873 1974
1874 TEST(Bounds) { 1975 TEST(BitsetGlb) {
1875 CcTest::InitializeVM(); 1976 CcTest::InitializeVM();
1876 ZoneTests().Bounds(); 1977 ZoneTests().BitsetGlb();
1877 HeapTests().Bounds(); 1978 HeapTests().BitsetGlb();
1878 } 1979 }
1879 1980
1880 1981
1982 TEST(BitsetLub) {
1983 CcTest::InitializeVM();
1984 ZoneTests().BitsetLub();
1985 HeapTests().BitsetLub();
1986 }
1987
1988
1881 TEST(Is) { 1989 TEST(Is) {
1882 CcTest::InitializeVM(); 1990 CcTest::InitializeVM();
1883 ZoneTests().Is(); 1991 ZoneTests().Is();
1884 HeapTests().Is(); 1992 HeapTests().Is();
1885 } 1993 }
1886 1994
1887 1995
1888 TEST(NowIs) { 1996 TEST(NowIs) {
1889 CcTest::InitializeVM(); 1997 CcTest::InitializeVM();
1890 ZoneTests().NowIs(); 1998 ZoneTests().NowIs();
(...skipping 15 matching lines...)
1906 } 2014 }
1907 2015
1908 2016
1909 TEST(Maybe) { 2017 TEST(Maybe) {
1910 CcTest::InitializeVM(); 2018 CcTest::InitializeVM();
1911 ZoneTests().Maybe(); 2019 ZoneTests().Maybe();
1912 HeapTests().Maybe(); 2020 HeapTests().Maybe();
1913 } 2021 }
1914 2022
1915 2023
1916 // TODO(rossberg): make me faster!
1917 #if 0
1918 TEST(Union1) { 2024 TEST(Union1) {
1919 CcTest::InitializeVM(); 2025 CcTest::InitializeVM();
1920 ZoneTests().Union1(); 2026 ZoneTests().Union1();
1921 HeapTests().Union1(); 2027 HeapTests().Union1();
1922 } 2028 }
1923 2029
1924 2030
2031 /*
1925 TEST(Union2) { 2032 TEST(Union2) {
1926 CcTest::InitializeVM(); 2033 CcTest::InitializeVM();
1927 ZoneTests().Union2(); 2034 ZoneTests().Union2();
1928 HeapTests().Union2(); 2035 HeapTests().Union2();
1929 } 2036 }
2037 */
1930 2038
1931 2039
1932 TEST(Intersect1) { 2040 TEST(Union3) {
1933 CcTest::InitializeVM(); 2041 CcTest::InitializeVM();
1934 ZoneTests().Intersect1(); 2042 ZoneTests().Union3();
1935 HeapTests().Intersect1(); 2043 HeapTests().Union3();
1936 } 2044 }
1937 2045
1938 2046
1939 TEST(Intersect2) { 2047 TEST(Union4) {
1940 CcTest::InitializeVM(); 2048 CcTest::InitializeVM();
1941 ZoneTests().Intersect2(); 2049 ZoneTests().Union4();
1942 HeapTests().Intersect2(); 2050 HeapTests().Union4();
1943 } 2051 }
1944 2052
1945 2053
1946 TEST(Distributivity1) { 2054 TEST(Intersect) {
1947 CcTest::InitializeVM(); 2055 CcTest::InitializeVM();
1948 ZoneTests().Distributivity1(); 2056 ZoneTests().Intersect();
1949 HeapTests().Distributivity1(); 2057 HeapTests().Intersect();
1950 } 2058 }
1951 2059
1952 2060
1953 TEST(Distributivity2) { 2061 /*
2062 TEST(Distributivity) {
1954 CcTest::InitializeVM(); 2063 CcTest::InitializeVM();
1955 ZoneTests().Distributivity2(); 2064 ZoneTests().Distributivity();
1956 HeapTests().Distributivity2(); 2065 HeapTests().Distributivity();
1957 } 2066 }
1958 #endif // TODO(rossberg): make me faster 2067 */
2068
1959 2069
1960 TEST(Convert) { 2070 TEST(Convert) {
1961 CcTest::InitializeVM(); 2071 CcTest::InitializeVM();
1962 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>(); 2072 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>();
1963 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); 2073 HeapTests().Convert<Type, Type*, Zone, ZoneRep>();
1964 } 2074 }
1965 2075
1966 2076
1967 TEST(HTypeFromType) { 2077 TEST(HTypeFromType) {
1968 CcTest::InitializeVM(); 2078 CcTest::InitializeVM();
1969 ZoneTests().HTypeFromType(); 2079 ZoneTests().HTypeFromType();
1970 HeapTests().HTypeFromType(); 2080 HeapTests().HTypeFromType();
1971 } 2081 }
OLDNEW
« src/types.cc ('K') | « src/types.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine