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

Side by Side Diff: pkg/kernel/test/reify/suite.dart

Issue 2713163002: Pass type arguments as a list in generic methods invocations (Closed)
Patch Set: Simplify 'isGenericMethod' procedure Created 3 years, 9 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) 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.reify.suite; 5 library test.kernel.reify.suite;
6 6
7 import 'dart:async' show Future; 7 import 'dart:async' show Future;
8 8
9 import 'dart:io' show Directory, File, Platform; 9 import 'dart:io' show Directory, File, Platform;
10 10
11 import 'package:analyzer/src/generated/sdk.dart' show DartSdk; 11 import 'package:analyzer/src/generated/sdk.dart' show DartSdk;
12 12
13 import 'package:kernel/analyzer/loader.dart' 13 import 'package:kernel/analyzer/loader.dart'
14 show DartLoader, DartOptions, createDartSdk; 14 show DartLoader, DartOptions, createDartSdk;
15 15
16 import 'package:kernel/target/targets.dart' show Target, TargetFlags, getTarget; 16 import 'package:kernel/target/targets.dart' show Target, TargetFlags, getTarget;
17 17
18 import 'package:kernel/target/vmcc.dart' show VmClosureConvertedTarget;
19
18 import 'kernel_chain.dart' 20 import 'kernel_chain.dart'
19 show MatchExpectation, Print, ReadDill, SanityCheck, WriteDill; 21 show MatchExpectation, Print, ReadDill, SanityCheck, WriteDill;
20 22
21 import 'package:testing/testing.dart' 23 import 'package:testing/testing.dart'
22 show 24 show
23 Chain, 25 Chain,
24 ChainContext, 26 ChainContext,
25 Result, 27 Result,
26 StdioProcess, 28 StdioProcess,
27 Step, 29 Step,
28 TestDescription, 30 TestDescription,
29 runMe; 31 runMe;
30 32
31 import 'package:kernel/ast.dart' show Program; 33 import 'package:kernel/ast.dart' show Program;
32 34
33 import 'package:kernel/transformations/closure_conversion.dart'
34 as closure_conversion;
35
36 import 'package:kernel/transformations/generic_types_reification.dart' 35 import 'package:kernel/transformations/generic_types_reification.dart'
37 as generic_types_reification; 36 as generic_types_reification;
38 37
39 import 'package:package_config/discovery.dart' show loadPackagesFile; 38 import 'package:package_config/discovery.dart' show loadPackagesFile;
40 39
41 class TestContext extends ChainContext { 40 class TestContext extends ChainContext {
42 final Uri vm; 41 final Uri vm;
43 42
44 final Uri packages; 43 final Uri packages;
45 44
46 final DartOptions options; 45 final DartOptions options;
47 46
48 final DartSdk dartSdk; 47 final DartSdk dartSdk;
49 48
50 final List<Step> steps; 49 final List<Step> steps;
51 50
52 TestContext(String sdk, this.vm, Uri packages, bool strongMode, this.dartSdk, 51 TestContext(String sdk, this.vm, Uri packages, bool strongMode, this.dartSdk,
53 bool updateExpectations) 52 bool updateExpectations)
54 : packages = packages, 53 : packages = packages,
55 options = new DartOptions( 54 options = new DartOptions(
56 strongMode: strongMode, 55 strongMode: strongMode,
57 sdk: sdk, 56 sdk: sdk,
58 packagePath: packages.toFilePath()), 57 packagePath: packages.toFilePath()),
59 steps = <Step>[ 58 steps = <Step>[
60 const Kernel(), 59 const NotReifiedKernel(),
61 const Print(), 60 const Print(),
62 const SanityCheck(), 61 const SanityCheck(),
63 const ClosureConversion(),
64 const GenericTypesReification(), 62 const GenericTypesReification(),
65 const Print(), 63 const Print(),
66 const SanityCheck(), 64 const SanityCheck(),
67 new MatchExpectation(".expect", 65 new MatchExpectation(".expect",
68 updateExpectations: updateExpectations), 66 updateExpectations: updateExpectations),
69 const WriteDill(), 67 const WriteDill(),
70 const ReadDill(), 68 const ReadDill(),
71 const Run(), 69 const Run(),
72 ]; 70 ];
73 71
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 const String asyncSources = "lib/async/async_sources.gypi"; 117 const String asyncSources = "lib/async/async_sources.gypi";
120 if (await fileExists(sdkUri, asyncSources)) { 118 if (await fileExists(sdkUri, asyncSources)) {
121 throw "Found '$asyncSources' in '$sdk', so it isn't a patched SDK. " 119 throw "Found '$asyncSources' in '$sdk', so it isn't a patched SDK. "
122 "$suggestion"; 120 "$suggestion";
123 } 121 }
124 122
125 // TODO(karlklose): select the VM based on the mode. 123 // TODO(karlklose): select the VM based on the mode.
126 Uri vm = Uri.base.resolve("out/ReleaseX64/dart"); 124 Uri vm = Uri.base.resolve("out/ReleaseX64/dart");
127 125
128 Uri packages = Uri.base.resolve(".packages"); 126 Uri packages = Uri.base.resolve(".packages");
129 bool strongMode = false; 127 // Strong mode is required to keep the type arguments in invocations of
130 bool updateExpectations = environment["updateExpectations"] == "true"; 128 // generic methods.
129 bool strongMode = true;
130 bool updateExpectations = const String.fromEnvironment("updateExpectations",
131 defaultValue: "false") ==
132 "true";
131 return new TestContext(sdk, vm, packages, strongMode, 133 return new TestContext(sdk, vm, packages, strongMode,
132 createDartSdk(sdk, strongMode: strongMode), updateExpectations); 134 createDartSdk(sdk, strongMode: strongMode), updateExpectations);
133 } 135 }
134 136
135 class Kernel extends Step<TestDescription, Program, TestContext> { 137 // [NotReifiedTarget] is intended to work as the [Target] class that
136 const Kernel(); 138 // [VmGenericTypesReifiedTarget] inherits from, but with some transformations
139 // disabled. Those include tree shaking and generic types information erasure
140 // passes.
141 // [NotReifiedTarget] also adds the necessary runtime libraries.
142 class NotReifiedTarget extends VmClosureConvertedTarget {
143 NotReifiedTarget(TargetFlags flags) : super(flags);
144
145 @override
146 String get name => "not reified target";
147
148 // Tree shaking needs to be disabled, because Generic Types Reification
149 // transformation relies on certain runtime libraries to be present in
150 // the program that is being transformed. If the tree shaker is enabled,
151 // it just deletes everything from those libraries, because they aren't
152 // used in the program being transform prior to the transformation.
153 @override
154 void performTreeShaking(Program program) {}
155
156 // Erasure needs to be disabled, because it removes the necessary information
157 // about type arguments for generic methods.
158 @override
159 void performErasure(Program program) {}
160
161 // Adds the necessary runtime libraries.
162 @override
163 List<String> get extraRequiredLibraries {
164 Target reifyTarget = getTarget("vmreify", this.flags);
165 var x = reifyTarget.extraRequiredLibraries;
166 return x;
167 }
168 }
169
170 class NotReifiedKernel extends Step<TestDescription, Program, TestContext> {
171 const NotReifiedKernel();
137 172
138 String get name => "kernel"; 173 String get name => "kernel";
139 174
140 Future<Result<Program>> run( 175 Future<Result<Program>> run(
141 TestDescription description, TestContext testContext) async { 176 TestDescription description, TestContext testContext) async {
142 try { 177 try {
143 DartLoader loader = await testContext.createLoader(); 178 DartLoader loader = await testContext.createLoader();
144 179
145 Target target = getTarget( 180 // Strong mode is required to keep the type arguments in invocations of
146 "vm", new TargetFlags(strongMode: testContext.options.strongMode)); 181 // generic methods.
147 // reifyTarget is used to add the GTR-specific runtime libraries 182 Target target = new NotReifiedTarget(new TargetFlags(
148 // when the program is being loaded 183 strongMode: true,
149 Target reifyTarget = getTarget( 184 kernelRuntime: Platform.script.resolve("../../runtime/")));
150 "vmreify",
151 new TargetFlags(
152 strongMode: testContext.options.strongMode,
153 kernelRuntime: Platform.script.resolve('../../runtime/')));
154 185
155 String path = description.file.path; 186 String path = description.file.path;
156 Uri uri = Uri.base.resolve(path); 187 Uri uri = Uri.base.resolve(path);
157 loader.loadProgram(uri, target: reifyTarget); 188 loader.loadProgram(uri, target: target);
158 var program = loader.program; 189 var program = loader.program;
159 for (var error in loader.errors) { 190 for (var error in loader.errors) {
160 return fail(program, "$error"); 191 return fail(program, "$error");
161 } 192 }
162 target 193 target
163 ..performModularTransformations(program) 194 ..performModularTransformations(program)
164 ..performGlobalTransformations(program); 195 ..performGlobalTransformations(program);
165 return pass(program); 196 return pass(program);
166 } catch (e, s) { 197 } catch (e, s) {
167 return crash(e, s); 198 return crash(e, s);
168 } 199 }
169 } 200 }
170 } 201 }
171 202
172 class ClosureConversion extends Step<Program, Program, TestContext> {
173 const ClosureConversion();
174
175 String get name => "closure conversion";
176
177 Future<Result<Program>> run(Program program, TestContext testContext) async {
178 try {
179 program = closure_conversion.transformProgram(program);
180 return pass(program);
181 } catch (e, s) {
182 return crash(e, s);
183 }
184 }
185 }
186
187 class GenericTypesReification extends Step<Program, Program, TestContext> { 203 class GenericTypesReification extends Step<Program, Program, TestContext> {
188 const GenericTypesReification(); 204 const GenericTypesReification();
189 205
190 String get name => "generic types reification"; 206 String get name => "generic types reification";
191 207
192 Future<Result<Program>> run(Program program, TestContext testContext) async { 208 Future<Result<Program>> run(Program program, TestContext testContext) async {
193 try { 209 try {
194 program = generic_types_reification.transformProgram(program); 210 program = generic_types_reification.transformProgram(program);
195 return pass(program); 211 return pass(program);
196 } catch (e, s) { 212 } catch (e, s) {
(...skipping 15 matching lines...) Expand all
212 await StdioProcess.run(context.vm.toFilePath(), [generated.path]); 228 await StdioProcess.run(context.vm.toFilePath(), [generated.path]);
213 print(process.output); 229 print(process.output);
214 } finally { 230 } finally {
215 generated.parent.delete(recursive: true); 231 generated.parent.delete(recursive: true);
216 } 232 }
217 return process.toResult(); 233 return process.toResult();
218 } 234 }
219 } 235 }
220 236
221 main(List<String> arguments) => runMe(arguments, createContext, "testing.json"); 237 main(List<String> arguments) => runMe(arguments, createContext, "testing.json");
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698