Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: pkg/compiler/lib/src/serialization/equivalence.dart

Issue 2874973003: Add more equivalence tests for ElementEnvironment (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 /// Functions for asserting equivalence across serialization. 5 /// Functions for asserting equivalence across serialization.
6 6
7 library dart2js.serialization.equivalence; 7 library dart2js.serialization.equivalence;
8 8
9 import '../closure.dart'; 9 import '../closure.dart';
10 import '../common/resolution.dart'; 10 import '../common/resolution.dart';
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 71
72 /// Returns `true` if the content of [map1] and [map2] is equivalent using 72 /// Returns `true` if the content of [map1] and [map2] is equivalent using
73 /// [keyEquivalence] and [valueEquivalence] to determine key/value equivalence. 73 /// [keyEquivalence] and [valueEquivalence] to determine key/value equivalence.
74 bool areMapsEquivalent(Map map1, Map map2, 74 bool areMapsEquivalent(Map map1, Map map2,
75 [bool keyEquivalence(a, b) = equality, 75 [bool keyEquivalence(a, b) = equality,
76 bool valueEquivalence(a, b) = equality]) { 76 bool valueEquivalence(a, b) = equality]) {
77 Set remaining = map2.keys.toSet(); 77 Set remaining = map2.keys.toSet();
78 for (var key1 in map1.keys) { 78 for (var key1 in map1.keys) {
79 bool found = false; 79 bool found = false;
80 for (var key2 in map2.keys) { 80 for (var key2 in map2.keys) {
81 if (keyEquivalence(key2, key2)) { 81 if (keyEquivalence(key1, key2)) {
Siggi Cherem (dart-lang) 2017/05/11 19:12:24 maybe we need tests for the equivalent checks :)
Johnni Winther 2017/05/12 08:11:25 ;)
82 found = true; 82 found = true;
83 remaining.remove(key2); 83 remaining.remove(key2);
84 if (!valueEquivalence(map1[key1], map2[key2])) { 84 if (!valueEquivalence(map1[key1], map2[key2])) {
85 return false; 85 return false;
86 } 86 }
87 break; 87 break;
88 } 88 }
89 } 89 }
90 if (!found) { 90 if (!found) {
91 return false; 91 return false;
(...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 907
908 bool visit(ConstantValue value1, ConstantValue value2) { 908 bool visit(ConstantValue value1, ConstantValue value2) {
909 if (identical(value1, value2)) return true; 909 if (identical(value1, value2)) return true;
910 return strategy.test(value1, value2, 'kind', value1.kind, value2.kind) && 910 return strategy.test(value1, value2, 'kind', value1.kind, value2.kind) &&
911 value1.accept(this, value2); 911 value1.accept(this, value2);
912 } 912 }
913 913
914 @override 914 @override
915 bool visitConstructed( 915 bool visitConstructed(
916 ConstructedConstantValue value1, ConstructedConstantValue value2) { 916 ConstructedConstantValue value1, ConstructedConstantValue value2) {
917 ResolutionInterfaceType type1 = value1.type; 917 return strategy.testTypes(
918 ResolutionInterfaceType type2 = value2.type; 918 value1, value2, 'type', value1.type, value2.type) &&
919 return strategy.testTypes(value1, value2, 'type', type1, type2) &&
920 strategy.testMaps( 919 strategy.testMaps(
921 value1, 920 value1,
922 value2, 921 value2,
923 'fields', 922 'fields',
924 value1.fields, 923 value1.fields,
925 value2.fields, 924 value2.fields,
926 areElementsEquivalent, 925 strategy.elementEquivalence,
927 (a, b) => strategy.testConstantValues( 926 (a, b) => strategy.testConstantValues(
928 value1, value2, 'fields.values', a, b)); 927 value1, value2, 'fields.values', a, b));
929 } 928 }
930 929
931 @override 930 @override
932 bool visitFunction( 931 bool visitFunction(
933 FunctionConstantValue value1, FunctionConstantValue value2) { 932 FunctionConstantValue value1, FunctionConstantValue value2) {
934 MethodElement method1 = value1.element; 933 return strategy.testElements(
935 MethodElement method2 = value2.element; 934 value1, value2, 'element', value1.element, value2.element);
936 return strategy.testElements(value1, value2, 'element', method1, method2);
937 } 935 }
938 936
939 @override 937 @override
940 bool visitList(ListConstantValue value1, ListConstantValue value2) { 938 bool visitList(ListConstantValue value1, ListConstantValue value2) {
941 ResolutionInterfaceType type1 = value1.type; 939 return strategy.testTypes(
942 ResolutionInterfaceType type2 = value2.type; 940 value1, value2, 'type', value1.type, value2.type) &&
943 return strategy.testTypes(value1, value2, 'type', type1, type2) &&
944 strategy.testConstantValueLists( 941 strategy.testConstantValueLists(
945 value1, value2, 'entries', value1.entries, value2.entries); 942 value1, value2, 'entries', value1.entries, value2.entries);
946 } 943 }
947 944
948 @override 945 @override
949 bool visitMap(MapConstantValue value1, MapConstantValue value2) { 946 bool visitMap(MapConstantValue value1, MapConstantValue value2) {
950 ResolutionInterfaceType type1 = value1.type; 947 return strategy.testTypes(
951 ResolutionInterfaceType type2 = value2.type; 948 value1, value2, 'type', value1.type, value2.type) &&
952 return strategy.testTypes(value1, value2, 'type', type1, type2) &&
953 strategy.testConstantValueLists( 949 strategy.testConstantValueLists(
954 value1, value2, 'keys', value1.keys, value2.keys) && 950 value1, value2, 'keys', value1.keys, value2.keys) &&
955 strategy.testConstantValueLists( 951 strategy.testConstantValueLists(
956 value1, value2, 'values', value1.values, value2.values); 952 value1, value2, 'values', value1.values, value2.values);
957 } 953 }
958 954
959 @override 955 @override
960 bool visitType(TypeConstantValue value1, TypeConstantValue value2) { 956 bool visitType(TypeConstantValue value1, TypeConstantValue value2) {
961 ResolutionInterfaceType type1 = value1.type; 957 return strategy.testTypes(value1, value2, 'type', value1.type, value2.type);
962 ResolutionInterfaceType type2 = value2.type;
963 return strategy.testTypes(value1, value2, 'type', type1, type2);
964 } 958 }
965 959
966 @override 960 @override
967 bool visitBool(BoolConstantValue value1, BoolConstantValue value2) { 961 bool visitBool(BoolConstantValue value1, BoolConstantValue value2) {
968 return strategy.test(value1, value2, 'primitiveValue', 962 return strategy.test(value1, value2, 'primitiveValue',
969 value1.primitiveValue, value2.primitiveValue); 963 value1.primitiveValue, value2.primitiveValue);
970 } 964 }
971 965
972 @override 966 @override
973 bool visitDouble(DoubleConstantValue value1, DoubleConstantValue value2) { 967 bool visitDouble(DoubleConstantValue value1, DoubleConstantValue value2) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 SyntheticConstantValue value1, SyntheticConstantValue value2) { 1005 SyntheticConstantValue value1, SyntheticConstantValue value2) {
1012 return strategy.test( 1006 return strategy.test(
1013 value1, value2, 'payload', value1.payload, value2.payload) && 1007 value1, value2, 'payload', value1.payload, value2.payload) &&
1014 strategy.test( 1008 strategy.test(
1015 value1, value2, 'valueKind', value1.valueKind, value2.valueKind); 1009 value1, value2, 'valueKind', value1.valueKind, value2.valueKind);
1016 } 1010 }
1017 1011
1018 @override 1012 @override
1019 bool visitInterceptor( 1013 bool visitInterceptor(
1020 InterceptorConstantValue value1, InterceptorConstantValue value2) { 1014 InterceptorConstantValue value1, InterceptorConstantValue value2) {
1021 ClassElement cls1 = value1.cls; 1015 return strategy.testElements(value1, value2, 'cls', value1.cls, value2.cls);
1022 ClassElement cls2 = value2.cls;
1023 return strategy.testElements(value1, value2, 'cls', cls1, cls2);
1024 } 1016 }
1025 } 1017 }
1026 1018
1027 /// Tests the equivalence of [impact1] and [impact2] using [strategy]. 1019 /// Tests the equivalence of [impact1] and [impact2] using [strategy].
1028 bool testResolutionImpactEquivalence( 1020 bool testResolutionImpactEquivalence(
1029 ResolutionImpact impact1, ResolutionImpact impact2, 1021 ResolutionImpact impact1, ResolutionImpact impact2,
1030 {TestStrategy strategy = const TestStrategy()}) { 1022 {TestStrategy strategy = const TestStrategy()}) {
1031 return strategy.testSets(impact1, impact2, 'constSymbolNames', 1023 return strategy.testSets(impact1, impact2, 'constSymbolNames',
1032 impact1.constSymbolNames, impact2.constSymbolNames) && 1024 impact1.constSymbolNames, impact2.constSymbolNames) &&
1033 strategy.testSets( 1025 strategy.testSets(
(...skipping 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after
2144 } 2136 }
2145 2137
2146 bool areMetadataAnnotationsEquivalent( 2138 bool areMetadataAnnotationsEquivalent(
2147 MetadataAnnotation metadata1, MetadataAnnotation metadata2) { 2139 MetadataAnnotation metadata1, MetadataAnnotation metadata2) {
2148 if (metadata1 == metadata2) return true; 2140 if (metadata1 == metadata2) return true;
2149 if (metadata1 == null || metadata2 == null) return false; 2141 if (metadata1 == null || metadata2 == null) return false;
2150 return areElementsEquivalent( 2142 return areElementsEquivalent(
2151 metadata1.annotatedElement, metadata2.annotatedElement) && 2143 metadata1.annotatedElement, metadata2.annotatedElement) &&
2152 areConstantsEquivalent(metadata1.constant, metadata2.constant); 2144 areConstantsEquivalent(metadata1.constant, metadata2.constant);
2153 } 2145 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/kernel/kernel.dart ('k') | tests/compiler/dart2js/kernel/closed_world2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698