| 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 154     Expect.equals(compilerNormal.enabledRuntimeType, | 155     Expect.equals(compilerNormal.enabledRuntimeType, | 
| 155         compilerDeserialized.enabledRuntimeType, | 156         compilerDeserialized.enabledRuntimeType, | 
| 156         "Compiler.enabledRuntimeType mismatch"); | 157         "Compiler.enabledRuntimeType mismatch"); | 
| 157     Expect.equals(compilerNormal.hasIsolateSupport, | 158     Expect.equals(compilerNormal.hasIsolateSupport, | 
| 158         compilerDeserialized.hasIsolateSupport, | 159         compilerDeserialized.hasIsolateSupport, | 
| 159         "Compiler.hasIsolateSupport mismatch"); | 160         "Compiler.hasIsolateSupport mismatch"); | 
| 160     Expect.equals( | 161     Expect.equals( | 
| 161         compilerNormal.deferredLoadTask.isProgramSplit, | 162         compilerNormal.deferredLoadTask.isProgramSplit, | 
| 162         compilerDeserialized.deferredLoadTask.isProgramSplit, | 163         compilerDeserialized.deferredLoadTask.isProgramSplit, | 
| 163         "isProgramSplit mismatch"); | 164         "isProgramSplit mismatch"); | 
|  | 165 | 
|  | 166     Map<ConstantValue, OutputUnit> constants1 = | 
|  | 167         compilerNormal.deferredLoadTask.outputUnitForConstantsForTesting; | 
|  | 168     Map<ConstantValue, OutputUnit> constants2 = | 
|  | 169         compilerDeserialized.deferredLoadTask.outputUnitForConstantsForTesting; | 
|  | 170     checkSets( | 
|  | 171         constants1.keys, | 
|  | 172         constants2.keys, | 
|  | 173         'deferredLoadTask._outputUnitForConstants.keys', | 
|  | 174         areConstantValuesEquivalent, | 
|  | 175         failOnUnfound: false, | 
|  | 176         failOnExtra: false, | 
|  | 177         onSameElement: (ConstantValue value1, ConstantValue value2) { | 
|  | 178           OutputUnit outputUnit1 = constants1[value1]; | 
|  | 179           OutputUnit outputUnit2 = constants2[value2]; | 
|  | 180           checkOutputUnits(outputUnit1, outputUnit2, | 
|  | 181               'for ${value1.toStructuredText()} ' | 
|  | 182                   'vs ${value2.toStructuredText()}'); | 
|  | 183         }, | 
|  | 184         onUnfoundElement: (ConstantValue value1) { | 
|  | 185           OutputUnit outputUnit1 = constants1[value1]; | 
|  | 186           Expect.isTrue(outputUnit1.isMainOutput, | 
|  | 187               "Missing deferred constant: ${value1.toStructuredText()}"); | 
|  | 188         }, | 
|  | 189         onExtraElement: (ConstantValue value2) { | 
|  | 190           OutputUnit outputUnit2 = constants2[value2]; | 
|  | 191           Expect.isTrue(outputUnit2.isMainOutput, | 
|  | 192               "Extra deferred constant: ${value2.toStructuredText()}"); | 
|  | 193         }, | 
|  | 194         elementToString: (a) { | 
|  | 195           return '${a.toStructuredText()} -> ${constants1[a]}/${constants2[a]}'; | 
|  | 196         }); | 
| 164   }); | 197   }); | 
| 165 } | 198 } | 
| 166 | 199 | 
| 167 void checkElements( | 200 void checkElements( | 
| 168     Compiler compiler1, Compiler compiler2, | 201     Compiler compiler1, Compiler compiler2, | 
| 169     Element element1, Element element2, | 202     Element element1, Element element2, | 
| 170     {bool verbose: false}) { | 203     {bool verbose: false}) { | 
| 171   if (element1.isFunction || | 204   if (element1.isFunction || | 
| 172       element1.isConstructor || | 205       element1.isConstructor || | 
| 173       (element1.isField && element1.isInstanceMember)) { | 206       (element1.isField && element1.isInstanceMember)) { | 
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 237           }); | 270           }); | 
| 238     } | 271     } | 
| 239   } | 272   } | 
| 240   JavaScriptBackend backend1 = compiler1.backend; | 273   JavaScriptBackend backend1 = compiler1.backend; | 
| 241   JavaScriptBackend backend2 = compiler2.backend; | 274   JavaScriptBackend backend2 = compiler2.backend; | 
| 242   Expect.equals( | 275   Expect.equals( | 
| 243       backend1.inlineCache.getCurrentCacheDecisionForTesting(element1), | 276       backend1.inlineCache.getCurrentCacheDecisionForTesting(element1), | 
| 244       backend2.inlineCache.getCurrentCacheDecisionForTesting(element2), | 277       backend2.inlineCache.getCurrentCacheDecisionForTesting(element2), | 
| 245       "Inline cache decision mismatch for $element1 vs $element2"); | 278       "Inline cache decision mismatch for $element1 vs $element2"); | 
| 246 | 279 | 
| 247   checkOutputUnits(compiler1, compiler2, element1, element2); | 280   checkElementOutputUnits(compiler1, compiler2, element1, element2); | 
| 248 } | 281 } | 
| 249 | 282 | 
| 250 void checkMixinUses( | 283 void checkMixinUses( | 
| 251     Compiler compiler1, Compiler compiler2, | 284     Compiler compiler1, Compiler compiler2, | 
| 252     ClassElement class1, ClassElement class2, | 285     ClassElement class1, ClassElement class2, | 
| 253     {bool verbose: false}) { | 286     {bool verbose: false}) { | 
| 254 | 287 | 
| 255   checkSets( | 288   checkSets( | 
| 256       compiler1.world.mixinUsesOf(class1), | 289       compiler1.world.mixinUsesOf(class1), | 
| 257       compiler2.world.mixinUsesOf(class2), | 290       compiler2.world.mixinUsesOf(class2), | 
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 353 } | 386 } | 
| 354 | 387 | 
| 355 String nodeToString(Node node) { | 388 String nodeToString(Node node) { | 
| 356   String text = '$node'; | 389   String text = '$node'; | 
| 357   if (text.length > 40) { | 390   if (text.length > 40) { | 
| 358     return '(${node.runtimeType}) ${text.substring(0, 37)}...'; | 391     return '(${node.runtimeType}) ${text.substring(0, 37)}...'; | 
| 359   } | 392   } | 
| 360   return '(${node.runtimeType}) $text'; | 393   return '(${node.runtimeType}) $text'; | 
| 361 } | 394 } | 
| 362 | 395 | 
| 363 void checkOutputUnits(Compiler compiler1, Compiler compiler2, Element element1, | 396 void checkElementOutputUnits( | 
| 364     Element element2) { | 397     Compiler compiler1, Compiler compiler2, | 
|  | 398     Element element1, Element element2) { | 
| 365   OutputUnit outputUnit1 = | 399   OutputUnit outputUnit1 = | 
| 366       compiler1.deferredLoadTask.outputUnitForElement(element1); | 400       compiler1.deferredLoadTask.getOutputUnitForElementForTesting(element1); | 
| 367   OutputUnit outputUnit2 = | 401   OutputUnit outputUnit2 = | 
| 368       compiler2.deferredLoadTask.outputUnitForElement(element2); | 402       compiler2.deferredLoadTask.getOutputUnitForElementForTesting(element2); | 
|  | 403   checkOutputUnits(outputUnit1, outputUnit2, 'for $element1 vs $element2'); | 
|  | 404 } | 
|  | 405 | 
|  | 406 void checkOutputUnits( | 
|  | 407     OutputUnit outputUnit1, OutputUnit outputUnit2, String message) { | 
|  | 408   if (outputUnit1 == null && outputUnit2 == null) return; | 
| 369   check(outputUnit1, outputUnit2, | 409   check(outputUnit1, outputUnit2, | 
| 370       'OutputUnit.isMainOutput for $element1 vs $element2', | 410       'OutputUnit.isMainOutput $message', | 
| 371       outputUnit1.isMainOutput, outputUnit2.isMainOutput); | 411       outputUnit1.isMainOutput, outputUnit2.isMainOutput); | 
| 372   checkSetEquivalence(outputUnit1, outputUnit2, | 412   checkSetEquivalence(outputUnit1, outputUnit2, | 
| 373       'OutputUnit.imports for $element1 vs $element2', | 413       'OutputUnit.imports $message', | 
| 374       outputUnit1.imports, outputUnit2.imports, | 414       outputUnit1.imports, outputUnit2.imports, | 
| 375       (a, b) => areElementsEquivalent(a.declaration, b.declaration)); | 415       (a, b) => areElementsEquivalent(a.declaration, b.declaration)); | 
| 376 } | 416 } | 
| OLD | NEW | 
|---|