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

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

Issue 2891053003: Add support for converted closures with explicit contexts to VM (Closed)
Patch Set: Created 3 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) 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:io' show File;
8
7 import 'dart:async' show Future; 9 import 'dart:async' show Future;
8 10
9 import 'package:front_end/physical_file_system.dart'; 11 import 'package:front_end/physical_file_system.dart';
10 import 'package:testing/testing.dart' 12 import 'package:testing/testing.dart'
11 show Chain, ChainContext, Result, Step, TestDescription, runMe; 13 show
14 Chain,
15 ChainContext,
16 Result,
17 Step,
18 TestDescription,
19 runMe,
20 StdioProcess;
12 21
13 import 'package:kernel/ast.dart' show Program; 22 import 'package:kernel/ast.dart' show Program;
14 23
15 import 'package:kernel/transformations/closure_conversion.dart'
16 as closure_conversion;
17
18 import 'package:front_end/src/fasta/testing/kernel_chain.dart' 24 import 'package:front_end/src/fasta/testing/kernel_chain.dart'
19 show Print, MatchExpectation, WriteDill, ReadDill, Verify; 25 show TestContext, Print, MatchExpectation, WriteDill, ReadDill, Verify;
20 26
21 import 'package:front_end/src/fasta/ticker.dart' show Ticker; 27 import 'package:front_end/src/fasta/ticker.dart' show Ticker;
22 28
23 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget; 29 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget;
24 30
25 import 'package:front_end/src/fasta/kernel/kernel_target.dart' 31 import 'package:front_end/src/fasta/kernel/kernel_target.dart'
26 show KernelTarget; 32 show KernelTarget;
27 33
28 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri; 34 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri;
29 35
30 import 'package:front_end/src/fasta/errors.dart' show InputError; 36 import 'package:front_end/src/fasta/errors.dart' show InputError;
31 37
32 import 'package:front_end/src/fasta/testing/patched_sdk_location.dart'; 38 import 'package:front_end/src/fasta/testing/patched_sdk_location.dart';
33 39
34 import 'package:kernel/kernel.dart' show loadProgramFromBinary; 40 import 'package:kernel/kernel.dart' show loadProgramFromBinary;
35 41
36 const String STRONG_MODE = " strong mode "; 42 const String STRONG_MODE = " strong mode ";
37 43
38 class ClosureConversionContext extends ChainContext { 44 class ClosureConversionContext extends ChainContext {
39 final bool strongMode;
40
41 final TranslateUri uriTranslator; 45 final TranslateUri uriTranslator;
42
43 final List<Step> steps; 46 final List<Step> steps;
47 final Uri vm;
44 48
45 ClosureConversionContext( 49 ClosureConversionContext(
46 this.strongMode, bool updateExpectations, this.uriTranslator) 50 this.vm, bool strongMode, bool updateExpectations, this.uriTranslator)
47 : steps = <Step>[ 51 : steps = <Step>[
48 const FastaCompile(), 52 new FastaCompile(strongMode),
49 const Print(),
50 const Verify(true),
51 const ClosureConversion(),
52 const Print(), 53 const Print(),
53 const Verify(true), 54 const Verify(true),
54 new MatchExpectation(".expect", 55 new MatchExpectation(".expect",
55 updateExpectations: updateExpectations), 56 updateExpectations: updateExpectations),
56 const WriteDill(), 57 const WriteDill(),
57 const ReadDill(), 58 const ReadDill(),
58 // TODO(29143): add `Run` step when Vectors are added to VM. 59 const Run(),
59 ]; 60 ];
60 61
61 Future<Program> loadPlatform() async { 62 // The platform in these tests are reloaded for each testscase, because the
62 Uri sdk = await computePatchedSdk(); 63 // closure conversion transformation is performed during the load, and it's
63 return loadProgramFromBinary(sdk.resolve('platform.dill').toFilePath()); 64 // not an idempotent transformation yet.
65 Future<Program> loadPlatform() {
66 return new Future<Program>(() async {
67 Uri sdk = await computePatchedSdk();
68 return loadProgramFromBinary(sdk.resolve('platform.dill').toFilePath());
69 });
64 } 70 }
65 71
66 static Future<ClosureConversionContext> create( 72 static Future<ClosureConversionContext> create(
67 Chain suite, Map<String, String> environment) async { 73 Chain suite, Map<String, String> environment) async {
74 Uri sdk = await computePatchedSdk();
75 Uri vm = computeDartVm(sdk);
68 Uri packages = Uri.base.resolve(".packages"); 76 Uri packages = Uri.base.resolve(".packages");
77 TranslateUri uriTranslator =
78 await TranslateUri.parse(PhysicalFileSystem.instance, packages);
69 bool strongMode = environment.containsKey(STRONG_MODE); 79 bool strongMode = environment.containsKey(STRONG_MODE);
70 bool updateExpectations = environment["updateExpectations"] == "true"; 80 bool updateExpectations = environment["updateExpectations"] == "true";
71 TranslateUri uriTranslator = 81
72 await TranslateUri.parse(PhysicalFileSystem.instance, packages);
73 return new ClosureConversionContext( 82 return new ClosureConversionContext(
74 strongMode, updateExpectations, uriTranslator); 83 vm, strongMode, updateExpectations, uriTranslator);
75 } 84 }
76 } 85 }
77 86
78 Future<ClosureConversionContext> createContext( 87 Future<ClosureConversionContext> createContext(
79 Chain suite, Map<String, String> environment) async { 88 Chain suite, Map<String, String> environment) async {
80 environment["updateExpectations"] = 89 environment["updateExpectations"] =
81 const String.fromEnvironment("updateExpectations"); 90 const String.fromEnvironment("updateExpectations");
82 return ClosureConversionContext.create(suite, environment); 91 return ClosureConversionContext.create(suite, environment);
83 } 92 }
84 93
85 class FastaCompile 94 class FastaCompile
86 extends Step<TestDescription, Program, ClosureConversionContext> { 95 extends Step<TestDescription, Program, ClosureConversionContext> {
87 const FastaCompile(); 96 final bool strongMode;
97
98 const FastaCompile(this.strongMode);
88 99
89 String get name => "fasta compilation"; 100 String get name => "fasta compilation";
90 101
91 Future<Result<Program>> run( 102 Future<Result<Program>> run(
92 TestDescription description, ClosureConversionContext context) async { 103 TestDescription description, ClosureConversionContext context) async {
93 Program platform = await context.loadPlatform(); 104 Program platform = await context.loadPlatform();
94 Ticker ticker = new Ticker(); 105 Ticker ticker = new Ticker();
95 DillTarget dillTarget = new DillTarget(ticker, context.uriTranslator); 106 DillTarget dillTarget = new DillTarget(ticker, context.uriTranslator);
96 platform.unbindCanonicalNames(); 107 platform.unbindCanonicalNames();
97 dillTarget.loader.appendLibraries(platform); 108 dillTarget.loader.appendLibraries(platform);
98 KernelTarget sourceTarget = new KernelTarget(PhysicalFileSystem.instance, 109 KernelTarget sourceTarget = new KernelTarget(PhysicalFileSystem.instance,
99 dillTarget, context.uriTranslator, context.strongMode); 110 dillTarget, context.uriTranslator, strongMode);
100 111
101 Program p; 112 Program p;
102 try { 113 try {
103 sourceTarget.read(description.uri); 114 sourceTarget.read(description.uri);
104 await dillTarget.buildOutlines(); 115 await dillTarget.buildOutlines();
105 await sourceTarget.buildOutlines(); 116 await sourceTarget.buildOutlines();
106 p = await sourceTarget.buildProgram(); 117 p = await sourceTarget.buildProgram();
107 } on InputError catch (e, s) { 118 } on InputError catch (e, s) {
108 return fail(null, e.error, s); 119 return fail(null, e.error, s);
109 } 120 }
110 return pass(p); 121 return pass(p);
111 } 122 }
112 } 123 }
113 124
114 class ClosureConversion 125 class Run extends Step<Uri, int, ClosureConversionContext> {
115 extends Step<Program, Program, ClosureConversionContext> { 126 const Run();
116 const ClosureConversion();
117 127
118 String get name => "closure conversion"; 128 String get name => "run";
119 129
120 Future<Result<Program>> run( 130 Future<Result<int>> run(Uri uri, ClosureConversionContext context) async {
121 Program program, ClosureConversionContext testContext) async { 131 File generated = new File.fromUri(uri);
132 StdioProcess process;
122 try { 133 try {
123 program = closure_conversion.transformProgram(program); 134 process =
124 return pass(program); 135 await StdioProcess.run(context.vm.toFilePath(), [generated.path]);
125 } catch (e, s) { 136 print(process.output);
126 return crash(e, s); 137 } finally {
138 generated.parent.delete(recursive: true);
127 } 139 }
140 return process.toResult();
128 } 141 }
129 } 142 }
130 143
131 main(List<String> arguments) => runMe(arguments, createContext, "testing.json"); 144 main(List<String> arguments) => runMe(arguments, createContext, "testing.json");
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698