| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// Equivalence test functions for data objects. | 5 /// Equivalence test functions for data objects. |
| 6 | 6 |
| 7 library dart2js.equivalence.functions; | 7 library dart2js.equivalence.functions; |
| 8 | 8 |
| 9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
| 10 import 'package:compiler/src/common/resolution.dart'; | 10 import 'package:compiler/src/common/resolution.dart'; |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 } | 206 } |
| 207 Expect.isFalse( | 207 Expect.isFalse( |
| 208 child.isInstantiated, | 208 child.isInstantiated, |
| 209 'Missing subclass ${child.cls} of ${node1.cls} in ' | 209 'Missing subclass ${child.cls} of ${node1.cls} in ' |
| 210 '${node2.directSubclasses}'); | 210 '${node2.directSubclasses}'); |
| 211 } | 211 } |
| 212 } | 212 } |
| 213 checkMixinUses( | 213 checkMixinUses( |
| 214 closedWorld1, closedWorld2, node1.cls, node2.cls, elementEquivalence, | 214 closedWorld1, closedWorld2, node1.cls, node2.cls, elementEquivalence, |
| 215 verbose: verbose); | 215 verbose: verbose); |
| 216 Expect.isNotNull( | 216 ClassSet classSet1 = closedWorld1.getClassSet(cls1); |
| 217 closedWorld1.getClassSet(cls1), "Missing ClassSet for $cls1"); | 217 ClassSet classSet2 = closedWorld2.getClassSet(cls2); |
| 218 Expect.isNotNull( | 218 Expect.isNotNull(classSet1, "Missing ClassSet for $cls1"); |
| 219 closedWorld2.getClassSet(cls2), "Missing ClassSet for $cls2"); | 219 Expect.isNotNull(classSet2, "Missing ClassSet for $cls2"); |
| 220 checkClassSets( |
| 221 closedWorld1, closedWorld2, classSet1, classSet2, elementEquivalence, |
| 222 verbose: verbose, allowMissingClosureClasses: allowMissingClosureClasses); |
| 223 } |
| 224 |
| 225 void checkClassSets( |
| 226 ClosedWorld closedWorld1, |
| 227 ClosedWorld closedWorld2, |
| 228 ClassSet classSet1, |
| 229 ClassSet classSet2, |
| 230 bool elementEquivalence(Entity a, Entity b), |
| 231 {bool verbose: false, |
| 232 bool allowMissingClosureClasses: false}) { |
| 233 for (ClassHierarchyNode child in classSet1.subtypeNodes) { |
| 234 bool found = false; |
| 235 for (ClassHierarchyNode other in classSet2.subtypeNodes) { |
| 236 ClassEntity child1 = child.cls; |
| 237 ClassEntity child2 = other.cls; |
| 238 if (elementEquivalence(child1, child2)) { |
| 239 found = true; |
| 240 break; |
| 241 } |
| 242 } |
| 243 if (!found && (!child.cls.isClosure || !allowMissingClosureClasses)) { |
| 244 if (child.isInstantiated) { |
| 245 print('Missing subtype ${child.cls} of ${classSet1.cls} ' |
| 246 'in ${classSet2.subtypeNodes}'); |
| 247 print(closedWorld1.dump( |
| 248 verbose ? closedWorld1.commonElements.objectClass : classSet1.cls)); |
| 249 print(closedWorld2.dump( |
| 250 verbose ? closedWorld2.commonElements.objectClass : classSet2.cls)); |
| 251 } |
| 252 Expect.isFalse( |
| 253 child.isInstantiated, |
| 254 'Missing subclass ${child.cls} of ${classSet1.cls} in ' |
| 255 '${classSet2.subtypeNodes}'); |
| 256 } |
| 257 } |
| 220 } | 258 } |
| 221 | 259 |
| 222 void checkMixinUses( | 260 void checkMixinUses( |
| 223 ClosedWorld closedWorld1, | 261 ClosedWorld closedWorld1, |
| 224 ClosedWorld closedWorld2, | 262 ClosedWorld closedWorld2, |
| 225 ClassEntity class1, | 263 ClassEntity class1, |
| 226 ClassEntity class2, | 264 ClassEntity class2, |
| 227 bool elementEquivalence(Entity a, Entity b), | 265 bool elementEquivalence(Entity a, Entity b), |
| 228 {bool verbose: false}) { | 266 {bool verbose: false}) { |
| 229 checkSets(closedWorld1.mixinUsesOf(class1), closedWorld2.mixinUsesOf(class2), | 267 checkSets(closedWorld1.mixinUsesOf(class1), closedWorld2.mixinUsesOf(class2), |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 check(usage1, usage2, 'isRuntimeTypeUsed', usage1.isRuntimeTypeUsed, | 485 check(usage1, usage2, 'isRuntimeTypeUsed', usage1.isRuntimeTypeUsed, |
| 448 usage2.isRuntimeTypeUsed); | 486 usage2.isRuntimeTypeUsed); |
| 449 check(usage1, usage2, 'isIsolateInUse', usage1.isIsolateInUse, | 487 check(usage1, usage2, 'isIsolateInUse', usage1.isIsolateInUse, |
| 450 usage2.isIsolateInUse); | 488 usage2.isIsolateInUse); |
| 451 check(usage1, usage2, 'isFunctionApplyUsed', usage1.isFunctionApplyUsed, | 489 check(usage1, usage2, 'isFunctionApplyUsed', usage1.isFunctionApplyUsed, |
| 452 usage2.isFunctionApplyUsed); | 490 usage2.isFunctionApplyUsed); |
| 453 check(usage1, usage2, 'isNoSuchMethodUsed', usage1.isNoSuchMethodUsed, | 491 check(usage1, usage2, 'isNoSuchMethodUsed', usage1.isNoSuchMethodUsed, |
| 454 usage2.isNoSuchMethodUsed); | 492 usage2.isNoSuchMethodUsed); |
| 455 } | 493 } |
| 456 | 494 |
| 457 checkElementEnvironment( | 495 checkElementEnvironment(ElementEnvironment env1, ElementEnvironment env2, |
| 458 ElementEnvironment env1, ElementEnvironment env2, TestStrategy strategy, | 496 DartTypes types1, DartTypes types2, TestStrategy strategy, |
| 459 {bool checkConstructorBodies: false}) { | 497 {bool checkConstructorBodies: false}) { |
| 460 strategy.testElements( | 498 strategy.testElements( |
| 461 env1, env2, 'mainLibrary', env1.mainLibrary, env2.mainLibrary); | 499 env1, env2, 'mainLibrary', env1.mainLibrary, env2.mainLibrary); |
| 462 strategy.testElements( | 500 strategy.testElements( |
| 463 env1, env2, 'mainFunction', env1.mainFunction, env2.mainFunction); | 501 env1, env2, 'mainFunction', env1.mainFunction, env2.mainFunction); |
| 464 | 502 |
| 465 checkMembers(MemberEntity member1, MemberEntity member2) { | 503 checkMembers(MemberEntity member1, MemberEntity member2) { |
| 466 Expect.equals(env1.isDeferredLoadLibraryGetter(member1), | 504 Expect.equals(env1.isDeferredLoadLibraryGetter(member1), |
| 467 env2.isDeferredLoadLibraryGetter(member2)); | 505 env2.isDeferredLoadLibraryGetter(member2)); |
| 468 | 506 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 check( | 582 check( |
| 545 cls1, | 583 cls1, |
| 546 cls2, | 584 cls2, |
| 547 'getEffectiveMixinClass', | 585 'getEffectiveMixinClass', |
| 548 env1.getEffectiveMixinClass(cls1), | 586 env1.getEffectiveMixinClass(cls1), |
| 549 env2.getEffectiveMixinClass(cls2), | 587 env2.getEffectiveMixinClass(cls2), |
| 550 strategy.elementEquivalence); | 588 strategy.elementEquivalence); |
| 551 | 589 |
| 552 // TODO(johnniwinther): Check type variable bounds. | 590 // TODO(johnniwinther): Check type variable bounds. |
| 553 | 591 |
| 592 check(cls1, cls2, 'callType', types1.getCallType(thisType1), |
| 593 types2.getCallType(thisType2), strategy.typeEquivalence); |
| 594 |
| 554 List<InterfaceType> supertypes1 = <InterfaceType>[]; | 595 List<InterfaceType> supertypes1 = <InterfaceType>[]; |
| 555 env1.forEachSupertype(cls1, supertypes1.add); | 596 env1.forEachSupertype(cls1, supertypes1.add); |
| 556 List<InterfaceType> supertypes2 = <InterfaceType>[]; | 597 List<InterfaceType> supertypes2 = <InterfaceType>[]; |
| 557 env2.forEachSupertype(cls2, supertypes2.add); | 598 env2.forEachSupertype(cls2, supertypes2.add); |
| 558 checkLists(supertypes1, supertypes2, 'supertypes on $cls1, $cls2', | 599 checkLists(supertypes1, supertypes2, 'supertypes on $cls1, $cls2', |
| 559 strategy.typeEquivalence); | 600 strategy.typeEquivalence); |
| 560 | 601 |
| 561 List<ClassEntity> mixins1 = <ClassEntity>[]; | 602 List<ClassEntity> mixins1 = <ClassEntity>[]; |
| 562 env1.forEachMixin(cls1, mixins1.add); | 603 env1.forEachMixin(cls1, mixins1.add); |
| 563 List<ClassEntity> mixins2 = <ClassEntity>[]; | 604 List<ClassEntity> mixins2 = <ClassEntity>[]; |
| (...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1179 print(' ${js.nodeToString(node1)}'); | 1220 print(' ${js.nodeToString(node1)}'); |
| 1180 print(' ${js.nodeToString(node2)}'); | 1221 print(' ${js.nodeToString(node2)}'); |
| 1181 } | 1222 } |
| 1182 return expectedValue == label2; | 1223 return expectedValue == label2; |
| 1183 } else { | 1224 } else { |
| 1184 labelsMap[label1] = label2; | 1225 labelsMap[label1] = label2; |
| 1185 return true; | 1226 return true; |
| 1186 } | 1227 } |
| 1187 } | 1228 } |
| 1188 } | 1229 } |
| OLD | NEW |