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

Side by Side Diff: utils/kernel-service/kernel-service.dart

Issue 2979053002: simplify and remove unnecessary checks in kernel service (Closed)
Patch Set: v1 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 | « no previous file | no next file » | 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 /// This is an interface to the Dart Kernel parser and Kernel binary generator. 5 /// This is an interface to the Dart Kernel parser and Kernel binary generator.
6 /// 6 ///
7 /// It is used by the kernel-isolate to load Dart source code and generate 7 /// It is used by the kernel-isolate to load Dart source code and generate
8 /// Kernel binary format. 8 /// Kernel binary format.
9 /// 9 ///
10 /// This is either invoked as the root script of the Kernel isolate when used 10 /// This is either invoked as the root script of the Kernel isolate when used
(...skipping 18 matching lines...) Expand all
29 import 'package:front_end/front_end.dart'; 29 import 'package:front_end/front_end.dart';
30 import 'package:front_end/memory_file_system.dart'; 30 import 'package:front_end/memory_file_system.dart';
31 import 'package:front_end/physical_file_system.dart'; 31 import 'package:front_end/physical_file_system.dart';
32 import 'package:front_end/src/fasta/kernel/utils.dart'; 32 import 'package:front_end/src/fasta/kernel/utils.dart';
33 import 'package:front_end/src/testing/hybrid_file_system.dart'; 33 import 'package:front_end/src/testing/hybrid_file_system.dart';
34 import 'package:kernel/kernel.dart' show Program; 34 import 'package:kernel/kernel.dart' show Program;
35 import 'package:kernel/target/targets.dart' show TargetFlags; 35 import 'package:kernel/target/targets.dart' show TargetFlags;
36 import 'package:kernel/target/vm_fasta.dart' show VmFastaTarget; 36 import 'package:kernel/target/vm_fasta.dart' show VmFastaTarget;
37 37
38 const bool verbose = const bool.fromEnvironment('DFE_VERBOSE'); 38 const bool verbose = const bool.fromEnvironment('DFE_VERBOSE');
39
40 const bool strongMode = const bool.fromEnvironment('DFE_STRONG_MODE'); 39 const bool strongMode = const bool.fromEnvironment('DFE_STRONG_MODE');
41 40
42 Future<CompilationResult> _parseScriptInFileSystem(
43 Uri script, FileSystem fileSystem,
44 {bool verbose: false, bool strongMode: false}) async {
45 final Uri packagesUri = (Platform.packageConfig != null)
46 ? Uri.parse(Platform.packageConfig)
47 : null;
48
49 final Uri patchedSdk = Uri.base
50 .resolveUri(new Uri.file(Platform.resolvedExecutable))
51 .resolveUri(new Uri.directory("patched_sdk"));
52
53 if (verbose) {
54 print("""DFE: Requesting compilation {
55 scriptUri: ${script}
56 packagesUri: ${packagesUri}
57 patchedSdk: ${patchedSdk}
58 }""");
59 }
60
61 try {
62 var errors = <String>[];
63 var options = new CompilerOptions()
64 ..strongMode = strongMode
65 ..fileSystem = fileSystem
66 ..target = new VmFastaTarget(new TargetFlags(strongMode: strongMode))
67 ..packagesFileUri = packagesUri
68 // TODO(sigmund): use outline.dill when the mixin transformer is modular.
69 ..sdkSummary = patchedSdk.resolve('platform.dill')
70 ..verbose = verbose
71 ..onError = (CompilationError e) => errors.add(e.message);
72
73 Program program = await kernelForProgram(script, options);
74 if (errors.isNotEmpty) return new CompilationResult.errors(errors);
75
76 // We serialize the program excluding platform.dill because the VM has these
77 // sources built-in. Everything loaded as a summary in [kernelForProgram] is
78 // marked `external`, so we can use that bit to decide what to excluce.
79 // TODO(sigmund): remove the following line (Issue #30111)
80 program.libraries.forEach((e) => e.isExternal = false);
81 return new CompilationResult.ok(
82 serializeProgram(program, filter: (lib) => !lib.isExternal));
83 } catch (err, stack) {
84 return new CompilationResult.crash(err, stack);
85 }
86 }
87
88 Future<CompilationResult> _processLoadRequestImpl(
89 String inputFilePathOrUri, FileSystem fileSystem) {
90 Uri scriptUri = Uri.parse(inputFilePathOrUri);
91
92 // Because we serve both Loader and bootstrapping requests we need to
93 // duplicate the logic from _resolveScriptUri(...) here and attempt to
94 // resolve schemaless uris using current working directory.
95 if (!scriptUri.hasScheme) {
96 // Script does not have a scheme, assume that it is a path,
97 // resolve it against the working directory.
98 scriptUri = Uri.base.resolveUri(new Uri.file(inputFilePathOrUri));
99 }
100
101 if (!scriptUri.isScheme('file')) {
102 // TODO(vegorov): Reuse loader code to support other schemes.
103 return new Future<CompilationResult>.value(new CompilationResult.errors(
104 ["Expected 'file' scheme for a script uri: got ${scriptUri.scheme}"]));
105 }
106 return _parseScriptInFileSystem(scriptUri, fileSystem,
107 verbose: verbose, strongMode: strongMode);
108 }
109
110 // Process a request from the runtime. See KernelIsolate::CompileToKernel in 41 // Process a request from the runtime. See KernelIsolate::CompileToKernel in
111 // kernel_isolate.cc and Loader::SendKernelRequest in loader.cc. 42 // kernel_isolate.cc and Loader::SendKernelRequest in loader.cc.
112 Future _processLoadRequest(request) async { 43 Future _processLoadRequest(request) async {
113 if (verbose) { 44 if (verbose) print("DFE: request: $request");
114 print("DFE: request: $request");
115 print("DFE: Platform.packageConfig: ${Platform.packageConfig}");
116 print("DFE: Platform.resolvedExecutable: ${Platform.resolvedExecutable}");
117 }
118 45
119 int tag = request[0]; 46 int tag = request[0];
120 final SendPort port = request[1]; 47 final SendPort port = request[1];
121 final String inputFileUrl = request[2]; 48 final String inputFileUri = request[2];
49 final Uri script = Uri.base.resolve(inputFileUri);
50
122 FileSystem fileSystem = request.length > 3 51 FileSystem fileSystem = request.length > 3
123 ? _buildFileSystem(request[3]) 52 ? _buildFileSystem(request[3])
124 : PhysicalFileSystem.instance; 53 : PhysicalFileSystem.instance;
125 54
55 Uri packagesUri = (Platform.packageConfig != null)
56 ? Uri.parse(Platform.packageConfig)
57 : null;
58
59 Uri sdkSummary = Uri.base
60 .resolveUri(new Uri.file(Platform.resolvedExecutable))
61 .resolveUri(new Uri.directory("patched_sdk"))
62 // TODO(sigmund): use outline.dill when the mixin transformer is modular.
63 .resolve('platform.dill');
64
65 if (verbose) {
66 print("DFE: scriptUri: ${script}");
67 print("DFE: Platform.packageConfig: ${Platform.packageConfig}");
68 print("DFE: packagesUri: ${packagesUri}");
69 print("DFE: Platform.resolvedExecutable: ${Platform.resolvedExecutable}");
70 print("DFE: sdkSummary: ${sdkSummary}");
71 }
72
73 var errors = <String>[];
74 var options = new CompilerOptions()
75 ..strongMode = strongMode
76 ..fileSystem = fileSystem
77 ..target = new VmFastaTarget(new TargetFlags(strongMode: strongMode))
78 ..packagesFileUri = packagesUri
79 ..sdkSummary = sdkSummary
80 ..verbose = verbose
81 ..onError = (CompilationError e) => errors.add(e.message);
82
126 CompilationResult result; 83 CompilationResult result;
127 try { 84 try {
128 result = await _processLoadRequestImpl(inputFileUrl, fileSystem); 85 Program program = await kernelForProgram(script, options);
86 if (errors.isNotEmpty) {
87 result = new CompilationResult.errors(errors);
88 } else {
89 // We serialize the program excluding platform.dill because the VM has
90 // these sources built-in. Everything loaded as a summary in
91 // [kernelForProgram] is marked `external`, so we can use that bit to
92 // decide what to excluce.
93 // TODO(sigmund): remove the following line (Issue #30111)
94 program.libraries.forEach((e) => e.isExternal = false);
95 result = new CompilationResult.ok(
96 serializeProgram(program, filter: (lib) => !lib.isExternal));
97 }
129 } catch (error, stack) { 98 } catch (error, stack) {
130 result = new CompilationResult.crash(error, stack); 99 result = new CompilationResult.crash(error, stack);
131 } 100 }
132 101
133 if (verbose) { 102 if (verbose) print("DFE:> ${result}");
134 print("DFE:> ${result}");
135 }
136 103
137 // Check whether this is a Loader request or a bootstrapping request from 104 // Check whether this is a Loader request or a bootstrapping request from
138 // KernelIsolate::CompileToKernel. 105 // KernelIsolate::CompileToKernel.
139 final isBootstrapRequest = tag == null; 106 final isBootstrapRequest = tag == null;
140 if (isBootstrapRequest) { 107 if (isBootstrapRequest) {
141 port.send(result.toResponse()); 108 port.send(result.toResponse());
142 } else { 109 } else {
143 // See loader.cc for the code that handles these replies. 110 // See loader.cc for the code that handles these replies.
144 if (result.status != Status.ok) { 111 if (result.status != Status.ok) {
145 tag = -tag; 112 tag = -tag;
146 } 113 }
147 port.send([tag, inputFileUrl, inputFileUrl, null, result.payload]); 114 port.send([tag, inputFileUri, inputFileUri, null, result.payload]);
148 } 115 }
149 } 116 }
150 117
151 /// Creates a file system containing the files specified in [namedSources] and 118 /// Creates a file system containing the files specified in [namedSources] and
152 /// that delegates to the underlying file system for any other file request. 119 /// that delegates to the underlying file system for any other file request.
153 /// The [namedSources] list interleaves file name string and 120 /// The [namedSources] list interleaves file name string and
154 /// raw file content Uint8List. 121 /// raw file content Uint8List.
155 /// 122 ///
156 /// The result can be used instead of PhysicalFileSystem.instance by the 123 /// The result can be used instead of PhysicalFileSystem.instance by the
157 /// frontend. 124 /// frontend.
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 _CompilationCrash(this.exception, this.stack); 241 _CompilationCrash(this.exception, this.stack);
275 242
276 @override 243 @override
277 Status get status => Status.crash; 244 Status get status => Status.crash;
278 245
279 @override 246 @override
280 String get errorString => "${exception}\n${stack}"; 247 String get errorString => "${exception}\n${stack}";
281 248
282 String toString() => "_CompilationCrash(${errorString})"; 249 String toString() => "_CompilationCrash(${errorString})";
283 } 250 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698