OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <vector> | 5 #include <vector> |
6 | 6 |
7 #include "src/crankshaft/hydrogen-types.h" | 7 #include "src/crankshaft/hydrogen-types.h" |
8 #include "src/types.h" | 8 #include "src/types.h" |
9 #include "test/cctest/cctest.h" | 9 #include "test/cctest/cctest.h" |
10 #include "test/cctest/types-fuzz.h" | 10 #include "test/cctest/types-fuzz.h" |
11 | 11 |
12 using namespace v8::internal; | 12 using namespace v8::internal; |
13 | 13 |
14 | 14 |
15 // Testing auxiliaries (breaking the Type abstraction). | 15 // Testing auxiliaries (breaking the Type abstraction). |
16 | 16 |
17 | 17 |
18 static bool IsInteger(double x) { | 18 static bool IsInteger(double x) { |
19 return nearbyint(x) == x && !i::IsMinusZero(x); // Allows for infinities. | 19 return nearbyint(x) == x && !i::IsMinusZero(x); // Allows for infinities. |
20 } | 20 } |
21 | 21 |
22 | 22 |
23 static bool IsInteger(i::Object* x) { | 23 static bool IsInteger(i::Object* x) { |
24 return x->IsNumber() && IsInteger(x->Number()); | 24 return x->IsNumber() && IsInteger(x->Number()); |
25 } | 25 } |
26 | 26 |
27 | 27 |
28 typedef uint32_t bitset; | 28 typedef uint32_t bitset; |
29 | 29 |
30 | 30 struct Tests { |
31 struct ZoneRep { | 31 typedef Types::TypeVector::iterator TypeIterator; |
32 typedef void* Struct; | 32 typedef Types::MapVector::iterator MapIterator; |
33 | 33 typedef Types::ValueVector::iterator ValueIterator; |
34 static bool IsStruct(Type* t, int tag) { | |
35 return !IsBitset(t) && reinterpret_cast<intptr_t>(AsStruct(t)[0]) == tag; | |
36 } | |
37 static bool IsBitset(Type* t) { return reinterpret_cast<uintptr_t>(t) & 1; } | |
38 // HACK: the number 5 below is the value of StructuralType::kUnionTag. | |
39 static bool IsUnion(Type* t) { return t->IsUnionForTesting(); } | |
40 | |
41 static Struct* AsStruct(Type* t) { | |
42 return reinterpret_cast<Struct*>(t); | |
43 } | |
44 static bitset AsBitset(Type* t) { | |
45 return static_cast<bitset>(reinterpret_cast<uintptr_t>(t) ^ 1u); | |
46 } | |
47 static Struct* AsUnion(Type* t) { | |
48 return AsStruct(t); | |
49 } | |
50 static int Length(Struct* structured) { | |
51 return static_cast<int>(reinterpret_cast<intptr_t>(structured[1])); | |
52 } | |
53 | |
54 static Zone* ToRegion(Zone* zone, Isolate* isolate) { return zone; } | |
55 | |
56 struct BitsetType : Type::BitsetType { | |
57 using Type::BitsetType::New; | |
58 using Type::BitsetType::Glb; | |
59 using Type::BitsetType::Lub; | |
60 using Type::BitsetType::IsInhabited; | |
61 }; | |
62 }; | |
63 | |
64 | |
65 template<class Type, class TypeHandle, class Region, class Rep> | |
66 struct Tests : Rep { | |
67 typedef Types<Type, TypeHandle, Region> TypesInstance; | |
68 typedef typename TypesInstance::TypeVector::iterator TypeIterator; | |
69 typedef typename TypesInstance::MapVector::iterator MapIterator; | |
70 typedef typename TypesInstance::ValueVector::iterator ValueIterator; | |
71 | 34 |
72 Isolate* isolate; | 35 Isolate* isolate; |
73 HandleScope scope; | 36 HandleScope scope; |
74 Zone zone; | 37 Zone zone; |
75 TypesInstance T; | 38 Types T; |
76 | 39 |
77 Tests() | 40 Tests() |
78 : isolate(CcTest::InitIsolateOnce()), | 41 : isolate(CcTest::InitIsolateOnce()), |
79 scope(isolate), | 42 scope(isolate), |
80 zone(), | 43 zone(), |
81 T(Rep::ToRegion(&zone, isolate), isolate, | 44 T(&zone, isolate, isolate->random_number_generator()) {} |
82 isolate->random_number_generator()) {} | |
83 | 45 |
84 bool Equal(TypeHandle type1, TypeHandle type2) { | 46 bool IsBitset(Type* type) { return type->IsBitsetForTesting(); } |
85 return | 47 bool IsUnion(Type* type) { return type->IsUnionForTesting(); } |
86 type1->Equals(type2) && | 48 BitsetType::bitset AsBitset(Type* type) { return type->AsBitsetForTesting(); } |
87 this->IsBitset(type1) == this->IsBitset(type2) && | 49 UnionType* AsUnion(Type* type) { return type->AsUnionForTesting(); } |
88 this->IsUnion(type1) == this->IsUnion(type2) && | 50 |
89 type1->NumClasses() == type2->NumClasses() && | 51 bool Equal(Type* type1, Type* type2) { |
90 type1->NumConstants() == type2->NumConstants() && | 52 return type1->Equals(type2) && |
91 (!this->IsBitset(type1) || | 53 this->IsBitset(type1) == this->IsBitset(type2) && |
92 this->AsBitset(type1) == this->AsBitset(type2)) && | 54 this->IsUnion(type1) == this->IsUnion(type2) && |
93 (!this->IsUnion(type1) || | 55 type1->NumClasses() == type2->NumClasses() && |
94 this->Length(this->AsUnion(type1)) == | 56 type1->NumConstants() == type2->NumConstants() && |
95 this->Length(this->AsUnion(type2))); | 57 (!this->IsBitset(type1) || |
| 58 this->AsBitset(type1) == this->AsBitset(type2)) && |
| 59 (!this->IsUnion(type1) || |
| 60 this->AsUnion(type1)->LengthForTesting() == |
| 61 this->AsUnion(type2)->LengthForTesting()); |
96 } | 62 } |
97 | 63 |
98 void CheckEqual(TypeHandle type1, TypeHandle type2) { | 64 void CheckEqual(Type* type1, Type* type2) { CHECK(Equal(type1, type2)); } |
99 CHECK(Equal(type1, type2)); | |
100 } | |
101 | 65 |
102 void CheckSub(TypeHandle type1, TypeHandle type2) { | 66 void CheckSub(Type* type1, Type* type2) { |
103 CHECK(type1->Is(type2)); | 67 CHECK(type1->Is(type2)); |
104 CHECK(!type2->Is(type1)); | 68 CHECK(!type2->Is(type1)); |
105 if (this->IsBitset(type1) && this->IsBitset(type2)) { | 69 if (this->IsBitset(type1) && this->IsBitset(type2)) { |
106 CHECK(this->AsBitset(type1) != this->AsBitset(type2)); | 70 CHECK(this->AsBitset(type1) != this->AsBitset(type2)); |
107 } | 71 } |
108 } | 72 } |
109 | 73 |
110 void CheckSubOrEqual(TypeHandle type1, TypeHandle type2) { | 74 void CheckSubOrEqual(Type* type1, Type* type2) { |
111 CHECK(type1->Is(type2)); | 75 CHECK(type1->Is(type2)); |
112 if (this->IsBitset(type1) && this->IsBitset(type2)) { | 76 if (this->IsBitset(type1) && this->IsBitset(type2)) { |
113 CHECK((this->AsBitset(type1) | this->AsBitset(type2)) | 77 CHECK((this->AsBitset(type1) | this->AsBitset(type2)) |
114 == this->AsBitset(type2)); | 78 == this->AsBitset(type2)); |
115 } | 79 } |
116 } | 80 } |
117 | 81 |
118 void CheckUnordered(TypeHandle type1, TypeHandle type2) { | 82 void CheckUnordered(Type* type1, Type* type2) { |
119 CHECK(!type1->Is(type2)); | 83 CHECK(!type1->Is(type2)); |
120 CHECK(!type2->Is(type1)); | 84 CHECK(!type2->Is(type1)); |
121 if (this->IsBitset(type1) && this->IsBitset(type2)) { | 85 if (this->IsBitset(type1) && this->IsBitset(type2)) { |
122 CHECK(this->AsBitset(type1) != this->AsBitset(type2)); | 86 CHECK(this->AsBitset(type1) != this->AsBitset(type2)); |
123 } | 87 } |
124 } | 88 } |
125 | 89 |
126 void CheckOverlap(TypeHandle type1, TypeHandle type2) { | 90 void CheckOverlap(Type* type1, Type* type2) { |
127 CHECK(type1->Maybe(type2)); | 91 CHECK(type1->Maybe(type2)); |
128 CHECK(type2->Maybe(type1)); | 92 CHECK(type2->Maybe(type1)); |
129 } | 93 } |
130 | 94 |
131 void CheckDisjoint(TypeHandle type1, TypeHandle type2) { | 95 void CheckDisjoint(Type* type1, Type* type2) { |
132 CHECK(!type1->Is(type2)); | 96 CHECK(!type1->Is(type2)); |
133 CHECK(!type2->Is(type1)); | 97 CHECK(!type2->Is(type1)); |
134 CHECK(!type1->Maybe(type2)); | 98 CHECK(!type1->Maybe(type2)); |
135 CHECK(!type2->Maybe(type1)); | 99 CHECK(!type2->Maybe(type1)); |
136 } | 100 } |
137 | 101 |
138 void IsSomeType() { | 102 void IsSomeType() { |
139 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 103 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
140 TypeHandle t = *it; | 104 Type* t = *it; |
141 CHECK(1 == | 105 CHECK(1 == |
142 this->IsBitset(t) + t->IsClass() + t->IsConstant() + t->IsRange() + | 106 this->IsBitset(t) + t->IsClass() + t->IsConstant() + t->IsRange() + |
143 this->IsUnion(t) + t->IsArray() + t->IsFunction() + t->IsContext()); | 107 this->IsUnion(t) + t->IsArray() + t->IsFunction() + t->IsContext()); |
144 } | 108 } |
145 } | 109 } |
146 | 110 |
147 void Bitset() { | 111 void Bitset() { |
148 // None and Any are bitsets. | 112 // None and Any are bitsets. |
149 CHECK(this->IsBitset(T.None)); | 113 CHECK(this->IsBitset(T.None)); |
150 CHECK(this->IsBitset(T.Any)); | 114 CHECK(this->IsBitset(T.Any)); |
151 | 115 |
152 CHECK(bitset(0) == this->AsBitset(T.None)); | 116 CHECK(bitset(0) == this->AsBitset(T.None)); |
153 CHECK(bitset(0xfffffffeu) == this->AsBitset(T.Any)); | 117 CHECK(bitset(0xfffffffeu) == this->AsBitset(T.Any)); |
154 | 118 |
155 // Union(T1, T2) is bitset for bitsets T1,T2 | 119 // Union(T1, T2) is bitset for bitsets T1,T2 |
156 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 120 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
157 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 121 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
158 TypeHandle type1 = *it1; | 122 Type* type1 = *it1; |
159 TypeHandle type2 = *it2; | 123 Type* type2 = *it2; |
160 TypeHandle union12 = T.Union(type1, type2); | 124 Type* union12 = T.Union(type1, type2); |
161 CHECK(!(this->IsBitset(type1) && this->IsBitset(type2)) || | 125 CHECK(!(this->IsBitset(type1) && this->IsBitset(type2)) || |
162 this->IsBitset(union12)); | 126 this->IsBitset(union12)); |
163 } | 127 } |
164 } | 128 } |
165 | 129 |
166 // Intersect(T1, T2) is bitset for bitsets T1,T2 | 130 // Intersect(T1, T2) is bitset for bitsets T1,T2 |
167 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 131 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
168 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 132 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
169 TypeHandle type1 = *it1; | 133 Type* type1 = *it1; |
170 TypeHandle type2 = *it2; | 134 Type* type2 = *it2; |
171 TypeHandle intersect12 = T.Intersect(type1, type2); | 135 Type* intersect12 = T.Intersect(type1, type2); |
172 CHECK(!(this->IsBitset(type1) && this->IsBitset(type2)) || | 136 CHECK(!(this->IsBitset(type1) && this->IsBitset(type2)) || |
173 this->IsBitset(intersect12)); | 137 this->IsBitset(intersect12)); |
174 } | 138 } |
175 } | 139 } |
176 | 140 |
177 // Union(T1, T2) is bitset if T2 is bitset and T1->Is(T2) | 141 // Union(T1, T2) is bitset if T2 is bitset and T1->Is(T2) |
178 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 142 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
179 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 143 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
180 TypeHandle type1 = *it1; | 144 Type* type1 = *it1; |
181 TypeHandle type2 = *it2; | 145 Type* type2 = *it2; |
182 TypeHandle union12 = T.Union(type1, type2); | 146 Type* union12 = T.Union(type1, type2); |
183 CHECK(!(this->IsBitset(type2) && type1->Is(type2)) || | 147 CHECK(!(this->IsBitset(type2) && type1->Is(type2)) || |
184 this->IsBitset(union12)); | 148 this->IsBitset(union12)); |
185 } | 149 } |
186 } | 150 } |
187 | 151 |
188 // Union(T1, T2) is bitwise disjunction for bitsets T1,T2 | 152 // Union(T1, T2) is bitwise disjunction for bitsets T1,T2 |
189 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 153 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
190 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 154 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
191 TypeHandle type1 = *it1; | 155 Type* type1 = *it1; |
192 TypeHandle type2 = *it2; | 156 Type* type2 = *it2; |
193 TypeHandle union12 = T.Union(type1, type2); | 157 Type* union12 = T.Union(type1, type2); |
194 if (this->IsBitset(type1) && this->IsBitset(type2)) { | 158 if (this->IsBitset(type1) && this->IsBitset(type2)) { |
195 CHECK( | 159 CHECK( |
196 (this->AsBitset(type1) | this->AsBitset(type2)) == | 160 (this->AsBitset(type1) | this->AsBitset(type2)) == |
197 this->AsBitset(union12)); | 161 this->AsBitset(union12)); |
198 } | 162 } |
199 } | 163 } |
200 } | 164 } |
201 | 165 |
202 // Intersect(T1, T2) is bitwise conjunction for bitsets T1,T2 (modulo None) | 166 // Intersect(T1, T2) is bitwise conjunction for bitsets T1,T2 (modulo None) |
203 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 167 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
204 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 168 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
205 TypeHandle type1 = *it1; | 169 Type* type1 = *it1; |
206 TypeHandle type2 = *it2; | 170 Type* type2 = *it2; |
207 if (this->IsBitset(type1) && this->IsBitset(type2)) { | 171 if (this->IsBitset(type1) && this->IsBitset(type2)) { |
208 TypeHandle intersect12 = T.Intersect(type1, type2); | 172 Type* intersect12 = T.Intersect(type1, type2); |
209 bitset bits = this->AsBitset(type1) & this->AsBitset(type2); | 173 bitset bits = this->AsBitset(type1) & this->AsBitset(type2); |
210 CHECK(bits == this->AsBitset(intersect12)); | 174 CHECK(bits == this->AsBitset(intersect12)); |
211 } | 175 } |
212 } | 176 } |
213 } | 177 } |
214 } | 178 } |
215 | 179 |
216 void PointwiseRepresentation() { | 180 void PointwiseRepresentation() { |
217 // Check we can decompose type into semantics and representation and | 181 // Check we can decompose type into semantics and representation and |
218 // then compose it back to get an equivalent type. | 182 // then compose it back to get an equivalent type. |
219 int counter = 0; | 183 int counter = 0; |
220 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 184 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
221 counter++; | 185 counter++; |
222 printf("Counter: %i\n", counter); | 186 printf("Counter: %i\n", counter); |
223 fflush(stdout); | 187 fflush(stdout); |
224 TypeHandle type1 = *it1; | 188 Type* type1 = *it1; |
225 TypeHandle representation = T.Representation(type1); | 189 Type* representation = T.Representation(type1); |
226 TypeHandle semantic = T.Semantic(type1); | 190 Type* semantic = T.Semantic(type1); |
227 TypeHandle composed = T.Union(representation, semantic); | 191 Type* composed = T.Union(representation, semantic); |
228 CHECK(type1->Equals(composed)); | 192 CHECK(type1->Equals(composed)); |
229 } | 193 } |
230 | 194 |
231 // Pointwiseness of Union. | 195 // Pointwiseness of Union. |
232 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 196 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
233 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 197 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
234 TypeHandle type1 = *it1; | 198 Type* type1 = *it1; |
235 TypeHandle type2 = *it2; | 199 Type* type2 = *it2; |
236 TypeHandle representation1 = T.Representation(type1); | 200 Type* representation1 = T.Representation(type1); |
237 TypeHandle semantic1 = T.Semantic(type1); | 201 Type* semantic1 = T.Semantic(type1); |
238 TypeHandle representation2 = T.Representation(type2); | 202 Type* representation2 = T.Representation(type2); |
239 TypeHandle semantic2 = T.Semantic(type2); | 203 Type* semantic2 = T.Semantic(type2); |
240 TypeHandle direct_union = T.Union(type1, type2); | 204 Type* direct_union = T.Union(type1, type2); |
241 TypeHandle representation_union = | 205 Type* representation_union = T.Union(representation1, representation2); |
242 T.Union(representation1, representation2); | 206 Type* semantic_union = T.Union(semantic1, semantic2); |
243 TypeHandle semantic_union = T.Union(semantic1, semantic2); | 207 Type* composed_union = T.Union(representation_union, semantic_union); |
244 TypeHandle composed_union = | |
245 T.Union(representation_union, semantic_union); | |
246 CHECK(direct_union->Equals(composed_union)); | 208 CHECK(direct_union->Equals(composed_union)); |
247 } | 209 } |
248 } | 210 } |
249 | 211 |
250 // Pointwiseness of Intersect. | 212 // Pointwiseness of Intersect. |
251 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 213 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
252 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 214 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
253 TypeHandle type1 = *it1; | 215 Type* type1 = *it1; |
254 TypeHandle type2 = *it2; | 216 Type* type2 = *it2; |
255 TypeHandle representation1 = T.Representation(type1); | 217 Type* representation1 = T.Representation(type1); |
256 TypeHandle semantic1 = T.Semantic(type1); | 218 Type* semantic1 = T.Semantic(type1); |
257 TypeHandle representation2 = T.Representation(type2); | 219 Type* representation2 = T.Representation(type2); |
258 TypeHandle semantic2 = T.Semantic(type2); | 220 Type* semantic2 = T.Semantic(type2); |
259 TypeHandle direct_intersection = T.Intersect(type1, type2); | 221 Type* direct_intersection = T.Intersect(type1, type2); |
260 TypeHandle representation_intersection = | 222 Type* representation_intersection = |
261 T.Intersect(representation1, representation2); | 223 T.Intersect(representation1, representation2); |
262 TypeHandle semantic_intersection = T.Intersect(semantic1, semantic2); | 224 Type* semantic_intersection = T.Intersect(semantic1, semantic2); |
263 TypeHandle composed_intersection = | 225 Type* composed_intersection = |
264 T.Union(representation_intersection, semantic_intersection); | 226 T.Union(representation_intersection, semantic_intersection); |
265 CHECK(direct_intersection->Equals(composed_intersection)); | 227 CHECK(direct_intersection->Equals(composed_intersection)); |
266 } | 228 } |
267 } | 229 } |
268 | 230 |
269 // Pointwiseness of Is. | 231 // Pointwiseness of Is. |
270 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 232 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
271 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 233 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
272 TypeHandle type1 = *it1; | 234 Type* type1 = *it1; |
273 TypeHandle type2 = *it2; | 235 Type* type2 = *it2; |
274 TypeHandle representation1 = T.Representation(type1); | 236 Type* representation1 = T.Representation(type1); |
275 TypeHandle semantic1 = T.Semantic(type1); | 237 Type* semantic1 = T.Semantic(type1); |
276 TypeHandle representation2 = T.Representation(type2); | 238 Type* representation2 = T.Representation(type2); |
277 TypeHandle semantic2 = T.Semantic(type2); | 239 Type* semantic2 = T.Semantic(type2); |
278 bool representation_is = representation1->Is(representation2); | 240 bool representation_is = representation1->Is(representation2); |
279 bool semantic_is = semantic1->Is(semantic2); | 241 bool semantic_is = semantic1->Is(semantic2); |
280 bool direct_is = type1->Is(type2); | 242 bool direct_is = type1->Is(type2); |
281 CHECK(direct_is == (semantic_is && representation_is)); | 243 CHECK(direct_is == (semantic_is && representation_is)); |
282 } | 244 } |
283 } | 245 } |
284 } | 246 } |
285 | 247 |
286 void Class() { | 248 void Class() { |
287 // Constructor | 249 // Constructor |
288 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) { | 250 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) { |
289 Handle<i::Map> map = *mt; | 251 Handle<i::Map> map = *mt; |
290 TypeHandle type = T.Class(map); | 252 Type* type = T.Class(map); |
291 CHECK(type->IsClass()); | 253 CHECK(type->IsClass()); |
292 } | 254 } |
293 | 255 |
294 // Map attribute | 256 // Map attribute |
295 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) { | 257 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) { |
296 Handle<i::Map> map = *mt; | 258 Handle<i::Map> map = *mt; |
297 TypeHandle type = T.Class(map); | 259 Type* type = T.Class(map); |
298 CHECK(*map == *type->AsClass()->Map()); | 260 CHECK(*map == *type->AsClass()->Map()); |
299 } | 261 } |
300 | 262 |
301 // Functionality & Injectivity: Class(M1) = Class(M2) iff M1 = M2 | 263 // Functionality & Injectivity: Class(M1) = Class(M2) iff M1 = M2 |
302 for (MapIterator mt1 = T.maps.begin(); mt1 != T.maps.end(); ++mt1) { | 264 for (MapIterator mt1 = T.maps.begin(); mt1 != T.maps.end(); ++mt1) { |
303 for (MapIterator mt2 = T.maps.begin(); mt2 != T.maps.end(); ++mt2) { | 265 for (MapIterator mt2 = T.maps.begin(); mt2 != T.maps.end(); ++mt2) { |
304 Handle<i::Map> map1 = *mt1; | 266 Handle<i::Map> map1 = *mt1; |
305 Handle<i::Map> map2 = *mt2; | 267 Handle<i::Map> map2 = *mt2; |
306 TypeHandle type1 = T.Class(map1); | 268 Type* type1 = T.Class(map1); |
307 TypeHandle type2 = T.Class(map2); | 269 Type* type2 = T.Class(map2); |
308 CHECK(Equal(type1, type2) == (*map1 == *map2)); | 270 CHECK(Equal(type1, type2) == (*map1 == *map2)); |
309 } | 271 } |
310 } | 272 } |
311 } | 273 } |
312 | 274 |
313 void Constant() { | 275 void Constant() { |
314 // Constructor | 276 // Constructor |
315 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { | 277 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { |
316 Handle<i::Object> value = *vt; | 278 Handle<i::Object> value = *vt; |
317 TypeHandle type = T.Constant(value); | 279 Type* type = T.Constant(value); |
318 CHECK(type->IsConstant()); | 280 CHECK(type->IsConstant()); |
319 } | 281 } |
320 | 282 |
321 // Value attribute | 283 // Value attribute |
322 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { | 284 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { |
323 Handle<i::Object> value = *vt; | 285 Handle<i::Object> value = *vt; |
324 TypeHandle type = T.Constant(value); | 286 Type* type = T.Constant(value); |
325 CHECK(*value == *type->AsConstant()->Value()); | 287 CHECK(*value == *type->AsConstant()->Value()); |
326 } | 288 } |
327 | 289 |
328 // Functionality & Injectivity: Constant(V1) = Constant(V2) iff V1 = V2 | 290 // Functionality & Injectivity: Constant(V1) = Constant(V2) iff V1 = V2 |
329 for (ValueIterator vt1 = T.values.begin(); vt1 != T.values.end(); ++vt1) { | 291 for (ValueIterator vt1 = T.values.begin(); vt1 != T.values.end(); ++vt1) { |
330 for (ValueIterator vt2 = T.values.begin(); vt2 != T.values.end(); ++vt2) { | 292 for (ValueIterator vt2 = T.values.begin(); vt2 != T.values.end(); ++vt2) { |
331 Handle<i::Object> value1 = *vt1; | 293 Handle<i::Object> value1 = *vt1; |
332 Handle<i::Object> value2 = *vt2; | 294 Handle<i::Object> value2 = *vt2; |
333 TypeHandle type1 = T.Constant(value1); | 295 Type* type1 = T.Constant(value1); |
334 TypeHandle type2 = T.Constant(value2); | 296 Type* type2 = T.Constant(value2); |
335 CHECK(Equal(type1, type2) == (*value1 == *value2)); | 297 CHECK(Equal(type1, type2) == (*value1 == *value2)); |
336 } | 298 } |
337 } | 299 } |
338 | 300 |
339 // Typing of numbers | 301 // Typing of numbers |
340 Factory* fac = isolate->factory(); | 302 Factory* fac = isolate->factory(); |
341 CHECK(T.Constant(fac->NewNumber(0))->Is(T.UnsignedSmall)); | 303 CHECK(T.Constant(fac->NewNumber(0))->Is(T.UnsignedSmall)); |
342 CHECK(T.Constant(fac->NewNumber(1))->Is(T.UnsignedSmall)); | 304 CHECK(T.Constant(fac->NewNumber(1))->Is(T.UnsignedSmall)); |
343 CHECK(T.Constant(fac->NewNumber(0x3fffffff))->Is(T.UnsignedSmall)); | 305 CHECK(T.Constant(fac->NewNumber(0x3fffffff))->Is(T.UnsignedSmall)); |
344 CHECK(T.Constant(fac->NewNumber(-1))->Is(T.Negative31)); | 306 CHECK(T.Constant(fac->NewNumber(-1))->Is(T.Negative31)); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 CHECK(!T.Constant(fac->NewNumber(-V8_INFINITY))->Is(T.Integral32)); | 349 CHECK(!T.Constant(fac->NewNumber(-V8_INFINITY))->Is(T.Integral32)); |
388 } | 350 } |
389 | 351 |
390 void Range() { | 352 void Range() { |
391 // Constructor | 353 // Constructor |
392 for (ValueIterator i = T.integers.begin(); i != T.integers.end(); ++i) { | 354 for (ValueIterator i = T.integers.begin(); i != T.integers.end(); ++i) { |
393 for (ValueIterator j = T.integers.begin(); j != T.integers.end(); ++j) { | 355 for (ValueIterator j = T.integers.begin(); j != T.integers.end(); ++j) { |
394 double min = (*i)->Number(); | 356 double min = (*i)->Number(); |
395 double max = (*j)->Number(); | 357 double max = (*j)->Number(); |
396 if (min > max) std::swap(min, max); | 358 if (min > max) std::swap(min, max); |
397 TypeHandle type = T.Range(min, max); | 359 Type* type = T.Range(min, max); |
398 CHECK(type->IsRange()); | 360 CHECK(type->IsRange()); |
399 } | 361 } |
400 } | 362 } |
401 | 363 |
402 // Range attributes | 364 // Range attributes |
403 for (ValueIterator i = T.integers.begin(); i != T.integers.end(); ++i) { | 365 for (ValueIterator i = T.integers.begin(); i != T.integers.end(); ++i) { |
404 for (ValueIterator j = T.integers.begin(); j != T.integers.end(); ++j) { | 366 for (ValueIterator j = T.integers.begin(); j != T.integers.end(); ++j) { |
405 double min = (*i)->Number(); | 367 double min = (*i)->Number(); |
406 double max = (*j)->Number(); | 368 double max = (*j)->Number(); |
407 if (min > max) std::swap(min, max); | 369 if (min > max) std::swap(min, max); |
408 TypeHandle type = T.Range(min, max); | 370 Type* type = T.Range(min, max); |
409 CHECK(min == type->AsRange()->Min()); | 371 CHECK(min == type->AsRange()->Min()); |
410 CHECK(max == type->AsRange()->Max()); | 372 CHECK(max == type->AsRange()->Max()); |
411 } | 373 } |
412 } | 374 } |
413 | 375 |
414 // Functionality & Injectivity: | 376 // Functionality & Injectivity: |
415 // Range(min1, max1) = Range(min2, max2) <=> min1 = min2 /\ max1 = max2 | 377 // Range(min1, max1) = Range(min2, max2) <=> min1 = min2 /\ max1 = max2 |
416 for (ValueIterator i1 = T.integers.begin(); | 378 for (ValueIterator i1 = T.integers.begin(); |
417 i1 != T.integers.end(); ++i1) { | 379 i1 != T.integers.end(); ++i1) { |
418 for (ValueIterator j1 = i1; | 380 for (ValueIterator j1 = i1; |
419 j1 != T.integers.end(); ++j1) { | 381 j1 != T.integers.end(); ++j1) { |
420 for (ValueIterator i2 = T.integers.begin(); | 382 for (ValueIterator i2 = T.integers.begin(); |
421 i2 != T.integers.end(); ++i2) { | 383 i2 != T.integers.end(); ++i2) { |
422 for (ValueIterator j2 = i2; | 384 for (ValueIterator j2 = i2; |
423 j2 != T.integers.end(); ++j2) { | 385 j2 != T.integers.end(); ++j2) { |
424 double min1 = (*i1)->Number(); | 386 double min1 = (*i1)->Number(); |
425 double max1 = (*j1)->Number(); | 387 double max1 = (*j1)->Number(); |
426 double min2 = (*i2)->Number(); | 388 double min2 = (*i2)->Number(); |
427 double max2 = (*j2)->Number(); | 389 double max2 = (*j2)->Number(); |
428 if (min1 > max1) std::swap(min1, max1); | 390 if (min1 > max1) std::swap(min1, max1); |
429 if (min2 > max2) std::swap(min2, max2); | 391 if (min2 > max2) std::swap(min2, max2); |
430 TypeHandle type1 = T.Range(min1, max1); | 392 Type* type1 = T.Range(min1, max1); |
431 TypeHandle type2 = T.Range(min2, max2); | 393 Type* type2 = T.Range(min2, max2); |
432 CHECK(Equal(type1, type2) == (min1 == min2 && max1 == max2)); | 394 CHECK(Equal(type1, type2) == (min1 == min2 && max1 == max2)); |
433 } | 395 } |
434 } | 396 } |
435 } | 397 } |
436 } | 398 } |
437 } | 399 } |
438 | 400 |
439 void Context() { | 401 void Context() { |
440 // Constructor | 402 // Constructor |
441 for (int i = 0; i < 20; ++i) { | 403 for (int i = 0; i < 20; ++i) { |
442 TypeHandle type = T.Random(); | 404 Type* type = T.Random(); |
443 TypeHandle context = T.Context(type); | 405 Type* context = T.Context(type); |
444 CHECK(context->Iscontext()); | 406 CHECK(context->IsContext()); |
445 } | 407 } |
446 | 408 |
447 // Attributes | 409 // Attributes |
448 for (int i = 0; i < 20; ++i) { | 410 for (int i = 0; i < 20; ++i) { |
449 TypeHandle type = T.Random(); | 411 Type* type = T.Random(); |
450 TypeHandle context = T.Context(type); | 412 Type* context = T.Context(type); |
451 CheckEqual(type, context->AsContext()->Outer()); | 413 CheckEqual(type, context->AsContext()->Outer()); |
452 } | 414 } |
453 | 415 |
454 // Functionality & Injectivity: Context(T1) = Context(T2) iff T1 = T2 | 416 // Functionality & Injectivity: Context(T1) = Context(T2) iff T1 = T2 |
455 for (int i = 0; i < 20; ++i) { | 417 for (int i = 0; i < 20; ++i) { |
456 for (int j = 0; j < 20; ++j) { | 418 for (int j = 0; j < 20; ++j) { |
457 TypeHandle type1 = T.Random(); | 419 Type* type1 = T.Random(); |
458 TypeHandle type2 = T.Random(); | 420 Type* type2 = T.Random(); |
459 TypeHandle context1 = T.Context(type1); | 421 Type* context1 = T.Context(type1); |
460 TypeHandle context2 = T.Context(type2); | 422 Type* context2 = T.Context(type2); |
461 CHECK(Equal(context1, context2) == Equal(type1, type2)); | 423 CHECK(Equal(context1, context2) == Equal(type1, type2)); |
462 } | 424 } |
463 } | 425 } |
464 } | 426 } |
465 | 427 |
466 void Array() { | 428 void Array() { |
467 // Constructor | 429 // Constructor |
468 for (int i = 0; i < 20; ++i) { | 430 for (int i = 0; i < 20; ++i) { |
469 TypeHandle type = T.Random(); | 431 Type* type = T.Random(); |
470 TypeHandle array = T.Array1(type); | 432 Type* array = T.Array1(type); |
471 CHECK(array->IsArray()); | 433 CHECK(array->IsArray()); |
472 } | 434 } |
473 | 435 |
474 // Attributes | 436 // Attributes |
475 for (int i = 0; i < 20; ++i) { | 437 for (int i = 0; i < 20; ++i) { |
476 TypeHandle type = T.Random(); | 438 Type* type = T.Random(); |
477 TypeHandle array = T.Array1(type); | 439 Type* array = T.Array1(type); |
478 CheckEqual(type, array->AsArray()->Element()); | 440 CheckEqual(type, array->AsArray()->Element()); |
479 } | 441 } |
480 | 442 |
481 // Functionality & Injectivity: Array(T1) = Array(T2) iff T1 = T2 | 443 // Functionality & Injectivity: Array(T1) = Array(T2) iff T1 = T2 |
482 for (int i = 0; i < 20; ++i) { | 444 for (int i = 0; i < 20; ++i) { |
483 for (int j = 0; j < 20; ++j) { | 445 for (int j = 0; j < 20; ++j) { |
484 TypeHandle type1 = T.Random(); | 446 Type* type1 = T.Random(); |
485 TypeHandle type2 = T.Random(); | 447 Type* type2 = T.Random(); |
486 TypeHandle array1 = T.Array1(type1); | 448 Type* array1 = T.Array1(type1); |
487 TypeHandle array2 = T.Array1(type2); | 449 Type* array2 = T.Array1(type2); |
488 CHECK(Equal(array1, array2) == Equal(type1, type2)); | 450 CHECK(Equal(array1, array2) == Equal(type1, type2)); |
489 } | 451 } |
490 } | 452 } |
491 } | 453 } |
492 | 454 |
493 void Function() { | 455 void Function() { |
494 // Constructors | 456 // Constructors |
495 for (int i = 0; i < 20; ++i) { | 457 for (int i = 0; i < 20; ++i) { |
496 for (int j = 0; j < 20; ++j) { | 458 for (int j = 0; j < 20; ++j) { |
497 for (int k = 0; k < 20; ++k) { | 459 for (int k = 0; k < 20; ++k) { |
498 TypeHandle type1 = T.Random(); | 460 Type* type1 = T.Random(); |
499 TypeHandle type2 = T.Random(); | 461 Type* type2 = T.Random(); |
500 TypeHandle type3 = T.Random(); | 462 Type* type3 = T.Random(); |
501 TypeHandle function0 = T.Function0(type1, type2); | 463 Type* function0 = T.Function0(type1, type2); |
502 TypeHandle function1 = T.Function1(type1, type2, type3); | 464 Type* function1 = T.Function1(type1, type2, type3); |
503 TypeHandle function2 = T.Function2(type1, type2, type3); | 465 Type* function2 = T.Function2(type1, type2, type3); |
504 CHECK(function0->IsFunction()); | 466 CHECK(function0->IsFunction()); |
505 CHECK(function1->IsFunction()); | 467 CHECK(function1->IsFunction()); |
506 CHECK(function2->IsFunction()); | 468 CHECK(function2->IsFunction()); |
507 } | 469 } |
508 } | 470 } |
509 } | 471 } |
510 | 472 |
511 // Attributes | 473 // Attributes |
512 for (int i = 0; i < 20; ++i) { | 474 for (int i = 0; i < 20; ++i) { |
513 for (int j = 0; j < 20; ++j) { | 475 for (int j = 0; j < 20; ++j) { |
514 for (int k = 0; k < 20; ++k) { | 476 for (int k = 0; k < 20; ++k) { |
515 TypeHandle type1 = T.Random(); | 477 Type* type1 = T.Random(); |
516 TypeHandle type2 = T.Random(); | 478 Type* type2 = T.Random(); |
517 TypeHandle type3 = T.Random(); | 479 Type* type3 = T.Random(); |
518 TypeHandle function0 = T.Function0(type1, type2); | 480 Type* function0 = T.Function0(type1, type2); |
519 TypeHandle function1 = T.Function1(type1, type2, type3); | 481 Type* function1 = T.Function1(type1, type2, type3); |
520 TypeHandle function2 = T.Function2(type1, type2, type3); | 482 Type* function2 = T.Function2(type1, type2, type3); |
521 CHECK_EQ(0, function0->AsFunction()->Arity()); | 483 CHECK_EQ(0, function0->AsFunction()->Arity()); |
522 CHECK_EQ(1, function1->AsFunction()->Arity()); | 484 CHECK_EQ(1, function1->AsFunction()->Arity()); |
523 CHECK_EQ(2, function2->AsFunction()->Arity()); | 485 CHECK_EQ(2, function2->AsFunction()->Arity()); |
524 CheckEqual(type1, function0->AsFunction()->Result()); | 486 CheckEqual(type1, function0->AsFunction()->Result()); |
525 CheckEqual(type1, function1->AsFunction()->Result()); | 487 CheckEqual(type1, function1->AsFunction()->Result()); |
526 CheckEqual(type1, function2->AsFunction()->Result()); | 488 CheckEqual(type1, function2->AsFunction()->Result()); |
527 CheckEqual(type2, function0->AsFunction()->Receiver()); | 489 CheckEqual(type2, function0->AsFunction()->Receiver()); |
528 CheckEqual(type2, function1->AsFunction()->Receiver()); | 490 CheckEqual(type2, function1->AsFunction()->Receiver()); |
529 CheckEqual(T.Any, function2->AsFunction()->Receiver()); | 491 CheckEqual(T.Any, function2->AsFunction()->Receiver()); |
530 CheckEqual(type3, function1->AsFunction()->Parameter(0)); | 492 CheckEqual(type3, function1->AsFunction()->Parameter(0)); |
531 CheckEqual(type2, function2->AsFunction()->Parameter(0)); | 493 CheckEqual(type2, function2->AsFunction()->Parameter(0)); |
532 CheckEqual(type3, function2->AsFunction()->Parameter(1)); | 494 CheckEqual(type3, function2->AsFunction()->Parameter(1)); |
533 } | 495 } |
534 } | 496 } |
535 } | 497 } |
536 | 498 |
537 // Functionality & Injectivity: Function(Ts1) = Function(Ts2) iff Ts1 = Ts2 | 499 // Functionality & Injectivity: Function(Ts1) = Function(Ts2) iff Ts1 = Ts2 |
538 for (int i = 0; i < 20; ++i) { | 500 for (int i = 0; i < 20; ++i) { |
539 for (int j = 0; j < 20; ++j) { | 501 for (int j = 0; j < 20; ++j) { |
540 for (int k = 0; k < 20; ++k) { | 502 for (int k = 0; k < 20; ++k) { |
541 TypeHandle type1 = T.Random(); | 503 Type* type1 = T.Random(); |
542 TypeHandle type2 = T.Random(); | 504 Type* type2 = T.Random(); |
543 TypeHandle type3 = T.Random(); | 505 Type* type3 = T.Random(); |
544 TypeHandle function01 = T.Function0(type1, type2); | 506 Type* function01 = T.Function0(type1, type2); |
545 TypeHandle function02 = T.Function0(type1, type3); | 507 Type* function02 = T.Function0(type1, type3); |
546 TypeHandle function03 = T.Function0(type3, type2); | 508 Type* function03 = T.Function0(type3, type2); |
547 TypeHandle function11 = T.Function1(type1, type2, type2); | 509 Type* function11 = T.Function1(type1, type2, type2); |
548 TypeHandle function12 = T.Function1(type1, type2, type3); | 510 Type* function12 = T.Function1(type1, type2, type3); |
549 TypeHandle function21 = T.Function2(type1, type2, type2); | 511 Type* function21 = T.Function2(type1, type2, type2); |
550 TypeHandle function22 = T.Function2(type1, type2, type3); | 512 Type* function22 = T.Function2(type1, type2, type3); |
551 TypeHandle function23 = T.Function2(type1, type3, type2); | 513 Type* function23 = T.Function2(type1, type3, type2); |
552 CHECK(Equal(function01, function02) == Equal(type2, type3)); | 514 CHECK(Equal(function01, function02) == Equal(type2, type3)); |
553 CHECK(Equal(function01, function03) == Equal(type1, type3)); | 515 CHECK(Equal(function01, function03) == Equal(type1, type3)); |
554 CHECK(Equal(function11, function12) == Equal(type2, type3)); | 516 CHECK(Equal(function11, function12) == Equal(type2, type3)); |
555 CHECK(Equal(function21, function22) == Equal(type2, type3)); | 517 CHECK(Equal(function21, function22) == Equal(type2, type3)); |
556 CHECK(Equal(function21, function23) == Equal(type2, type3)); | 518 CHECK(Equal(function21, function23) == Equal(type2, type3)); |
557 } | 519 } |
558 } | 520 } |
559 } | 521 } |
560 } | 522 } |
561 | 523 |
562 void Of() { | 524 void Of() { |
563 // Constant(V)->Is(Of(V)) | 525 // Constant(V)->Is(Of(V)) |
564 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { | 526 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { |
565 Handle<i::Object> value = *vt; | 527 Handle<i::Object> value = *vt; |
566 TypeHandle const_type = T.Constant(value); | 528 Type* const_type = T.Constant(value); |
567 TypeHandle of_type = T.Of(value); | 529 Type* of_type = T.Of(value); |
568 CHECK(const_type->Is(of_type)); | 530 CHECK(const_type->Is(of_type)); |
569 } | 531 } |
570 | 532 |
571 // If Of(V)->Is(T), then Constant(V)->Is(T) | 533 // If Of(V)->Is(T), then Constant(V)->Is(T) |
572 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { | 534 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { |
573 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 535 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
574 Handle<i::Object> value = *vt; | 536 Handle<i::Object> value = *vt; |
575 TypeHandle type = *it; | 537 Type* type = *it; |
576 TypeHandle const_type = T.Constant(value); | 538 Type* const_type = T.Constant(value); |
577 TypeHandle of_type = T.Of(value); | 539 Type* of_type = T.Of(value); |
578 CHECK(!of_type->Is(type) || const_type->Is(type)); | 540 CHECK(!of_type->Is(type) || const_type->Is(type)); |
579 } | 541 } |
580 } | 542 } |
581 | 543 |
582 // If Constant(V)->Is(T), then Of(V)->Is(T) or T->Maybe(Constant(V)) | 544 // If Constant(V)->Is(T), then Of(V)->Is(T) or T->Maybe(Constant(V)) |
583 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { | 545 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { |
584 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 546 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
585 Handle<i::Object> value = *vt; | 547 Handle<i::Object> value = *vt; |
586 TypeHandle type = *it; | 548 Type* type = *it; |
587 TypeHandle const_type = T.Constant(value); | 549 Type* const_type = T.Constant(value); |
588 TypeHandle of_type = T.Of(value); | 550 Type* of_type = T.Of(value); |
589 CHECK(!const_type->Is(type) || | 551 CHECK(!const_type->Is(type) || |
590 of_type->Is(type) || type->Maybe(const_type)); | 552 of_type->Is(type) || type->Maybe(const_type)); |
591 } | 553 } |
592 } | 554 } |
593 } | 555 } |
594 | 556 |
595 void NowOf() { | 557 void NowOf() { |
596 // Constant(V)->NowIs(NowOf(V)) | 558 // Constant(V)->NowIs(NowOf(V)) |
597 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { | 559 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { |
598 Handle<i::Object> value = *vt; | 560 Handle<i::Object> value = *vt; |
599 TypeHandle const_type = T.Constant(value); | 561 Type* const_type = T.Constant(value); |
600 TypeHandle nowof_type = T.NowOf(value); | 562 Type* nowof_type = T.NowOf(value); |
601 CHECK(const_type->NowIs(nowof_type)); | 563 CHECK(const_type->NowIs(nowof_type)); |
602 } | 564 } |
603 | 565 |
604 // NowOf(V)->Is(Of(V)) | 566 // NowOf(V)->Is(Of(V)) |
605 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { | 567 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { |
606 Handle<i::Object> value = *vt; | 568 Handle<i::Object> value = *vt; |
607 TypeHandle nowof_type = T.NowOf(value); | 569 Type* nowof_type = T.NowOf(value); |
608 TypeHandle of_type = T.Of(value); | 570 Type* of_type = T.Of(value); |
609 CHECK(nowof_type->Is(of_type)); | 571 CHECK(nowof_type->Is(of_type)); |
610 } | 572 } |
611 | 573 |
612 // If NowOf(V)->NowIs(T), then Constant(V)->NowIs(T) | 574 // If NowOf(V)->NowIs(T), then Constant(V)->NowIs(T) |
613 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { | 575 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { |
614 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 576 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
615 Handle<i::Object> value = *vt; | 577 Handle<i::Object> value = *vt; |
616 TypeHandle type = *it; | 578 Type* type = *it; |
617 TypeHandle const_type = T.Constant(value); | 579 Type* const_type = T.Constant(value); |
618 TypeHandle nowof_type = T.NowOf(value); | 580 Type* nowof_type = T.NowOf(value); |
619 CHECK(!nowof_type->NowIs(type) || const_type->NowIs(type)); | 581 CHECK(!nowof_type->NowIs(type) || const_type->NowIs(type)); |
620 } | 582 } |
621 } | 583 } |
622 | 584 |
623 // If Constant(V)->NowIs(T), | 585 // If Constant(V)->NowIs(T), |
624 // then NowOf(V)->NowIs(T) or T->Maybe(Constant(V)) | 586 // then NowOf(V)->NowIs(T) or T->Maybe(Constant(V)) |
625 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { | 587 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { |
626 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 588 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
627 Handle<i::Object> value = *vt; | 589 Handle<i::Object> value = *vt; |
628 TypeHandle type = *it; | 590 Type* type = *it; |
629 TypeHandle const_type = T.Constant(value); | 591 Type* const_type = T.Constant(value); |
630 TypeHandle nowof_type = T.NowOf(value); | 592 Type* nowof_type = T.NowOf(value); |
631 CHECK(!const_type->NowIs(type) || | 593 CHECK(!const_type->NowIs(type) || |
632 nowof_type->NowIs(type) || type->Maybe(const_type)); | 594 nowof_type->NowIs(type) || type->Maybe(const_type)); |
633 } | 595 } |
634 } | 596 } |
635 | 597 |
636 // If Constant(V)->Is(T), | 598 // If Constant(V)->Is(T), |
637 // then NowOf(V)->Is(T) or T->Maybe(Constant(V)) | 599 // then NowOf(V)->Is(T) or T->Maybe(Constant(V)) |
638 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { | 600 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { |
639 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 601 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
640 Handle<i::Object> value = *vt; | 602 Handle<i::Object> value = *vt; |
641 TypeHandle type = *it; | 603 Type* type = *it; |
642 TypeHandle const_type = T.Constant(value); | 604 Type* const_type = T.Constant(value); |
643 TypeHandle nowof_type = T.NowOf(value); | 605 Type* nowof_type = T.NowOf(value); |
644 CHECK(!const_type->Is(type) || | 606 CHECK(!const_type->Is(type) || |
645 nowof_type->Is(type) || type->Maybe(const_type)); | 607 nowof_type->Is(type) || type->Maybe(const_type)); |
646 } | 608 } |
647 } | 609 } |
648 } | 610 } |
649 | 611 |
650 void MinMax() { | 612 void MinMax() { |
651 // If b is regular numeric bitset, then Range(b->Min(), b->Max())->Is(b). | 613 // If b is regular numeric bitset, then Range(b->Min(), b->Max())->Is(b). |
652 // TODO(neis): Need to ignore representation for this to be true. | 614 // TODO(neis): Need to ignore representation for this to be true. |
653 /* | 615 /* |
654 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 616 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
655 TypeHandle type = *it; | 617 Type* type = *it; |
656 if (this->IsBitset(type) && type->Is(T.Number) && | 618 if (this->IsBitset(type) && type->Is(T.Number) && |
657 !type->Is(T.None) && !type->Is(T.NaN)) { | 619 !type->Is(T.None) && !type->Is(T.NaN)) { |
658 TypeHandle range = T.Range( | 620 Type* range = T.Range( |
659 isolate->factory()->NewNumber(type->Min()), | 621 isolate->factory()->NewNumber(type->Min()), |
660 isolate->factory()->NewNumber(type->Max())); | 622 isolate->factory()->NewNumber(type->Max())); |
661 CHECK(range->Is(type)); | 623 CHECK(range->Is(type)); |
662 } | 624 } |
663 } | 625 } |
664 */ | 626 */ |
665 | 627 |
666 // If b is regular numeric bitset, then b->Min() and b->Max() are integers. | 628 // If b is regular numeric bitset, then b->Min() and b->Max() are integers. |
667 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 629 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
668 TypeHandle type = *it; | 630 Type* type = *it; |
669 if (this->IsBitset(type) && type->Is(T.Number) && !type->Is(T.NaN)) { | 631 if (this->IsBitset(type) && type->Is(T.Number) && !type->Is(T.NaN)) { |
670 CHECK(IsInteger(type->Min()) && IsInteger(type->Max())); | 632 CHECK(IsInteger(type->Min()) && IsInteger(type->Max())); |
671 } | 633 } |
672 } | 634 } |
673 | 635 |
674 // If b1 and b2 are regular numeric bitsets with b1->Is(b2), then | 636 // If b1 and b2 are regular numeric bitsets with b1->Is(b2), then |
675 // b1->Min() >= b2->Min() and b1->Max() <= b2->Max(). | 637 // b1->Min() >= b2->Min() and b1->Max() <= b2->Max(). |
676 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 638 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
677 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 639 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
678 TypeHandle type1 = *it1; | 640 Type* type1 = *it1; |
679 TypeHandle type2 = *it2; | 641 Type* type2 = *it2; |
680 if (this->IsBitset(type1) && type1->Is(type2) && type2->Is(T.Number) && | 642 if (this->IsBitset(type1) && type1->Is(type2) && type2->Is(T.Number) && |
681 !type1->Is(T.NaN) && !type2->Is(T.NaN)) { | 643 !type1->Is(T.NaN) && !type2->Is(T.NaN)) { |
682 CHECK(type1->Min() >= type2->Min()); | 644 CHECK(type1->Min() >= type2->Min()); |
683 CHECK(type1->Max() <= type2->Max()); | 645 CHECK(type1->Max() <= type2->Max()); |
684 } | 646 } |
685 } | 647 } |
686 } | 648 } |
687 | 649 |
688 // Lub(Range(x,y))->Min() <= x and y <= Lub(Range(x,y))->Max() | 650 // Lub(Range(x,y))->Min() <= x and y <= Lub(Range(x,y))->Max() |
689 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 651 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
690 TypeHandle type = *it; | 652 Type* type = *it; |
691 if (type->IsRange()) { | 653 if (type->IsRange()) { |
692 TypeHandle lub = Rep::BitsetType::New( | 654 Type* lub = BitsetType::NewForTesting(BitsetType::Lub(type)); |
693 Rep::BitsetType::Lub(type), T.region()); | |
694 CHECK(lub->Min() <= type->Min() && type->Max() <= lub->Max()); | 655 CHECK(lub->Min() <= type->Min() && type->Max() <= lub->Max()); |
695 } | 656 } |
696 } | 657 } |
697 | 658 |
698 // Rangification: If T->Is(Range(-inf,+inf)) and T is inhabited, then | 659 // Rangification: If T->Is(Range(-inf,+inf)) and T is inhabited, then |
699 // T->Is(Range(T->Min(), T->Max())). | 660 // T->Is(Range(T->Min(), T->Max())). |
700 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 661 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
701 TypeHandle type = *it; | 662 Type* type = *it; |
702 CHECK(!type->Is(T.Integer) || !type->IsInhabited() || | 663 CHECK(!type->Is(T.Integer) || !type->IsInhabited() || |
703 type->Is(T.Range(type->Min(), type->Max()))); | 664 type->Is(T.Range(type->Min(), type->Max()))); |
704 } | 665 } |
705 } | 666 } |
706 | 667 |
707 void BitsetGlb() { | 668 void BitsetGlb() { |
708 // Lower: (T->BitsetGlb())->Is(T) | 669 // Lower: (T->BitsetGlb())->Is(T) |
709 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 670 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
710 TypeHandle type = *it; | 671 Type* type = *it; |
711 TypeHandle glb = | 672 Type* glb = BitsetType::NewForTesting(BitsetType::Glb(type)); |
712 Rep::BitsetType::New(Rep::BitsetType::Glb(type), T.region()); | |
713 CHECK(glb->Is(type)); | 673 CHECK(glb->Is(type)); |
714 } | 674 } |
715 | 675 |
716 // Greatest: If T1->IsBitset() and T1->Is(T2), then T1->Is(T2->BitsetGlb()) | 676 // Greatest: If T1->IsBitset() and T1->Is(T2), then T1->Is(T2->BitsetGlb()) |
717 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 677 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
718 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 678 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
719 TypeHandle type1 = *it1; | 679 Type* type1 = *it1; |
720 TypeHandle type2 = *it2; | 680 Type* type2 = *it2; |
721 TypeHandle glb2 = | 681 Type* glb2 = BitsetType::NewForTesting(BitsetType::Glb(type2)); |
722 Rep::BitsetType::New(Rep::BitsetType::Glb(type2), T.region()); | |
723 CHECK(!this->IsBitset(type1) || !type1->Is(type2) || type1->Is(glb2)); | 682 CHECK(!this->IsBitset(type1) || !type1->Is(type2) || type1->Is(glb2)); |
724 } | 683 } |
725 } | 684 } |
726 | 685 |
727 // Monotonicity: T1->Is(T2) implies (T1->BitsetGlb())->Is(T2->BitsetGlb()) | 686 // Monotonicity: T1->Is(T2) implies (T1->BitsetGlb())->Is(T2->BitsetGlb()) |
728 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 687 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
729 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 688 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
730 TypeHandle type1 = *it1; | 689 Type* type1 = *it1; |
731 TypeHandle type2 = *it2; | 690 Type* type2 = *it2; |
732 TypeHandle glb1 = | 691 Type* glb1 = BitsetType::NewForTesting(BitsetType::Glb(type1)); |
733 Rep::BitsetType::New(Rep::BitsetType::Glb(type1), T.region()); | 692 Type* glb2 = BitsetType::NewForTesting(BitsetType::Glb(type2)); |
734 TypeHandle glb2 = | |
735 Rep::BitsetType::New(Rep::BitsetType::Glb(type2), T.region()); | |
736 CHECK(!type1->Is(type2) || glb1->Is(glb2)); | 693 CHECK(!type1->Is(type2) || glb1->Is(glb2)); |
737 } | 694 } |
738 } | 695 } |
739 } | 696 } |
740 | 697 |
741 void BitsetLub() { | 698 void BitsetLub() { |
742 // Upper: T->Is(T->BitsetLub()) | 699 // Upper: T->Is(T->BitsetLub()) |
743 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 700 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
744 TypeHandle type = *it; | 701 Type* type = *it; |
745 TypeHandle lub = | 702 Type* lub = BitsetType::NewForTesting(BitsetType::Lub(type)); |
746 Rep::BitsetType::New(Rep::BitsetType::Lub(type), T.region()); | |
747 CHECK(type->Is(lub)); | 703 CHECK(type->Is(lub)); |
748 } | 704 } |
749 | 705 |
750 // Least: If T2->IsBitset() and T1->Is(T2), then (T1->BitsetLub())->Is(T2) | 706 // Least: If T2->IsBitset() and T1->Is(T2), then (T1->BitsetLub())->Is(T2) |
751 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 707 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
752 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 708 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
753 TypeHandle type1 = *it1; | 709 Type* type1 = *it1; |
754 TypeHandle type2 = *it2; | 710 Type* type2 = *it2; |
755 TypeHandle lub1 = | 711 Type* lub1 = BitsetType::NewForTesting(BitsetType::Lub(type1)); |
756 Rep::BitsetType::New(Rep::BitsetType::Lub(type1), T.region()); | |
757 CHECK(!this->IsBitset(type2) || !type1->Is(type2) || lub1->Is(type2)); | 712 CHECK(!this->IsBitset(type2) || !type1->Is(type2) || lub1->Is(type2)); |
758 } | 713 } |
759 } | 714 } |
760 | 715 |
761 // Monotonicity: T1->Is(T2) implies (T1->BitsetLub())->Is(T2->BitsetLub()) | 716 // Monotonicity: T1->Is(T2) implies (T1->BitsetLub())->Is(T2->BitsetLub()) |
762 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 717 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
763 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 718 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
764 TypeHandle type1 = *it1; | 719 Type* type1 = *it1; |
765 TypeHandle type2 = *it2; | 720 Type* type2 = *it2; |
766 TypeHandle lub1 = | 721 Type* lub1 = BitsetType::NewForTesting(BitsetType::Lub(type1)); |
767 Rep::BitsetType::New(Rep::BitsetType::Lub(type1), T.region()); | 722 Type* lub2 = BitsetType::NewForTesting(BitsetType::Lub(type2)); |
768 TypeHandle lub2 = | |
769 Rep::BitsetType::New(Rep::BitsetType::Lub(type2), T.region()); | |
770 CHECK(!type1->Is(type2) || lub1->Is(lub2)); | 723 CHECK(!type1->Is(type2) || lub1->Is(lub2)); |
771 } | 724 } |
772 } | 725 } |
773 } | 726 } |
774 | 727 |
775 void Is1() { | 728 void Is1() { |
776 // Least Element (Bottom): None->Is(T) | 729 // Least Element (Bottom): None->Is(T) |
777 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 730 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
778 TypeHandle type = *it; | 731 Type* type = *it; |
779 CHECK(T.None->Is(type)); | 732 CHECK(T.None->Is(type)); |
780 } | 733 } |
781 | 734 |
782 // Greatest Element (Top): T->Is(Any) | 735 // Greatest Element (Top): T->Is(Any) |
783 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 736 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
784 TypeHandle type = *it; | 737 Type* type = *it; |
785 CHECK(type->Is(T.Any)); | 738 CHECK(type->Is(T.Any)); |
786 } | 739 } |
787 | 740 |
788 // Bottom Uniqueness: T->Is(None) implies T = None | 741 // Bottom Uniqueness: T->Is(None) implies T = None |
789 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 742 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
790 TypeHandle type = *it; | 743 Type* type = *it; |
791 if (type->Is(T.None)) CheckEqual(type, T.None); | 744 if (type->Is(T.None)) CheckEqual(type, T.None); |
792 } | 745 } |
793 | 746 |
794 // Top Uniqueness: Any->Is(T) implies T = Any | 747 // Top Uniqueness: Any->Is(T) implies T = Any |
795 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 748 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
796 TypeHandle type = *it; | 749 Type* type = *it; |
797 if (T.Any->Is(type)) CheckEqual(type, T.Any); | 750 if (T.Any->Is(type)) CheckEqual(type, T.Any); |
798 } | 751 } |
799 | 752 |
800 // Reflexivity: T->Is(T) | 753 // Reflexivity: T->Is(T) |
801 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 754 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
802 TypeHandle type = *it; | 755 Type* type = *it; |
803 CHECK(type->Is(type)); | 756 CHECK(type->Is(type)); |
804 } | 757 } |
805 | 758 |
806 // Transitivity: T1->Is(T2) and T2->Is(T3) implies T1->Is(T3) | 759 // Transitivity: T1->Is(T2) and T2->Is(T3) implies T1->Is(T3) |
807 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 760 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
808 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 761 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
809 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { | 762 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { |
810 TypeHandle type1 = *it1; | 763 Type* type1 = *it1; |
811 TypeHandle type2 = *it2; | 764 Type* type2 = *it2; |
812 TypeHandle type3 = *it3; | 765 Type* type3 = *it3; |
813 CHECK(!(type1->Is(type2) && type2->Is(type3)) || type1->Is(type3)); | 766 CHECK(!(type1->Is(type2) && type2->Is(type3)) || type1->Is(type3)); |
814 } | 767 } |
815 } | 768 } |
816 } | 769 } |
817 | 770 |
818 // Antisymmetry: T1->Is(T2) and T2->Is(T1) iff T1 = T2 | 771 // Antisymmetry: T1->Is(T2) and T2->Is(T1) iff T1 = T2 |
819 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 772 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
820 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 773 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
821 TypeHandle type1 = *it1; | 774 Type* type1 = *it1; |
822 TypeHandle type2 = *it2; | 775 Type* type2 = *it2; |
823 CHECK((type1->Is(type2) && type2->Is(type1)) == Equal(type1, type2)); | 776 CHECK((type1->Is(type2) && type2->Is(type1)) == Equal(type1, type2)); |
824 } | 777 } |
825 } | 778 } |
826 | 779 |
827 // (In-)Compatibilities. | 780 // (In-)Compatibilities. |
828 for (TypeIterator i = T.types.begin(); i != T.types.end(); ++i) { | 781 for (TypeIterator i = T.types.begin(); i != T.types.end(); ++i) { |
829 for (TypeIterator j = T.types.begin(); j != T.types.end(); ++j) { | 782 for (TypeIterator j = T.types.begin(); j != T.types.end(); ++j) { |
830 TypeHandle type1 = *i; | 783 Type* type1 = *i; |
831 TypeHandle type2 = *j; | 784 Type* type2 = *j; |
832 CHECK(!type1->Is(type2) || this->IsBitset(type2) || | 785 CHECK(!type1->Is(type2) || this->IsBitset(type2) || |
833 this->IsUnion(type2) || this->IsUnion(type1) || | 786 this->IsUnion(type2) || this->IsUnion(type1) || |
834 (type1->IsClass() && type2->IsClass()) || | 787 (type1->IsClass() && type2->IsClass()) || |
835 (type1->IsConstant() && type2->IsConstant()) || | 788 (type1->IsConstant() && type2->IsConstant()) || |
836 (type1->IsConstant() && type2->IsRange()) || | 789 (type1->IsConstant() && type2->IsRange()) || |
837 (this->IsBitset(type1) && type2->IsRange()) || | 790 (this->IsBitset(type1) && type2->IsRange()) || |
838 (type1->IsRange() && type2->IsRange()) || | 791 (type1->IsRange() && type2->IsRange()) || |
839 (type1->IsContext() && type2->IsContext()) || | 792 (type1->IsContext() && type2->IsContext()) || |
840 (type1->IsArray() && type2->IsArray()) || | 793 (type1->IsArray() && type2->IsArray()) || |
841 (type1->IsFunction() && type2->IsFunction()) || | 794 (type1->IsFunction() && type2->IsFunction()) || |
842 !type1->IsInhabited()); | 795 !type1->IsInhabited()); |
843 } | 796 } |
844 } | 797 } |
845 } | 798 } |
846 | 799 |
847 void Is2() { | 800 void Is2() { |
848 // Class(M1)->Is(Class(M2)) iff M1 = M2 | 801 // Class(M1)->Is(Class(M2)) iff M1 = M2 |
849 for (MapIterator mt1 = T.maps.begin(); mt1 != T.maps.end(); ++mt1) { | 802 for (MapIterator mt1 = T.maps.begin(); mt1 != T.maps.end(); ++mt1) { |
850 for (MapIterator mt2 = T.maps.begin(); mt2 != T.maps.end(); ++mt2) { | 803 for (MapIterator mt2 = T.maps.begin(); mt2 != T.maps.end(); ++mt2) { |
851 Handle<i::Map> map1 = *mt1; | 804 Handle<i::Map> map1 = *mt1; |
852 Handle<i::Map> map2 = *mt2; | 805 Handle<i::Map> map2 = *mt2; |
853 TypeHandle class_type1 = T.Class(map1); | 806 Type* class_type1 = T.Class(map1); |
854 TypeHandle class_type2 = T.Class(map2); | 807 Type* class_type2 = T.Class(map2); |
855 CHECK(class_type1->Is(class_type2) == (*map1 == *map2)); | 808 CHECK(class_type1->Is(class_type2) == (*map1 == *map2)); |
856 } | 809 } |
857 } | 810 } |
858 | 811 |
859 // Range(X1, Y1)->Is(Range(X2, Y2)) iff X1 >= X2 /\ Y1 <= Y2 | 812 // Range(X1, Y1)->Is(Range(X2, Y2)) iff X1 >= X2 /\ Y1 <= Y2 |
860 for (ValueIterator i1 = T.integers.begin(); | 813 for (ValueIterator i1 = T.integers.begin(); |
861 i1 != T.integers.end(); ++i1) { | 814 i1 != T.integers.end(); ++i1) { |
862 for (ValueIterator j1 = i1; | 815 for (ValueIterator j1 = i1; |
863 j1 != T.integers.end(); ++j1) { | 816 j1 != T.integers.end(); ++j1) { |
864 for (ValueIterator i2 = T.integers.begin(); | 817 for (ValueIterator i2 = T.integers.begin(); |
865 i2 != T.integers.end(); ++i2) { | 818 i2 != T.integers.end(); ++i2) { |
866 for (ValueIterator j2 = i2; | 819 for (ValueIterator j2 = i2; |
867 j2 != T.integers.end(); ++j2) { | 820 j2 != T.integers.end(); ++j2) { |
868 double min1 = (*i1)->Number(); | 821 double min1 = (*i1)->Number(); |
869 double max1 = (*j1)->Number(); | 822 double max1 = (*j1)->Number(); |
870 double min2 = (*i2)->Number(); | 823 double min2 = (*i2)->Number(); |
871 double max2 = (*j2)->Number(); | 824 double max2 = (*j2)->Number(); |
872 if (min1 > max1) std::swap(min1, max1); | 825 if (min1 > max1) std::swap(min1, max1); |
873 if (min2 > max2) std::swap(min2, max2); | 826 if (min2 > max2) std::swap(min2, max2); |
874 TypeHandle type1 = T.Range(min1, max1); | 827 Type* type1 = T.Range(min1, max1); |
875 TypeHandle type2 = T.Range(min2, max2); | 828 Type* type2 = T.Range(min2, max2); |
876 CHECK(type1->Is(type2) == (min1 >= min2 && max1 <= max2)); | 829 CHECK(type1->Is(type2) == (min1 >= min2 && max1 <= max2)); |
877 } | 830 } |
878 } | 831 } |
879 } | 832 } |
880 } | 833 } |
881 | 834 |
882 // Constant(V1)->Is(Constant(V2)) iff V1 = V2 | 835 // Constant(V1)->Is(Constant(V2)) iff V1 = V2 |
883 for (ValueIterator vt1 = T.values.begin(); vt1 != T.values.end(); ++vt1) { | 836 for (ValueIterator vt1 = T.values.begin(); vt1 != T.values.end(); ++vt1) { |
884 for (ValueIterator vt2 = T.values.begin(); vt2 != T.values.end(); ++vt2) { | 837 for (ValueIterator vt2 = T.values.begin(); vt2 != T.values.end(); ++vt2) { |
885 Handle<i::Object> value1 = *vt1; | 838 Handle<i::Object> value1 = *vt1; |
886 Handle<i::Object> value2 = *vt2; | 839 Handle<i::Object> value2 = *vt2; |
887 TypeHandle const_type1 = T.Constant(value1); | 840 Type* const_type1 = T.Constant(value1); |
888 TypeHandle const_type2 = T.Constant(value2); | 841 Type* const_type2 = T.Constant(value2); |
889 CHECK(const_type1->Is(const_type2) == (*value1 == *value2)); | 842 CHECK(const_type1->Is(const_type2) == (*value1 == *value2)); |
890 } | 843 } |
891 } | 844 } |
892 | 845 |
893 // Context(T1)->Is(Context(T2)) iff T1 = T2 | 846 // Context(T1)->Is(Context(T2)) iff T1 = T2 |
894 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 847 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
895 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 848 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
896 TypeHandle outer1 = *it1; | 849 Type* outer1 = *it1; |
897 TypeHandle outer2 = *it2; | 850 Type* outer2 = *it2; |
898 TypeHandle type1 = T.Context(outer1); | 851 Type* type1 = T.Context(outer1); |
899 TypeHandle type2 = T.Context(outer2); | 852 Type* type2 = T.Context(outer2); |
900 CHECK(type1->Is(type2) == outer1->Equals(outer2)); | 853 CHECK(type1->Is(type2) == outer1->Equals(outer2)); |
901 } | 854 } |
902 } | 855 } |
903 | 856 |
904 // Array(T1)->Is(Array(T2)) iff T1 = T2 | 857 // Array(T1)->Is(Array(T2)) iff T1 = T2 |
905 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 858 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
906 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 859 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
907 TypeHandle element1 = *it1; | 860 Type* element1 = *it1; |
908 TypeHandle element2 = *it2; | 861 Type* element2 = *it2; |
909 TypeHandle type1 = T.Array1(element1); | 862 Type* type1 = T.Array1(element1); |
910 TypeHandle type2 = T.Array1(element2); | 863 Type* type2 = T.Array1(element2); |
911 CHECK(type1->Is(type2) == element1->Equals(element2)); | 864 CHECK(type1->Is(type2) == element1->Equals(element2)); |
912 } | 865 } |
913 } | 866 } |
914 | 867 |
915 // Function0(S1, T1)->Is(Function0(S2, T2)) iff S1 = S2 and T1 = T2 | 868 // Function0(S1, T1)->Is(Function0(S2, T2)) iff S1 = S2 and T1 = T2 |
916 for (TypeIterator i = T.types.begin(); i != T.types.end(); ++i) { | 869 for (TypeIterator i = T.types.begin(); i != T.types.end(); ++i) { |
917 for (TypeIterator j = T.types.begin(); j != T.types.end(); ++j) { | 870 for (TypeIterator j = T.types.begin(); j != T.types.end(); ++j) { |
918 TypeHandle result1 = *i; | 871 Type* result1 = *i; |
919 TypeHandle receiver1 = *j; | 872 Type* receiver1 = *j; |
920 TypeHandle type1 = T.Function0(result1, receiver1); | 873 Type* type1 = T.Function0(result1, receiver1); |
921 TypeHandle result2 = T.Random(); | 874 Type* result2 = T.Random(); |
922 TypeHandle receiver2 = T.Random(); | 875 Type* receiver2 = T.Random(); |
923 TypeHandle type2 = T.Function0(result2, receiver2); | 876 Type* type2 = T.Function0(result2, receiver2); |
924 CHECK(type1->Is(type2) == | 877 CHECK(type1->Is(type2) == |
925 (result1->Equals(result2) && receiver1->Equals(receiver2))); | 878 (result1->Equals(result2) && receiver1->Equals(receiver2))); |
926 } | 879 } |
927 } | 880 } |
928 | 881 |
929 | 882 |
930 // Range-specific subtyping | 883 // Range-specific subtyping |
931 | 884 |
932 // If IsInteger(v) then Constant(v)->Is(Range(v, v)). | 885 // If IsInteger(v) then Constant(v)->Is(Range(v, v)). |
933 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 886 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
934 TypeHandle type = *it; | 887 Type* type = *it; |
935 if (type->IsConstant() && IsInteger(*type->AsConstant()->Value())) { | 888 if (type->IsConstant() && IsInteger(*type->AsConstant()->Value())) { |
936 CHECK(type->Is(T.Range(type->AsConstant()->Value()->Number(), | 889 CHECK(type->Is(T.Range(type->AsConstant()->Value()->Number(), |
937 type->AsConstant()->Value()->Number()))); | 890 type->AsConstant()->Value()->Number()))); |
938 } | 891 } |
939 } | 892 } |
940 | 893 |
941 // If Constant(x)->Is(Range(min,max)) then IsInteger(v) and min <= x <= max. | 894 // If Constant(x)->Is(Range(min,max)) then IsInteger(v) and min <= x <= max. |
942 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 895 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
943 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 896 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
944 TypeHandle type1 = *it1; | 897 Type* type1 = *it1; |
945 TypeHandle type2 = *it2; | 898 Type* type2 = *it2; |
946 if (type1->IsConstant() && type2->IsRange() && type1->Is(type2)) { | 899 if (type1->IsConstant() && type2->IsRange() && type1->Is(type2)) { |
947 double x = type1->AsConstant()->Value()->Number(); | 900 double x = type1->AsConstant()->Value()->Number(); |
948 double min = type2->AsRange()->Min(); | 901 double min = type2->AsRange()->Min(); |
949 double max = type2->AsRange()->Max(); | 902 double max = type2->AsRange()->Max(); |
950 CHECK(IsInteger(x) && min <= x && x <= max); | 903 CHECK(IsInteger(x) && min <= x && x <= max); |
951 } | 904 } |
952 } | 905 } |
953 } | 906 } |
954 | 907 |
955 // Lub(Range(x,y))->Is(T.Union(T.Integral32, T.OtherNumber)) | 908 // Lub(Range(x,y))->Is(T.Union(T.Integral32, T.OtherNumber)) |
956 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 909 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
957 TypeHandle type = *it; | 910 Type* type = *it; |
958 if (type->IsRange()) { | 911 if (type->IsRange()) { |
959 TypeHandle lub = Rep::BitsetType::New( | 912 Type* lub = BitsetType::NewForTesting(BitsetType::Lub(type)); |
960 Rep::BitsetType::Lub(type), T.region()); | |
961 CHECK(lub->Is(T.PlainNumber)); | 913 CHECK(lub->Is(T.PlainNumber)); |
962 } | 914 } |
963 } | 915 } |
964 | 916 |
965 | 917 |
966 // Subtyping between concrete basic types | 918 // Subtyping between concrete basic types |
967 | 919 |
968 CheckUnordered(T.Boolean, T.Null); | 920 CheckUnordered(T.Boolean, T.Null); |
969 CheckUnordered(T.Undefined, T.Null); | 921 CheckUnordered(T.Undefined, T.Null); |
970 CheckUnordered(T.Boolean, T.Undefined); | 922 CheckUnordered(T.Boolean, T.Undefined); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 | 983 |
1032 CheckSub(T.MethodFunction, T.Object); | 984 CheckSub(T.MethodFunction, T.Object); |
1033 CheckSub(T.NumberFunction1, T.Object); | 985 CheckSub(T.NumberFunction1, T.Object); |
1034 CheckUnordered(T.SignedFunction1, T.NumberFunction1); | 986 CheckUnordered(T.SignedFunction1, T.NumberFunction1); |
1035 CheckUnordered(T.NumberFunction1, T.NumberFunction2); | 987 CheckUnordered(T.NumberFunction1, T.NumberFunction2); |
1036 } | 988 } |
1037 | 989 |
1038 void NowIs() { | 990 void NowIs() { |
1039 // Least Element (Bottom): None->NowIs(T) | 991 // Least Element (Bottom): None->NowIs(T) |
1040 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 992 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
1041 TypeHandle type = *it; | 993 Type* type = *it; |
1042 CHECK(T.None->NowIs(type)); | 994 CHECK(T.None->NowIs(type)); |
1043 } | 995 } |
1044 | 996 |
1045 // Greatest Element (Top): T->NowIs(Any) | 997 // Greatest Element (Top): T->NowIs(Any) |
1046 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 998 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
1047 TypeHandle type = *it; | 999 Type* type = *it; |
1048 CHECK(type->NowIs(T.Any)); | 1000 CHECK(type->NowIs(T.Any)); |
1049 } | 1001 } |
1050 | 1002 |
1051 // Bottom Uniqueness: T->NowIs(None) implies T = None | 1003 // Bottom Uniqueness: T->NowIs(None) implies T = None |
1052 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 1004 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
1053 TypeHandle type = *it; | 1005 Type* type = *it; |
1054 if (type->NowIs(T.None)) CheckEqual(type, T.None); | 1006 if (type->NowIs(T.None)) CheckEqual(type, T.None); |
1055 } | 1007 } |
1056 | 1008 |
1057 // Top Uniqueness: Any->NowIs(T) implies T = Any | 1009 // Top Uniqueness: Any->NowIs(T) implies T = Any |
1058 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 1010 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
1059 TypeHandle type = *it; | 1011 Type* type = *it; |
1060 if (T.Any->NowIs(type)) CheckEqual(type, T.Any); | 1012 if (T.Any->NowIs(type)) CheckEqual(type, T.Any); |
1061 } | 1013 } |
1062 | 1014 |
1063 // Reflexivity: T->NowIs(T) | 1015 // Reflexivity: T->NowIs(T) |
1064 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 1016 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
1065 TypeHandle type = *it; | 1017 Type* type = *it; |
1066 CHECK(type->NowIs(type)); | 1018 CHECK(type->NowIs(type)); |
1067 } | 1019 } |
1068 | 1020 |
1069 // Transitivity: T1->NowIs(T2) and T2->NowIs(T3) implies T1->NowIs(T3) | 1021 // Transitivity: T1->NowIs(T2) and T2->NowIs(T3) implies T1->NowIs(T3) |
1070 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1022 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
1071 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1023 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
1072 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { | 1024 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { |
1073 TypeHandle type1 = *it1; | 1025 Type* type1 = *it1; |
1074 TypeHandle type2 = *it2; | 1026 Type* type2 = *it2; |
1075 TypeHandle type3 = *it3; | 1027 Type* type3 = *it3; |
1076 CHECK(!(type1->NowIs(type2) && type2->NowIs(type3)) || | 1028 CHECK(!(type1->NowIs(type2) && type2->NowIs(type3)) || |
1077 type1->NowIs(type3)); | 1029 type1->NowIs(type3)); |
1078 } | 1030 } |
1079 } | 1031 } |
1080 } | 1032 } |
1081 | 1033 |
1082 // Antisymmetry: T1->NowIs(T2) and T2->NowIs(T1) iff T1 = T2 | 1034 // Antisymmetry: T1->NowIs(T2) and T2->NowIs(T1) iff T1 = T2 |
1083 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1035 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
1084 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1036 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
1085 TypeHandle type1 = *it1; | 1037 Type* type1 = *it1; |
1086 TypeHandle type2 = *it2; | 1038 Type* type2 = *it2; |
1087 CHECK((type1->NowIs(type2) && type2->NowIs(type1)) == | 1039 CHECK((type1->NowIs(type2) && type2->NowIs(type1)) == |
1088 Equal(type1, type2)); | 1040 Equal(type1, type2)); |
1089 } | 1041 } |
1090 } | 1042 } |
1091 | 1043 |
1092 // T1->Is(T2) implies T1->NowIs(T2) | 1044 // T1->Is(T2) implies T1->NowIs(T2) |
1093 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1045 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
1094 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1046 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
1095 TypeHandle type1 = *it1; | 1047 Type* type1 = *it1; |
1096 TypeHandle type2 = *it2; | 1048 Type* type2 = *it2; |
1097 CHECK(!type1->Is(type2) || type1->NowIs(type2)); | 1049 CHECK(!type1->Is(type2) || type1->NowIs(type2)); |
1098 } | 1050 } |
1099 } | 1051 } |
1100 | 1052 |
1101 // Constant(V1)->NowIs(Constant(V2)) iff V1 = V2 | 1053 // Constant(V1)->NowIs(Constant(V2)) iff V1 = V2 |
1102 for (ValueIterator vt1 = T.values.begin(); vt1 != T.values.end(); ++vt1) { | 1054 for (ValueIterator vt1 = T.values.begin(); vt1 != T.values.end(); ++vt1) { |
1103 for (ValueIterator vt2 = T.values.begin(); vt2 != T.values.end(); ++vt2) { | 1055 for (ValueIterator vt2 = T.values.begin(); vt2 != T.values.end(); ++vt2) { |
1104 Handle<i::Object> value1 = *vt1; | 1056 Handle<i::Object> value1 = *vt1; |
1105 Handle<i::Object> value2 = *vt2; | 1057 Handle<i::Object> value2 = *vt2; |
1106 TypeHandle const_type1 = T.Constant(value1); | 1058 Type* const_type1 = T.Constant(value1); |
1107 TypeHandle const_type2 = T.Constant(value2); | 1059 Type* const_type2 = T.Constant(value2); |
1108 CHECK(const_type1->NowIs(const_type2) == (*value1 == *value2)); | 1060 CHECK(const_type1->NowIs(const_type2) == (*value1 == *value2)); |
1109 } | 1061 } |
1110 } | 1062 } |
1111 | 1063 |
1112 // Class(M1)->NowIs(Class(M2)) iff M1 = M2 | 1064 // Class(M1)->NowIs(Class(M2)) iff M1 = M2 |
1113 for (MapIterator mt1 = T.maps.begin(); mt1 != T.maps.end(); ++mt1) { | 1065 for (MapIterator mt1 = T.maps.begin(); mt1 != T.maps.end(); ++mt1) { |
1114 for (MapIterator mt2 = T.maps.begin(); mt2 != T.maps.end(); ++mt2) { | 1066 for (MapIterator mt2 = T.maps.begin(); mt2 != T.maps.end(); ++mt2) { |
1115 Handle<i::Map> map1 = *mt1; | 1067 Handle<i::Map> map1 = *mt1; |
1116 Handle<i::Map> map2 = *mt2; | 1068 Handle<i::Map> map2 = *mt2; |
1117 TypeHandle class_type1 = T.Class(map1); | 1069 Type* class_type1 = T.Class(map1); |
1118 TypeHandle class_type2 = T.Class(map2); | 1070 Type* class_type2 = T.Class(map2); |
1119 CHECK(class_type1->NowIs(class_type2) == (*map1 == *map2)); | 1071 CHECK(class_type1->NowIs(class_type2) == (*map1 == *map2)); |
1120 } | 1072 } |
1121 } | 1073 } |
1122 | 1074 |
1123 // Constant(V)->NowIs(Class(M)) iff V has map M | 1075 // Constant(V)->NowIs(Class(M)) iff V has map M |
1124 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) { | 1076 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) { |
1125 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { | 1077 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { |
1126 Handle<i::Map> map = *mt; | 1078 Handle<i::Map> map = *mt; |
1127 Handle<i::Object> value = *vt; | 1079 Handle<i::Object> value = *vt; |
1128 TypeHandle const_type = T.Constant(value); | 1080 Type* const_type = T.Constant(value); |
1129 TypeHandle class_type = T.Class(map); | 1081 Type* class_type = T.Class(map); |
1130 CHECK((value->IsHeapObject() && | 1082 CHECK((value->IsHeapObject() && |
1131 i::HeapObject::cast(*value)->map() == *map) | 1083 i::HeapObject::cast(*value)->map() == *map) |
1132 == const_type->NowIs(class_type)); | 1084 == const_type->NowIs(class_type)); |
1133 } | 1085 } |
1134 } | 1086 } |
1135 | 1087 |
1136 // Class(M)->NowIs(Constant(V)) never | 1088 // Class(M)->NowIs(Constant(V)) never |
1137 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) { | 1089 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) { |
1138 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { | 1090 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { |
1139 Handle<i::Map> map = *mt; | 1091 Handle<i::Map> map = *mt; |
1140 Handle<i::Object> value = *vt; | 1092 Handle<i::Object> value = *vt; |
1141 TypeHandle const_type = T.Constant(value); | 1093 Type* const_type = T.Constant(value); |
1142 TypeHandle class_type = T.Class(map); | 1094 Type* class_type = T.Class(map); |
1143 CHECK(!class_type->NowIs(const_type)); | 1095 CHECK(!class_type->NowIs(const_type)); |
1144 } | 1096 } |
1145 } | 1097 } |
1146 } | 1098 } |
1147 | 1099 |
1148 void Contains() { | 1100 void Contains() { |
1149 // T->Contains(V) iff Constant(V)->Is(T) | 1101 // T->Contains(V) iff Constant(V)->Is(T) |
1150 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 1102 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
1151 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { | 1103 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { |
1152 TypeHandle type = *it; | 1104 Type* type = *it; |
1153 Handle<i::Object> value = *vt; | 1105 Handle<i::Object> value = *vt; |
1154 TypeHandle const_type = T.Constant(value); | 1106 Type* const_type = T.Constant(value); |
1155 CHECK(type->Contains(value) == const_type->Is(type)); | 1107 CHECK(type->Contains(value) == const_type->Is(type)); |
1156 } | 1108 } |
1157 } | 1109 } |
1158 } | 1110 } |
1159 | 1111 |
1160 void NowContains() { | 1112 void NowContains() { |
1161 // T->NowContains(V) iff Constant(V)->NowIs(T) | 1113 // T->NowContains(V) iff Constant(V)->NowIs(T) |
1162 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 1114 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
1163 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { | 1115 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { |
1164 TypeHandle type = *it; | 1116 Type* type = *it; |
1165 Handle<i::Object> value = *vt; | 1117 Handle<i::Object> value = *vt; |
1166 TypeHandle const_type = T.Constant(value); | 1118 Type* const_type = T.Constant(value); |
1167 CHECK(type->NowContains(value) == const_type->NowIs(type)); | 1119 CHECK(type->NowContains(value) == const_type->NowIs(type)); |
1168 } | 1120 } |
1169 } | 1121 } |
1170 | 1122 |
1171 // T->Contains(V) implies T->NowContains(V) | 1123 // T->Contains(V) implies T->NowContains(V) |
1172 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 1124 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
1173 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { | 1125 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { |
1174 TypeHandle type = *it; | 1126 Type* type = *it; |
1175 Handle<i::Object> value = *vt; | 1127 Handle<i::Object> value = *vt; |
1176 CHECK(!type->Contains(value) || type->NowContains(value)); | 1128 CHECK(!type->Contains(value) || type->NowContains(value)); |
1177 } | 1129 } |
1178 } | 1130 } |
1179 | 1131 |
1180 // NowOf(V)->Is(T) implies T->NowContains(V) | 1132 // NowOf(V)->Is(T) implies T->NowContains(V) |
1181 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 1133 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
1182 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { | 1134 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { |
1183 TypeHandle type = *it; | 1135 Type* type = *it; |
1184 Handle<i::Object> value = *vt; | 1136 Handle<i::Object> value = *vt; |
1185 TypeHandle nowof_type = T.Of(value); | 1137 Type* nowof_type = T.Of(value); |
1186 CHECK(!nowof_type->NowIs(type) || type->NowContains(value)); | 1138 CHECK(!nowof_type->NowIs(type) || type->NowContains(value)); |
1187 } | 1139 } |
1188 } | 1140 } |
1189 } | 1141 } |
1190 | 1142 |
1191 void Maybe() { | 1143 void Maybe() { |
1192 // T->Maybe(Any) iff T inhabited | 1144 // T->Maybe(Any) iff T inhabited |
1193 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 1145 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
1194 TypeHandle type = *it; | 1146 Type* type = *it; |
1195 CHECK(type->Maybe(T.Any) == type->IsInhabited()); | 1147 CHECK(type->Maybe(T.Any) == type->IsInhabited()); |
1196 } | 1148 } |
1197 | 1149 |
1198 // T->Maybe(None) never | 1150 // T->Maybe(None) never |
1199 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 1151 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
1200 TypeHandle type = *it; | 1152 Type* type = *it; |
1201 CHECK(!type->Maybe(T.None)); | 1153 CHECK(!type->Maybe(T.None)); |
1202 } | 1154 } |
1203 | 1155 |
1204 // Reflexivity upto Inhabitation: T->Maybe(T) iff T inhabited | 1156 // Reflexivity upto Inhabitation: T->Maybe(T) iff T inhabited |
1205 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 1157 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
1206 TypeHandle type = *it; | 1158 Type* type = *it; |
1207 CHECK(type->Maybe(type) == type->IsInhabited()); | 1159 CHECK(type->Maybe(type) == type->IsInhabited()); |
1208 } | 1160 } |
1209 | 1161 |
1210 // Symmetry: T1->Maybe(T2) iff T2->Maybe(T1) | 1162 // Symmetry: T1->Maybe(T2) iff T2->Maybe(T1) |
1211 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1163 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
1212 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1164 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
1213 TypeHandle type1 = *it1; | 1165 Type* type1 = *it1; |
1214 TypeHandle type2 = *it2; | 1166 Type* type2 = *it2; |
1215 CHECK(type1->Maybe(type2) == type2->Maybe(type1)); | 1167 CHECK(type1->Maybe(type2) == type2->Maybe(type1)); |
1216 } | 1168 } |
1217 } | 1169 } |
1218 | 1170 |
1219 // T1->Maybe(T2) implies T1, T2 inhabited | 1171 // T1->Maybe(T2) implies T1, T2 inhabited |
1220 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1172 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
1221 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1173 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
1222 TypeHandle type1 = *it1; | 1174 Type* type1 = *it1; |
1223 TypeHandle type2 = *it2; | 1175 Type* type2 = *it2; |
1224 CHECK(!type1->Maybe(type2) || | 1176 CHECK(!type1->Maybe(type2) || |
1225 (type1->IsInhabited() && type2->IsInhabited())); | 1177 (type1->IsInhabited() && type2->IsInhabited())); |
1226 } | 1178 } |
1227 } | 1179 } |
1228 | 1180 |
1229 // T1->Maybe(T2) implies Intersect(T1, T2) inhabited | 1181 // T1->Maybe(T2) implies Intersect(T1, T2) inhabited |
1230 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1182 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
1231 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1183 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
1232 TypeHandle type1 = *it1; | 1184 Type* type1 = *it1; |
1233 TypeHandle type2 = *it2; | 1185 Type* type2 = *it2; |
1234 TypeHandle intersect12 = T.Intersect(type1, type2); | 1186 Type* intersect12 = T.Intersect(type1, type2); |
1235 CHECK(!type1->Maybe(type2) || intersect12->IsInhabited()); | 1187 CHECK(!type1->Maybe(type2) || intersect12->IsInhabited()); |
1236 } | 1188 } |
1237 } | 1189 } |
1238 | 1190 |
1239 // T1->Is(T2) and T1 inhabited implies T1->Maybe(T2) | 1191 // T1->Is(T2) and T1 inhabited implies T1->Maybe(T2) |
1240 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1192 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
1241 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1193 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
1242 TypeHandle type1 = *it1; | 1194 Type* type1 = *it1; |
1243 TypeHandle type2 = *it2; | 1195 Type* type2 = *it2; |
1244 CHECK(!(type1->Is(type2) && type1->IsInhabited()) || | 1196 CHECK(!(type1->Is(type2) && type1->IsInhabited()) || |
1245 type1->Maybe(type2)); | 1197 type1->Maybe(type2)); |
1246 } | 1198 } |
1247 } | 1199 } |
1248 | 1200 |
1249 // Constant(V1)->Maybe(Constant(V2)) iff V1 = V2 | 1201 // Constant(V1)->Maybe(Constant(V2)) iff V1 = V2 |
1250 for (ValueIterator vt1 = T.values.begin(); vt1 != T.values.end(); ++vt1) { | 1202 for (ValueIterator vt1 = T.values.begin(); vt1 != T.values.end(); ++vt1) { |
1251 for (ValueIterator vt2 = T.values.begin(); vt2 != T.values.end(); ++vt2) { | 1203 for (ValueIterator vt2 = T.values.begin(); vt2 != T.values.end(); ++vt2) { |
1252 Handle<i::Object> value1 = *vt1; | 1204 Handle<i::Object> value1 = *vt1; |
1253 Handle<i::Object> value2 = *vt2; | 1205 Handle<i::Object> value2 = *vt2; |
1254 TypeHandle const_type1 = T.Constant(value1); | 1206 Type* const_type1 = T.Constant(value1); |
1255 TypeHandle const_type2 = T.Constant(value2); | 1207 Type* const_type2 = T.Constant(value2); |
1256 CHECK(const_type1->Maybe(const_type2) == (*value1 == *value2)); | 1208 CHECK(const_type1->Maybe(const_type2) == (*value1 == *value2)); |
1257 } | 1209 } |
1258 } | 1210 } |
1259 | 1211 |
1260 // Class(M1)->Maybe(Class(M2)) iff M1 = M2 | 1212 // Class(M1)->Maybe(Class(M2)) iff M1 = M2 |
1261 for (MapIterator mt1 = T.maps.begin(); mt1 != T.maps.end(); ++mt1) { | 1213 for (MapIterator mt1 = T.maps.begin(); mt1 != T.maps.end(); ++mt1) { |
1262 for (MapIterator mt2 = T.maps.begin(); mt2 != T.maps.end(); ++mt2) { | 1214 for (MapIterator mt2 = T.maps.begin(); mt2 != T.maps.end(); ++mt2) { |
1263 Handle<i::Map> map1 = *mt1; | 1215 Handle<i::Map> map1 = *mt1; |
1264 Handle<i::Map> map2 = *mt2; | 1216 Handle<i::Map> map2 = *mt2; |
1265 TypeHandle class_type1 = T.Class(map1); | 1217 Type* class_type1 = T.Class(map1); |
1266 TypeHandle class_type2 = T.Class(map2); | 1218 Type* class_type2 = T.Class(map2); |
1267 CHECK(class_type1->Maybe(class_type2) == (*map1 == *map2)); | 1219 CHECK(class_type1->Maybe(class_type2) == (*map1 == *map2)); |
1268 } | 1220 } |
1269 } | 1221 } |
1270 | 1222 |
1271 // Constant(V)->Maybe(Class(M)) never | 1223 // Constant(V)->Maybe(Class(M)) never |
1272 // This does NOT hold! | 1224 // This does NOT hold! |
1273 /* | 1225 /* |
1274 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) { | 1226 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) { |
1275 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { | 1227 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { |
1276 Handle<i::Map> map = *mt; | 1228 Handle<i::Map> map = *mt; |
1277 Handle<i::Object> value = *vt; | 1229 Handle<i::Object> value = *vt; |
1278 TypeHandle const_type = T.Constant(value); | 1230 Type* const_type = T.Constant(value); |
1279 TypeHandle class_type = T.Class(map); | 1231 Type* class_type = T.Class(map); |
1280 CHECK(!const_type->Maybe(class_type)); | 1232 CHECK(!const_type->Maybe(class_type)); |
1281 } | 1233 } |
1282 } | 1234 } |
1283 */ | 1235 */ |
1284 | 1236 |
1285 // Class(M)->Maybe(Constant(V)) never | 1237 // Class(M)->Maybe(Constant(V)) never |
1286 // This does NOT hold! | 1238 // This does NOT hold! |
1287 /* | 1239 /* |
1288 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) { | 1240 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) { |
1289 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { | 1241 for (ValueIterator vt = T.values.begin(); vt != T.values.end(); ++vt) { |
1290 Handle<i::Map> map = *mt; | 1242 Handle<i::Map> map = *mt; |
1291 Handle<i::Object> value = *vt; | 1243 Handle<i::Object> value = *vt; |
1292 TypeHandle const_type = T.Constant(value); | 1244 Type* const_type = T.Constant(value); |
1293 TypeHandle class_type = T.Class(map); | 1245 Type* class_type = T.Class(map); |
1294 CHECK(!class_type->Maybe(const_type)); | 1246 CHECK(!class_type->Maybe(const_type)); |
1295 } | 1247 } |
1296 } | 1248 } |
1297 */ | 1249 */ |
1298 | 1250 |
1299 // Basic types | 1251 // Basic types |
1300 CheckDisjoint(T.Boolean, T.Null); | 1252 CheckDisjoint(T.Boolean, T.Null); |
1301 CheckDisjoint(T.Undefined, T.Null); | 1253 CheckDisjoint(T.Undefined, T.Null); |
1302 CheckDisjoint(T.Boolean, T.Undefined); | 1254 CheckDisjoint(T.Boolean, T.Undefined); |
1303 CheckOverlap(T.SignedSmall, T.Number); | 1255 CheckOverlap(T.SignedSmall, T.Number); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1346 CheckDisjoint(T.NumberFunction1, T.NumberFunction2); | 1298 CheckDisjoint(T.NumberFunction1, T.NumberFunction2); |
1347 CheckDisjoint(T.SignedFunction1, T.MethodFunction); | 1299 CheckDisjoint(T.SignedFunction1, T.MethodFunction); |
1348 CheckOverlap(T.ObjectConstant1, T.ObjectClass); // !!! | 1300 CheckOverlap(T.ObjectConstant1, T.ObjectClass); // !!! |
1349 CheckOverlap(T.ObjectConstant2, T.ObjectClass); // !!! | 1301 CheckOverlap(T.ObjectConstant2, T.ObjectClass); // !!! |
1350 CheckOverlap(T.NumberClass, T.Intersect(T.Number, T.Tagged)); // !!! | 1302 CheckOverlap(T.NumberClass, T.Intersect(T.Number, T.Tagged)); // !!! |
1351 } | 1303 } |
1352 | 1304 |
1353 void Union1() { | 1305 void Union1() { |
1354 // Identity: Union(T, None) = T | 1306 // Identity: Union(T, None) = T |
1355 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 1307 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
1356 TypeHandle type = *it; | 1308 Type* type = *it; |
1357 TypeHandle union_type = T.Union(type, T.None); | 1309 Type* union_type = T.Union(type, T.None); |
1358 CheckEqual(union_type, type); | 1310 CheckEqual(union_type, type); |
1359 } | 1311 } |
1360 | 1312 |
1361 // Domination: Union(T, Any) = Any | 1313 // Domination: Union(T, Any) = Any |
1362 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 1314 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
1363 TypeHandle type = *it; | 1315 Type* type = *it; |
1364 TypeHandle union_type = T.Union(type, T.Any); | 1316 Type* union_type = T.Union(type, T.Any); |
1365 CheckEqual(union_type, T.Any); | 1317 CheckEqual(union_type, T.Any); |
1366 } | 1318 } |
1367 | 1319 |
1368 // Idempotence: Union(T, T) = T | 1320 // Idempotence: Union(T, T) = T |
1369 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 1321 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
1370 TypeHandle type = *it; | 1322 Type* type = *it; |
1371 TypeHandle union_type = T.Union(type, type); | 1323 Type* union_type = T.Union(type, type); |
1372 CheckEqual(union_type, type); | 1324 CheckEqual(union_type, type); |
1373 } | 1325 } |
1374 | 1326 |
1375 // Commutativity: Union(T1, T2) = Union(T2, T1) | 1327 // Commutativity: Union(T1, T2) = Union(T2, T1) |
1376 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1328 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
1377 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1329 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
1378 TypeHandle type1 = *it1; | 1330 Type* type1 = *it1; |
1379 TypeHandle type2 = *it2; | 1331 Type* type2 = *it2; |
1380 TypeHandle union12 = T.Union(type1, type2); | 1332 Type* union12 = T.Union(type1, type2); |
1381 TypeHandle union21 = T.Union(type2, type1); | 1333 Type* union21 = T.Union(type2, type1); |
1382 CheckEqual(union12, union21); | 1334 CheckEqual(union12, union21); |
1383 } | 1335 } |
1384 } | 1336 } |
1385 | 1337 |
1386 // Associativity: Union(T1, Union(T2, T3)) = Union(Union(T1, T2), T3) | 1338 // Associativity: Union(T1, Union(T2, T3)) = Union(Union(T1, T2), T3) |
1387 // This does NOT hold! For example: | 1339 // This does NOT hold! For example: |
1388 // (Unsigned32 \/ Range(0,5)) \/ Range(-5,0) = Unsigned32 \/ Range(-5,0) | 1340 // (Unsigned32 \/ Range(0,5)) \/ Range(-5,0) = Unsigned32 \/ Range(-5,0) |
1389 // Unsigned32 \/ (Range(0,5) \/ Range(-5,0)) = Unsigned32 \/ Range(-5,5) | 1341 // Unsigned32 \/ (Range(0,5) \/ Range(-5,0)) = Unsigned32 \/ Range(-5,5) |
1390 /* | 1342 /* |
1391 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1343 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
1392 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1344 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
1393 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { | 1345 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { |
1394 TypeHandle type1 = *it1; | 1346 Type* type1 = *it1; |
1395 TypeHandle type2 = *it2; | 1347 Type* type2 = *it2; |
1396 TypeHandle type3 = *it3; | 1348 Type* type3 = *it3; |
1397 TypeHandle union12 = T.Union(type1, type2); | 1349 Type* union12 = T.Union(type1, type2); |
1398 TypeHandle union23 = T.Union(type2, type3); | 1350 Type* union23 = T.Union(type2, type3); |
1399 TypeHandle union1_23 = T.Union(type1, union23); | 1351 Type* union1_23 = T.Union(type1, union23); |
1400 TypeHandle union12_3 = T.Union(union12, type3); | 1352 Type* union12_3 = T.Union(union12, type3); |
1401 CheckEqual(union1_23, union12_3); | 1353 CheckEqual(union1_23, union12_3); |
1402 } | 1354 } |
1403 } | 1355 } |
1404 } | 1356 } |
1405 */ | 1357 */ |
1406 | 1358 |
1407 // Meet: T1->Is(Union(T1, T2)) and T2->Is(Union(T1, T2)) | 1359 // Meet: T1->Is(Union(T1, T2)) and T2->Is(Union(T1, T2)) |
1408 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1360 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
1409 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1361 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
1410 TypeHandle type1 = *it1; | 1362 Type* type1 = *it1; |
1411 TypeHandle type2 = *it2; | 1363 Type* type2 = *it2; |
1412 TypeHandle union12 = T.Union(type1, type2); | 1364 Type* union12 = T.Union(type1, type2); |
1413 CHECK(type1->Is(union12)); | 1365 CHECK(type1->Is(union12)); |
1414 CHECK(type2->Is(union12)); | 1366 CHECK(type2->Is(union12)); |
1415 } | 1367 } |
1416 } | 1368 } |
1417 | 1369 |
1418 // Upper Boundedness: T1->Is(T2) implies Union(T1, T2) = T2 | 1370 // Upper Boundedness: T1->Is(T2) implies Union(T1, T2) = T2 |
1419 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1371 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
1420 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1372 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
1421 TypeHandle type1 = *it1; | 1373 Type* type1 = *it1; |
1422 TypeHandle type2 = *it2; | 1374 Type* type2 = *it2; |
1423 TypeHandle union12 = T.Union(type1, type2); | 1375 Type* union12 = T.Union(type1, type2); |
1424 if (type1->Is(type2)) CheckEqual(union12, type2); | 1376 if (type1->Is(type2)) CheckEqual(union12, type2); |
1425 } | 1377 } |
1426 } | 1378 } |
1427 | 1379 |
1428 // Monotonicity: T1->Is(T2) implies Union(T1, T3)->Is(Union(T2, T3)) | 1380 // Monotonicity: T1->Is(T2) implies Union(T1, T3)->Is(Union(T2, T3)) |
1429 // This does NOT hold. For example: | 1381 // This does NOT hold. For example: |
1430 // Range(-5,-1) <= Signed32 | 1382 // Range(-5,-1) <= Signed32 |
1431 // Range(-5,-1) \/ Range(1,5) = Range(-5,5) </= Signed32 \/ Range(1,5) | 1383 // Range(-5,-1) \/ Range(1,5) = Range(-5,5) </= Signed32 \/ Range(1,5) |
1432 /* | 1384 /* |
1433 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1385 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
1434 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1386 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
1435 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { | 1387 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { |
1436 TypeHandle type1 = *it1; | 1388 Type* type1 = *it1; |
1437 TypeHandle type2 = *it2; | 1389 Type* type2 = *it2; |
1438 TypeHandle type3 = *it3; | 1390 Type* type3 = *it3; |
1439 TypeHandle union13 = T.Union(type1, type3); | 1391 Type* union13 = T.Union(type1, type3); |
1440 TypeHandle union23 = T.Union(type2, type3); | 1392 Type* union23 = T.Union(type2, type3); |
1441 CHECK(!type1->Is(type2) || union13->Is(union23)); | 1393 CHECK(!type1->Is(type2) || union13->Is(union23)); |
1442 } | 1394 } |
1443 } | 1395 } |
1444 } | 1396 } |
1445 */ | 1397 */ |
1446 } | 1398 } |
1447 | 1399 |
1448 void Union2() { | 1400 void Union2() { |
1449 // Monotonicity: T1->Is(T3) and T2->Is(T3) implies Union(T1, T2)->Is(T3) | 1401 // Monotonicity: T1->Is(T3) and T2->Is(T3) implies Union(T1, T2)->Is(T3) |
1450 // This does NOT hold. For example: | 1402 // This does NOT hold. For example: |
1451 // Range(-2^33, -2^33) <= OtherNumber | 1403 // Range(-2^33, -2^33) <= OtherNumber |
1452 // Range(2^33, 2^33) <= OtherNumber | 1404 // Range(2^33, 2^33) <= OtherNumber |
1453 // Range(-2^33, 2^33) </= OtherNumber | 1405 // Range(-2^33, 2^33) </= OtherNumber |
1454 /* | 1406 /* |
1455 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1407 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
1456 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1408 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
1457 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { | 1409 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { |
1458 TypeHandle type1 = *it1; | 1410 Type* type1 = *it1; |
1459 TypeHandle type2 = *it2; | 1411 Type* type2 = *it2; |
1460 TypeHandle type3 = *it3; | 1412 Type* type3 = *it3; |
1461 TypeHandle union12 = T.Union(type1, type2); | 1413 Type* union12 = T.Union(type1, type2); |
1462 CHECK(!(type1->Is(type3) && type2->Is(type3)) || union12->Is(type3)); | 1414 CHECK(!(type1->Is(type3) && type2->Is(type3)) || union12->Is(type3)); |
1463 } | 1415 } |
1464 } | 1416 } |
1465 } | 1417 } |
1466 */ | 1418 */ |
1467 } | 1419 } |
1468 | 1420 |
1469 void Union3() { | 1421 void Union3() { |
1470 // Monotonicity: T1->Is(T2) or T1->Is(T3) implies T1->Is(Union(T2, T3)) | 1422 // Monotonicity: T1->Is(T2) or T1->Is(T3) implies T1->Is(Union(T2, T3)) |
1471 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1423 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
1472 HandleScope scope(isolate); | 1424 HandleScope scope(isolate); |
1473 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1425 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
1474 for (TypeIterator it3 = it2; it3 != T.types.end(); ++it3) { | 1426 for (TypeIterator it3 = it2; it3 != T.types.end(); ++it3) { |
1475 TypeHandle type1 = *it1; | 1427 Type* type1 = *it1; |
1476 TypeHandle type2 = *it2; | 1428 Type* type2 = *it2; |
1477 TypeHandle type3 = *it3; | 1429 Type* type3 = *it3; |
1478 TypeHandle union23 = T.Union(type2, type3); | 1430 Type* union23 = T.Union(type2, type3); |
1479 CHECK(!(type1->Is(type2) || type1->Is(type3)) || type1->Is(union23)); | 1431 CHECK(!(type1->Is(type2) || type1->Is(type3)) || type1->Is(union23)); |
1480 } | 1432 } |
1481 } | 1433 } |
1482 } | 1434 } |
1483 } | 1435 } |
1484 | 1436 |
1485 void Union4() { | 1437 void Union4() { |
1486 // Class-class | 1438 // Class-class |
1487 CheckSub(T.Union(T.ObjectClass, T.ArrayClass), T.Object); | 1439 CheckSub(T.Union(T.ObjectClass, T.ArrayClass), T.Object); |
1488 CheckOverlap(T.Union(T.ObjectClass, T.ArrayClass), T.OtherObject); | 1440 CheckOverlap(T.Union(T.ObjectClass, T.ArrayClass), T.OtherObject); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1591 T.Union(T.ObjectConstant1, T.ObjectConstant2)), | 1543 T.Union(T.ObjectConstant1, T.ObjectConstant2)), |
1592 T.Union(T.ObjectConstant2, T.ObjectConstant1)); | 1544 T.Union(T.ObjectConstant2, T.ObjectConstant1)); |
1593 CheckEqual(T.Union(T.Union(T.Number, T.ArrayClass), | 1545 CheckEqual(T.Union(T.Union(T.Number, T.ArrayClass), |
1594 T.Union(T.SignedSmall, T.Receiver)), | 1546 T.Union(T.SignedSmall, T.Receiver)), |
1595 T.Union(T.Number, T.Receiver)); | 1547 T.Union(T.Number, T.Receiver)); |
1596 } | 1548 } |
1597 | 1549 |
1598 void Intersect() { | 1550 void Intersect() { |
1599 // Identity: Intersect(T, Any) = T | 1551 // Identity: Intersect(T, Any) = T |
1600 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 1552 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
1601 TypeHandle type = *it; | 1553 Type* type = *it; |
1602 TypeHandle intersect_type = T.Intersect(type, T.Any); | 1554 Type* intersect_type = T.Intersect(type, T.Any); |
1603 CheckEqual(intersect_type, type); | 1555 CheckEqual(intersect_type, type); |
1604 } | 1556 } |
1605 | 1557 |
1606 // Domination: Intersect(T, None) = None | 1558 // Domination: Intersect(T, None) = None |
1607 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 1559 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
1608 TypeHandle type = *it; | 1560 Type* type = *it; |
1609 TypeHandle intersect_type = T.Intersect(type, T.None); | 1561 Type* intersect_type = T.Intersect(type, T.None); |
1610 CheckEqual(intersect_type, T.None); | 1562 CheckEqual(intersect_type, T.None); |
1611 } | 1563 } |
1612 | 1564 |
1613 // Idempotence: Intersect(T, T) = T | 1565 // Idempotence: Intersect(T, T) = T |
1614 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | 1566 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
1615 TypeHandle type = *it; | 1567 Type* type = *it; |
1616 TypeHandle intersect_type = T.Intersect(type, type); | 1568 Type* intersect_type = T.Intersect(type, type); |
1617 CheckEqual(intersect_type, type); | 1569 CheckEqual(intersect_type, type); |
1618 } | 1570 } |
1619 | 1571 |
1620 // Commutativity: Intersect(T1, T2) = Intersect(T2, T1) | 1572 // Commutativity: Intersect(T1, T2) = Intersect(T2, T1) |
1621 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1573 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
1622 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1574 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
1623 TypeHandle type1 = *it1; | 1575 Type* type1 = *it1; |
1624 TypeHandle type2 = *it2; | 1576 Type* type2 = *it2; |
1625 TypeHandle intersect12 = T.Intersect(type1, type2); | 1577 Type* intersect12 = T.Intersect(type1, type2); |
1626 TypeHandle intersect21 = T.Intersect(type2, type1); | 1578 Type* intersect21 = T.Intersect(type2, type1); |
1627 CheckEqual(intersect12, intersect21); | 1579 CheckEqual(intersect12, intersect21); |
1628 } | 1580 } |
1629 } | 1581 } |
1630 | 1582 |
1631 // Associativity: | 1583 // Associativity: |
1632 // Intersect(T1, Intersect(T2, T3)) = Intersect(Intersect(T1, T2), T3) | 1584 // Intersect(T1, Intersect(T2, T3)) = Intersect(Intersect(T1, T2), T3) |
1633 // This does NOT hold. For example: | 1585 // This does NOT hold. For example: |
1634 // (Class(..stringy1..) /\ Class(..stringy2..)) /\ Constant(..string..) = | 1586 // (Class(..stringy1..) /\ Class(..stringy2..)) /\ Constant(..string..) = |
1635 // None | 1587 // None |
1636 // Class(..stringy1..) /\ (Class(..stringy2..) /\ Constant(..string..)) = | 1588 // Class(..stringy1..) /\ (Class(..stringy2..) /\ Constant(..string..)) = |
1637 // Constant(..string..) | 1589 // Constant(..string..) |
1638 /* | 1590 /* |
1639 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1591 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
1640 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1592 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
1641 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { | 1593 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { |
1642 TypeHandle type1 = *it1; | 1594 Type* type1 = *it1; |
1643 TypeHandle type2 = *it2; | 1595 Type* type2 = *it2; |
1644 TypeHandle type3 = *it3; | 1596 Type* type3 = *it3; |
1645 TypeHandle intersect12 = T.Intersect(type1, type2); | 1597 Type* intersect12 = T.Intersect(type1, type2); |
1646 TypeHandle intersect23 = T.Intersect(type2, type3); | 1598 Type* intersect23 = T.Intersect(type2, type3); |
1647 TypeHandle intersect1_23 = T.Intersect(type1, intersect23); | 1599 Type* intersect1_23 = T.Intersect(type1, intersect23); |
1648 TypeHandle intersect12_3 = T.Intersect(intersect12, type3); | 1600 Type* intersect12_3 = T.Intersect(intersect12, type3); |
1649 CheckEqual(intersect1_23, intersect12_3); | 1601 CheckEqual(intersect1_23, intersect12_3); |
1650 } | 1602 } |
1651 } | 1603 } |
1652 } | 1604 } |
1653 */ | 1605 */ |
1654 | 1606 |
1655 // Join: Intersect(T1, T2)->Is(T1) and Intersect(T1, T2)->Is(T2) | 1607 // Join: Intersect(T1, T2)->Is(T1) and Intersect(T1, T2)->Is(T2) |
1656 // This does NOT hold. For example: | 1608 // This does NOT hold. For example: |
1657 // Class(..stringy..) /\ Constant(..string..) = Constant(..string..) | 1609 // Class(..stringy..) /\ Constant(..string..) = Constant(..string..) |
1658 // Currently, not even the disjunction holds: | 1610 // Currently, not even the disjunction holds: |
1659 // Class(Internal/TaggedPtr) /\ (Any/Untagged \/ Context(..)) = | 1611 // Class(Internal/TaggedPtr) /\ (Any/Untagged \/ Context(..)) = |
1660 // Class(Internal/TaggedPtr) \/ Context(..) | 1612 // Class(Internal/TaggedPtr) \/ Context(..) |
1661 /* | 1613 /* |
1662 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1614 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
1663 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1615 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
1664 TypeHandle type1 = *it1; | 1616 Type* type1 = *it1; |
1665 TypeHandle type2 = *it2; | 1617 Type* type2 = *it2; |
1666 TypeHandle intersect12 = T.Intersect(type1, type2); | 1618 Type* intersect12 = T.Intersect(type1, type2); |
1667 CHECK(intersect12->Is(type1)); | 1619 CHECK(intersect12->Is(type1)); |
1668 CHECK(intersect12->Is(type2)); | 1620 CHECK(intersect12->Is(type2)); |
1669 } | 1621 } |
1670 } | 1622 } |
1671 */ | 1623 */ |
1672 | 1624 |
1673 // Lower Boundedness: T1->Is(T2) implies Intersect(T1, T2) = T1 | 1625 // Lower Boundedness: T1->Is(T2) implies Intersect(T1, T2) = T1 |
1674 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1626 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
1675 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1627 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
1676 TypeHandle type1 = *it1; | 1628 Type* type1 = *it1; |
1677 TypeHandle type2 = *it2; | 1629 Type* type2 = *it2; |
1678 TypeHandle intersect12 = T.Intersect(type1, type2); | 1630 Type* intersect12 = T.Intersect(type1, type2); |
1679 if (type1->Is(type2)) CheckEqual(intersect12, type1); | 1631 if (type1->Is(type2)) CheckEqual(intersect12, type1); |
1680 } | 1632 } |
1681 } | 1633 } |
1682 | 1634 |
1683 // Monotonicity: T1->Is(T2) implies Intersect(T1, T3)->Is(Intersect(T2, T3)) | 1635 // Monotonicity: T1->Is(T2) implies Intersect(T1, T3)->Is(Intersect(T2, T3)) |
1684 // This does NOT hold. For example: | 1636 // This does NOT hold. For example: |
1685 // Class(OtherObject/TaggedPtr) <= Any/TaggedPtr | 1637 // Class(OtherObject/TaggedPtr) <= Any/TaggedPtr |
1686 // Class(OtherObject/TaggedPtr) /\ Any/UntaggedInt1 = Class(..) | 1638 // Class(OtherObject/TaggedPtr) /\ Any/UntaggedInt1 = Class(..) |
1687 // Any/TaggedPtr /\ Any/UntaggedInt1 = None | 1639 // Any/TaggedPtr /\ Any/UntaggedInt1 = None |
1688 /* | 1640 /* |
1689 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1641 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
1690 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1642 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
1691 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { | 1643 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { |
1692 TypeHandle type1 = *it1; | 1644 Type* type1 = *it1; |
1693 TypeHandle type2 = *it2; | 1645 Type* type2 = *it2; |
1694 TypeHandle type3 = *it3; | 1646 Type* type3 = *it3; |
1695 TypeHandle intersect13 = T.Intersect(type1, type3); | 1647 Type* intersect13 = T.Intersect(type1, type3); |
1696 TypeHandle intersect23 = T.Intersect(type2, type3); | 1648 Type* intersect23 = T.Intersect(type2, type3); |
1697 CHECK(!type1->Is(type2) || intersect13->Is(intersect23)); | 1649 CHECK(!type1->Is(type2) || intersect13->Is(intersect23)); |
1698 } | 1650 } |
1699 } | 1651 } |
1700 } | 1652 } |
1701 */ | 1653 */ |
1702 | 1654 |
1703 // Monotonicity: T1->Is(T3) or T2->Is(T3) implies Intersect(T1, T2)->Is(T3) | 1655 // Monotonicity: T1->Is(T3) or T2->Is(T3) implies Intersect(T1, T2)->Is(T3) |
1704 // This does NOT hold. For example: | 1656 // This does NOT hold. For example: |
1705 // Class(..stringy..) <= Class(..stringy..) | 1657 // Class(..stringy..) <= Class(..stringy..) |
1706 // Class(..stringy..) /\ Constant(..string..) = Constant(..string..) | 1658 // Class(..stringy..) /\ Constant(..string..) = Constant(..string..) |
1707 // Constant(..string..) </= Class(..stringy..) | 1659 // Constant(..string..) </= Class(..stringy..) |
1708 /* | 1660 /* |
1709 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1661 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
1710 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1662 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
1711 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { | 1663 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { |
1712 TypeHandle type1 = *it1; | 1664 Type* type1 = *it1; |
1713 TypeHandle type2 = *it2; | 1665 Type* type2 = *it2; |
1714 TypeHandle type3 = *it3; | 1666 Type* type3 = *it3; |
1715 TypeHandle intersect12 = T.Intersect(type1, type2); | 1667 Type* intersect12 = T.Intersect(type1, type2); |
1716 CHECK(!(type1->Is(type3) || type2->Is(type3)) || | 1668 CHECK(!(type1->Is(type3) || type2->Is(type3)) || |
1717 intersect12->Is(type3)); | 1669 intersect12->Is(type3)); |
1718 } | 1670 } |
1719 } | 1671 } |
1720 } | 1672 } |
1721 */ | 1673 */ |
1722 | 1674 |
1723 // Monotonicity: T1->Is(T2) and T1->Is(T3) implies T1->Is(Intersect(T2, T3)) | 1675 // Monotonicity: T1->Is(T2) and T1->Is(T3) implies T1->Is(Intersect(T2, T3)) |
1724 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1676 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
1725 HandleScope scope(isolate); | 1677 HandleScope scope(isolate); |
1726 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1678 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
1727 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { | 1679 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { |
1728 TypeHandle type1 = *it1; | 1680 Type* type1 = *it1; |
1729 TypeHandle type2 = *it2; | 1681 Type* type2 = *it2; |
1730 TypeHandle type3 = *it3; | 1682 Type* type3 = *it3; |
1731 TypeHandle intersect23 = T.Intersect(type2, type3); | 1683 Type* intersect23 = T.Intersect(type2, type3); |
1732 CHECK(!(type1->Is(type2) && type1->Is(type3)) || | 1684 CHECK(!(type1->Is(type2) && type1->Is(type3)) || |
1733 type1->Is(intersect23)); | 1685 type1->Is(intersect23)); |
1734 } | 1686 } |
1735 } | 1687 } |
1736 } | 1688 } |
1737 | 1689 |
1738 // Bitset-class | 1690 // Bitset-class |
1739 CheckEqual(T.Intersect(T.ObjectClass, T.Object), T.ObjectClass); | 1691 CheckEqual(T.Intersect(T.ObjectClass, T.Object), T.ObjectClass); |
1740 CheckEqual(T.Semantic(T.Intersect(T.ObjectClass, T.Number)), T.None); | 1692 CheckEqual(T.Semantic(T.Intersect(T.ObjectClass, T.Number)), T.None); |
1741 | 1693 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1834 // Union(T1, Intersect(T2, T3)) = Intersect(Union(T1, T2), Union(T1, T3)) | 1786 // Union(T1, Intersect(T2, T3)) = Intersect(Union(T1, T2), Union(T1, T3)) |
1835 // This does NOT hold. For example: | 1787 // This does NOT hold. For example: |
1836 // Untagged \/ (Untagged /\ Class(../Tagged)) = Untagged \/ Class(../Tagged) | 1788 // Untagged \/ (Untagged /\ Class(../Tagged)) = Untagged \/ Class(../Tagged) |
1837 // (Untagged \/ Untagged) /\ (Untagged \/ Class(../Tagged)) = | 1789 // (Untagged \/ Untagged) /\ (Untagged \/ Class(../Tagged)) = |
1838 // Untagged /\ (Untagged \/ Class(../Tagged)) = Untagged | 1790 // Untagged /\ (Untagged \/ Class(../Tagged)) = Untagged |
1839 // because Untagged <= Untagged \/ Class(../Tagged) | 1791 // because Untagged <= Untagged \/ Class(../Tagged) |
1840 /* | 1792 /* |
1841 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1793 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
1842 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1794 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
1843 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { | 1795 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { |
1844 TypeHandle type1 = *it1; | 1796 Type* type1 = *it1; |
1845 TypeHandle type2 = *it2; | 1797 Type* type2 = *it2; |
1846 TypeHandle type3 = *it3; | 1798 Type* type3 = *it3; |
1847 TypeHandle union12 = T.Union(type1, type2); | 1799 Type* union12 = T.Union(type1, type2); |
1848 TypeHandle union13 = T.Union(type1, type3); | 1800 Type* union13 = T.Union(type1, type3); |
1849 TypeHandle intersect23 = T.Intersect(type2, type3); | 1801 Type* intersect23 = T.Intersect(type2, type3); |
1850 TypeHandle union1_23 = T.Union(type1, intersect23); | 1802 Type* union1_23 = T.Union(type1, intersect23); |
1851 TypeHandle intersect12_13 = T.Intersect(union12, union13); | 1803 Type* intersect12_13 = T.Intersect(union12, union13); |
1852 CHECK(Equal(union1_23, intersect12_13)); | 1804 CHECK(Equal(union1_23, intersect12_13)); |
1853 } | 1805 } |
1854 } | 1806 } |
1855 } | 1807 } |
1856 */ | 1808 */ |
1857 | 1809 |
1858 // Intersect(T1, Union(T2, T3)) = Union(Intersect(T1, T2), Intersect(T1,T3)) | 1810 // Intersect(T1, Union(T2, T3)) = Union(Intersect(T1, T2), Intersect(T1,T3)) |
1859 // This does NOT hold. For example: | 1811 // This does NOT hold. For example: |
1860 // Untagged /\ (Untagged \/ Class(../Tagged)) = Untagged | 1812 // Untagged /\ (Untagged \/ Class(../Tagged)) = Untagged |
1861 // (Untagged /\ Untagged) \/ (Untagged /\ Class(../Tagged)) = | 1813 // (Untagged /\ Untagged) \/ (Untagged /\ Class(../Tagged)) = |
1862 // Untagged \/ Class(../Tagged) | 1814 // Untagged \/ Class(../Tagged) |
1863 /* | 1815 /* |
1864 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1816 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
1865 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1817 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
1866 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { | 1818 for (TypeIterator it3 = T.types.begin(); it3 != T.types.end(); ++it3) { |
1867 TypeHandle type1 = *it1; | 1819 Type* type1 = *it1; |
1868 TypeHandle type2 = *it2; | 1820 Type* type2 = *it2; |
1869 TypeHandle type3 = *it3; | 1821 Type* type3 = *it3; |
1870 TypeHandle intersect12 = T.Intersect(type1, type2); | 1822 Type* intersect12 = T.Intersect(type1, type2); |
1871 TypeHandle intersect13 = T.Intersect(type1, type3); | 1823 Type* intersect13 = T.Intersect(type1, type3); |
1872 TypeHandle union23 = T.Union(type2, type3); | 1824 Type* union23 = T.Union(type2, type3); |
1873 TypeHandle intersect1_23 = T.Intersect(type1, union23); | 1825 Type* intersect1_23 = T.Intersect(type1, union23); |
1874 TypeHandle union12_13 = T.Union(intersect12, intersect13); | 1826 Type* union12_13 = T.Union(intersect12, intersect13); |
1875 CHECK(Equal(intersect1_23, union12_13)); | 1827 CHECK(Equal(intersect1_23, union12_13)); |
1876 } | 1828 } |
1877 } | 1829 } |
1878 } | 1830 } |
1879 */ | 1831 */ |
1880 } | 1832 } |
1881 | 1833 |
1882 void GetRange() { | 1834 void GetRange() { |
1883 // GetRange(Range(a, b)) = Range(a, b). | 1835 // GetRange(Range(a, b)) = Range(a, b). |
1884 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1836 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
1885 TypeHandle type1 = *it1; | 1837 Type* type1 = *it1; |
1886 if (type1->IsRange()) { | 1838 if (type1->IsRange()) { |
1887 typename Type::RangeType* range = type1->GetRange(); | 1839 RangeType* range = type1->GetRange()->AsRange(); |
1888 CHECK(type1->Min() == range->Min()); | 1840 CHECK(type1->Min() == range->Min()); |
1889 CHECK(type1->Max() == range->Max()); | 1841 CHECK(type1->Max() == range->Max()); |
1890 } | 1842 } |
1891 } | 1843 } |
1892 | 1844 |
1893 // GetRange(Union(Constant(x), Range(min,max))) == Range(min, max). | 1845 // GetRange(Union(Constant(x), Range(min,max))) == Range(min, max). |
1894 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1846 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
1895 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1847 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
1896 TypeHandle type1 = *it1; | 1848 Type* type1 = *it1; |
1897 TypeHandle type2 = *it2; | 1849 Type* type2 = *it2; |
1898 if (type1->IsConstant() && type2->IsRange()) { | 1850 if (type1->IsConstant() && type2->IsRange()) { |
1899 TypeHandle u = T.Union(type1, type2); | 1851 Type* u = T.Union(type1, type2); |
1900 | 1852 |
1901 CHECK(type2->Min() == u->GetRange()->Min()); | 1853 CHECK(type2->Min() == u->GetRange()->Min()); |
1902 CHECK(type2->Max() == u->GetRange()->Max()); | 1854 CHECK(type2->Max() == u->GetRange()->Max()); |
1903 } | 1855 } |
1904 } | 1856 } |
1905 } | 1857 } |
1906 } | 1858 } |
1907 | 1859 |
1908 template<class Type2, class TypeHandle2, class Region2, class Rep2> | |
1909 void Convert() { | |
1910 Types<Type2, TypeHandle2, Region2> T2(Rep2::ToRegion(&zone, isolate), | |
1911 isolate, | |
1912 isolate->random_number_generator()); | |
1913 for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { | |
1914 TypeHandle type1 = *it; | |
1915 TypeHandle2 type2 = T2.template Convert<Type>(type1); | |
1916 TypeHandle type3 = T.template Convert<Type2>(type2); | |
1917 CheckEqual(type1, type3); | |
1918 } | |
1919 } | |
1920 | |
1921 void HTypeFromType() { | 1860 void HTypeFromType() { |
1922 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { | 1861 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { |
1923 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { | 1862 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { |
1924 TypeHandle type1 = *it1; | 1863 Type* type1 = *it1; |
1925 TypeHandle type2 = *it2; | 1864 Type* type2 = *it2; |
1926 HType htype1 = HType::FromType(type1); | 1865 HType htype1 = HType::FromType(type1); |
1927 HType htype2 = HType::FromType(type2); | 1866 HType htype2 = HType::FromType(type2); |
1928 CHECK(!type1->Is(type2) || htype1.IsSubtypeOf(htype2)); | 1867 CHECK(!type1->Is(type2) || htype1.IsSubtypeOf(htype2)); |
1929 } | 1868 } |
1930 } | 1869 } |
1931 } | 1870 } |
1932 }; | 1871 }; |
1933 | 1872 |
1934 typedef Tests<Type, Type*, Zone, ZoneRep> ZoneTests; | 1873 TEST(IsSomeType_zone) { Tests().IsSomeType(); } |
1935 | 1874 |
| 1875 TEST(PointwiseRepresentation_zone) { Tests().PointwiseRepresentation(); } |
1936 | 1876 |
1937 TEST(IsSomeType_zone) { ZoneTests().IsSomeType(); } | 1877 TEST(BitsetType_zone) { Tests().Bitset(); } |
1938 | 1878 |
| 1879 TEST(ClassType_zone) { Tests().Class(); } |
1939 | 1880 |
1940 TEST(PointwiseRepresentation_zone) { ZoneTests().PointwiseRepresentation(); } | 1881 TEST(ConstantType_zone) { Tests().Constant(); } |
1941 | 1882 |
| 1883 TEST(RangeType_zone) { Tests().Range(); } |
1942 | 1884 |
1943 TEST(BitsetType_zone) { ZoneTests().Bitset(); } | 1885 TEST(ArrayType_zone) { Tests().Array(); } |
1944 | 1886 |
| 1887 TEST(FunctionType_zone) { Tests().Function(); } |
1945 | 1888 |
1946 TEST(ClassType_zone) { ZoneTests().Class(); } | 1889 TEST(Of_zone) { Tests().Of(); } |
1947 | 1890 |
| 1891 TEST(NowOf_zone) { Tests().NowOf(); } |
1948 | 1892 |
1949 TEST(ConstantType_zone) { ZoneTests().Constant(); } | 1893 TEST(MinMax_zone) { Tests().MinMax(); } |
1950 | 1894 |
| 1895 TEST(BitsetGlb_zone) { Tests().BitsetGlb(); } |
1951 | 1896 |
1952 TEST(RangeType_zone) { ZoneTests().Range(); } | 1897 TEST(BitsetLub_zone) { Tests().BitsetLub(); } |
1953 | 1898 |
| 1899 TEST(Is1_zone) { Tests().Is1(); } |
1954 | 1900 |
1955 TEST(ArrayType_zone) { ZoneTests().Array(); } | 1901 TEST(Is2_zone) { Tests().Is2(); } |
1956 | 1902 |
| 1903 TEST(NowIs_zone) { Tests().NowIs(); } |
1957 | 1904 |
1958 TEST(FunctionType_zone) { ZoneTests().Function(); } | 1905 TEST(Contains_zone) { Tests().Contains(); } |
1959 | 1906 |
| 1907 TEST(NowContains_zone) { Tests().NowContains(); } |
1960 | 1908 |
1961 TEST(Of_zone) { ZoneTests().Of(); } | 1909 TEST(Maybe_zone) { Tests().Maybe(); } |
1962 | 1910 |
| 1911 TEST(Union1_zone) { Tests().Union1(); } |
1963 | 1912 |
1964 TEST(NowOf_zone) { ZoneTests().NowOf(); } | 1913 TEST(Union2_zone) { Tests().Union2(); } |
1965 | 1914 |
| 1915 TEST(Union3_zone) { Tests().Union3(); } |
1966 | 1916 |
1967 TEST(MinMax_zone) { ZoneTests().MinMax(); } | 1917 TEST(Union4_zone) { Tests().Union4(); } |
1968 | 1918 |
| 1919 TEST(Intersect_zone) { Tests().Intersect(); } |
1969 | 1920 |
1970 TEST(BitsetGlb_zone) { ZoneTests().BitsetGlb(); } | 1921 TEST(Distributivity_zone) { Tests().Distributivity(); } |
1971 | 1922 |
| 1923 TEST(GetRange_zone) { Tests().GetRange(); } |
1972 | 1924 |
1973 TEST(BitsetLub_zone) { ZoneTests().BitsetLub(); } | 1925 TEST(HTypeFromType_zone) { Tests().HTypeFromType(); } |
1974 | |
1975 | |
1976 TEST(Is1_zone) { ZoneTests().Is1(); } | |
1977 | |
1978 | |
1979 TEST(Is2_zone) { ZoneTests().Is2(); } | |
1980 | |
1981 | |
1982 TEST(NowIs_zone) { ZoneTests().NowIs(); } | |
1983 | |
1984 | |
1985 TEST(Contains_zone) { ZoneTests().Contains(); } | |
1986 | |
1987 | |
1988 TEST(NowContains_zone) { ZoneTests().NowContains(); } | |
1989 | |
1990 | |
1991 TEST(Maybe_zone) { ZoneTests().Maybe(); } | |
1992 | |
1993 | |
1994 TEST(Union1_zone) { ZoneTests().Union1(); } | |
1995 | |
1996 | |
1997 TEST(Union2_zone) { ZoneTests().Union2(); } | |
1998 | |
1999 | |
2000 TEST(Union3_zone) { ZoneTests().Union3(); } | |
2001 | |
2002 | |
2003 TEST(Union4_zone) { ZoneTests().Union4(); } | |
2004 | |
2005 | |
2006 TEST(Intersect_zone) { ZoneTests().Intersect(); } | |
2007 | |
2008 | |
2009 TEST(Distributivity_zone) { ZoneTests().Distributivity(); } | |
2010 | |
2011 | |
2012 TEST(GetRange_zone) { ZoneTests().GetRange(); } | |
2013 | |
2014 | |
2015 TEST(HTypeFromType_zone) { ZoneTests().HTypeFromType(); } | |
OLD | NEW |