| 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/compiler_options.dart'; |
| 7 import 'package:front_end/file_system.dart'; | 8 import 'package:front_end/file_system.dart'; |
| 8 import 'package:front_end/compiler_options.dart'; | |
| 9 import 'package:front_end/src/base/api_signature.dart'; | 9 import 'package:front_end/src/base/api_signature.dart'; |
| 10 import 'package:front_end/src/base/performace_logger.dart'; |
| 10 import 'package:front_end/src/base/processed_options.dart'; | 11 import 'package:front_end/src/base/processed_options.dart'; |
| 11 import 'package:front_end/src/base/performace_logger.dart'; | |
| 12 import 'package:front_end/src/fasta/compiler_context.dart'; | 12 import 'package:front_end/src/fasta/compiler_context.dart'; |
| 13 import 'package:front_end/src/fasta/dill/dill_library_builder.dart'; | 13 import 'package:front_end/src/fasta/dill/dill_library_builder.dart'; |
| 14 import 'package:front_end/src/fasta/dill/dill_target.dart'; | 14 import 'package:front_end/src/fasta/dill/dill_target.dart'; |
| 15 import 'package:front_end/src/fasta/kernel/kernel_target.dart'; | 15 import 'package:front_end/src/fasta/kernel/kernel_target.dart'; |
| 16 import 'package:front_end/src/fasta/kernel/utils.dart'; | 16 import 'package:front_end/src/fasta/kernel/utils.dart'; |
| 17 import 'package:front_end/src/fasta/ticker.dart'; | 17 import 'package:front_end/src/fasta/ticker.dart'; |
| 18 import 'package:front_end/src/fasta/uri_translator.dart'; | 18 import 'package:front_end/src/fasta/uri_translator.dart'; |
| 19 import 'package:front_end/src/incremental/byte_store.dart'; | 19 import 'package:front_end/src/incremental/byte_store.dart'; |
| 20 import 'package:front_end/src/incremental/file_state.dart'; | 20 import 'package:front_end/src/incremental/file_state.dart'; |
| 21 import 'package:kernel/binary/ast_from_binary.dart'; | 21 import 'package:kernel/binary/ast_from_binary.dart'; |
| 22 import 'package:kernel/core_types.dart'; |
| 22 import 'package:kernel/kernel.dart' hide Source; | 23 import 'package:kernel/kernel.dart' hide Source; |
| 24 import 'package:kernel/src/incremental_class_hierarchy.dart'; |
| 23 import 'package:kernel/target/targets.dart' show Target; | 25 import 'package:kernel/target/targets.dart' show Target; |
| 26 import 'package:kernel/type_environment.dart'; |
| 24 import 'package:meta/meta.dart'; | 27 import 'package:meta/meta.dart'; |
| 25 | 28 |
| 26 /// This function is invoked for each newly discovered file, and the returned | 29 /// This function is invoked for each newly discovered file, and the returned |
| 27 /// [Future] is awaited before reading the file content. | 30 /// [Future] is awaited before reading the file content. |
| 28 typedef Future<Null> KernelDriverFileAddedFn(Uri uri); | 31 typedef Future<Null> KernelDriverFileAddedFn(Uri uri); |
| 29 | 32 |
| 30 /// This class computes [KernelResult]s for Dart files. | 33 /// This class computes [KernelResult]s for Dart files. |
| 31 /// | 34 /// |
| 32 /// Let the "current file state" represent a map from file URI to the file | 35 /// Let the "current file state" represent a map from file URI to the file |
| 33 /// contents most recently read from that file. When the driver needs to | 36 /// contents most recently read from that file. When the driver needs to |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 List<LibraryCycleResult> results = []; | 141 List<LibraryCycleResult> results = []; |
| 139 _testView.compiledCycles.clear(); | 142 _testView.compiledCycles.clear(); |
| 140 await _logger.runAsync('Compute results for cycles', () async { | 143 await _logger.runAsync('Compute results for cycles', () async { |
| 141 for (LibraryCycle cycle in cycles) { | 144 for (LibraryCycle cycle in cycles) { |
| 142 LibraryCycleResult result = | 145 LibraryCycleResult result = |
| 143 await _compileCycle(nameRoot, dillTarget, cycle); | 146 await _compileCycle(nameRoot, dillTarget, cycle); |
| 144 results.add(result); | 147 results.add(result); |
| 145 } | 148 } |
| 146 }); | 149 }); |
| 147 | 150 |
| 148 return new KernelResult(nameRoot, results); | 151 TypeEnvironment types = _buildTypeEnvironment(nameRoot, results); |
| 152 |
| 153 return new KernelResult(nameRoot, types, results); |
| 149 }); | 154 }); |
| 150 } | 155 } |
| 151 | 156 |
| 152 Future<T> runWithFrontEndContext<T>(String msg, Future<T> f()) async { | |
| 153 var options = new CompilerOptions() | |
| 154 ..target = _target | |
| 155 // Note: we do not report error on the console because the driver is an | |
| 156 // ongoing background service that shouldn't polute stdout. | |
| 157 // TODO(scheglov,sigmund): add an error handler to forward errors to | |
| 158 // analyzer driver and incremental kernel generator. | |
| 159 ..reportMessages = false; | |
| 160 return await CompilerContext.runWithOptions( | |
| 161 new ProcessedOptions(options), (_) => _logger.runAsync(msg, f)); | |
| 162 } | |
| 163 | |
| 164 /// The file with the given [uri] might have changed - updated, added, or | 157 /// The file with the given [uri] might have changed - updated, added, or |
| 165 /// removed. Or not, we don't know. Or it might have, but then changed back. | 158 /// removed. Or not, we don't know. Or it might have, but then changed back. |
| 166 /// | 159 /// |
| 167 /// The [uri] must be absolute and normalized file URI. | 160 /// The [uri] must be absolute and normalized file URI. |
| 168 /// | 161 /// |
| 169 /// Schedules the file contents for the [uri] to be read into the current | 162 /// Schedules the file contents for the [uri] to be read into the current |
| 170 /// file state prior the next invocation of [getKernel] returns the result. | 163 /// file state prior the next invocation of [getKernel] returns the result. |
| 171 /// | 164 /// |
| 172 /// Invocation of this method will not prevent a [Future] returned from | 165 /// Invocation of this method will not prevent a [Future] returned from |
| 173 /// [getKernel] from completing with a result, but the result is not | 166 /// [getKernel] from completing with a result, but the result is not |
| 174 /// guaranteed to be consistent with the new current file state after this | 167 /// guaranteed to be consistent with the new current file state after this |
| 175 /// [invalidate] invocation. | 168 /// [invalidate] invocation. |
| 176 void invalidate(Uri uri) { | 169 void invalidate(Uri uri) { |
| 177 _invalidatedFiles.add(uri); | 170 _invalidatedFiles.add(uri); |
| 178 } | 171 } |
| 179 | 172 |
| 173 Future<T> runWithFrontEndContext<T>(String msg, Future<T> f()) async { |
| 174 var options = new CompilerOptions() |
| 175 ..target = _target |
| 176 // Note: we do not report error on the console because the driver is an |
| 177 // ongoing background service that shouldn't polute stdout. |
| 178 // TODO(scheglov,sigmund): add an error handler to forward errors to |
| 179 // analyzer driver and incremental kernel generator. |
| 180 ..reportMessages = false; |
| 181 return await CompilerContext.runWithOptions( |
| 182 new ProcessedOptions(options), (_) => _logger.runAsync(msg, f)); |
| 183 } |
| 184 |
| 185 /// Return the [TypeEnvironment] that corresponds to the [results]. |
| 186 /// All the libraries for [CoreTypes] are expected to be in the first result. |
| 187 TypeEnvironment _buildTypeEnvironment( |
| 188 CanonicalName nameRoot, List<LibraryCycleResult> results) { |
| 189 var coreLibraries = results.first.kernelLibraries; |
| 190 var program = new Program(nameRoot: nameRoot, libraries: coreLibraries); |
| 191 return new TypeEnvironment( |
| 192 new CoreTypes(program), new IncrementalClassHierarchy()); |
| 193 } |
| 194 |
| 180 /// Ensure that [dillTarget] includes the [cycle] libraries. It already | 195 /// Ensure that [dillTarget] includes the [cycle] libraries. It already |
| 181 /// contains all the libraries that sorted before the given [cycle] in | 196 /// contains all the libraries that sorted before the given [cycle] in |
| 182 /// topological order. Return the result with the cycle libraries. | 197 /// topological order. Return the result with the cycle libraries. |
| 183 Future<LibraryCycleResult> _compileCycle( | 198 Future<LibraryCycleResult> _compileCycle( |
| 184 CanonicalName nameRoot, DillTarget dillTarget, LibraryCycle cycle) async { | 199 CanonicalName nameRoot, DillTarget dillTarget, LibraryCycle cycle) async { |
| 185 return _logger.runAsync('Compile cycle $cycle', () async { | 200 return _logger.runAsync('Compile cycle $cycle', () async { |
| 186 String signature = _getCycleSignature(cycle); | 201 String signature = _getCycleSignature(cycle); |
| 187 | 202 |
| 188 _logger.writeln('Signature: $signature.'); | 203 _logger.writeln('Signature: $signature.'); |
| 189 var kernelKey = '$signature.kernel'; | 204 var kernelKey = '$signature.kernel'; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 await file.refresh(); | 357 await file.refresh(); |
| 343 } | 358 } |
| 344 } | 359 } |
| 345 }); | 360 }); |
| 346 } | 361 } |
| 347 } | 362 } |
| 348 | 363 |
| 349 /// The result of compiling of a single file. | 364 /// The result of compiling of a single file. |
| 350 class KernelResult { | 365 class KernelResult { |
| 351 final CanonicalName nameRoot; | 366 final CanonicalName nameRoot; |
| 367 final TypeEnvironment types; |
| 352 final List<LibraryCycleResult> results; | 368 final List<LibraryCycleResult> results; |
| 353 | 369 |
| 354 KernelResult(this.nameRoot, this.results); | 370 KernelResult(this.nameRoot, this.types, this.results); |
| 355 } | 371 } |
| 356 | 372 |
| 357 /// Compilation result for a library cycle. | 373 /// Compilation result for a library cycle. |
| 358 class LibraryCycleResult { | 374 class LibraryCycleResult { |
| 359 final LibraryCycle cycle; | 375 final LibraryCycle cycle; |
| 360 | 376 |
| 361 /// The signature of the result. | 377 /// The signature of the result. |
| 362 /// | 378 /// |
| 363 /// It is based on the full content of the libraries in the [cycle], and | 379 /// It is based on the full content of the libraries in the [cycle], and |
| 364 /// either API signatures of the transitive dependencies (usually), or | 380 /// either API signatures of the transitive dependencies (usually), or |
| 365 /// the full content of them (in the [cycle] has a library with a mixin | 381 /// the full content of them (in the [cycle] has a library with a mixin |
| 366 /// application). | 382 /// application). |
| 367 final String signature; | 383 final String signature; |
| 368 | 384 |
| 369 /// Kernel libraries for libraries in the [cycle]. Bodies of dependencies | 385 /// Kernel libraries for libraries in the [cycle]. Bodies of dependencies |
| 370 /// are not included, but but references to those dependencies are included. | 386 /// are not included, but but references to those dependencies are included. |
| 371 final List<Library> kernelLibraries; | 387 final List<Library> kernelLibraries; |
| 372 | 388 |
| 373 LibraryCycleResult(this.cycle, this.signature, this.kernelLibraries); | 389 LibraryCycleResult(this.cycle, this.signature, this.kernelLibraries); |
| 374 } | 390 } |
| 375 | 391 |
| 376 @visibleForTesting | 392 @visibleForTesting |
| 377 class _TestView { | 393 class _TestView { |
| 378 /// The list of [LibraryCycle]s compiled for the last delta. | 394 /// The list of [LibraryCycle]s compiled for the last delta. |
| 379 /// It does not include libraries which were read from the cache. | 395 /// It does not include libraries which were read from the cache. |
| 380 final List<LibraryCycle> compiledCycles = []; | 396 final List<LibraryCycle> compiledCycles = []; |
| 381 } | 397 } |
| OLD | NEW |