| 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'; |
| 11 import 'package:compiler/src/closure.dart'; | 11 import 'package:compiler/src/closure.dart'; |
| 12 import 'package:compiler/src/commandline_options.dart'; | 12 import 'package:compiler/src/commandline_options.dart'; |
| 13 import 'package:compiler/src/common.dart'; | 13 import 'package:compiler/src/common.dart'; |
| 14 import 'package:compiler/src/constants/values.dart'; |
| 14 import 'package:compiler/src/compiler.dart'; | 15 import 'package:compiler/src/compiler.dart'; |
| 15 import 'package:compiler/src/deferred_load.dart'; | 16 import 'package:compiler/src/deferred_load.dart'; |
| 16 import 'package:compiler/src/elements/elements.dart'; | 17 import 'package:compiler/src/elements/elements.dart'; |
| 17 import 'package:compiler/src/filenames.dart'; | 18 import 'package:compiler/src/filenames.dart'; |
| 18 import 'package:compiler/src/js_backend/js_backend.dart'; | 19 import 'package:compiler/src/js_backend/js_backend.dart'; |
| 19 import 'package:compiler/src/serialization/equivalence.dart'; | 20 import 'package:compiler/src/serialization/equivalence.dart'; |
| 20 import 'package:compiler/src/tree/nodes.dart'; | 21 import 'package:compiler/src/tree/nodes.dart'; |
| 21 import 'package:compiler/src/universe/class_set.dart'; | 22 import 'package:compiler/src/universe/class_set.dart'; |
| 22 import '../memory_compiler.dart'; | 23 import '../memory_compiler.dart'; |
| 23 import 'helper.dart'; | 24 import 'helper.dart'; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 Expect.equals(compilerNormal.enabledRuntimeType, | 149 Expect.equals(compilerNormal.enabledRuntimeType, |
| 149 compilerDeserialized.enabledRuntimeType, | 150 compilerDeserialized.enabledRuntimeType, |
| 150 "Compiler.enabledRuntimeType mismatch"); | 151 "Compiler.enabledRuntimeType mismatch"); |
| 151 Expect.equals(compilerNormal.hasIsolateSupport, | 152 Expect.equals(compilerNormal.hasIsolateSupport, |
| 152 compilerDeserialized.hasIsolateSupport, | 153 compilerDeserialized.hasIsolateSupport, |
| 153 "Compiler.hasIsolateSupport mismatch"); | 154 "Compiler.hasIsolateSupport mismatch"); |
| 154 Expect.equals( | 155 Expect.equals( |
| 155 compilerNormal.deferredLoadTask.isProgramSplit, | 156 compilerNormal.deferredLoadTask.isProgramSplit, |
| 156 compilerDeserialized.deferredLoadTask.isProgramSplit, | 157 compilerDeserialized.deferredLoadTask.isProgramSplit, |
| 157 "isProgramSplit mismatch"); | 158 "isProgramSplit mismatch"); |
| 159 |
| 160 Map<ConstantValue, OutputUnit> constants1 = |
| 161 compilerNormal.deferredLoadTask.outputUnitForConstantsForTesting; |
| 162 Map<ConstantValue, OutputUnit> constants2 = |
| 163 compilerDeserialized.deferredLoadTask.outputUnitForConstantsForTesting; |
| 164 checkSets( |
| 165 constants1.keys, |
| 166 constants2.keys, |
| 167 'deferredLoadTask._outputUnitForConstants.keys', |
| 168 areConstantValuesEquivalent, |
| 169 failOnUnfound: false, |
| 170 failOnExtra: false, |
| 171 onSameElement: (ConstantValue value1, ConstantValue value2) { |
| 172 OutputUnit outputUnit1 = constants1[value1]; |
| 173 OutputUnit outputUnit2 = constants2[value2]; |
| 174 checkOutputUnits(outputUnit1, outputUnit2, |
| 175 'for ${value1.toStructuredText()} ' |
| 176 'vs ${value2.toStructuredText()}'); |
| 177 }, |
| 178 onUnfoundElement: (ConstantValue value1) { |
| 179 OutputUnit outputUnit1 = constants1[value1]; |
| 180 Expect.isTrue(outputUnit1.isMainOutput, |
| 181 "Missing deferred constant: ${value1.toStructuredText()}"); |
| 182 }, |
| 183 onExtraElement: (ConstantValue value2) { |
| 184 OutputUnit outputUnit2 = constants2[value2]; |
| 185 Expect.isTrue(outputUnit2.isMainOutput, |
| 186 "Extra deferred constant: ${value2.toStructuredText()}"); |
| 187 }, |
| 188 elementToString: (a) { |
| 189 return '${a.toStructuredText()} -> ${constants1[a]}/${constants2[a]}'; |
| 190 }); |
| 158 }); | 191 }); |
| 159 } | 192 } |
| 160 | 193 |
| 161 void checkElements( | 194 void checkElements( |
| 162 Compiler compiler1, Compiler compiler2, | 195 Compiler compiler1, Compiler compiler2, |
| 163 Element element1, Element element2, | 196 Element element1, Element element2, |
| 164 {bool verbose: false}) { | 197 {bool verbose: false}) { |
| 165 if (element1.isFunction || | 198 if (element1.isFunction || |
| 166 element1.isConstructor || | 199 element1.isConstructor || |
| 167 (element1.isField && element1.isInstanceMember)) { | 200 (element1.isField && element1.isInstanceMember)) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 }); | 264 }); |
| 232 } | 265 } |
| 233 } | 266 } |
| 234 JavaScriptBackend backend1 = compiler1.backend; | 267 JavaScriptBackend backend1 = compiler1.backend; |
| 235 JavaScriptBackend backend2 = compiler2.backend; | 268 JavaScriptBackend backend2 = compiler2.backend; |
| 236 Expect.equals( | 269 Expect.equals( |
| 237 backend1.inlineCache.getCurrentCacheDecisionForTesting(element1), | 270 backend1.inlineCache.getCurrentCacheDecisionForTesting(element1), |
| 238 backend2.inlineCache.getCurrentCacheDecisionForTesting(element2), | 271 backend2.inlineCache.getCurrentCacheDecisionForTesting(element2), |
| 239 "Inline cache decision mismatch for $element1 vs $element2"); | 272 "Inline cache decision mismatch for $element1 vs $element2"); |
| 240 | 273 |
| 241 checkOutputUnits(compiler1, compiler2, element1, element2); | 274 checkElementOutputUnits(compiler1, compiler2, element1, element2); |
| 242 } | 275 } |
| 243 | 276 |
| 244 void checkMixinUses( | 277 void checkMixinUses( |
| 245 Compiler compiler1, Compiler compiler2, | 278 Compiler compiler1, Compiler compiler2, |
| 246 ClassElement class1, ClassElement class2, | 279 ClassElement class1, ClassElement class2, |
| 247 {bool verbose: false}) { | 280 {bool verbose: false}) { |
| 248 | 281 |
| 249 checkSets( | 282 checkSets( |
| 250 compiler1.world.mixinUsesOf(class1), | 283 compiler1.world.mixinUsesOf(class1), |
| 251 compiler2.world.mixinUsesOf(class2), | 284 compiler2.world.mixinUsesOf(class2), |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 } | 380 } |
| 348 | 381 |
| 349 String nodeToString(Node node) { | 382 String nodeToString(Node node) { |
| 350 String text = '$node'; | 383 String text = '$node'; |
| 351 if (text.length > 40) { | 384 if (text.length > 40) { |
| 352 return '(${node.runtimeType}) ${text.substring(0, 37)}...'; | 385 return '(${node.runtimeType}) ${text.substring(0, 37)}...'; |
| 353 } | 386 } |
| 354 return '(${node.runtimeType}) $text'; | 387 return '(${node.runtimeType}) $text'; |
| 355 } | 388 } |
| 356 | 389 |
| 357 void checkOutputUnits(Compiler compiler1, Compiler compiler2, Element element1, | 390 void checkElementOutputUnits( |
| 358 Element element2) { | 391 Compiler compiler1, Compiler compiler2, |
| 392 Element element1, Element element2) { |
| 359 OutputUnit outputUnit1 = | 393 OutputUnit outputUnit1 = |
| 360 compiler1.deferredLoadTask.outputUnitForElement(element1); | 394 compiler1.deferredLoadTask.getOutputUnitForElementForTesting(element1); |
| 361 OutputUnit outputUnit2 = | 395 OutputUnit outputUnit2 = |
| 362 compiler2.deferredLoadTask.outputUnitForElement(element2); | 396 compiler2.deferredLoadTask.getOutputUnitForElementForTesting(element2); |
| 397 checkOutputUnits(outputUnit1, outputUnit2, 'for $element1 vs $element2'); |
| 398 } |
| 399 |
| 400 void checkOutputUnits( |
| 401 OutputUnit outputUnit1, OutputUnit outputUnit2, String message) { |
| 402 if (outputUnit1 == null && outputUnit2 == null) return; |
| 363 check(outputUnit1, outputUnit2, | 403 check(outputUnit1, outputUnit2, |
| 364 'OutputUnit.isMainOutput for $element1 vs $element2', | 404 'OutputUnit.isMainOutput $message', |
| 365 outputUnit1.isMainOutput, outputUnit2.isMainOutput); | 405 outputUnit1.isMainOutput, outputUnit2.isMainOutput); |
| 366 checkSetEquivalence(outputUnit1, outputUnit2, | 406 checkSetEquivalence(outputUnit1, outputUnit2, |
| 367 'OutputUnit.imports for $element1 vs $element2', | 407 'OutputUnit.imports $message', |
| 368 outputUnit1.imports, outputUnit2.imports, | 408 outputUnit1.imports, outputUnit2.imports, |
| 369 (a, b) => areElementsEquivalent(a.declaration, b.declaration)); | 409 (a, b) => areElementsEquivalent(a.declaration, b.declaration)); |
| 370 } | 410 } |
| OLD | NEW |