Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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_model_test; | 5 library dart2js.serialization_model_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'package:async_helper/async_helper.dart'; | 9 import 'package:async_helper/async_helper.dart'; |
| 10 import 'package:expect/expect.dart'; | 10 import 'package:expect/expect.dart'; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 bool verbose: false}) async { | 59 bool verbose: false}) async { |
| 60 | 60 |
| 61 print('------------------------------------------------------------------'); | 61 print('------------------------------------------------------------------'); |
| 62 print('compile normal'); | 62 print('compile normal'); |
| 63 print('------------------------------------------------------------------'); | 63 print('------------------------------------------------------------------'); |
| 64 Compiler compilerNormal = compilerFor( | 64 Compiler compilerNormal = compilerFor( |
| 65 memorySourceFiles: sourceFiles, | 65 memorySourceFiles: sourceFiles, |
| 66 options: [Flags.analyzeOnly]); | 66 options: [Flags.analyzeOnly]); |
| 67 compilerNormal.resolution.retainCachesForTesting = true; | 67 compilerNormal.resolution.retainCachesForTesting = true; |
| 68 await compilerNormal.run(entryPoint); | 68 await compilerNormal.run(entryPoint); |
| 69 compilerNormal.phase = Compiler.PHASE_DONE_RESOLVING; | |
| 69 compilerNormal.world.populate(); | 70 compilerNormal.world.populate(); |
| 70 | 71 |
| 71 print('------------------------------------------------------------------'); | 72 print('------------------------------------------------------------------'); |
| 72 print('compile deserialized'); | 73 print('compile deserialized'); |
| 73 print('------------------------------------------------------------------'); | 74 print('------------------------------------------------------------------'); |
| 74 Compiler compilerDeserialized = compilerFor( | 75 Compiler compilerDeserialized = compilerFor( |
| 75 memorySourceFiles: sourceFiles, | 76 memorySourceFiles: sourceFiles, |
| 76 options: [Flags.analyzeOnly]); | 77 options: [Flags.analyzeOnly]); |
| 77 compilerDeserialized.resolution.retainCachesForTesting = true; | 78 compilerDeserialized.resolution.retainCachesForTesting = true; |
| 78 deserialize(compilerDeserialized, serializedData); | 79 deserialize(compilerDeserialized, serializedData); |
| 79 await compilerDeserialized.run(entryPoint); | 80 await compilerDeserialized.run(entryPoint); |
| 81 compilerDeserialized.phase = Compiler.PHASE_DONE_RESOLVING; | |
| 80 compilerDeserialized.world.populate(); | 82 compilerDeserialized.world.populate(); |
| 81 | 83 |
| 82 checkAllImpacts( | 84 checkAllImpacts( |
| 83 compilerNormal, compilerDeserialized, | 85 compilerNormal, compilerDeserialized, |
| 84 verbose: verbose); | 86 verbose: verbose); |
| 85 | 87 |
| 86 checkSets( | 88 checkSets( |
| 87 compilerNormal.resolverWorld.directlyInstantiatedClasses, | 89 compilerNormal.resolverWorld.directlyInstantiatedClasses, |
| 88 compilerDeserialized.resolverWorld.directlyInstantiatedClasses, | 90 compilerDeserialized.resolverWorld.directlyInstantiatedClasses, |
| 89 "Directly instantiated classes mismatch", | 91 "Directly instantiated classes mismatch", |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 109 compilerDeserialized.enqueuer.resolution.processedElements, | 111 compilerDeserialized.enqueuer.resolution.processedElements, |
| 110 "Processed element mismatch", | 112 "Processed element mismatch", |
| 111 areElementsEquivalent, | 113 areElementsEquivalent, |
| 112 verbose: verbose); | 114 verbose: verbose); |
| 113 | 115 |
| 114 checkClassHierarchyNodes( | 116 checkClassHierarchyNodes( |
| 115 compilerNormal.world.getClassHierarchyNode( | 117 compilerNormal.world.getClassHierarchyNode( |
| 116 compilerNormal.coreClasses.objectClass), | 118 compilerNormal.coreClasses.objectClass), |
| 117 compilerDeserialized.world.getClassHierarchyNode( | 119 compilerDeserialized.world.getClassHierarchyNode( |
| 118 compilerDeserialized.coreClasses.objectClass), | 120 compilerDeserialized.coreClasses.objectClass), |
| 121 onClasses: (a, b) { | |
| 122 checkMixinUses( | |
| 123 compilerNormal, compilerDeserialized, a, b, verbose: verbose); | |
| 124 }, | |
| 119 verbose: verbose); | 125 verbose: verbose); |
| 120 } | 126 } |
| 121 | 127 |
| 128 void checkMixinUses( | |
| 129 Compiler compiler1, Compiler compiler2, | |
| 130 ClassElement class1, ClassElement class2, | |
| 131 {bool verbose: false}) { | |
| 132 | |
| 133 checkSets( | |
| 134 compiler1.world.mixinUsesOf(class1), | |
| 135 compiler2.world.mixinUsesOf(class2), | |
| 136 "Mixin uses of $class1 vs $class2", | |
| 137 areElementsEquivalent, | |
| 138 verbose: verbose); | |
| 139 | |
| 140 } | |
| 141 | |
| 122 void checkClassHierarchyNodes( | 142 void checkClassHierarchyNodes( |
| 123 ClassHierarchyNode a, ClassHierarchyNode b, | 143 ClassHierarchyNode a, ClassHierarchyNode b, |
| 124 {bool verbose: false}) { | 144 {void onClasses(ClassElement a, ClassElement b), |
| 145 bool verbose: false}) { | |
| 125 if (verbose) { | 146 if (verbose) { |
| 126 print('Checking $a vs $b'); | 147 print('Checking $a vs $b'); |
| 127 } | 148 } |
| 128 Expect.isTrue( | 149 Expect.isTrue( |
| 129 areElementsEquivalent(a.cls, b.cls), | 150 areElementsEquivalent(a.cls, b.cls), |
| 130 "Element identity mismatch for ${a.cls} vs ${b.cls}."); | 151 "Element identity mismatch for ${a.cls} vs ${b.cls}."); |
| 131 Expect.equals( | 152 Expect.equals( |
| 132 a.isDirectlyInstantiated, | 153 a.isDirectlyInstantiated, |
| 133 b.isDirectlyInstantiated, | 154 b.isDirectlyInstantiated, |
| 134 "Value mismatch for 'isDirectlyInstantiated' for ${a.cls} vs ${b.cls}."); | 155 "Value mismatch for 'isDirectlyInstantiated' for ${a.cls} vs ${b.cls}."); |
| 135 Expect.equals( | 156 Expect.equals( |
| 136 a.isIndirectlyInstantiated, | 157 a.isIndirectlyInstantiated, |
| 137 b.isIndirectlyInstantiated, | 158 b.isIndirectlyInstantiated, |
| 138 "Value mismatch for 'isIndirectlyInstantiated' " | 159 "Value mismatch for 'isIndirectlyInstantiated' " |
| 139 "for ${a.cls} vs ${b.cls}."); | 160 "for ${a.cls} vs ${b.cls}."); |
| 140 // TODO(johnniwinther): Enforce a canonical and stable order on direct | 161 // TODO(johnniwinther): Enforce a canonical and stable order on direct |
| 141 // subclasses. | 162 // subclasses. |
| 142 for (ClassHierarchyNode child in a.directSubclasses) { | 163 for (ClassHierarchyNode child in a.directSubclasses) { |
| 143 bool found = false; | 164 bool found = false; |
| 144 for (ClassHierarchyNode other in b.directSubclasses) { | 165 for (ClassHierarchyNode other in b.directSubclasses) { |
| 145 if (areElementsEquivalent(child.cls, other.cls)) { | 166 if (areElementsEquivalent(child.cls, other.cls)) { |
| 146 checkClassHierarchyNodes(child, other, | 167 checkClassHierarchyNodes(child, other, |
| 147 verbose: verbose); | 168 onClasses: onClasses, verbose: verbose); |
| 148 found = true; | 169 found = true; |
| 149 break; | 170 break; |
| 150 } | 171 } |
| 151 } | 172 } |
| 152 if (!found) { | 173 if (!found) { |
| 153 Expect.isFalse( | 174 Expect.isFalse( |
| 154 child.isInstantiated, 'Missing subclass ${child.cls} of ${a.cls}'); | 175 child.isInstantiated, 'Missing subclass ${child.cls} of ${a.cls}'); |
| 155 } | 176 } |
| 156 } | 177 } |
| 178 onClasses(a.cls, b.cls); | |
|
Siggi Cherem (dart-lang)
2016/05/10 17:17:48
nit: the `onClasses` callback argument feels like
Johnni Winther
2016/05/11 07:53:12
Done.
| |
| 157 } | 179 } |
| 158 | 180 |
| 159 void checkSets( | 181 void checkSets( |
| 160 Iterable set1, | 182 Iterable set1, |
| 161 Iterable set2, | 183 Iterable set2, |
| 162 String messagePrefix, | 184 String messagePrefix, |
| 163 bool areEquivalent(a, b), | 185 bool areEquivalent(a, b), |
| 164 {bool failOnUnfound: true, | 186 {bool failOnUnfound: true, |
| 165 bool verbose: false}) { | 187 bool verbose: false}) { |
| 166 List common = []; | 188 List common = []; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 183 | 205 |
| 184 if (failOnUnfound || remaining.isNotEmpty) { | 206 if (failOnUnfound || remaining.isNotEmpty) { |
| 185 Expect.fail(message); | 207 Expect.fail(message); |
| 186 } else { | 208 } else { |
| 187 print(message); | 209 print(message); |
| 188 } | 210 } |
| 189 } else if (verbose) { | 211 } else if (verbose) { |
| 190 print(message); | 212 print(message); |
| 191 } | 213 } |
| 192 } | 214 } |
| OLD | NEW |