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 file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:convert'; | 6 import 'dart:convert'; |
7 import 'dart:typed_data'; | 7 import 'dart:typed_data'; |
8 | 8 |
9 import 'package:convert/convert.dart'; | 9 import 'package:convert/convert.dart'; |
10 import 'package:crypto/crypto.dart'; | 10 import 'package:crypto/crypto.dart'; |
11 import 'package:front_end/file_system.dart'; | 11 import 'package:front_end/file_system.dart'; |
12 import 'package:front_end/src/base/resolve_relative_uri.dart'; | 12 import 'package:front_end/src/base/resolve_relative_uri.dart'; |
13 import 'package:front_end/src/dependency_walker.dart' as graph; | 13 import 'package:front_end/src/dependency_walker.dart' as graph; |
14 import 'package:front_end/src/fasta/uri_translator.dart'; | 14 import 'package:front_end/src/fasta/uri_translator.dart'; |
15 import 'package:front_end/src/byte_store/byte_store.dart'; | 15 import 'package:front_end/src/byte_store/byte_store.dart'; |
16 import 'package:front_end/src/incremental/format.dart'; | 16 import 'package:front_end/src/incremental/format.dart'; |
17 import 'package:front_end/src/incremental/unlinked_unit.dart'; | 17 import 'package:front_end/src/incremental/unlinked_unit.dart'; |
18 import 'package:kernel/target/vm.dart'; | 18 import 'package:kernel/target/targets.dart'; |
19 | 19 |
20 /// This function is called for each newly discovered file, and the returned | 20 /// This function is called for each newly discovered file, and the returned |
21 /// [Future] is awaited before reading the file content. | 21 /// [Future] is awaited before reading the file content. |
22 typedef Future<Null> NewFileFn(Uri uri); | 22 typedef Future<Null> NewFileFn(Uri uri); |
23 | 23 |
24 /// Information about a file being compiled, explicitly or implicitly. | 24 /// Information about a file being compiled, explicitly or implicitly. |
25 /// | 25 /// |
26 /// It provides a consistent view on its properties. | 26 /// It provides a consistent view on its properties. |
27 /// | 27 /// |
28 /// The properties are not guaranteed to represent the most recent state | 28 /// The properties are not guaranteed to represent the most recent state |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 if (coreFile != null) { | 175 if (coreFile != null) { |
176 _importedLibraries.add(coreFile); | 176 _importedLibraries.add(coreFile); |
177 } | 177 } |
178 } | 178 } |
179 for (var import_ in unlinkedUnit.imports) { | 179 for (var import_ in unlinkedUnit.imports) { |
180 FileState file = await _getFileForRelativeUri(import_.uri); | 180 FileState file = await _getFileForRelativeUri(import_.uri); |
181 if (file != null) { | 181 if (file != null) { |
182 _importedLibraries.add(file); | 182 _importedLibraries.add(file); |
183 } | 183 } |
184 } | 184 } |
185 await _addVmTargetImportsForCore(); | 185 await _addTargetExtraRequiredLibraries(); |
186 for (var export_ in unlinkedUnit.exports) { | 186 for (var export_ in unlinkedUnit.exports) { |
187 FileState file = await _getFileForRelativeUri(export_.uri); | 187 FileState file = await _getFileForRelativeUri(export_.uri); |
188 if (file != null) { | 188 if (file != null) { |
189 _exportedLibraries.add(file); | 189 _exportedLibraries.add(file); |
190 _exports.add(new NamespaceExport(file, export_.combinators)); | 190 _exports.add(new NamespaceExport(file, export_.combinators)); |
191 } | 191 } |
192 } | 192 } |
193 for (var part_ in unlinkedUnit.parts) { | 193 for (var part_ in unlinkedUnit.parts) { |
194 FileState file = await _getFileForRelativeUri(part_); | 194 FileState file = await _getFileForRelativeUri(part_); |
195 if (file != null) { | 195 if (file != null) { |
(...skipping 25 matching lines...) Expand all Loading... |
221 } | 221 } |
222 } | 222 } |
223 } | 223 } |
224 | 224 |
225 @override | 225 @override |
226 String toString() { | 226 String toString() { |
227 if (uri.scheme == 'file') return uri.path; | 227 if (uri.scheme == 'file') return uri.path; |
228 return uri.toString(); | 228 return uri.toString(); |
229 } | 229 } |
230 | 230 |
231 /// Fasta unconditionally loads all VM libraries. In order to be able to | 231 /// Fasta unconditionally loads extra libraries based on the target. In order |
232 /// serve them using the file system view, pretend that all of them were | 232 /// to be able to serve them using the file system view, pretend that all of |
233 /// imported into `dart:core`. | 233 /// them were imported into `dart:core`. |
234 /// TODO(scheglov) Ask VM people whether all these libraries are required. | 234 /// TODO(scheglov,sigmund): remove this implicit import, instead make fasta |
235 Future<Null> _addVmTargetImportsForCore() async { | 235 /// and IKG aware of extra code that needs to be loaded. |
| 236 Future<Null> _addTargetExtraRequiredLibraries() async { |
236 if (uri.toString() != 'dart:core') return; | 237 if (uri.toString() != 'dart:core') return; |
237 for (String uri in new VmTarget(null).extraRequiredLibraries) { | 238 for (String uri in _fsState.target.extraRequiredLibraries) { |
238 FileState file = await _getFileForRelativeUri(uri); | 239 FileState file = await _getFileForRelativeUri(uri); |
239 // TODO(scheglov) add error handling | 240 // TODO(scheglov) add error handling |
240 if (file != null) { | 241 if (file != null) { |
241 _importedLibraries.add(file); | 242 _importedLibraries.add(file); |
242 } | 243 } |
243 } | 244 } |
244 } | 245 } |
245 | 246 |
246 /// Return the [FileState] for the given [relativeUri] or `null` if the URI | 247 /// Return the [FileState] for the given [relativeUri] or `null` if the URI |
247 /// cannot be parsed, cannot correspond any file, etc. | 248 /// cannot be parsed, cannot correspond any file, etc. |
(...skipping 12 matching lines...) Expand all Loading... |
260 } | 261 } |
261 | 262 |
262 return await _fsState.getFile(absoluteUri); | 263 return await _fsState.getFile(absoluteUri); |
263 } | 264 } |
264 } | 265 } |
265 | 266 |
266 /// Information about known file system state. | 267 /// Information about known file system state. |
267 class FileSystemState { | 268 class FileSystemState { |
268 final ByteStore _byteStore; | 269 final ByteStore _byteStore; |
269 final FileSystem fileSystem; | 270 final FileSystem fileSystem; |
| 271 final Target target; |
270 final UriTranslator uriTranslator; | 272 final UriTranslator uriTranslator; |
271 final List<int> _salt; | 273 final List<int> _salt; |
272 final NewFileFn _newFileFn; | 274 final NewFileFn _newFileFn; |
273 | 275 |
274 _FileSystemView _fileSystemView; | 276 _FileSystemView _fileSystemView; |
275 | 277 |
276 /// Mapping from import URIs to corresponding [FileState]s. For example, this | 278 /// Mapping from import URIs to corresponding [FileState]s. For example, this |
277 /// may contain an entry for `dart:core`. | 279 /// may contain an entry for `dart:core`. |
278 final Map<Uri, FileState> _uriToFile = {}; | 280 final Map<Uri, FileState> _uriToFile = {}; |
279 | 281 |
280 /// Mapping from file URIs to corresponding [FileState]s. This map should only | 282 /// Mapping from file URIs to corresponding [FileState]s. This map should only |
281 /// contain `file:*` URIs as keys. | 283 /// contain `file:*` URIs as keys. |
282 final Map<Uri, FileState> _fileUriToFile = {}; | 284 final Map<Uri, FileState> _fileUriToFile = {}; |
283 | 285 |
284 /// The set of absolute URIs with the `dart` scheme that should be skipped. | 286 /// The set of absolute URIs with the `dart` scheme that should be skipped. |
285 /// We do this when we use SDK outline instead of compiling SDK sources. | 287 /// We do this when we use SDK outline instead of compiling SDK sources. |
286 final Set<Uri> skipSdkLibraries = new Set<Uri>(); | 288 final Set<Uri> skipSdkLibraries = new Set<Uri>(); |
287 | 289 |
288 FileSystemState(this._byteStore, this.fileSystem, this.uriTranslator, | 290 FileSystemState(this._byteStore, this.fileSystem, this.target, |
289 this._salt, this._newFileFn); | 291 this.uriTranslator, this._salt, this._newFileFn); |
290 | 292 |
291 /// Return the [FileSystem] that is backed by this [FileSystemState]. The | 293 /// Return the [FileSystem] that is backed by this [FileSystemState]. The |
292 /// files in this [FileSystem] always have the same content as the | 294 /// files in this [FileSystem] always have the same content as the |
293 /// corresponding [FileState]s, thus avoiding race conditions when a file | 295 /// corresponding [FileState]s, thus avoiding race conditions when a file |
294 /// is updated on the actual file system. | 296 /// is updated on the actual file system. |
295 FileSystem get fileSystemView { | 297 FileSystem get fileSystemView { |
296 return _fileSystemView ??= new _FileSystemView(this); | 298 return _fileSystemView ??= new _FileSystemView(this); |
297 } | 299 } |
298 | 300 |
299 /// The `file:` URI of all files currently tracked by this instance. | 301 /// The `file:` URI of all files currently tracked by this instance. |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 cycle.libraries.add(node.file); | 522 cycle.libraries.add(node.file); |
521 fileToCycleMap[node.file] = cycle; | 523 fileToCycleMap[node.file] = cycle; |
522 } | 524 } |
523 topologicallySortedCycles.add(cycle); | 525 topologicallySortedCycles.add(cycle); |
524 } | 526 } |
525 | 527 |
526 _LibraryNode getNode(FileState file) { | 528 _LibraryNode getNode(FileState file) { |
527 return nodesOfFiles.putIfAbsent(file, () => new _LibraryNode(this, file)); | 529 return nodesOfFiles.putIfAbsent(file, () => new _LibraryNode(this, file)); |
528 } | 530 } |
529 } | 531 } |
OLD | NEW |