| 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 | 6 |
| 7 import 'package:front_end/file_system.dart'; | 7 import 'package:front_end/file_system.dart'; |
| 8 import 'package:front_end/src/base/api_signature.dart'; | 8 import 'package:front_end/src/base/api_signature.dart'; |
| 9 import 'package:front_end/src/base/performace_logger.dart'; | 9 import 'package:front_end/src/base/performace_logger.dart'; |
| 10 import 'package:front_end/src/base/processed_options.dart'; | 10 import 'package:front_end/src/base/processed_options.dart'; |
| 11 import 'package:front_end/src/byte_store/byte_store.dart'; |
| 11 import 'package:front_end/src/fasta/compiler_context.dart'; | 12 import 'package:front_end/src/fasta/compiler_context.dart'; |
| 12 import 'package:front_end/src/fasta/dill/dill_library_builder.dart'; | 13 import 'package:front_end/src/fasta/dill/dill_library_builder.dart'; |
| 13 import 'package:front_end/src/fasta/dill/dill_target.dart'; | 14 import 'package:front_end/src/fasta/dill/dill_target.dart'; |
| 14 import 'package:front_end/src/fasta/kernel/kernel_target.dart'; | 15 import 'package:front_end/src/fasta/kernel/kernel_target.dart'; |
| 15 import 'package:front_end/src/fasta/kernel/utils.dart'; | 16 import 'package:front_end/src/fasta/kernel/utils.dart'; |
| 16 import 'package:front_end/src/fasta/ticker.dart'; | 17 import 'package:front_end/src/fasta/ticker.dart'; |
| 17 import 'package:front_end/src/fasta/uri_translator.dart'; | 18 import 'package:front_end/src/fasta/uri_translator.dart'; |
| 18 import 'package:front_end/src/byte_store/byte_store.dart'; | |
| 19 import 'package:front_end/src/incremental/file_state.dart'; | 19 import 'package:front_end/src/incremental/file_state.dart'; |
| 20 import 'package:kernel/binary/ast_from_binary.dart'; | 20 import 'package:kernel/binary/ast_from_binary.dart'; |
| 21 import 'package:kernel/core_types.dart'; | 21 import 'package:kernel/core_types.dart'; |
| 22 import 'package:kernel/kernel.dart' hide Source; | 22 import 'package:kernel/kernel.dart' hide Source; |
| 23 import 'package:kernel/src/incremental_class_hierarchy.dart'; | 23 import 'package:kernel/src/incremental_class_hierarchy.dart'; |
| 24 import 'package:kernel/type_environment.dart'; | 24 import 'package:kernel/type_environment.dart'; |
| 25 import 'package:meta/meta.dart'; | 25 import 'package:meta/meta.dart'; |
| 26 | 26 |
| 27 /// This function is invoked for each newly discovered file, and the returned | 27 /// This function is invoked for each newly discovered file, and the returned |
| 28 /// [Future] is awaited before reading the file content. | 28 /// [Future] is awaited before reading the file content. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 /// reported using [invalidate]. | 124 /// reported using [invalidate]. |
| 125 /// | 125 /// |
| 126 /// If the driver has the cached result for the file with the current file | 126 /// If the driver has the cached result for the file with the current file |
| 127 /// state, it is returned. | 127 /// state, it is returned. |
| 128 /// | 128 /// |
| 129 /// Otherwise the driver will compute new kernel files and return them. | 129 /// Otherwise the driver will compute new kernel files and return them. |
| 130 Future<KernelResult> getKernel(Uri uri) async { | 130 Future<KernelResult> getKernel(Uri uri) async { |
| 131 return await runWithFrontEndContext('Compute delta', () async { | 131 return await runWithFrontEndContext('Compute delta', () async { |
| 132 await _refreshInvalidatedFiles(); | 132 await _refreshInvalidatedFiles(); |
| 133 | 133 |
| 134 CanonicalName nameRoot = new CanonicalName.root(); |
| 135 |
| 134 // Load the SDK outline before building the graph, so that the file | 136 // Load the SDK outline before building the graph, so that the file |
| 135 // system state is configured to skip SDK libraries. | 137 // system state is configured to skip SDK libraries. |
| 136 await _loadSdkOutline(); | 138 await _loadSdkOutline(nameRoot); |
| 137 | 139 |
| 138 // Ensure that the graph starting at the entry point is ready. | 140 // Ensure that the graph starting at the entry point is ready. |
| 139 FileState entryLibrary = | 141 FileState entryLibrary = |
| 140 await _logger.runAsync('Build graph of files', () async { | 142 await _logger.runAsync('Build graph of files', () async { |
| 141 return await _fsState.getFile(uri); | 143 return await _fsState.getFile(uri); |
| 142 }); | 144 }); |
| 143 | 145 |
| 144 List<LibraryCycle> cycles = _logger.run('Compute library cycles', () { | 146 List<LibraryCycle> cycles = _logger.run('Compute library cycles', () { |
| 145 List<LibraryCycle> cycles = entryLibrary.topologicalOrder; | 147 List<LibraryCycle> cycles = entryLibrary.topologicalOrder; |
| 146 _logger.writeln('Computed ${cycles.length} cycles.'); | 148 _logger.writeln('Computed ${cycles.length} cycles.'); |
| 147 return cycles; | 149 return cycles; |
| 148 }); | 150 }); |
| 149 | 151 |
| 150 CanonicalName nameRoot = new CanonicalName.root(); | |
| 151 DillTarget dillTarget = new DillTarget( | 152 DillTarget dillTarget = new DillTarget( |
| 152 new Ticker(isVerbose: false), _uriTranslator, _options.target); | 153 new Ticker(isVerbose: false), _uriTranslator, _options.target); |
| 153 | 154 |
| 154 // If there is SDK outline, load it. | 155 // If there is SDK outline, load it. |
| 155 if (_sdkOutline != null) { | 156 if (_sdkOutline != null) { |
| 156 dillTarget.loader.appendLibraries(_sdkOutline); | 157 dillTarget.loader.appendLibraries(_sdkOutline); |
| 157 await dillTarget.buildOutlines(); | 158 await dillTarget.buildOutlines(); |
| 158 } | 159 } |
| 159 | 160 |
| 160 List<LibraryCycleResult> results = []; | 161 List<LibraryCycleResult> results = []; |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 for (var part in library.partFiles) { | 353 for (var part in library.partFiles) { |
| 353 signatureBuilder.addBytes(part.contentHash); | 354 signatureBuilder.addBytes(part.contentHash); |
| 354 } | 355 } |
| 355 } | 356 } |
| 356 | 357 |
| 357 return signatureBuilder.toHex(); | 358 return signatureBuilder.toHex(); |
| 358 } | 359 } |
| 359 | 360 |
| 360 /// Load the SDK outline if its bytes are provided, and configure the file | 361 /// Load the SDK outline if its bytes are provided, and configure the file |
| 361 /// system state to skip SDK library files. | 362 /// system state to skip SDK library files. |
| 362 Future<Null> _loadSdkOutline() async { | 363 Future<Null> _loadSdkOutline(CanonicalName nameRoot) async { |
| 363 if (_sdkOutlineBytes != null) { | 364 if (_sdkOutlineBytes != null) { |
| 364 if (_sdkOutline == null) { | 365 await _logger.runAsync('Load SDK outline from bytes.', () async { |
| 365 await _logger.runAsync('Load SDK outline from bytes.', () async { | 366 _sdkOutline = new Program(nameRoot: nameRoot); |
| 366 _sdkOutline = new Program(); | 367 new BinaryBuilder(_sdkOutlineBytes).readProgram(_sdkOutline); |
| 367 new BinaryBuilder(_sdkOutlineBytes).readProgram(_sdkOutline); | 368 // Configure the file system state to skip the outline libraries. |
| 368 // Configure the file system state to skip the outline libraries. | 369 for (var outlineLibrary in _sdkOutline.libraries) { |
| 369 for (var outlineLibrary in _sdkOutline.libraries) { | 370 _fsState.skipSdkLibraries.add(outlineLibrary.importUri); |
| 370 _fsState.skipSdkLibraries.add(outlineLibrary.importUri); | 371 } |
| 371 } | 372 }); |
| 372 }); | |
| 373 } | |
| 374 } | 373 } |
| 375 } | 374 } |
| 376 | 375 |
| 377 /// Refresh all the invalidated files and update dependencies. | 376 /// Refresh all the invalidated files and update dependencies. |
| 378 Future<Null> _refreshInvalidatedFiles() async { | 377 Future<Null> _refreshInvalidatedFiles() async { |
| 379 await _logger.runAsync('Refresh invalidated files', () async { | 378 await _logger.runAsync('Refresh invalidated files', () async { |
| 380 // Create a copy to avoid concurrent modifications. | 379 // Create a copy to avoid concurrent modifications. |
| 381 var invalidatedFiles = _invalidatedFiles.toList(); | 380 var invalidatedFiles = _invalidatedFiles.toList(); |
| 382 _invalidatedFiles.clear(); | 381 _invalidatedFiles.clear(); |
| 383 | 382 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 | 419 |
| 421 LibraryCycleResult(this.cycle, this.signature, this.kernelLibraries); | 420 LibraryCycleResult(this.cycle, this.signature, this.kernelLibraries); |
| 422 } | 421 } |
| 423 | 422 |
| 424 @visibleForTesting | 423 @visibleForTesting |
| 425 class _TestView { | 424 class _TestView { |
| 426 /// The list of [LibraryCycle]s compiled for the last delta. | 425 /// The list of [LibraryCycle]s compiled for the last delta. |
| 427 /// It does not include libraries which were read from the cache. | 426 /// It does not include libraries which were read from the cache. |
| 428 final List<LibraryCycle> compiledCycles = []; | 427 final List<LibraryCycle> compiledCycles = []; |
| 429 } | 428 } |
| OLD | NEW |