| 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 15 matching lines...) Expand all Loading... |
| 105 verbose: verbose); | 107 verbose: verbose); |
| 106 | 108 |
| 107 checkSets( | 109 checkSets( |
| 108 compilerNormal.enqueuer.resolution.processedElements, | 110 compilerNormal.enqueuer.resolution.processedElements, |
| 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, |
| 116 compilerNormal.coreClasses.objectClass), | 118 compilerDeserialized, |
| 117 compilerDeserialized.world.getClassHierarchyNode( | 119 compilerNormal.world.getClassHierarchyNode( |
| 118 compilerDeserialized.coreClasses.objectClass), | 120 compilerNormal.coreClasses.objectClass), |
| 119 verbose: verbose); | 121 compilerDeserialized.world.getClassHierarchyNode( |
| 122 compilerDeserialized.coreClasses.objectClass), |
| 123 verbose: verbose); |
| 124 } |
| 125 |
| 126 void checkMixinUses( |
| 127 Compiler compiler1, Compiler compiler2, |
| 128 ClassElement class1, ClassElement class2, |
| 129 {bool verbose: false}) { |
| 130 |
| 131 checkSets( |
| 132 compiler1.world.mixinUsesOf(class1), |
| 133 compiler2.world.mixinUsesOf(class2), |
| 134 "Mixin uses of $class1 vs $class2", |
| 135 areElementsEquivalent, |
| 136 verbose: verbose); |
| 137 |
| 120 } | 138 } |
| 121 | 139 |
| 122 void checkClassHierarchyNodes( | 140 void checkClassHierarchyNodes( |
| 123 ClassHierarchyNode a, ClassHierarchyNode b, | 141 Compiler compiler1, |
| 142 Compiler compiler2, |
| 143 ClassHierarchyNode node1, ClassHierarchyNode node2, |
| 124 {bool verbose: false}) { | 144 {bool verbose: false}) { |
| 125 if (verbose) { | 145 if (verbose) { |
| 126 print('Checking $a vs $b'); | 146 print('Checking $node1 vs $node2'); |
| 127 } | 147 } |
| 128 Expect.isTrue( | 148 Expect.isTrue( |
| 129 areElementsEquivalent(a.cls, b.cls), | 149 areElementsEquivalent(node1.cls, node2.cls), |
| 130 "Element identity mismatch for ${a.cls} vs ${b.cls}."); | 150 "Element identity mismatch for ${node1.cls} vs ${node2.cls}."); |
| 131 Expect.equals( | 151 Expect.equals( |
| 132 a.isDirectlyInstantiated, | 152 node1.isDirectlyInstantiated, |
| 133 b.isDirectlyInstantiated, | 153 node2.isDirectlyInstantiated, |
| 134 "Value mismatch for 'isDirectlyInstantiated' for ${a.cls} vs ${b.cls}."); | 154 "Value mismatch for 'isDirectlyInstantiated' " |
| 155 "for ${node1.cls} vs ${node2.cls}."); |
| 135 Expect.equals( | 156 Expect.equals( |
| 136 a.isIndirectlyInstantiated, | 157 node1.isIndirectlyInstantiated, |
| 137 b.isIndirectlyInstantiated, | 158 node2.isIndirectlyInstantiated, |
| 138 "Value mismatch for 'isIndirectlyInstantiated' " | 159 "Value mismatch for 'isIndirectlyInstantiated' " |
| 139 "for ${a.cls} vs ${b.cls}."); | 160 "for ${node1.cls} vs ${node2.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 node1.directSubclasses) { |
| 143 bool found = false; | 164 bool found = false; |
| 144 for (ClassHierarchyNode other in b.directSubclasses) { | 165 for (ClassHierarchyNode other in node2.directSubclasses) { |
| 145 if (areElementsEquivalent(child.cls, other.cls)) { | 166 if (areElementsEquivalent(child.cls, other.cls)) { |
| 146 checkClassHierarchyNodes(child, other, | 167 checkClassHierarchyNodes(compiler1, compiler2, |
| 147 verbose: verbose); | 168 child, other, 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(child.isInstantiated, |
| 154 child.isInstantiated, 'Missing subclass ${child.cls} of ${a.cls}'); | 175 'Missing subclass ${child.cls} of ${node1.cls}'); |
| 155 } | 176 } |
| 156 } | 177 } |
| 178 checkMixinUses(compiler1, compiler2, node1.cls, node2.cls, verbose: verbose); |
| 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 |