| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library dart2js.serialization_test_helper; | 5 library dart2js.serialization_test_helper; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'package:compiler/src/common/resolution.dart'; | 8 import 'package:compiler/src/common/resolution.dart'; |
| 9 import 'package:compiler/src/constants/expressions.dart'; | 9 import 'package:compiler/src/constants/expressions.dart'; |
| 10 import 'package:compiler/src/constants/values.dart'; | 10 import 'package:compiler/src/constants/values.dart'; |
| 11 import 'package:compiler/src/compiler.dart'; | 11 import 'package:compiler/src/compiler.dart'; |
| 12 import 'package:compiler/src/elements/elements.dart'; | 12 import 'package:compiler/src/elements/elements.dart'; |
| 13 import 'package:compiler/src/elements/entities.dart'; | 13 import 'package:compiler/src/elements/entities.dart'; |
| 14 import 'package:compiler/src/elements/resolution_types.dart'; | 14 import 'package:compiler/src/elements/resolution_types.dart'; |
| 15 import 'package:compiler/src/elements/types.dart'; | 15 import 'package:compiler/src/elements/types.dart'; |
| 16 import 'package:compiler/src/kernel/elements.dart'; | 16 import 'package:compiler/src/kernel/elements.dart'; |
| 17 import 'package:compiler/src/kernel/world_builder.dart'; | 17 import 'package:compiler/src/kernel/world_builder.dart'; |
| 18 import 'package:compiler/src/serialization/equivalence.dart'; | 18 import 'package:compiler/src/serialization/equivalence.dart'; |
| 19 import 'package:compiler/src/util/util.dart'; |
| 19 import 'package:expect/expect.dart'; | 20 import 'package:expect/expect.dart'; |
| 20 import 'test_data.dart'; | 21 import 'test_data.dart'; |
| 21 | 22 |
| 22 Check currentCheck; | 23 Check currentCheck; |
| 23 | 24 |
| 24 class Check { | 25 class Check { |
| 25 final Check parent; | 26 final Check parent; |
| 26 final Object object1; | 27 final Object object1; |
| 27 final Object object2; | 28 final Object object2; |
| 28 final String property; | 29 final String property; |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 } else if (index == count) { | 630 } else if (index == count) { |
| 630 return [segmentNumber(index - 1)]; | 631 return [segmentNumber(index - 1)]; |
| 631 } else { | 632 } else { |
| 632 return [segmentNumber(index - 1), segmentNumber(index)]; | 633 return [segmentNumber(index - 1), segmentNumber(index)]; |
| 633 } | 634 } |
| 634 } | 635 } |
| 635 | 636 |
| 636 class KernelEquivalence { | 637 class KernelEquivalence { |
| 637 final WorldDeconstructionForTesting testing; | 638 final WorldDeconstructionForTesting testing; |
| 638 | 639 |
| 640 /// Set of mixin applications assumed to be equivalent. |
| 641 /// |
| 642 /// We need co-inductive reasoning because mixin applications are compared |
| 643 /// structurally and therefore, in the case of generic mixin applications, |
| 644 /// meet themselves through the equivalence check of their type variables. |
| 645 Set<Pair<ClassEntity, ClassEntity>> assumedMixinApplications = |
| 646 new Set<Pair<ClassEntity, ClassEntity>>(); |
| 647 |
| 639 KernelEquivalence(KernelWorldBuilder builder) | 648 KernelEquivalence(KernelWorldBuilder builder) |
| 640 : testing = new WorldDeconstructionForTesting(builder); | 649 : testing = new WorldDeconstructionForTesting(builder); |
| 641 | 650 |
| 642 TestStrategy get defaultStrategy => new TestStrategy( | 651 TestStrategy get defaultStrategy => new TestStrategy( |
| 643 elementEquivalence: entityEquivalence, typeEquivalence: typeEquivalence); | 652 elementEquivalence: entityEquivalence, typeEquivalence: typeEquivalence); |
| 644 | 653 |
| 645 bool entityEquivalence(Element a, Entity b, {TestStrategy strategy}) { | 654 bool entityEquivalence(Element a, Entity b, {TestStrategy strategy}) { |
| 646 if (identical(a, b)) return true; | 655 if (identical(a, b)) return true; |
| 647 if (a == null || b == null) return false; | 656 if (a == null || b == null) return false; |
| 648 strategy ??= defaultStrategy; | 657 strategy ??= defaultStrategy; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 676 InterfaceType mixinType = testing.getMixinTypeForClass(bClass); | 685 InterfaceType mixinType = testing.getMixinTypeForClass(bClass); |
| 677 if (mixinType == null) break; | 686 if (mixinType == null) break; |
| 678 bMixinTypes.add(mixinType); | 687 bMixinTypes.add(mixinType); |
| 679 bClass = testing.getSuperclassForClass(bClass); | 688 bClass = testing.getSuperclassForClass(bClass); |
| 680 } | 689 } |
| 681 if (aMixinTypes.isNotEmpty || aMixinTypes.isNotEmpty) { | 690 if (aMixinTypes.isNotEmpty || aMixinTypes.isNotEmpty) { |
| 682 if (aClass.isNamedMixinApplication && | 691 if (aClass.isNamedMixinApplication && |
| 683 !strategy.test(a, b, 'name', a.name, b.name)) { | 692 !strategy.test(a, b, 'name', a.name, b.name)) { |
| 684 return false; | 693 return false; |
| 685 } | 694 } |
| 686 return strategy.testTypeLists( | 695 Pair<ClassEntity, ClassEntity> pair = |
| 687 a, b, 'mixinTypes', aMixinTypes, bMixinTypes); | 696 new Pair<ClassEntity, ClassEntity>(aClass, bClass); |
| 697 if (assumedMixinApplications.contains(pair)) { |
| 698 return true; |
| 699 } else { |
| 700 assumedMixinApplications.add(pair); |
| 701 bool result = strategy.testTypeLists( |
| 702 a, b, 'mixinTypes', aMixinTypes, bMixinTypes); |
| 703 assumedMixinApplications.remove(pair); |
| 704 return result; |
| 705 } |
| 688 } | 706 } |
| 689 return strategy.test(a, b, 'name', a.name, b.name) && | 707 return strategy.test(a, b, 'name', a.name, b.name) && |
| 690 strategy.testElements( | 708 strategy.testElements( |
| 691 a, b, 'library', a.library, testing.getLibraryForClass(b)); | 709 a, b, 'library', a.library, testing.getLibraryForClass(b)); |
| 692 } | 710 } |
| 693 return false; | 711 return false; |
| 694 case ElementKind.LIBRARY: | 712 case ElementKind.LIBRARY: |
| 695 if (b is KLibrary) { | 713 if (b is KLibrary) { |
| 696 LibraryElement libraryA = a; | 714 LibraryElement libraryA = a; |
| 697 return libraryA.canonicalUri == testing.getLibraryUri(b); | 715 return libraryA.canonicalUri == testing.getLibraryUri(b); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 strategy.testTypeLists(a, b, 'namedParameterTypes', | 821 strategy.testTypeLists(a, b, 'namedParameterTypes', |
| 804 aType.namedParameterTypes, b.namedParameterTypes); | 822 aType.namedParameterTypes, b.namedParameterTypes); |
| 805 } | 823 } |
| 806 return false; | 824 return false; |
| 807 default: | 825 default: |
| 808 throw new UnsupportedError('Unsupported equivalence: ' | 826 throw new UnsupportedError('Unsupported equivalence: ' |
| 809 '$a (${a.runtimeType}) vs $b (${b.runtimeType})'); | 827 '$a (${a.runtimeType}) vs $b (${b.runtimeType})'); |
| 810 } | 828 } |
| 811 } | 829 } |
| 812 } | 830 } |
| OLD | NEW |