Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: tests/compiler/dart2js/deferred_follow_constant_dependencies_test.dart

Issue 1927963002: Support compilation of Hello World (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fixes Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 that constants depended on by other constants are correctly deferred. 5 // Test that constants depended on by other constants are correctly deferred.
6 6
7 import 'package:async_helper/async_helper.dart'; 7 import 'package:async_helper/async_helper.dart';
8 import 'package:compiler/src/common.dart';
8 import 'package:compiler/src/constants/values.dart'; 9 import 'package:compiler/src/constants/values.dart';
9 import 'package:compiler/src/compiler.dart'; 10 import 'package:compiler/src/compiler.dart';
10 import 'package:expect/expect.dart'; 11 import 'package:expect/expect.dart';
11 import 'memory_compiler.dart'; 12 import 'memory_compiler.dart';
12 13
13 void main() { 14 void main() {
14 asyncTest(() async { 15 asyncTest(() async {
15 CompilationResult result = 16 CompilationResult result =
16 await runCompiler(memorySourceFiles: MEMORY_SOURCE_FILES); 17 await runCompiler(memorySourceFiles: MEMORY_SOURCE_FILES);
17 Compiler compiler = result.compiler; 18 Compiler compiler = result.compiler;
18 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; 19 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement;
19 var outputUnitForConstant = compiler.deferredLoadTask.outputUnitForConstant; 20 var outputUnitForConstant = compiler.deferredLoadTask.outputUnitForConstant;
20 var mainOutputUnit = compiler.deferredLoadTask.mainOutputUnit; 21 var mainOutputUnit = compiler.deferredLoadTask.mainOutputUnit;
21 var lib = 22 var lib =
22 compiler.libraryLoader.lookupLibrary(Uri.parse("memory:lib.dart")); 23 compiler.libraryLoader.lookupLibrary(Uri.parse("memory:lib.dart"));
23 var backend = compiler.backend; 24 var backend = compiler.backend;
24 List<ConstantValue> allConstants = []; 25 List<ConstantValue> allConstants = [];
25 26
26 addConstantWithDependendencies(ConstantValue c) { 27 addConstantWithDependendencies(ConstantValue c) {
27 allConstants.add(c); 28 allConstants.add(c);
28 c.getDependencies().forEach(addConstantWithDependendencies); 29 c.getDependencies().forEach(addConstantWithDependendencies);
29 } 30 }
30 31
31 backend.constants.compiledConstants.forEach(addConstantWithDependendencies); 32 backend.constants.compiledConstants.forEach(addConstantWithDependendencies);
32 for (String stringValue in ["cA", "cB", "cC"]) { 33 for (String stringValue in ["cA", "cB", "cC"]) {
33 ConstantValue constant = allConstants.firstWhere((constant) { 34 ConstantValue constant = allConstants.firstWhere((constant) {
34 return constant.isString 35 return constant.isString
35 && constant.primitiveValue.slowToString() == stringValue; 36 && constant.primitiveValue.slowToString() == stringValue;
36 }); 37 });
37 Expect.notEquals(null, outputUnitForConstant(constant)); 38 Expect.notEquals(null, outputUnitForConstant(constant),
38 Expect.notEquals(mainOutputUnit, outputUnitForConstant(constant)); 39 "Constant value ${constant.toStructuredText()} has no output unit.");
40 Expect.notEquals(mainOutputUnit, outputUnitForConstant(constant),
41 "Constant value ${constant.toStructuredText()} "
42 "is in the main output unit.");
39 } 43 }
40 }); 44 });
41 } 45 }
42 46
43 // The main library imports lib1 and lib2 deferred and use lib1.foo1 and 47 // The main library imports lib1 and lib2 deferred and use lib1.foo1 and
44 // lib2.foo2. This should trigger seperate outputunits for main, lib1 and lib2. 48 // lib2.foo2. This should trigger seperate outputunits for main, lib1 and lib2.
45 // 49 //
46 // Both lib1 and lib2 import lib3 directly and 50 // Both lib1 and lib2 import lib3 directly and
47 // both use lib3.foo3. Therefore a shared output unit for lib1 and lib2 should 51 // both use lib3.foo3. Therefore a shared output unit for lib1 and lib2 should
48 // be created. 52 // be created.
49 // 53 //
50 // lib1 and lib2 also import lib4 deferred, but lib1 uses lib4.bar1 and lib2 54 // lib1 and lib2 also import lib4 deferred, but lib1 uses lib4.bar1 and lib2
51 // uses lib4.bar2. So two output units should be created for lib4, one for each 55 // uses lib4.bar2. So two output units should be created for lib4, one for each
52 // import. 56 // import.
53 const Map MEMORY_SOURCE_FILES = const {"main.dart": """ 57 const Map MEMORY_SOURCE_FILES = const {"main.dart": """
54 import 'lib.dart' deferred as lib; 58 import 'lib.dart' deferred as lib;
55 59
56 void main() { 60 void main() {
57 print(lib.L); 61 print(lib.L);
58 } 62 }
59 """, "lib.dart": """ 63 """, "lib.dart": """
60 class C { 64 class C {
61 final a; 65 final a;
62 const C(this.a); 66 const C(this.a);
63 } 67 }
64 68
65 const L = const {"cA": const C(const {"cB": "cC"})}; 69 const L = const {"cA": const C(const {"cB": "cC"})};
66 """,}; 70 """,};
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/ssa/builder.dart ('k') | tests/compiler/dart2js/serialization_compilation_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698