OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 12 matching lines...) Expand all Loading... |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #include "cctest.h" | 28 #include "cctest.h" |
29 #include "types.h" | 29 #include "types.h" |
30 | 30 |
31 using namespace v8::internal; | 31 using namespace v8::internal; |
32 | 32 |
33 // Testing auxiliaries (breaking the Type abstraction). | 33 template<class Type, class TypeHandle, class Region> |
34 static bool IsBitset(Handle<Type> t) { return t->IsSmi(); } | 34 class Types { |
35 static bool IsClass(Handle<Type> t) { return t->IsMap(); } | |
36 static bool IsConstant(Handle<Type> t) { return t->IsBox(); } | |
37 static bool IsUnion(Handle<Type> t) { return t->IsFixedArray(); } | |
38 | |
39 static int AsBitset(Handle<Type> t) { return Smi::cast(*t)->value(); } | |
40 static Map* AsClass(Handle<Type> t) { return Map::cast(*t); } | |
41 static Object* AsConstant(Handle<Type> t) { return Box::cast(*t)->value(); } | |
42 static FixedArray* AsUnion(Handle<Type> t) { return FixedArray::cast(*t); } | |
43 | |
44 | |
45 static void CheckEqual(Handle<Type> type1, Handle<Type> type2) { | |
46 CHECK_EQ(IsBitset(type1), IsBitset(type2)); | |
47 CHECK_EQ(IsClass(type1), IsClass(type2)); | |
48 CHECK_EQ(IsConstant(type1), IsConstant(type2)); | |
49 CHECK_EQ(IsUnion(type1), IsUnion(type2)); | |
50 CHECK_EQ(type1->NumClasses(), type2->NumClasses()); | |
51 CHECK_EQ(type1->NumConstants(), type2->NumConstants()); | |
52 if (IsBitset(type1)) { | |
53 CHECK_EQ(AsBitset(type1), AsBitset(type2)); | |
54 } else if (IsClass(type1)) { | |
55 CHECK_EQ(AsClass(type1), AsClass(type2)); | |
56 } else if (IsConstant(type1)) { | |
57 CHECK_EQ(AsConstant(type1), AsConstant(type2)); | |
58 } else if (IsUnion(type1)) { | |
59 CHECK_EQ(AsUnion(type1)->length(), AsUnion(type2)->length()); | |
60 } | |
61 CHECK(type1->Is(type2)); | |
62 CHECK(type2->Is(type1)); | |
63 } | |
64 | |
65 | |
66 static void CheckSub(Handle<Type> type1, Handle<Type> type2) { | |
67 CHECK(type1->Is(type2)); | |
68 CHECK(!type2->Is(type1)); | |
69 if (IsBitset(type1) && IsBitset(type2)) { | |
70 CHECK_NE(AsBitset(type1), AsBitset(type2)); | |
71 } | |
72 } | |
73 | |
74 | |
75 static void CheckUnordered(Handle<Type> type1, Handle<Type> type2) { | |
76 CHECK(!type1->Is(type2)); | |
77 CHECK(!type2->Is(type1)); | |
78 if (IsBitset(type1) && IsBitset(type2)) { | |
79 CHECK_NE(AsBitset(type1), AsBitset(type2)); | |
80 } | |
81 } | |
82 | |
83 | |
84 static void CheckOverlap(Handle<Type> type1, Handle<Type> type2) { | |
85 CHECK(type1->Maybe(type2)); | |
86 CHECK(type2->Maybe(type1)); | |
87 if (IsBitset(type1) && IsBitset(type2)) { | |
88 CHECK_NE(0, AsBitset(type1) & AsBitset(type2)); | |
89 } | |
90 } | |
91 | |
92 | |
93 static void CheckDisjoint(Handle<Type> type1, Handle<Type> type2) { | |
94 CHECK(!type1->Is(type2)); | |
95 CHECK(!type2->Is(type1)); | |
96 CHECK(!type1->Maybe(type2)); | |
97 CHECK(!type2->Maybe(type1)); | |
98 if (IsBitset(type1) && IsBitset(type2)) { | |
99 CHECK_EQ(0, AsBitset(type1) & AsBitset(type2)); | |
100 } | |
101 } | |
102 | |
103 | |
104 class HandlifiedTypes { | |
105 public: | 35 public: |
106 explicit HandlifiedTypes(Isolate* isolate) : | 36 Types(Region* region, Isolate* isolate) : |
107 None(Type::None(isolate)), | 37 None(Type::None(region)), |
108 Any(Type::Any(isolate)), | 38 Any(Type::Any(region)), |
109 Oddball(Type::Oddball(isolate)), | 39 Oddball(Type::Oddball(region)), |
110 Boolean(Type::Boolean(isolate)), | 40 Boolean(Type::Boolean(region)), |
111 Null(Type::Null(isolate)), | 41 Null(Type::Null(region)), |
112 Undefined(Type::Undefined(isolate)), | 42 Undefined(Type::Undefined(region)), |
113 Number(Type::Number(isolate)), | 43 Number(Type::Number(region)), |
114 Smi(Type::Smi(isolate)), | 44 Smi(Type::Smi(region)), |
115 Signed32(Type::Signed32(isolate)), | 45 Signed32(Type::Signed32(region)), |
116 Double(Type::Double(isolate)), | 46 Double(Type::Double(region)), |
117 Name(Type::Name(isolate)), | 47 Name(Type::Name(region)), |
118 UniqueName(Type::UniqueName(isolate)), | 48 UniqueName(Type::UniqueName(region)), |
119 String(Type::String(isolate)), | 49 String(Type::String(region)), |
120 InternalizedString(Type::InternalizedString(isolate)), | 50 InternalizedString(Type::InternalizedString(region)), |
121 Symbol(Type::Symbol(isolate)), | 51 Symbol(Type::Symbol(region)), |
122 Receiver(Type::Receiver(isolate)), | 52 Receiver(Type::Receiver(region)), |
123 Object(Type::Object(isolate)), | 53 Object(Type::Object(region)), |
124 Array(Type::Array(isolate)), | 54 Array(Type::Array(region)), |
125 Function(Type::Function(isolate)), | 55 Function(Type::Function(region)), |
126 Proxy(Type::Proxy(isolate)), | 56 Proxy(Type::Proxy(region)), |
127 object_map(isolate->factory()->NewMap(JS_OBJECT_TYPE, 3 * kPointerSize)), | 57 object_map(isolate->factory()->NewMap(JS_OBJECT_TYPE, 3 * kPointerSize)), |
128 array_map(isolate->factory()->NewMap(JS_ARRAY_TYPE, 4 * kPointerSize)), | 58 array_map(isolate->factory()->NewMap(JS_ARRAY_TYPE, 4 * kPointerSize)), |
129 isolate_(isolate) { | 59 region_(region) { |
130 smi = handle(Smi::FromInt(666), isolate); | 60 smi = handle(Smi::FromInt(666), isolate); |
131 signed32 = isolate->factory()->NewHeapNumber(0x40000000); | 61 signed32 = isolate->factory()->NewHeapNumber(0x40000000); |
132 object1 = isolate->factory()->NewJSObjectFromMap(object_map); | 62 object1 = isolate->factory()->NewJSObjectFromMap(object_map); |
133 object2 = isolate->factory()->NewJSObjectFromMap(object_map); | 63 object2 = isolate->factory()->NewJSObjectFromMap(object_map); |
134 array = isolate->factory()->NewJSArray(20); | 64 array = isolate->factory()->NewJSArray(20); |
135 ObjectClass = Type::Class(object_map, isolate); | 65 ObjectClass = Type::Class(object_map, region); |
136 ArrayClass = Type::Class(array_map, isolate); | 66 ArrayClass = Type::Class(array_map, region); |
137 SmiConstant = Type::Constant(smi, isolate); | 67 SmiConstant = Type::Constant(smi, region); |
138 Signed32Constant = Type::Constant(signed32, isolate); | 68 Signed32Constant = Type::Constant(signed32, region); |
139 ObjectConstant1 = Type::Constant(object1, isolate); | 69 ObjectConstant1 = Type::Constant(object1, region); |
140 ObjectConstant2 = Type::Constant(object2, isolate); | 70 ObjectConstant2 = Type::Constant(object2, region); |
141 ArrayConstant1 = Type::Constant(array, isolate); | 71 ArrayConstant1 = Type::Constant(array, region); |
142 ArrayConstant2 = Type::Constant(array, isolate); | 72 ArrayConstant2 = Type::Constant(array, region); |
143 } | 73 } |
144 | 74 |
145 Handle<Type> None; | 75 TypeHandle None; |
146 Handle<Type> Any; | 76 TypeHandle Any; |
147 Handle<Type> Oddball; | 77 TypeHandle Oddball; |
148 Handle<Type> Boolean; | 78 TypeHandle Boolean; |
149 Handle<Type> Null; | 79 TypeHandle Null; |
150 Handle<Type> Undefined; | 80 TypeHandle Undefined; |
151 Handle<Type> Number; | 81 TypeHandle Number; |
152 Handle<Type> Smi; | 82 TypeHandle Smi; |
153 Handle<Type> Signed32; | 83 TypeHandle Signed32; |
154 Handle<Type> Double; | 84 TypeHandle Double; |
155 Handle<Type> Name; | 85 TypeHandle Name; |
156 Handle<Type> UniqueName; | 86 TypeHandle UniqueName; |
157 Handle<Type> String; | 87 TypeHandle String; |
158 Handle<Type> InternalizedString; | 88 TypeHandle InternalizedString; |
159 Handle<Type> Symbol; | 89 TypeHandle Symbol; |
160 Handle<Type> Receiver; | 90 TypeHandle Receiver; |
161 Handle<Type> Object; | 91 TypeHandle Object; |
162 Handle<Type> Array; | 92 TypeHandle Array; |
163 Handle<Type> Function; | 93 TypeHandle Function; |
164 Handle<Type> Proxy; | 94 TypeHandle Proxy; |
165 | 95 |
166 Handle<Type> ObjectClass; | 96 TypeHandle ObjectClass; |
167 Handle<Type> ArrayClass; | 97 TypeHandle ArrayClass; |
168 | 98 |
169 Handle<Type> SmiConstant; | 99 TypeHandle SmiConstant; |
170 Handle<Type> Signed32Constant; | 100 TypeHandle Signed32Constant; |
171 Handle<Type> ObjectConstant1; | 101 TypeHandle ObjectConstant1; |
172 Handle<Type> ObjectConstant2; | 102 TypeHandle ObjectConstant2; |
173 Handle<Type> ArrayConstant1; | 103 TypeHandle ArrayConstant1; |
174 Handle<Type> ArrayConstant2; | 104 TypeHandle ArrayConstant2; |
175 | 105 |
176 Handle<Map> object_map; | 106 Handle<i::Map> object_map; |
177 Handle<Map> array_map; | 107 Handle<i::Map> array_map; |
178 | 108 |
179 Handle<i::Smi> smi; | 109 Handle<i::Smi> smi; |
180 Handle<HeapNumber> signed32; | 110 Handle<i::HeapNumber> signed32; |
181 Handle<JSObject> object1; | 111 Handle<i::JSObject> object1; |
182 Handle<JSObject> object2; | 112 Handle<i::JSObject> object2; |
183 Handle<JSArray> array; | 113 Handle<i::JSArray> array; |
184 | 114 |
185 Handle<Type> Union(Handle<Type> t1, Handle<Type> t2) { | 115 TypeHandle Union(TypeHandle t1, TypeHandle t2) { |
186 return Type::Union(t1, t2, isolate_); | 116 return Type::Union(t1, t2, region_); |
187 } | 117 } |
188 Handle<Type> Intersect(Handle<Type> t1, Handle<Type> t2) { | 118 TypeHandle Intersect(TypeHandle t1, TypeHandle t2) { |
189 return Type::Intersect(t1, t2, isolate_); | 119 return Type::Intersect(t1, t2, region_); |
190 } | 120 } |
191 | 121 |
192 private: | 122 private: |
193 Isolate* isolate_; | 123 Region* region_; |
194 }; | 124 }; |
195 | 125 |
196 | 126 |
| 127 // Testing auxiliaries (breaking the Type abstraction). |
| 128 struct ZoneRep { |
| 129 static bool IsTagged(ZoneType* t, int tag) { |
| 130 return !IsBitset(t) |
| 131 && reinterpret_cast<int>(AsTagged(t)->at(0)) == tag; |
| 132 } |
| 133 static bool IsBitset(ZoneType* t) { return reinterpret_cast<int>(t) & 1; } |
| 134 static bool IsClass(ZoneType* t) { return IsTagged(t, 0); } |
| 135 static bool IsConstant(ZoneType* t) { return IsTagged(t, 1); } |
| 136 static bool IsUnion(ZoneType* t) { return IsTagged(t, 2); } |
| 137 |
| 138 static ZoneList<void*>* AsTagged(ZoneType* t) { |
| 139 return reinterpret_cast<ZoneList<void*>*>(t); |
| 140 } |
| 141 static int AsBitset(ZoneType* t) { |
| 142 return reinterpret_cast<int>(t) >> 1; |
| 143 } |
| 144 static Map* AsClass(ZoneType* t) { |
| 145 return *reinterpret_cast<Map**>(AsTagged(t)->at(1)); |
| 146 } |
| 147 static Object* AsConstant(ZoneType* t) { |
| 148 return *reinterpret_cast<Object**>(AsTagged(t)->at(1)); |
| 149 } |
| 150 static ZoneList<ZoneType*>* AsUnion(ZoneType* t) { |
| 151 return reinterpret_cast<ZoneList<ZoneType*>*>(AsTagged(t)); |
| 152 } |
| 153 |
| 154 static Zone* Region(Zone* zone, Isolate* isolate) { return zone; } |
| 155 }; |
| 156 |
| 157 |
| 158 struct HeapRep { |
| 159 static bool IsBitset(Handle<Type> t) { return t->IsSmi(); } |
| 160 static bool IsClass(Handle<Type> t) { return t->IsMap(); } |
| 161 static bool IsConstant(Handle<Type> t) { return t->IsBox(); } |
| 162 static bool IsUnion(Handle<Type> t) { return t->IsFixedArray(); } |
| 163 |
| 164 static int AsBitset(Handle<Type> t) { return Smi::cast(*t)->value(); } |
| 165 static Map* AsClass(Handle<Type> t) { return Map::cast(*t); } |
| 166 static Object* AsConstant(Handle<Type> t) { return Box::cast(*t)->value(); } |
| 167 static FixedArray* AsUnion(Handle<Type> t) { return FixedArray::cast(*t); } |
| 168 |
| 169 static Isolate* Region(Zone* zone, Isolate* isolate) { return isolate; } |
| 170 }; |
| 171 |
| 172 |
| 173 template<class Type, class TypeHandle, class Region, class Rep> |
| 174 struct Tests : Rep { |
| 175 Isolate* isolate; |
| 176 HandleScope scope; |
| 177 Zone zone; |
| 178 Types<Type, TypeHandle, Region> T; |
| 179 |
| 180 Tests() : |
| 181 isolate(CcTest::i_isolate()), |
| 182 scope(isolate), |
| 183 zone(isolate), |
| 184 T(Rep::Region(&zone, isolate), isolate) { |
| 185 } |
| 186 |
| 187 static void CheckEqual(TypeHandle type1, TypeHandle type2) { |
| 188 CHECK_EQ(Rep::IsBitset(type1), Rep::IsBitset(type2)); |
| 189 CHECK_EQ(Rep::IsClass(type1), Rep::IsClass(type2)); |
| 190 CHECK_EQ(Rep::IsConstant(type1), Rep::IsConstant(type2)); |
| 191 CHECK_EQ(Rep::IsUnion(type1), Rep::IsUnion(type2)); |
| 192 CHECK_EQ(type1->NumClasses(), type2->NumClasses()); |
| 193 CHECK_EQ(type1->NumConstants(), type2->NumConstants()); |
| 194 if (Rep::IsBitset(type1)) { |
| 195 CHECK_EQ(Rep::AsBitset(type1), Rep::AsBitset(type2)); |
| 196 } else if (Rep::IsClass(type1)) { |
| 197 CHECK_EQ(Rep::AsClass(type1), Rep::AsClass(type2)); |
| 198 } else if (Rep::IsConstant(type1)) { |
| 199 CHECK_EQ(Rep::AsConstant(type1), Rep::AsConstant(type2)); |
| 200 } else if (Rep::IsUnion(type1)) { |
| 201 CHECK_EQ(Rep::AsUnion(type1)->length(), Rep::AsUnion(type2)->length()); |
| 202 } |
| 203 CHECK(type1->Is(type2)); |
| 204 CHECK(type2->Is(type1)); |
| 205 } |
| 206 |
| 207 static void CheckSub(TypeHandle type1, TypeHandle type2) { |
| 208 CHECK(type1->Is(type2)); |
| 209 CHECK(!type2->Is(type1)); |
| 210 if (Rep::IsBitset(type1) && Rep::IsBitset(type2)) { |
| 211 CHECK_NE(Rep::AsBitset(type1), Rep::AsBitset(type2)); |
| 212 } |
| 213 } |
| 214 |
| 215 static void CheckUnordered(TypeHandle type1, TypeHandle type2) { |
| 216 CHECK(!type1->Is(type2)); |
| 217 CHECK(!type2->Is(type1)); |
| 218 if (Rep::IsBitset(type1) && Rep::IsBitset(type2)) { |
| 219 CHECK_NE(Rep::AsBitset(type1), Rep::AsBitset(type2)); |
| 220 } |
| 221 } |
| 222 |
| 223 static void CheckOverlap(TypeHandle type1, TypeHandle type2) { |
| 224 CHECK(type1->Maybe(type2)); |
| 225 CHECK(type2->Maybe(type1)); |
| 226 if (Rep::IsBitset(type1) && Rep::IsBitset(type2)) { |
| 227 CHECK_NE(0, Rep::AsBitset(type1) & Rep::AsBitset(type2)); |
| 228 } |
| 229 } |
| 230 |
| 231 static void CheckDisjoint(TypeHandle type1, TypeHandle type2) { |
| 232 CHECK(!type1->Is(type2)); |
| 233 CHECK(!type2->Is(type1)); |
| 234 CHECK(!type1->Maybe(type2)); |
| 235 CHECK(!type2->Maybe(type1)); |
| 236 if (Rep::IsBitset(type1) && Rep::IsBitset(type2)) { |
| 237 CHECK_EQ(0, Rep::AsBitset(type1) & Rep::AsBitset(type2)); |
| 238 } |
| 239 } |
| 240 |
| 241 void Bitset() { |
| 242 CHECK(IsBitset(T.None)); |
| 243 CHECK(IsBitset(T.Any)); |
| 244 CHECK(IsBitset(T.String)); |
| 245 CHECK(IsBitset(T.Object)); |
| 246 |
| 247 CHECK(IsBitset(T.Union(T.String, T.Number))); |
| 248 CHECK(IsBitset(T.Union(T.String, T.Receiver))); |
| 249 |
| 250 CHECK_EQ(0, AsBitset(T.None)); |
| 251 CHECK_EQ(AsBitset(T.Number) | AsBitset(T.String), |
| 252 AsBitset(T.Union(T.String, T.Number))); |
| 253 CHECK_EQ(AsBitset(T.Receiver), |
| 254 AsBitset(T.Union(T.Receiver, T.Object))); |
| 255 } |
| 256 |
| 257 void Class() { |
| 258 CHECK(IsClass(T.ObjectClass)); |
| 259 CHECK(IsClass(T.ArrayClass)); |
| 260 |
| 261 CHECK(*T.object_map == AsClass(T.ObjectClass)); |
| 262 CHECK(*T.array_map == AsClass(T.ArrayClass)); |
| 263 } |
| 264 |
| 265 void Constant() { |
| 266 CHECK(IsConstant(T.SmiConstant)); |
| 267 CHECK(IsConstant(T.ObjectConstant1)); |
| 268 CHECK(IsConstant(T.ObjectConstant2)); |
| 269 CHECK(IsConstant(T.ArrayConstant1)); |
| 270 CHECK(IsConstant(T.ArrayConstant2)); |
| 271 |
| 272 CHECK(*T.smi == AsConstant(T.SmiConstant)); |
| 273 CHECK(*T.object1 == AsConstant(T.ObjectConstant1)); |
| 274 CHECK(*T.object2 == AsConstant(T.ObjectConstant2)); |
| 275 CHECK(*T.object1 != AsConstant(T.ObjectConstant2)); |
| 276 CHECK(*T.array == AsConstant(T.ArrayConstant1)); |
| 277 CHECK(*T.array == AsConstant(T.ArrayConstant2)); |
| 278 } |
| 279 |
| 280 void Is() { |
| 281 // Reflexivity |
| 282 CHECK(T.None->Is(T.None)); |
| 283 CHECK(T.Any->Is(T.Any)); |
| 284 CHECK(T.Object->Is(T.Object)); |
| 285 |
| 286 CHECK(T.ObjectClass->Is(T.ObjectClass)); |
| 287 CHECK(T.ObjectConstant1->Is(T.ObjectConstant1)); |
| 288 CHECK(T.ArrayConstant1->Is(T.ArrayConstant2)); |
| 289 |
| 290 // Symmetry and Transitivity |
| 291 CheckSub(T.None, T.Number); |
| 292 CheckSub(T.None, T.Any); |
| 293 |
| 294 CheckSub(T.Oddball, T.Any); |
| 295 CheckSub(T.Boolean, T.Oddball); |
| 296 CheckSub(T.Null, T.Oddball); |
| 297 CheckSub(T.Undefined, T.Oddball); |
| 298 CheckUnordered(T.Boolean, T.Null); |
| 299 CheckUnordered(T.Undefined, T.Null); |
| 300 CheckUnordered(T.Boolean, T.Undefined); |
| 301 |
| 302 CheckSub(T.Number, T.Any); |
| 303 CheckSub(T.Smi, T.Number); |
| 304 CheckSub(T.Signed32, T.Number); |
| 305 CheckSub(T.Double, T.Number); |
| 306 CheckSub(T.Smi, T.Signed32); |
| 307 CheckUnordered(T.Smi, T.Double); |
| 308 CheckUnordered(T.Signed32, T.Double); |
| 309 |
| 310 CheckSub(T.Name, T.Any); |
| 311 CheckSub(T.UniqueName, T.Any); |
| 312 CheckSub(T.UniqueName, T.Name); |
| 313 CheckSub(T.String, T.Name); |
| 314 CheckSub(T.InternalizedString, T.String); |
| 315 CheckSub(T.InternalizedString, T.UniqueName); |
| 316 CheckSub(T.InternalizedString, T.Name); |
| 317 CheckSub(T.Symbol, T.UniqueName); |
| 318 CheckSub(T.Symbol, T.Name); |
| 319 CheckUnordered(T.String, T.UniqueName); |
| 320 CheckUnordered(T.String, T.Symbol); |
| 321 CheckUnordered(T.InternalizedString, T.Symbol); |
| 322 |
| 323 CheckSub(T.Receiver, T.Any); |
| 324 CheckSub(T.Object, T.Any); |
| 325 CheckSub(T.Object, T.Receiver); |
| 326 CheckSub(T.Array, T.Object); |
| 327 CheckSub(T.Function, T.Object); |
| 328 CheckSub(T.Proxy, T.Receiver); |
| 329 CheckUnordered(T.Object, T.Proxy); |
| 330 CheckUnordered(T.Array, T.Function); |
| 331 |
| 332 // Structured subtyping |
| 333 CheckSub(T.None, T.ObjectClass); |
| 334 CheckSub(T.None, T.ObjectConstant1); |
| 335 CheckSub(T.ObjectClass, T.Any); |
| 336 CheckSub(T.ObjectConstant1, T.Any); |
| 337 |
| 338 CheckSub(T.ObjectClass, T.Object); |
| 339 CheckSub(T.ArrayClass, T.Object); |
| 340 CheckUnordered(T.ObjectClass, T.ArrayClass); |
| 341 |
| 342 CheckSub(T.SmiConstant, T.Smi); |
| 343 CheckSub(T.SmiConstant, T.Signed32); |
| 344 CheckSub(T.SmiConstant, T.Number); |
| 345 CheckSub(T.ObjectConstant1, T.Object); |
| 346 CheckSub(T.ObjectConstant2, T.Object); |
| 347 CheckSub(T.ArrayConstant1, T.Object); |
| 348 CheckSub(T.ArrayConstant1, T.Array); |
| 349 CheckUnordered(T.ObjectConstant1, T.ObjectConstant2); |
| 350 CheckUnordered(T.ObjectConstant1, T.ArrayConstant1); |
| 351 |
| 352 CheckUnordered(T.ObjectConstant1, T.ObjectClass); |
| 353 CheckUnordered(T.ObjectConstant2, T.ObjectClass); |
| 354 CheckUnordered(T.ObjectConstant1, T.ArrayClass); |
| 355 CheckUnordered(T.ObjectConstant2, T.ArrayClass); |
| 356 CheckUnordered(T.ArrayConstant1, T.ObjectClass); |
| 357 } |
| 358 |
| 359 void Maybe() { |
| 360 CheckOverlap(T.Any, T.Any); |
| 361 CheckOverlap(T.Object, T.Object); |
| 362 |
| 363 CheckOverlap(T.Oddball, T.Any); |
| 364 CheckOverlap(T.Boolean, T.Oddball); |
| 365 CheckOverlap(T.Null, T.Oddball); |
| 366 CheckOverlap(T.Undefined, T.Oddball); |
| 367 CheckDisjoint(T.Boolean, T.Null); |
| 368 CheckDisjoint(T.Undefined, T.Null); |
| 369 CheckDisjoint(T.Boolean, T.Undefined); |
| 370 |
| 371 CheckOverlap(T.Number, T.Any); |
| 372 CheckOverlap(T.Smi, T.Number); |
| 373 CheckOverlap(T.Double, T.Number); |
| 374 CheckDisjoint(T.Signed32, T.Double); |
| 375 |
| 376 CheckOverlap(T.Name, T.Any); |
| 377 CheckOverlap(T.UniqueName, T.Any); |
| 378 CheckOverlap(T.UniqueName, T.Name); |
| 379 CheckOverlap(T.String, T.Name); |
| 380 CheckOverlap(T.InternalizedString, T.String); |
| 381 CheckOverlap(T.InternalizedString, T.UniqueName); |
| 382 CheckOverlap(T.InternalizedString, T.Name); |
| 383 CheckOverlap(T.Symbol, T.UniqueName); |
| 384 CheckOverlap(T.Symbol, T.Name); |
| 385 CheckOverlap(T.String, T.UniqueName); |
| 386 CheckDisjoint(T.String, T.Symbol); |
| 387 CheckDisjoint(T.InternalizedString, T.Symbol); |
| 388 |
| 389 CheckOverlap(T.Receiver, T.Any); |
| 390 CheckOverlap(T.Object, T.Any); |
| 391 CheckOverlap(T.Object, T.Receiver); |
| 392 CheckOverlap(T.Array, T.Object); |
| 393 CheckOverlap(T.Function, T.Object); |
| 394 CheckOverlap(T.Proxy, T.Receiver); |
| 395 CheckDisjoint(T.Object, T.Proxy); |
| 396 CheckDisjoint(T.Array, T.Function); |
| 397 |
| 398 CheckOverlap(T.ObjectClass, T.Any); |
| 399 CheckOverlap(T.ObjectConstant1, T.Any); |
| 400 |
| 401 CheckOverlap(T.ObjectClass, T.Object); |
| 402 CheckOverlap(T.ArrayClass, T.Object); |
| 403 CheckOverlap(T.ObjectClass, T.ObjectClass); |
| 404 CheckOverlap(T.ArrayClass, T.ArrayClass); |
| 405 CheckDisjoint(T.ObjectClass, T.ArrayClass); |
| 406 |
| 407 CheckOverlap(T.SmiConstant, T.Smi); |
| 408 CheckOverlap(T.SmiConstant, T.Signed32); |
| 409 CheckOverlap(T.SmiConstant, T.Number); |
| 410 CheckDisjoint(T.SmiConstant, T.Double); |
| 411 CheckOverlap(T.ObjectConstant1, T.Object); |
| 412 CheckOverlap(T.ObjectConstant2, T.Object); |
| 413 CheckOverlap(T.ArrayConstant1, T.Object); |
| 414 CheckOverlap(T.ArrayConstant1, T.Array); |
| 415 CheckOverlap(T.ArrayConstant1, T.ArrayConstant2); |
| 416 CheckOverlap(T.ObjectConstant1, T.ObjectConstant1); |
| 417 CheckDisjoint(T.ObjectConstant1, T.ObjectConstant2); |
| 418 CheckDisjoint(T.ObjectConstant1, T.ArrayConstant1); |
| 419 |
| 420 CheckDisjoint(T.ObjectConstant1, T.ObjectClass); |
| 421 CheckDisjoint(T.ObjectConstant2, T.ObjectClass); |
| 422 CheckDisjoint(T.ObjectConstant1, T.ArrayClass); |
| 423 CheckDisjoint(T.ObjectConstant2, T.ArrayClass); |
| 424 CheckDisjoint(T.ArrayConstant1, T.ObjectClass); |
| 425 } |
| 426 |
| 427 void Union() { |
| 428 // Bitset-bitset |
| 429 CHECK(IsBitset(T.Union(T.Object, T.Number))); |
| 430 CHECK(IsBitset(T.Union(T.Object, T.Object))); |
| 431 CHECK(IsBitset(T.Union(T.Any, T.None))); |
| 432 |
| 433 CheckEqual(T.Union(T.None, T.Number), T.Number); |
| 434 CheckEqual(T.Union(T.Object, T.Proxy), T.Receiver); |
| 435 CheckEqual(T.Union(T.Number, T.String), T.Union(T.String, T.Number)); |
| 436 CheckSub(T.Union(T.Number, T.String), T.Any); |
| 437 |
| 438 // Class-class |
| 439 CHECK(IsClass(T.Union(T.ObjectClass, T.ObjectClass))); |
| 440 CHECK(IsUnion(T.Union(T.ObjectClass, T.ArrayClass))); |
| 441 |
| 442 CheckEqual(T.Union(T.ObjectClass, T.ObjectClass), T.ObjectClass); |
| 443 CheckSub(T.None, T.Union(T.ObjectClass, T.ArrayClass)); |
| 444 CheckSub(T.Union(T.ObjectClass, T.ArrayClass), T.Any); |
| 445 CheckSub(T.ObjectClass, T.Union(T.ObjectClass, T.ArrayClass)); |
| 446 CheckSub(T.ArrayClass, T.Union(T.ObjectClass, T.ArrayClass)); |
| 447 CheckSub(T.Union(T.ObjectClass, T.ArrayClass), T.Object); |
| 448 CheckUnordered(T.Union(T.ObjectClass, T.ArrayClass), T.Array); |
| 449 CheckOverlap(T.Union(T.ObjectClass, T.ArrayClass), T.Array); |
| 450 CheckDisjoint(T.Union(T.ObjectClass, T.ArrayClass), T.Number); |
| 451 |
| 452 // Constant-constant |
| 453 CHECK(IsConstant(T.Union(T.ObjectConstant1, T.ObjectConstant1))); |
| 454 CHECK(IsConstant(T.Union(T.ArrayConstant1, T.ArrayConstant1))); |
| 455 CHECK(IsUnion(T.Union(T.ObjectConstant1, T.ObjectConstant2))); |
| 456 |
| 457 CheckEqual( |
| 458 T.Union(T.ObjectConstant1, T.ObjectConstant1), |
| 459 T.ObjectConstant1); |
| 460 CheckEqual(T.Union(T.ArrayConstant1, T.ArrayConstant1), T.ArrayConstant1); |
| 461 CheckEqual(T.Union(T.ArrayConstant1, T.ArrayConstant1), T.ArrayConstant2); |
| 462 CheckSub(T.None, T.Union(T.ObjectConstant1, T.ObjectConstant2)); |
| 463 CheckSub(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.Any); |
| 464 CheckSub(T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)); |
| 465 CheckSub(T.ObjectConstant2, T.Union(T.ObjectConstant1, T.ObjectConstant2)); |
| 466 CheckSub(T.ArrayConstant2, T.Union(T.ArrayConstant1, T.ObjectConstant2)); |
| 467 CheckSub(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.Object); |
| 468 CheckUnordered( |
| 469 T.Union(T.ObjectConstant1, T.ObjectConstant2), T.ObjectClass); |
| 470 CheckUnordered(T.Union(T.ObjectConstant1, T.ArrayConstant1), T.Array); |
| 471 CheckOverlap(T.Union(T.ObjectConstant1, T.ArrayConstant1), T.Array); |
| 472 CheckOverlap( |
| 473 T.Union(T.ObjectConstant1, T.ArrayConstant1), T.ArrayConstant2); |
| 474 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayConstant1), T.Number); |
| 475 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayConstant1), T.ObjectClass); |
| 476 |
| 477 // Bitset-class |
| 478 CHECK(IsBitset(T.Union(T.ObjectClass, T.Object))); |
| 479 CHECK(IsUnion(T.Union(T.ObjectClass, T.Number))); |
| 480 |
| 481 CheckEqual(T.Union(T.ObjectClass, T.Object), T.Object); |
| 482 CheckSub(T.None, T.Union(T.ObjectClass, T.Number)); |
| 483 CheckSub(T.Union(T.ObjectClass, T.Number), T.Any); |
| 484 CheckSub(T.Union(T.ObjectClass, T.Smi), T.Union(T.Object, T.Number)); |
| 485 CheckSub(T.Union(T.ObjectClass, T.Array), T.Object); |
| 486 CheckUnordered(T.Union(T.ObjectClass, T.String), T.Array); |
| 487 CheckOverlap(T.Union(T.ObjectClass, T.String), T.Object); |
| 488 CheckDisjoint(T.Union(T.ObjectClass, T.String), T.Number); |
| 489 |
| 490 // Bitset-constant |
| 491 CHECK(IsBitset(T.Union(T.SmiConstant, T.Number))); |
| 492 CHECK(IsBitset(T.Union(T.ObjectConstant1, T.Object))); |
| 493 CHECK(IsUnion(T.Union(T.ObjectConstant2, T.Number))); |
| 494 |
| 495 CheckEqual(T.Union(T.SmiConstant, T.Number), T.Number); |
| 496 CheckEqual(T.Union(T.ObjectConstant1, T.Object), T.Object); |
| 497 CheckSub(T.None, T.Union(T.ObjectConstant1, T.Number)); |
| 498 CheckSub(T.Union(T.ObjectConstant1, T.Number), T.Any); |
| 499 CheckSub( |
| 500 T.Union(T.ObjectConstant1, T.Signed32), T.Union(T.Object, T.Number)); |
| 501 CheckSub(T.Union(T.ObjectConstant1, T.Array), T.Object); |
| 502 CheckUnordered(T.Union(T.ObjectConstant1, T.String), T.Array); |
| 503 CheckOverlap(T.Union(T.ObjectConstant1, T.String), T.Object); |
| 504 CheckDisjoint(T.Union(T.ObjectConstant1, T.String), T.Number); |
| 505 CheckEqual(T.Union(T.Signed32, T.Signed32Constant), T.Signed32); |
| 506 |
| 507 // Class-constant |
| 508 CHECK(IsUnion(T.Union(T.ObjectConstant1, T.ObjectClass))); |
| 509 CHECK(IsUnion(T.Union(T.ArrayClass, T.ObjectConstant2))); |
| 510 |
| 511 CheckSub(T.None, T.Union(T.ObjectConstant1, T.ArrayClass)); |
| 512 CheckSub(T.Union(T.ObjectConstant1, T.ArrayClass), T.Any); |
| 513 CheckSub(T.Union(T.ObjectConstant1, T.ArrayClass), T.Object); |
| 514 CheckSub(T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ArrayClass)); |
| 515 CheckSub(T.ArrayClass, T.Union(T.ObjectConstant1, T.ArrayClass)); |
| 516 CheckUnordered(T.ObjectClass, T.Union(T.ObjectConstant1, T.ArrayClass)); |
| 517 CheckSub( |
| 518 T.Union(T.ObjectConstant1, T.ArrayClass), T.Union(T.Array, T.Object)); |
| 519 CheckUnordered(T.Union(T.ObjectConstant1, T.ArrayClass), T.ArrayConstant1); |
| 520 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayClass), T.ObjectConstant2); |
| 521 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayClass), T.ObjectClass); |
| 522 |
| 523 // Bitset-union |
| 524 CHECK(IsBitset( |
| 525 T.Union(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)))); |
| 526 CHECK(IsUnion(T.Union(T.Union(T.ArrayClass, T.ObjectConstant2), T.Number))); |
| 527 |
| 528 CheckEqual( |
| 529 T.Union(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)), |
| 530 T.Object); |
| 531 CheckEqual( |
| 532 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Number), |
| 533 T.Union(T.ObjectConstant1, T.Union(T.Number, T.ArrayClass))); |
| 534 CheckSub( |
| 535 T.Double, |
| 536 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Number)); |
| 537 CheckSub( |
| 538 T.ObjectConstant1, |
| 539 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Double)); |
| 540 CheckSub( |
| 541 T.None, |
| 542 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Double)); |
| 543 CheckSub( |
| 544 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Double), |
| 545 T.Any); |
| 546 CheckSub( |
| 547 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Double), |
| 548 T.Union(T.ObjectConstant1, T.Union(T.Number, T.ArrayClass))); |
| 549 |
| 550 // Class-union |
| 551 CHECK(IsUnion( |
| 552 T.Union(T.Union(T.ArrayClass, T.ObjectConstant2), T.ArrayClass))); |
| 553 CHECK(IsUnion( |
| 554 T.Union(T.Union(T.ArrayClass, T.ObjectConstant2), T.ObjectClass))); |
| 555 |
| 556 CheckEqual( |
| 557 T.Union(T.ObjectClass, T.Union(T.ObjectConstant1, T.ObjectClass)), |
| 558 T.Union(T.ObjectClass, T.ObjectConstant1)); |
| 559 CheckSub( |
| 560 T.None, |
| 561 T.Union(T.ObjectClass, T.Union(T.ObjectConstant1, T.ObjectClass))); |
| 562 CheckSub( |
| 563 T.Union(T.ObjectClass, T.Union(T.ObjectConstant1, T.ObjectClass)), |
| 564 T.Any); |
| 565 CheckSub( |
| 566 T.Union(T.ObjectClass, T.Union(T.ObjectConstant1, T.ObjectClass)), |
| 567 T.Object); |
| 568 CheckEqual( |
| 569 T.Union(T.Union(T.ArrayClass, T.ObjectConstant2), T.ArrayClass), |
| 570 T.Union(T.ArrayClass, T.ObjectConstant2)); |
| 571 |
| 572 // Constant-union |
| 573 CHECK(IsUnion(T.Union( |
| 574 T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)))); |
| 575 CHECK(IsUnion(T.Union( |
| 576 T.Union(T.ArrayConstant1, T.ObjectClass), T.ObjectConstant1))); |
| 577 CHECK(IsUnion(T.Union( |
| 578 T.Union(T.ArrayConstant1, T.ObjectConstant2), T.ObjectConstant1))); |
| 579 |
| 580 CheckEqual( |
| 581 T.Union( |
| 582 T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)), |
| 583 T.Union(T.ObjectConstant2, T.ObjectConstant1)); |
| 584 CheckEqual( |
| 585 T.Union( |
| 586 T.Union(T.ArrayConstant1, T.ObjectConstant2), T.ObjectConstant1), |
| 587 T.Union( |
| 588 T.ObjectConstant2, T.Union(T.ArrayConstant1, T.ObjectConstant1))); |
| 589 |
| 590 // Union-union |
| 591 CHECK(IsBitset(T.Union( |
| 592 T.Union(T.Number, T.ArrayClass), |
| 593 T.Union(T.Signed32, T.Array)))); |
| 594 CHECK(IsUnion(T.Union( |
| 595 T.Union(T.Number, T.ArrayClass), |
| 596 T.Union(T.ObjectClass, T.ArrayClass)))); |
| 597 |
| 598 CheckEqual( |
| 599 T.Union( |
| 600 T.Union(T.ObjectConstant2, T.ObjectConstant1), |
| 601 T.Union(T.ObjectConstant1, T.ObjectConstant2)), |
| 602 T.Union(T.ObjectConstant2, T.ObjectConstant1)); |
| 603 CheckEqual( |
| 604 T.Union( |
| 605 T.Union(T.ObjectConstant2, T.ArrayConstant1), |
| 606 T.Union(T.ObjectConstant1, T.ArrayConstant2)), |
| 607 T.Union( |
| 608 T.Union(T.ObjectConstant1, T.ObjectConstant2), |
| 609 T.ArrayConstant1)); |
| 610 CheckEqual( |
| 611 T.Union(T.Union(T.Number, T.ArrayClass), T.Union(T.Smi, T.Array)), |
| 612 T.Union(T.Number, T.Array)); |
| 613 } |
| 614 |
| 615 void Intersect() { |
| 616 // Bitset-bitset |
| 617 CHECK(IsBitset(T.Intersect(T.Object, T.Number))); |
| 618 CHECK(IsBitset(T.Intersect(T.Object, T.Object))); |
| 619 CHECK(IsBitset(T.Intersect(T.Any, T.None))); |
| 620 |
| 621 CheckEqual(T.Intersect(T.None, T.Number), T.None); |
| 622 CheckEqual(T.Intersect(T.Object, T.Proxy), T.None); |
| 623 CheckEqual(T.Intersect(T.Name, T.String), T.Intersect(T.String, T.Name)); |
| 624 CheckEqual(T.Intersect(T.UniqueName, T.String), T.InternalizedString); |
| 625 |
| 626 // Class-class |
| 627 CHECK(IsClass(T.Intersect(T.ObjectClass, T.ObjectClass))); |
| 628 CHECK(IsBitset(T.Intersect(T.ObjectClass, T.ArrayClass))); |
| 629 |
| 630 CheckEqual(T.Intersect(T.ObjectClass, T.ObjectClass), T.ObjectClass); |
| 631 CheckEqual(T.Intersect(T.ObjectClass, T.ArrayClass), T.None); |
| 632 |
| 633 // Constant-constant |
| 634 CHECK(IsConstant(T.Intersect(T.ObjectConstant1, T.ObjectConstant1))); |
| 635 CHECK(IsConstant(T.Intersect(T.ArrayConstant1, T.ArrayConstant2))); |
| 636 CHECK(IsBitset(T.Intersect(T.ObjectConstant1, T.ObjectConstant2))); |
| 637 |
| 638 CheckEqual( |
| 639 T.Intersect(T.ObjectConstant1, T.ObjectConstant1), T.ObjectConstant1); |
| 640 CheckEqual( |
| 641 T.Intersect(T.ArrayConstant1, T.ArrayConstant2), T.ArrayConstant1); |
| 642 CheckEqual(T.Intersect(T.ObjectConstant1, T.ObjectConstant2), T.None); |
| 643 |
| 644 // Bitset-class |
| 645 CHECK(IsClass(T.Intersect(T.ObjectClass, T.Object))); |
| 646 CHECK(IsBitset(T.Intersect(T.ObjectClass, T.Number))); |
| 647 |
| 648 CheckEqual(T.Intersect(T.ObjectClass, T.Object), T.ObjectClass); |
| 649 CheckEqual(T.Intersect(T.ObjectClass, T.Array), T.None); |
| 650 CheckEqual(T.Intersect(T.ObjectClass, T.Number), T.None); |
| 651 |
| 652 // Bitset-constant |
| 653 CHECK(IsBitset(T.Intersect(T.Smi, T.Number))); |
| 654 CHECK(IsConstant(T.Intersect(T.SmiConstant, T.Number))); |
| 655 CHECK(IsConstant(T.Intersect(T.ObjectConstant1, T.Object))); |
| 656 |
| 657 CheckEqual(T.Intersect(T.Smi, T.Number), T.Smi); |
| 658 CheckEqual(T.Intersect(T.SmiConstant, T.Number), T.SmiConstant); |
| 659 CheckEqual(T.Intersect(T.ObjectConstant1, T.Object), T.ObjectConstant1); |
| 660 |
| 661 // Class-constant |
| 662 CHECK(IsBitset(T.Intersect(T.ObjectConstant1, T.ObjectClass))); |
| 663 CHECK(IsBitset(T.Intersect(T.ArrayClass, T.ObjectConstant2))); |
| 664 |
| 665 CheckEqual(T.Intersect(T.ObjectConstant1, T.ObjectClass), T.None); |
| 666 CheckEqual(T.Intersect(T.ArrayClass, T.ObjectConstant2), T.None); |
| 667 |
| 668 // Bitset-union |
| 669 CHECK(IsUnion( |
| 670 T.Intersect(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)))); |
| 671 CHECK(IsBitset( |
| 672 T.Intersect(T.Union(T.ArrayClass, T.ObjectConstant2), T.Number))); |
| 673 |
| 674 CheckEqual( |
| 675 T.Intersect(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)), |
| 676 T.Union(T.ObjectConstant1, T.ObjectClass)); |
| 677 CheckEqual( |
| 678 T.Intersect(T.Union(T.ArrayClass, T.ObjectConstant1), T.Number), |
| 679 T.None); |
| 680 |
| 681 // Class-union |
| 682 CHECK(IsClass( |
| 683 T.Intersect(T.Union(T.ArrayClass, T.ObjectConstant2), T.ArrayClass))); |
| 684 CHECK(IsClass( |
| 685 T.Intersect(T.Union(T.Object, T.SmiConstant), T.ArrayClass))); |
| 686 CHECK(IsBitset( |
| 687 T.Intersect(T.Union(T.ObjectClass, T.ArrayConstant1), T.ArrayClass))); |
| 688 |
| 689 CheckEqual( |
| 690 T.Intersect(T.ArrayClass, T.Union(T.ObjectConstant2, T.ArrayClass)), |
| 691 T.ArrayClass); |
| 692 CheckEqual( |
| 693 T.Intersect(T.ArrayClass, T.Union(T.Object, T.SmiConstant)), |
| 694 T.ArrayClass); |
| 695 CheckEqual( |
| 696 T.Intersect(T.Union(T.ObjectClass, T.ArrayConstant1), T.ArrayClass), |
| 697 T.None); |
| 698 |
| 699 // Constant-union |
| 700 CHECK(IsConstant(T.Intersect( |
| 701 T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)))); |
| 702 CHECK(IsConstant(T.Intersect( |
| 703 T.Union(T.Number, T.ObjectClass), T.SmiConstant))); |
| 704 CHECK(IsBitset(T.Intersect( |
| 705 T.Union(T.ArrayConstant1, T.ObjectClass), T.ObjectConstant1))); |
| 706 |
| 707 CheckEqual( |
| 708 T.Intersect( |
| 709 T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)), |
| 710 T.ObjectConstant1); |
| 711 CheckEqual( |
| 712 T.Intersect(T.SmiConstant, T.Union(T.Number, T.ObjectConstant2)), |
| 713 T.SmiConstant); |
| 714 CheckEqual( |
| 715 T.Intersect( |
| 716 T.Union(T.ArrayConstant1, T.ObjectClass), T.ObjectConstant1), |
| 717 T.None); |
| 718 |
| 719 // Union-union |
| 720 CHECK(IsUnion(T.Intersect( |
| 721 T.Union(T.Number, T.ArrayClass), T.Union(T.Signed32, T.Array)))); |
| 722 CHECK(IsBitset(T.Intersect( |
| 723 T.Union(T.Number, T.ObjectClass), T.Union(T.Signed32, T.Array)))); |
| 724 |
| 725 CheckEqual( |
| 726 T.Intersect( |
| 727 T.Union(T.Number, T.ArrayClass), |
| 728 T.Union(T.Smi, T.Array)), |
| 729 T.Union(T.Smi, T.ArrayClass)); |
| 730 CheckEqual( |
| 731 T.Intersect( |
| 732 T.Union(T.Number, T.ObjectClass), |
| 733 T.Union(T.Signed32, T.Array)), |
| 734 T.Signed32); |
| 735 CheckEqual( |
| 736 T.Intersect( |
| 737 T.Union(T.ObjectConstant2, T.ObjectConstant1), |
| 738 T.Union(T.ObjectConstant1, T.ObjectConstant2)), |
| 739 T.Union(T.ObjectConstant2, T.ObjectConstant1)); |
| 740 CheckEqual( |
| 741 T.Intersect( |
| 742 T.Union( |
| 743 T.Union(T.ObjectConstant2, T.ObjectConstant1), T.ArrayClass), |
| 744 T.Union( |
| 745 T.ObjectConstant1, |
| 746 T.Union(T.ArrayConstant1, T.ObjectConstant2))), |
| 747 T.Union(T.ObjectConstant2, T.ObjectConstant1)); |
| 748 CheckEqual( |
| 749 T.Intersect( |
| 750 T.Union(T.ObjectConstant2, T.ArrayConstant1), |
| 751 T.Union(T.ObjectConstant1, T.ArrayConstant2)), |
| 752 T.ArrayConstant1); |
| 753 } |
| 754 }; |
| 755 |
| 756 typedef Tests<ZoneType, ZoneType*, Zone, ZoneRep> ZoneTests; |
| 757 typedef Tests<Type, Handle<Type>, Isolate, HeapRep> HeapTests; |
| 758 |
| 759 |
197 TEST(Bitset) { | 760 TEST(Bitset) { |
198 CcTest::InitializeVM(); | 761 CcTest::InitializeVM(); |
199 Isolate* isolate = CcTest::i_isolate(); | 762 ZoneTests().Bitset(); |
200 HandleScope scope(isolate); | 763 HeapTests().Bitset(); |
201 HandlifiedTypes T(isolate); | |
202 | |
203 CHECK(IsBitset(T.None)); | |
204 CHECK(IsBitset(T.Any)); | |
205 CHECK(IsBitset(T.String)); | |
206 CHECK(IsBitset(T.Object)); | |
207 | |
208 CHECK(IsBitset(T.Union(T.String, T.Number))); | |
209 CHECK(IsBitset(T.Union(T.String, T.Receiver))); | |
210 | |
211 CHECK_EQ(0, AsBitset(T.None)); | |
212 CHECK_EQ(AsBitset(T.Number) | AsBitset(T.String), | |
213 AsBitset(T.Union(T.String, T.Number))); | |
214 CHECK_EQ(AsBitset(T.Receiver), | |
215 AsBitset(T.Union(T.Receiver, T.Object))); | |
216 } | 764 } |
217 | 765 |
218 | 766 |
219 TEST(Class) { | 767 TEST(Class) { |
220 CcTest::InitializeVM(); | 768 CcTest::InitializeVM(); |
221 Isolate* isolate = CcTest::i_isolate(); | 769 ZoneTests().Class(); |
222 HandleScope scope(isolate); | 770 HeapTests().Class(); |
223 HandlifiedTypes T(isolate); | |
224 | |
225 CHECK(IsClass(T.ObjectClass)); | |
226 CHECK(IsClass(T.ArrayClass)); | |
227 | |
228 CHECK(*T.object_map == AsClass(T.ObjectClass)); | |
229 CHECK(*T.array_map == AsClass(T.ArrayClass)); | |
230 } | 771 } |
231 | 772 |
232 | 773 |
233 TEST(Constant) { | 774 TEST(Constant) { |
234 CcTest::InitializeVM(); | 775 CcTest::InitializeVM(); |
235 Isolate* isolate = CcTest::i_isolate(); | 776 ZoneTests().Constant(); |
236 HandleScope scope(isolate); | 777 HeapTests().Constant(); |
237 HandlifiedTypes T(isolate); | |
238 | |
239 CHECK(IsConstant(T.SmiConstant)); | |
240 CHECK(IsConstant(T.ObjectConstant1)); | |
241 CHECK(IsConstant(T.ObjectConstant2)); | |
242 CHECK(IsConstant(T.ArrayConstant1)); | |
243 CHECK(IsConstant(T.ArrayConstant2)); | |
244 | |
245 CHECK(*T.smi == AsConstant(T.SmiConstant)); | |
246 CHECK(*T.object1 == AsConstant(T.ObjectConstant1)); | |
247 CHECK(*T.object2 == AsConstant(T.ObjectConstant2)); | |
248 CHECK(*T.object1 != AsConstant(T.ObjectConstant2)); | |
249 CHECK(*T.array == AsConstant(T.ArrayConstant1)); | |
250 CHECK(*T.array == AsConstant(T.ArrayConstant2)); | |
251 } | 778 } |
252 | 779 |
253 | 780 |
254 TEST(Is) { | 781 TEST(Is) { |
255 CcTest::InitializeVM(); | 782 CcTest::InitializeVM(); |
256 Isolate* isolate = CcTest::i_isolate(); | 783 ZoneTests().Is(); |
257 HandleScope scope(isolate); | 784 HeapTests().Is(); |
258 HandlifiedTypes T(isolate); | |
259 | |
260 // Reflexivity | |
261 CHECK(T.None->Is(T.None)); | |
262 CHECK(T.Any->Is(T.Any)); | |
263 CHECK(T.Object->Is(T.Object)); | |
264 | |
265 CHECK(T.ObjectClass->Is(T.ObjectClass)); | |
266 CHECK(T.ObjectConstant1->Is(T.ObjectConstant1)); | |
267 CHECK(T.ArrayConstant1->Is(T.ArrayConstant2)); | |
268 | |
269 // Symmetry and Transitivity | |
270 CheckSub(T.None, T.Number); | |
271 CheckSub(T.None, T.Any); | |
272 | |
273 CheckSub(T.Oddball, T.Any); | |
274 CheckSub(T.Boolean, T.Oddball); | |
275 CheckSub(T.Null, T.Oddball); | |
276 CheckSub(T.Undefined, T.Oddball); | |
277 CheckUnordered(T.Boolean, T.Null); | |
278 CheckUnordered(T.Undefined, T.Null); | |
279 CheckUnordered(T.Boolean, T.Undefined); | |
280 | |
281 CheckSub(T.Number, T.Any); | |
282 CheckSub(T.Smi, T.Number); | |
283 CheckSub(T.Signed32, T.Number); | |
284 CheckSub(T.Double, T.Number); | |
285 CheckSub(T.Smi, T.Signed32); | |
286 CheckUnordered(T.Smi, T.Double); | |
287 CheckUnordered(T.Signed32, T.Double); | |
288 | |
289 CheckSub(T.Name, T.Any); | |
290 CheckSub(T.UniqueName, T.Any); | |
291 CheckSub(T.UniqueName, T.Name); | |
292 CheckSub(T.String, T.Name); | |
293 CheckSub(T.InternalizedString, T.String); | |
294 CheckSub(T.InternalizedString, T.UniqueName); | |
295 CheckSub(T.InternalizedString, T.Name); | |
296 CheckSub(T.Symbol, T.UniqueName); | |
297 CheckSub(T.Symbol, T.Name); | |
298 CheckUnordered(T.String, T.UniqueName); | |
299 CheckUnordered(T.String, T.Symbol); | |
300 CheckUnordered(T.InternalizedString, T.Symbol); | |
301 | |
302 CheckSub(T.Receiver, T.Any); | |
303 CheckSub(T.Object, T.Any); | |
304 CheckSub(T.Object, T.Receiver); | |
305 CheckSub(T.Array, T.Object); | |
306 CheckSub(T.Function, T.Object); | |
307 CheckSub(T.Proxy, T.Receiver); | |
308 CheckUnordered(T.Object, T.Proxy); | |
309 CheckUnordered(T.Array, T.Function); | |
310 | |
311 // Structured subtyping | |
312 CheckSub(T.None, T.ObjectClass); | |
313 CheckSub(T.None, T.ObjectConstant1); | |
314 CheckSub(T.ObjectClass, T.Any); | |
315 CheckSub(T.ObjectConstant1, T.Any); | |
316 | |
317 CheckSub(T.ObjectClass, T.Object); | |
318 CheckSub(T.ArrayClass, T.Object); | |
319 CheckUnordered(T.ObjectClass, T.ArrayClass); | |
320 | |
321 CheckSub(T.SmiConstant, T.Smi); | |
322 CheckSub(T.SmiConstant, T.Signed32); | |
323 CheckSub(T.SmiConstant, T.Number); | |
324 CheckSub(T.ObjectConstant1, T.Object); | |
325 CheckSub(T.ObjectConstant2, T.Object); | |
326 CheckSub(T.ArrayConstant1, T.Object); | |
327 CheckSub(T.ArrayConstant1, T.Array); | |
328 CheckUnordered(T.ObjectConstant1, T.ObjectConstant2); | |
329 CheckUnordered(T.ObjectConstant1, T.ArrayConstant1); | |
330 | |
331 CheckUnordered(T.ObjectConstant1, T.ObjectClass); | |
332 CheckUnordered(T.ObjectConstant2, T.ObjectClass); | |
333 CheckUnordered(T.ObjectConstant1, T.ArrayClass); | |
334 CheckUnordered(T.ObjectConstant2, T.ArrayClass); | |
335 CheckUnordered(T.ArrayConstant1, T.ObjectClass); | |
336 } | 785 } |
337 | 786 |
338 | 787 |
339 TEST(Maybe) { | 788 TEST(Maybe) { |
340 CcTest::InitializeVM(); | 789 CcTest::InitializeVM(); |
341 Isolate* isolate = CcTest::i_isolate(); | 790 ZoneTests().Maybe(); |
342 HandleScope scope(isolate); | 791 HeapTests().Maybe(); |
343 HandlifiedTypes T(isolate); | |
344 | |
345 CheckOverlap(T.Any, T.Any); | |
346 CheckOverlap(T.Object, T.Object); | |
347 | |
348 CheckOverlap(T.Oddball, T.Any); | |
349 CheckOverlap(T.Boolean, T.Oddball); | |
350 CheckOverlap(T.Null, T.Oddball); | |
351 CheckOverlap(T.Undefined, T.Oddball); | |
352 CheckDisjoint(T.Boolean, T.Null); | |
353 CheckDisjoint(T.Undefined, T.Null); | |
354 CheckDisjoint(T.Boolean, T.Undefined); | |
355 | |
356 CheckOverlap(T.Number, T.Any); | |
357 CheckOverlap(T.Smi, T.Number); | |
358 CheckOverlap(T.Double, T.Number); | |
359 CheckDisjoint(T.Signed32, T.Double); | |
360 | |
361 CheckOverlap(T.Name, T.Any); | |
362 CheckOverlap(T.UniqueName, T.Any); | |
363 CheckOverlap(T.UniqueName, T.Name); | |
364 CheckOverlap(T.String, T.Name); | |
365 CheckOverlap(T.InternalizedString, T.String); | |
366 CheckOverlap(T.InternalizedString, T.UniqueName); | |
367 CheckOverlap(T.InternalizedString, T.Name); | |
368 CheckOverlap(T.Symbol, T.UniqueName); | |
369 CheckOverlap(T.Symbol, T.Name); | |
370 CheckOverlap(T.String, T.UniqueName); | |
371 CheckDisjoint(T.String, T.Symbol); | |
372 CheckDisjoint(T.InternalizedString, T.Symbol); | |
373 | |
374 CheckOverlap(T.Receiver, T.Any); | |
375 CheckOverlap(T.Object, T.Any); | |
376 CheckOverlap(T.Object, T.Receiver); | |
377 CheckOverlap(T.Array, T.Object); | |
378 CheckOverlap(T.Function, T.Object); | |
379 CheckOverlap(T.Proxy, T.Receiver); | |
380 CheckDisjoint(T.Object, T.Proxy); | |
381 CheckDisjoint(T.Array, T.Function); | |
382 | |
383 CheckOverlap(T.ObjectClass, T.Any); | |
384 CheckOverlap(T.ObjectConstant1, T.Any); | |
385 | |
386 CheckOverlap(T.ObjectClass, T.Object); | |
387 CheckOverlap(T.ArrayClass, T.Object); | |
388 CheckOverlap(T.ObjectClass, T.ObjectClass); | |
389 CheckOverlap(T.ArrayClass, T.ArrayClass); | |
390 CheckDisjoint(T.ObjectClass, T.ArrayClass); | |
391 | |
392 CheckOverlap(T.SmiConstant, T.Smi); | |
393 CheckOverlap(T.SmiConstant, T.Signed32); | |
394 CheckOverlap(T.SmiConstant, T.Number); | |
395 CheckDisjoint(T.SmiConstant, T.Double); | |
396 CheckOverlap(T.ObjectConstant1, T.Object); | |
397 CheckOverlap(T.ObjectConstant2, T.Object); | |
398 CheckOverlap(T.ArrayConstant1, T.Object); | |
399 CheckOverlap(T.ArrayConstant1, T.Array); | |
400 CheckOverlap(T.ArrayConstant1, T.ArrayConstant2); | |
401 CheckOverlap(T.ObjectConstant1, T.ObjectConstant1); | |
402 CheckDisjoint(T.ObjectConstant1, T.ObjectConstant2); | |
403 CheckDisjoint(T.ObjectConstant1, T.ArrayConstant1); | |
404 | |
405 CheckDisjoint(T.ObjectConstant1, T.ObjectClass); | |
406 CheckDisjoint(T.ObjectConstant2, T.ObjectClass); | |
407 CheckDisjoint(T.ObjectConstant1, T.ArrayClass); | |
408 CheckDisjoint(T.ObjectConstant2, T.ArrayClass); | |
409 CheckDisjoint(T.ArrayConstant1, T.ObjectClass); | |
410 } | 792 } |
411 | 793 |
412 | 794 |
413 TEST(Union) { | 795 TEST(Union) { |
414 CcTest::InitializeVM(); | 796 CcTest::InitializeVM(); |
415 Isolate* isolate = CcTest::i_isolate(); | 797 ZoneTests().Union(); |
416 HandleScope scope(isolate); | 798 HeapTests().Union(); |
417 HandlifiedTypes T(isolate); | |
418 | |
419 // Bitset-bitset | |
420 CHECK(IsBitset(T.Union(T.Object, T.Number))); | |
421 CHECK(IsBitset(T.Union(T.Object, T.Object))); | |
422 CHECK(IsBitset(T.Union(T.Any, T.None))); | |
423 | |
424 CheckEqual(T.Union(T.None, T.Number), T.Number); | |
425 CheckEqual(T.Union(T.Object, T.Proxy), T.Receiver); | |
426 CheckEqual(T.Union(T.Number, T.String), T.Union(T.String, T.Number)); | |
427 CheckSub(T.Union(T.Number, T.String), T.Any); | |
428 | |
429 // Class-class | |
430 CHECK(IsClass(T.Union(T.ObjectClass, T.ObjectClass))); | |
431 CHECK(IsUnion(T.Union(T.ObjectClass, T.ArrayClass))); | |
432 | |
433 CheckEqual(T.Union(T.ObjectClass, T.ObjectClass), T.ObjectClass); | |
434 CheckSub(T.None, T.Union(T.ObjectClass, T.ArrayClass)); | |
435 CheckSub(T.Union(T.ObjectClass, T.ArrayClass), T.Any); | |
436 CheckSub(T.ObjectClass, T.Union(T.ObjectClass, T.ArrayClass)); | |
437 CheckSub(T.ArrayClass, T.Union(T.ObjectClass, T.ArrayClass)); | |
438 CheckSub(T.Union(T.ObjectClass, T.ArrayClass), T.Object); | |
439 CheckUnordered(T.Union(T.ObjectClass, T.ArrayClass), T.Array); | |
440 CheckOverlap(T.Union(T.ObjectClass, T.ArrayClass), T.Array); | |
441 CheckDisjoint(T.Union(T.ObjectClass, T.ArrayClass), T.Number); | |
442 | |
443 // Constant-constant | |
444 CHECK(IsConstant(T.Union(T.ObjectConstant1, T.ObjectConstant1))); | |
445 CHECK(IsConstant(T.Union(T.ArrayConstant1, T.ArrayConstant1))); | |
446 CHECK(IsUnion(T.Union(T.ObjectConstant1, T.ObjectConstant2))); | |
447 | |
448 CheckEqual(T.Union(T.ObjectConstant1, T.ObjectConstant1), T.ObjectConstant1); | |
449 CheckEqual(T.Union(T.ArrayConstant1, T.ArrayConstant1), T.ArrayConstant1); | |
450 CheckEqual(T.Union(T.ArrayConstant1, T.ArrayConstant1), T.ArrayConstant2); | |
451 CheckSub(T.None, T.Union(T.ObjectConstant1, T.ObjectConstant2)); | |
452 CheckSub(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.Any); | |
453 CheckSub(T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)); | |
454 CheckSub(T.ObjectConstant2, T.Union(T.ObjectConstant1, T.ObjectConstant2)); | |
455 CheckSub(T.ArrayConstant2, T.Union(T.ArrayConstant1, T.ObjectConstant2)); | |
456 CheckSub(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.Object); | |
457 CheckUnordered(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.ObjectClass); | |
458 CheckUnordered(T.Union(T.ObjectConstant1, T.ArrayConstant1), T.Array); | |
459 CheckOverlap(T.Union(T.ObjectConstant1, T.ArrayConstant1), T.Array); | |
460 CheckOverlap(T.Union(T.ObjectConstant1, T.ArrayConstant1), T.ArrayConstant2); | |
461 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayConstant1), T.Number); | |
462 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayConstant1), T.ObjectClass); | |
463 | |
464 // Bitset-class | |
465 CHECK(IsBitset(T.Union(T.ObjectClass, T.Object))); | |
466 CHECK(IsUnion(T.Union(T.ObjectClass, T.Number))); | |
467 | |
468 CheckEqual(T.Union(T.ObjectClass, T.Object), T.Object); | |
469 CheckSub(T.None, T.Union(T.ObjectClass, T.Number)); | |
470 CheckSub(T.Union(T.ObjectClass, T.Number), T.Any); | |
471 CheckSub(T.Union(T.ObjectClass, T.Smi), T.Union(T.Object, T.Number)); | |
472 CheckSub(T.Union(T.ObjectClass, T.Array), T.Object); | |
473 CheckUnordered(T.Union(T.ObjectClass, T.String), T.Array); | |
474 CheckOverlap(T.Union(T.ObjectClass, T.String), T.Object); | |
475 CheckDisjoint(T.Union(T.ObjectClass, T.String), T.Number); | |
476 | |
477 // Bitset-constant | |
478 CHECK(IsBitset(T.Union(T.SmiConstant, T.Number))); | |
479 CHECK(IsBitset(T.Union(T.ObjectConstant1, T.Object))); | |
480 CHECK(IsUnion(T.Union(T.ObjectConstant2, T.Number))); | |
481 | |
482 CheckEqual(T.Union(T.SmiConstant, T.Number), T.Number); | |
483 CheckEqual(T.Union(T.ObjectConstant1, T.Object), T.Object); | |
484 CheckSub(T.None, T.Union(T.ObjectConstant1, T.Number)); | |
485 CheckSub(T.Union(T.ObjectConstant1, T.Number), T.Any); | |
486 CheckSub(T.Union(T.ObjectConstant1, T.Signed32), T.Union(T.Object, T.Number)); | |
487 CheckSub(T.Union(T.ObjectConstant1, T.Array), T.Object); | |
488 CheckUnordered(T.Union(T.ObjectConstant1, T.String), T.Array); | |
489 CheckOverlap(T.Union(T.ObjectConstant1, T.String), T.Object); | |
490 CheckDisjoint(T.Union(T.ObjectConstant1, T.String), T.Number); | |
491 CheckEqual(T.Union(T.Signed32, T.Signed32Constant), T.Signed32); | |
492 | |
493 // Class-constant | |
494 CHECK(IsUnion(T.Union(T.ObjectConstant1, T.ObjectClass))); | |
495 CHECK(IsUnion(T.Union(T.ArrayClass, T.ObjectConstant2))); | |
496 | |
497 CheckSub(T.None, T.Union(T.ObjectConstant1, T.ArrayClass)); | |
498 CheckSub(T.Union(T.ObjectConstant1, T.ArrayClass), T.Any); | |
499 CheckSub(T.Union(T.ObjectConstant1, T.ArrayClass), T.Object); | |
500 CheckSub(T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ArrayClass)); | |
501 CheckSub(T.ArrayClass, T.Union(T.ObjectConstant1, T.ArrayClass)); | |
502 CheckUnordered(T.ObjectClass, T.Union(T.ObjectConstant1, T.ArrayClass)); | |
503 CheckSub( | |
504 T.Union(T.ObjectConstant1, T.ArrayClass), T.Union(T.Array, T.Object)); | |
505 CheckUnordered(T.Union(T.ObjectConstant1, T.ArrayClass), T.ArrayConstant1); | |
506 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayClass), T.ObjectConstant2); | |
507 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayClass), T.ObjectClass); | |
508 | |
509 // Bitset-union | |
510 CHECK(IsBitset(T.Union(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)))); | |
511 CHECK(IsUnion(T.Union(T.Union(T.ArrayClass, T.ObjectConstant2), T.Number))); | |
512 | |
513 CheckEqual( | |
514 T.Union(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)), | |
515 T.Object); | |
516 CheckEqual( | |
517 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Number), | |
518 T.Union(T.ObjectConstant1, T.Union(T.Number, T.ArrayClass))); | |
519 CheckSub( | |
520 T.Double, | |
521 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Number)); | |
522 CheckSub( | |
523 T.ObjectConstant1, | |
524 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Double)); | |
525 CheckSub( | |
526 T.None, | |
527 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Double)); | |
528 CheckSub( | |
529 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Double), | |
530 T.Any); | |
531 CheckSub( | |
532 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Double), | |
533 T.Union(T.ObjectConstant1, T.Union(T.Number, T.ArrayClass))); | |
534 | |
535 // Class-union | |
536 CHECK(IsUnion( | |
537 T.Union(T.Union(T.ArrayClass, T.ObjectConstant2), T.ArrayClass))); | |
538 CHECK(IsUnion( | |
539 T.Union(T.Union(T.ArrayClass, T.ObjectConstant2), T.ObjectClass))); | |
540 | |
541 CheckEqual( | |
542 T.Union(T.ObjectClass, T.Union(T.ObjectConstant1, T.ObjectClass)), | |
543 T.Union(T.ObjectClass, T.ObjectConstant1)); | |
544 CheckSub( | |
545 T.None, | |
546 T.Union(T.ObjectClass, T.Union(T.ObjectConstant1, T.ObjectClass))); | |
547 CheckSub( | |
548 T.Union(T.ObjectClass, T.Union(T.ObjectConstant1, T.ObjectClass)), | |
549 T.Any); | |
550 CheckSub( | |
551 T.Union(T.ObjectClass, T.Union(T.ObjectConstant1, T.ObjectClass)), | |
552 T.Object); | |
553 CheckEqual( | |
554 T.Union(T.Union(T.ArrayClass, T.ObjectConstant2), T.ArrayClass), | |
555 T.Union(T.ArrayClass, T.ObjectConstant2)); | |
556 | |
557 // Constant-union | |
558 CHECK(IsUnion(T.Union( | |
559 T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)))); | |
560 CHECK(IsUnion(T.Union( | |
561 T.Union(T.ArrayConstant1, T.ObjectClass), T.ObjectConstant1))); | |
562 CHECK(IsUnion(T.Union( | |
563 T.Union(T.ArrayConstant1, T.ObjectConstant2), T.ObjectConstant1))); | |
564 | |
565 CheckEqual( | |
566 T.Union(T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)), | |
567 T.Union(T.ObjectConstant2, T.ObjectConstant1)); | |
568 CheckEqual( | |
569 T.Union(T.Union(T.ArrayConstant1, T.ObjectConstant2), T.ObjectConstant1), | |
570 T.Union(T.ObjectConstant2, T.Union(T.ArrayConstant1, T.ObjectConstant1))); | |
571 | |
572 // Union-union | |
573 CHECK(IsBitset(T.Union( | |
574 T.Union(T.Number, T.ArrayClass), T.Union(T.Signed32, T.Array)))); | |
575 CHECK(IsUnion(T.Union( | |
576 T.Union(T.Number, T.ArrayClass), T.Union(T.ObjectClass, T.ArrayClass)))); | |
577 | |
578 CheckEqual( | |
579 T.Union( | |
580 T.Union(T.ObjectConstant2, T.ObjectConstant1), | |
581 T.Union(T.ObjectConstant1, T.ObjectConstant2)), | |
582 T.Union(T.ObjectConstant2, T.ObjectConstant1)); | |
583 CheckEqual( | |
584 T.Union( | |
585 T.Union(T.ObjectConstant2, T.ArrayConstant1), | |
586 T.Union(T.ObjectConstant1, T.ArrayConstant2)), | |
587 T.Union(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.ArrayConstant1)); | |
588 CheckEqual( | |
589 T.Union(T.Union(T.Number, T.ArrayClass), T.Union(T.Smi, T.Array)), | |
590 T.Union(T.Number, T.Array)); | |
591 } | 799 } |
592 | 800 |
593 | 801 |
594 TEST(Intersect) { | 802 TEST(Intersect) { |
595 CcTest::InitializeVM(); | 803 CcTest::InitializeVM(); |
596 Isolate* isolate = CcTest::i_isolate(); | 804 ZoneTests().Intersect(); |
597 HandleScope scope(isolate); | 805 HeapTests().Intersect(); |
598 HandlifiedTypes T(isolate); | |
599 | |
600 // Bitset-bitset | |
601 CHECK(IsBitset(T.Intersect(T.Object, T.Number))); | |
602 CHECK(IsBitset(T.Intersect(T.Object, T.Object))); | |
603 CHECK(IsBitset(T.Intersect(T.Any, T.None))); | |
604 | |
605 CheckEqual(T.Intersect(T.None, T.Number), T.None); | |
606 CheckEqual(T.Intersect(T.Object, T.Proxy), T.None); | |
607 CheckEqual(T.Intersect(T.Name, T.String), T.Intersect(T.String, T.Name)); | |
608 CheckEqual(T.Intersect(T.UniqueName, T.String), T.InternalizedString); | |
609 | |
610 // Class-class | |
611 CHECK(IsClass(T.Intersect(T.ObjectClass, T.ObjectClass))); | |
612 CHECK(IsBitset(T.Intersect(T.ObjectClass, T.ArrayClass))); | |
613 | |
614 CheckEqual(T.Intersect(T.ObjectClass, T.ObjectClass), T.ObjectClass); | |
615 CheckEqual(T.Intersect(T.ObjectClass, T.ArrayClass), T.None); | |
616 | |
617 // Constant-constant | |
618 CHECK(IsConstant(T.Intersect(T.ObjectConstant1, T.ObjectConstant1))); | |
619 CHECK(IsConstant(T.Intersect(T.ArrayConstant1, T.ArrayConstant2))); | |
620 CHECK(IsBitset(T.Intersect(T.ObjectConstant1, T.ObjectConstant2))); | |
621 | |
622 CheckEqual( | |
623 T.Intersect(T.ObjectConstant1, T.ObjectConstant1), T.ObjectConstant1); | |
624 CheckEqual( | |
625 T.Intersect(T.ArrayConstant1, T.ArrayConstant2), T.ArrayConstant1); | |
626 CheckEqual(T.Intersect(T.ObjectConstant1, T.ObjectConstant2), T.None); | |
627 | |
628 // Bitset-class | |
629 CHECK(IsClass(T.Intersect(T.ObjectClass, T.Object))); | |
630 CHECK(IsBitset(T.Intersect(T.ObjectClass, T.Number))); | |
631 | |
632 CheckEqual(T.Intersect(T.ObjectClass, T.Object), T.ObjectClass); | |
633 CheckEqual(T.Intersect(T.ObjectClass, T.Array), T.None); | |
634 CheckEqual(T.Intersect(T.ObjectClass, T.Number), T.None); | |
635 | |
636 // Bitset-constant | |
637 CHECK(IsBitset(T.Intersect(T.Smi, T.Number))); | |
638 CHECK(IsConstant(T.Intersect(T.SmiConstant, T.Number))); | |
639 CHECK(IsConstant(T.Intersect(T.ObjectConstant1, T.Object))); | |
640 | |
641 CheckEqual(T.Intersect(T.Smi, T.Number), T.Smi); | |
642 CheckEqual(T.Intersect(T.SmiConstant, T.Number), T.SmiConstant); | |
643 CheckEqual(T.Intersect(T.ObjectConstant1, T.Object), T.ObjectConstant1); | |
644 | |
645 // Class-constant | |
646 CHECK(IsBitset(T.Intersect(T.ObjectConstant1, T.ObjectClass))); | |
647 CHECK(IsBitset(T.Intersect(T.ArrayClass, T.ObjectConstant2))); | |
648 | |
649 CheckEqual(T.Intersect(T.ObjectConstant1, T.ObjectClass), T.None); | |
650 CheckEqual(T.Intersect(T.ArrayClass, T.ObjectConstant2), T.None); | |
651 | |
652 // Bitset-union | |
653 CHECK(IsUnion( | |
654 T.Intersect(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)))); | |
655 CHECK(IsBitset( | |
656 T.Intersect(T.Union(T.ArrayClass, T.ObjectConstant2), T.Number))); | |
657 | |
658 CheckEqual( | |
659 T.Intersect(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)), | |
660 T.Union(T.ObjectConstant1, T.ObjectClass)); | |
661 CheckEqual( | |
662 T.Intersect(T.Union(T.ArrayClass, T.ObjectConstant1), T.Number), | |
663 T.None); | |
664 | |
665 // Class-union | |
666 CHECK(IsClass( | |
667 T.Intersect(T.Union(T.ArrayClass, T.ObjectConstant2), T.ArrayClass))); | |
668 CHECK(IsClass( | |
669 T.Intersect(T.Union(T.Object, T.SmiConstant), T.ArrayClass))); | |
670 CHECK(IsBitset( | |
671 T.Intersect(T.Union(T.ObjectClass, T.ArrayConstant1), T.ArrayClass))); | |
672 | |
673 CheckEqual( | |
674 T.Intersect(T.ArrayClass, T.Union(T.ObjectConstant2, T.ArrayClass)), | |
675 T.ArrayClass); | |
676 CheckEqual( | |
677 T.Intersect(T.ArrayClass, T.Union(T.Object, T.SmiConstant)), | |
678 T.ArrayClass); | |
679 CheckEqual( | |
680 T.Intersect(T.Union(T.ObjectClass, T.ArrayConstant1), T.ArrayClass), | |
681 T.None); | |
682 | |
683 // Constant-union | |
684 CHECK(IsConstant(T.Intersect( | |
685 T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)))); | |
686 CHECK(IsConstant(T.Intersect( | |
687 T.Union(T.Number, T.ObjectClass), T.SmiConstant))); | |
688 CHECK(IsBitset(T.Intersect( | |
689 T.Union(T.ArrayConstant1, T.ObjectClass), T.ObjectConstant1))); | |
690 | |
691 CheckEqual( | |
692 T.Intersect( | |
693 T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)), | |
694 T.ObjectConstant1); | |
695 CheckEqual( | |
696 T.Intersect(T.SmiConstant, T.Union(T.Number, T.ObjectConstant2)), | |
697 T.SmiConstant); | |
698 CheckEqual( | |
699 T.Intersect(T.Union(T.ArrayConstant1, T.ObjectClass), T.ObjectConstant1), | |
700 T.None); | |
701 | |
702 // Union-union | |
703 CHECK(IsUnion(T.Intersect( | |
704 T.Union(T.Number, T.ArrayClass), T.Union(T.Signed32, T.Array)))); | |
705 CHECK(IsBitset(T.Intersect( | |
706 T.Union(T.Number, T.ObjectClass), T.Union(T.Signed32, T.Array)))); | |
707 | |
708 CheckEqual( | |
709 T.Intersect( | |
710 T.Union(T.Number, T.ArrayClass), | |
711 T.Union(T.Smi, T.Array)), | |
712 T.Union(T.Smi, T.ArrayClass)); | |
713 CheckEqual( | |
714 T.Intersect( | |
715 T.Union(T.Number, T.ObjectClass), | |
716 T.Union(T.Signed32, T.Array)), | |
717 T.Signed32); | |
718 CheckEqual( | |
719 T.Intersect( | |
720 T.Union(T.ObjectConstant2, T.ObjectConstant1), | |
721 T.Union(T.ObjectConstant1, T.ObjectConstant2)), | |
722 T.Union(T.ObjectConstant2, T.ObjectConstant1)); | |
723 CheckEqual( | |
724 T.Intersect( | |
725 T.Union(T.Union(T.ObjectConstant2, T.ObjectConstant1), T.ArrayClass), | |
726 T.Union( | |
727 T.ObjectConstant1, T.Union(T.ArrayConstant1, T.ObjectConstant2))), | |
728 T.Union(T.ObjectConstant2, T.ObjectConstant1)); | |
729 CheckEqual( | |
730 T.Intersect( | |
731 T.Union(T.ObjectConstant2, T.ArrayConstant1), | |
732 T.Union(T.ObjectConstant1, T.ArrayConstant2)), | |
733 T.ArrayConstant1); | |
734 } | 806 } |
OLD | NEW |