OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 library test.kernel.closures.suite; | 5 library test.kernel.closures.suite; |
6 | 6 |
7 import 'dart:async' show Future; | 7 import 'dart:async' show Future; |
8 | 8 |
9 import 'package:front_end/physical_file_system.dart' show PhysicalFileSystem; | |
10 | |
11 import 'package:kernel/core_types.dart' show CoreTypes; | 9 import 'package:kernel/core_types.dart' show CoreTypes; |
12 | 10 |
13 import 'package:testing/testing.dart' | 11 import 'package:testing/testing.dart' |
14 show Chain, ChainContext, Result, Step, TestDescription, runMe; | 12 show Chain, ChainContext, Result, Step, runMe; |
15 | |
16 import 'package:front_end/src/fasta/testing/patched_sdk_location.dart' | |
17 show computePatchedSdk; | |
18 | 13 |
19 import 'package:kernel/ast.dart' show Program, Library; | 14 import 'package:kernel/ast.dart' show Program, Library; |
20 | 15 |
21 import 'package:kernel/transformations/closure_conversion.dart' | 16 import 'package:kernel/transformations/closure_conversion.dart' |
22 as closure_conversion; | 17 as closure_conversion; |
23 | 18 |
24 import 'package:front_end/src/fasta/testing/kernel_chain.dart' | 19 import 'package:front_end/src/fasta/testing/kernel_chain.dart' |
25 show Print, MatchExpectation, WriteDill, ReadDill, Verify; | 20 show |
26 | 21 Print, |
27 import 'package:front_end/src/fasta/ticker.dart' show Ticker; | 22 MatchExpectation, |
28 | 23 WriteDill, |
29 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget; | 24 ReadDill, |
30 | 25 Verify, |
31 import 'package:front_end/src/fasta/kernel/kernel_target.dart' | 26 Compile, |
32 show KernelTarget; | 27 CompileContext; |
33 | |
34 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri; | |
35 | |
36 import 'package:front_end/src/fasta/errors.dart' show InputError; | |
37 | |
38 import 'package:front_end/src/fasta/testing/patched_sdk_location.dart'; | |
39 | |
40 import 'package:kernel/kernel.dart' show loadProgramFromBinary; | |
41 | |
42 import 'package:kernel/target/targets.dart' show TargetFlags; | |
43 | |
44 import 'package:kernel/target/vm_fasta.dart' show VmFastaTarget; | |
45 | 28 |
46 const String STRONG_MODE = " strong mode "; | 29 const String STRONG_MODE = " strong mode "; |
47 | 30 |
48 class ClosureConversionContext extends ChainContext { | 31 class ClosureConversionContext extends ChainContext implements CompileContext { |
49 final bool strongMode; | 32 final bool strongMode; |
50 | 33 |
51 final TranslateUri uriTranslator; | |
52 | |
53 final List<Step> steps; | 34 final List<Step> steps; |
54 | 35 |
55 ClosureConversionContext( | 36 ClosureConversionContext(this.strongMode, bool updateExpectations) |
56 this.strongMode, bool updateExpectations, this.uriTranslator) | |
57 : steps = <Step>[ | 37 : steps = <Step>[ |
58 const FastaCompile(), | 38 const Compile(), |
59 const Print(), | 39 const Print(), |
60 const Verify(true), | 40 const Verify(true), |
61 const ClosureConversion(), | 41 const ClosureConversion(), |
62 const Print(), | 42 const Print(), |
63 const Verify(true), | 43 const Verify(true), |
64 new MatchExpectation(".expect", | 44 new MatchExpectation(".expect", |
65 updateExpectations: updateExpectations), | 45 updateExpectations: updateExpectations), |
66 const WriteDill(), | 46 const WriteDill(), |
67 const ReadDill(), | 47 const ReadDill(), |
68 // TODO(29143): add `Run` step when Vectors are added to VM. | 48 // TODO(29143): add `Run` step when Vectors are added to VM. |
69 ]; | 49 ]; |
70 | 50 |
71 Future<Program> loadPlatform() async { | |
72 Uri sdk = await computePatchedSdk(); | |
73 return loadProgramFromBinary(sdk.resolve('platform.dill').toFilePath()); | |
74 } | |
75 | |
76 static Future<ClosureConversionContext> create( | 51 static Future<ClosureConversionContext> create( |
77 Chain suite, Map<String, String> environment) async { | 52 Chain suite, Map<String, String> environment) async { |
78 Uri sdk = await computePatchedSdk(); | |
79 Uri packages = Uri.base.resolve(".packages"); | |
80 bool strongMode = environment.containsKey(STRONG_MODE); | 53 bool strongMode = environment.containsKey(STRONG_MODE); |
81 bool updateExpectations = environment["updateExpectations"] == "true"; | 54 bool updateExpectations = environment["updateExpectations"] == "true"; |
82 TranslateUri uriTranslator = await TranslateUri | 55 return new ClosureConversionContext(strongMode, updateExpectations); |
83 .parse(PhysicalFileSystem.instance, sdk, packages: packages); | |
84 return new ClosureConversionContext( | |
85 strongMode, updateExpectations, uriTranslator); | |
86 } | 56 } |
87 } | 57 } |
88 | 58 |
89 Future<ClosureConversionContext> createContext( | 59 Future<ClosureConversionContext> createContext( |
90 Chain suite, Map<String, String> environment) async { | 60 Chain suite, Map<String, String> environment) async { |
91 environment["updateExpectations"] = | 61 environment["updateExpectations"] = |
92 const String.fromEnvironment("updateExpectations"); | 62 const String.fromEnvironment("updateExpectations"); |
93 return ClosureConversionContext.create(suite, environment); | 63 return ClosureConversionContext.create(suite, environment); |
94 } | 64 } |
95 | 65 |
96 class FastaCompile | |
97 extends Step<TestDescription, Program, ClosureConversionContext> { | |
98 const FastaCompile(); | |
99 | |
100 String get name => "fasta compilation"; | |
101 | |
102 Future<Result<Program>> run( | |
103 TestDescription description, ClosureConversionContext context) async { | |
104 Program platform = await context.loadPlatform(); | |
105 Ticker ticker = new Ticker(); | |
106 DillTarget dillTarget = new DillTarget(ticker, context.uriTranslator, | |
107 new VmFastaTarget(new TargetFlags(strongMode: context.strongMode))); | |
108 platform.unbindCanonicalNames(); | |
109 dillTarget.loader.appendLibraries(platform); | |
110 KernelTarget sourceTarget = new KernelTarget( | |
111 PhysicalFileSystem.instance, dillTarget, context.uriTranslator); | |
112 | |
113 Program p; | |
114 try { | |
115 sourceTarget.read(description.uri); | |
116 await dillTarget.buildOutlines(); | |
117 await sourceTarget.buildOutlines(); | |
118 p = await sourceTarget.buildProgram(); | |
119 } on InputError catch (e, s) { | |
120 return fail(null, e.error, s); | |
121 } | |
122 return pass(p); | |
123 } | |
124 } | |
125 | |
126 class ClosureConversion | 66 class ClosureConversion |
127 extends Step<Program, Program, ClosureConversionContext> { | 67 extends Step<Program, Program, ClosureConversionContext> { |
128 const ClosureConversion(); | 68 const ClosureConversion(); |
129 | 69 |
130 String get name => "closure conversion"; | 70 String get name => "closure conversion"; |
131 | 71 |
132 Future<Result<Program>> run( | 72 Future<Result<Program>> run( |
133 Program program, ClosureConversionContext testContext) async { | 73 Program program, ClosureConversionContext testContext) async { |
134 try { | 74 try { |
135 CoreTypes coreTypes = new CoreTypes(program); | 75 CoreTypes coreTypes = new CoreTypes(program); |
136 Library library = program.libraries | 76 Library library = program.libraries |
137 .firstWhere((Library library) => library.importUri.scheme != "dart"); | 77 .firstWhere((Library library) => library.importUri.scheme != "dart"); |
138 closure_conversion.transformLibraries(coreTypes, <Library>[library]); | 78 closure_conversion.transformLibraries(coreTypes, <Library>[library]); |
139 return pass(program); | 79 return pass(program); |
140 } catch (e, s) { | 80 } catch (e, s) { |
141 return crash(e, s); | 81 return crash(e, s); |
142 } | 82 } |
143 } | 83 } |
144 } | 84 } |
145 | 85 |
146 main(List<String> arguments) => runMe(arguments, createContext, "testing.json"); | 86 main(List<String> arguments) => runMe(arguments, createContext, "testing.json"); |
OLD | NEW |