| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // Test of the graph segmentation algorithm used by deferred loading | 5 // Test of the graph segmentation algorithm used by deferred loading |
| 6 // to determine which elements can be deferred and which libraries | 6 // to determine which elements can be deferred and which libraries |
| 7 // much be included in the initial download (loaded eagerly). | 7 // much be included in the initial download (loaded eagerly). |
| 8 | 8 |
| 9 import 'package:async_helper/async_helper.dart'; | 9 import 'package:async_helper/async_helper.dart'; |
| 10 import 'package:compiler/src/compiler.dart'; | 10 import 'package:compiler/src/compiler.dart'; |
| 11 import 'package:compiler/src/deferred_load.dart'; | 11 import 'package:compiler/src/deferred_load.dart'; |
| 12 import 'package:expect/expect.dart'; | 12 import 'package:expect/expect.dart'; |
| 13 import 'memory_compiler.dart'; | 13 import 'memory_compiler.dart'; |
| 14 | 14 |
| 15 void main() { | 15 void main() { |
| 16 asyncTest(() async { | 16 asyncTest(() async { |
| 17 CompilationResult result = | 17 CompilationResult result = |
| 18 await runCompiler(memorySourceFiles: MEMORY_SOURCE_FILES); | 18 await runCompiler(memorySourceFiles: MEMORY_SOURCE_FILES); |
| 19 Compiler compiler = result.compiler; | 19 Compiler compiler = result.compiler; |
| 20 | 20 |
| 21 lookupLibrary(name) { | 21 lookupLibrary(name) { |
| 22 return compiler.libraryLoader.lookupLibrary(Uri.parse(name)); | 22 return compiler.libraryLoader.lookupLibrary(Uri.parse(name)); |
| 23 } | 23 } |
| 24 | 24 |
| 25 var main = compiler.frontendStrategy.elementEnvironment.mainFunction; | 25 var main = compiler.frontendStrategy.elementEnvironment.mainFunction; |
| 26 Expect.isNotNull(main, "Could not find 'main'"); | 26 Expect.isNotNull(main, "Could not find 'main'"); |
| 27 | 27 |
| 28 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; | 28 var outputUnitForEntity = compiler.deferredLoadTask.outputUnitForEntity; |
| 29 | 29 |
| 30 var mainOutputUnit = compiler.deferredLoadTask.mainOutputUnit; | 30 var mainOutputUnit = compiler.deferredLoadTask.mainOutputUnit; |
| 31 var backend = compiler.backend; | 31 var backend = compiler.backend; |
| 32 var classes = backend.emitter.neededClasses; | 32 var classes = backend.emitter.neededClasses; |
| 33 var inputElement = classes.where((e) => e.name == 'InputElement').single; | 33 var inputElement = classes.where((e) => e.name == 'InputElement').single; |
| 34 dynamic lib1 = lookupLibrary("memory:lib1.dart"); | 34 dynamic lib1 = lookupLibrary("memory:lib1.dart"); |
| 35 var foo1 = lib1.find("foo1"); | 35 var foo1 = lib1.find("foo1"); |
| 36 dynamic lib2 = lookupLibrary("memory:lib2.dart"); | 36 dynamic lib2 = lookupLibrary("memory:lib2.dart"); |
| 37 var foo2 = lib2.find("foo2"); | 37 var foo2 = lib2.find("foo2"); |
| 38 dynamic lib3 = lookupLibrary("memory:lib3.dart"); | 38 dynamic lib3 = lookupLibrary("memory:lib3.dart"); |
| 39 var foo3 = lib3.find("foo3"); | 39 var foo3 = lib3.find("foo3"); |
| 40 dynamic lib4 = lookupLibrary("memory:lib4.dart"); | 40 dynamic lib4 = lookupLibrary("memory:lib4.dart"); |
| 41 var bar1 = lib4.find("bar1"); | 41 var bar1 = lib4.find("bar1"); |
| 42 var bar2 = lib4.find("bar2"); | 42 var bar2 = lib4.find("bar2"); |
| 43 | 43 |
| 44 OutputUnit ou_lib1 = outputUnitForElement(foo1); | 44 OutputUnit ou_lib1 = outputUnitForEntity(foo1); |
| 45 OutputUnit ou_lib2 = outputUnitForElement(foo2); | 45 OutputUnit ou_lib2 = outputUnitForEntity(foo2); |
| 46 OutputUnit ou_lib1_lib2 = outputUnitForElement(foo3); | 46 OutputUnit ou_lib1_lib2 = outputUnitForEntity(foo3); |
| 47 OutputUnit ou_lib4_1 = outputUnitForElement(bar1); | 47 OutputUnit ou_lib4_1 = outputUnitForEntity(bar1); |
| 48 OutputUnit ou_lib4_2 = outputUnitForElement(bar2); | 48 OutputUnit ou_lib4_2 = outputUnitForEntity(bar2); |
| 49 | 49 |
| 50 Expect.equals(mainOutputUnit, outputUnitForElement(main)); | 50 Expect.equals(mainOutputUnit, outputUnitForEntity(main)); |
| 51 Expect.notEquals(mainOutputUnit, outputUnitForElement(foo1)); | 51 Expect.notEquals(mainOutputUnit, outputUnitForEntity(foo1)); |
| 52 Expect.notEquals(ou_lib1, ou_lib1_lib2); | 52 Expect.notEquals(ou_lib1, ou_lib1_lib2); |
| 53 Expect.notEquals(ou_lib2, ou_lib1_lib2); | 53 Expect.notEquals(ou_lib2, ou_lib1_lib2); |
| 54 Expect.notEquals(ou_lib1, ou_lib2); | 54 Expect.notEquals(ou_lib1, ou_lib2); |
| 55 Expect.notEquals(ou_lib4_1, ou_lib4_2); | 55 Expect.notEquals(ou_lib4_1, ou_lib4_2); |
| 56 Expect.notEquals(ou_lib1, ou_lib4_2); | 56 Expect.notEquals(ou_lib1, ou_lib4_2); |
| 57 // InputElement is native, so it should be in the mainOutputUnit. | 57 // InputElement is native, so it should be in the mainOutputUnit. |
| 58 Expect.equals(mainOutputUnit, outputUnitForElement(inputElement)); | 58 Expect.equals(mainOutputUnit, outputUnitForEntity(inputElement)); |
| 59 | 59 |
| 60 var hunksToLoad = compiler.deferredLoadTask.hunksToLoad; | 60 var hunksToLoad = compiler.deferredLoadTask.hunksToLoad; |
| 61 | 61 |
| 62 var hunksLib1 = hunksToLoad["lib1"]; | 62 var hunksLib1 = hunksToLoad["lib1"]; |
| 63 var hunksLib2 = hunksToLoad["lib2"]; | 63 var hunksLib2 = hunksToLoad["lib2"]; |
| 64 var hunksLib4_1 = hunksToLoad["lib4_1"]; | 64 var hunksLib4_1 = hunksToLoad["lib4_1"]; |
| 65 var hunksLib4_2 = hunksToLoad["lib4_2"]; | 65 var hunksLib4_2 = hunksToLoad["lib4_2"]; |
| 66 Expect.listEquals([ou_lib1_lib2, ou_lib1], hunksLib1); | 66 Expect.listEquals([ou_lib1_lib2, ou_lib1], hunksLib1); |
| 67 Expect.listEquals([ou_lib1_lib2, ou_lib2], hunksLib2); | 67 Expect.listEquals([ou_lib1_lib2, ou_lib2], hunksLib2); |
| 68 Expect.listEquals([ou_lib4_1], hunksLib4_1); | 68 Expect.listEquals([ou_lib4_1], hunksLib4_1); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 | 141 |
| 142 bar1() { | 142 bar1() { |
| 143 return "hello"; | 143 return "hello"; |
| 144 } | 144 } |
| 145 | 145 |
| 146 bar2() { | 146 bar2() { |
| 147 return 2; | 147 return 2; |
| 148 } | 148 } |
| 149 """, | 149 """, |
| 150 }; | 150 }; |
| OLD | NEW |