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

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

Issue 2979463002: Revert "Tweak public APIs and use them in patch_sdk, dart2js, and kernel-service." (Closed)
Patch Set: Created 3 years, 5 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
« no previous file with comments | « pkg/kernel/lib/target/vm.dart ('k') | pkg/kernel/test/interpreter/suite.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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:async' show Future; 7 import 'dart:async' show Future;
8 8
9 import 'package:front_end/physical_file_system.dart' show PhysicalFileSystem;
10
9 import 'package:kernel/core_types.dart' show CoreTypes; 11 import 'package:kernel/core_types.dart' show CoreTypes;
10 12
11 import 'package:testing/testing.dart' 13 import 'package:testing/testing.dart'
12 show Chain, ChainContext, Result, Step, runMe; 14 show Chain, ChainContext, Result, Step, TestDescription, runMe;
15
16 import 'package:front_end/src/fasta/testing/patched_sdk_location.dart'
17 show computePatchedSdk;
13 18
14 import 'package:kernel/ast.dart' show Program, Library; 19 import 'package:kernel/ast.dart' show Program, Library;
15 20
16 import 'package:kernel/transformations/closure_conversion.dart' 21 import 'package:kernel/transformations/closure_conversion.dart'
17 as closure_conversion; 22 as closure_conversion;
18 23
19 import 'package:front_end/src/fasta/testing/kernel_chain.dart' 24 import 'package:front_end/src/fasta/testing/kernel_chain.dart'
20 show 25 show Print, MatchExpectation, WriteDill, ReadDill, Verify;
21 Print, 26
22 MatchExpectation, 27 import 'package:front_end/src/fasta/ticker.dart' show Ticker;
23 WriteDill, 28
24 ReadDill, 29 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget;
25 Verify, 30
26 Compile, 31 import 'package:front_end/src/fasta/kernel/kernel_target.dart'
27 CompileContext; 32 show KernelTarget;
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;
28 45
29 const String STRONG_MODE = " strong mode "; 46 const String STRONG_MODE = " strong mode ";
30 47
31 class ClosureConversionContext extends ChainContext implements CompileContext { 48 class ClosureConversionContext extends ChainContext {
32 final bool strongMode; 49 final bool strongMode;
33 50
51 final TranslateUri uriTranslator;
52
34 final List<Step> steps; 53 final List<Step> steps;
35 54
36 ClosureConversionContext(this.strongMode, bool updateExpectations) 55 ClosureConversionContext(
56 this.strongMode, bool updateExpectations, this.uriTranslator)
37 : steps = <Step>[ 57 : steps = <Step>[
38 const Compile(), 58 const FastaCompile(),
39 const Print(), 59 const Print(),
40 const Verify(true), 60 const Verify(true),
41 const ClosureConversion(), 61 const ClosureConversion(),
42 const Print(), 62 const Print(),
43 const Verify(true), 63 const Verify(true),
44 new MatchExpectation(".expect", 64 new MatchExpectation(".expect",
45 updateExpectations: updateExpectations), 65 updateExpectations: updateExpectations),
46 const WriteDill(), 66 const WriteDill(),
47 const ReadDill(), 67 const ReadDill(),
48 // TODO(29143): add `Run` step when Vectors are added to VM. 68 // TODO(29143): add `Run` step when Vectors are added to VM.
49 ]; 69 ];
50 70
71 Future<Program> loadPlatform() async {
72 Uri sdk = await computePatchedSdk();
73 return loadProgramFromBinary(sdk.resolve('platform.dill').toFilePath());
74 }
75
51 static Future<ClosureConversionContext> create( 76 static Future<ClosureConversionContext> create(
52 Chain suite, Map<String, String> environment) async { 77 Chain suite, Map<String, String> environment) async {
78 Uri sdk = await computePatchedSdk();
79 Uri packages = Uri.base.resolve(".packages");
53 bool strongMode = environment.containsKey(STRONG_MODE); 80 bool strongMode = environment.containsKey(STRONG_MODE);
54 bool updateExpectations = environment["updateExpectations"] == "true"; 81 bool updateExpectations = environment["updateExpectations"] == "true";
55 return new ClosureConversionContext(strongMode, updateExpectations); 82 TranslateUri uriTranslator = await TranslateUri
83 .parse(PhysicalFileSystem.instance, sdk, packages: packages);
84 return new ClosureConversionContext(
85 strongMode, updateExpectations, uriTranslator);
56 } 86 }
57 } 87 }
58 88
59 Future<ClosureConversionContext> createContext( 89 Future<ClosureConversionContext> createContext(
60 Chain suite, Map<String, String> environment) async { 90 Chain suite, Map<String, String> environment) async {
61 environment["updateExpectations"] = 91 environment["updateExpectations"] =
62 const String.fromEnvironment("updateExpectations"); 92 const String.fromEnvironment("updateExpectations");
63 return ClosureConversionContext.create(suite, environment); 93 return ClosureConversionContext.create(suite, environment);
64 } 94 }
65 95
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
66 class ClosureConversion 126 class ClosureConversion
67 extends Step<Program, Program, ClosureConversionContext> { 127 extends Step<Program, Program, ClosureConversionContext> {
68 const ClosureConversion(); 128 const ClosureConversion();
69 129
70 String get name => "closure conversion"; 130 String get name => "closure conversion";
71 131
72 Future<Result<Program>> run( 132 Future<Result<Program>> run(
73 Program program, ClosureConversionContext testContext) async { 133 Program program, ClosureConversionContext testContext) async {
74 try { 134 try {
75 CoreTypes coreTypes = new CoreTypes(program); 135 CoreTypes coreTypes = new CoreTypes(program);
76 Library library = program.libraries 136 Library library = program.libraries
77 .firstWhere((Library library) => library.importUri.scheme != "dart"); 137 .firstWhere((Library library) => library.importUri.scheme != "dart");
78 closure_conversion.transformLibraries(coreTypes, <Library>[library]); 138 closure_conversion.transformLibraries(coreTypes, <Library>[library]);
79 return pass(program); 139 return pass(program);
80 } catch (e, s) { 140 } catch (e, s) {
81 return crash(e, s); 141 return crash(e, s);
82 } 142 }
83 } 143 }
84 } 144 }
85 145
86 main(List<String> arguments) => runMe(arguments, createContext, "testing.json"); 146 main(List<String> arguments) => runMe(arguments, createContext, "testing.json");
OLDNEW
« no previous file with comments | « pkg/kernel/lib/target/vm.dart ('k') | pkg/kernel/test/interpreter/suite.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698