| 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:io'; |
| 6 | 7 |
| 7 import 'package:front_end/file_system.dart'; | 8 import 'package:front_end/file_system.dart'; |
| 8 import 'package:front_end/incremental_kernel_generator.dart'; | 9 import 'package:front_end/incremental_kernel_generator.dart'; |
| 9 import 'package:front_end/src/base/api_signature.dart'; | 10 import 'package:front_end/src/base/api_signature.dart'; |
| 10 import 'package:front_end/src/base/performace_logger.dart'; | 11 import 'package:front_end/src/base/performace_logger.dart'; |
| 11 import 'package:front_end/src/base/processed_options.dart'; | 12 import 'package:front_end/src/base/processed_options.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/ticker.dart'; | 16 import 'package:front_end/src/fasta/ticker.dart'; |
| 17 import 'package:front_end/src/fasta/translate_uri.dart'; | 17 import 'package:front_end/src/fasta/translate_uri.dart'; |
| 18 import 'package:front_end/src/incremental/byte_store.dart'; | 18 import 'package:front_end/src/incremental/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/binary/limited_ast_to_binary.dart'; |
| 21 import 'package:kernel/kernel.dart' hide Source; | 22 import 'package:kernel/kernel.dart' hide Source; |
| 22 import 'package:kernel/target/targets.dart' show TargetFlags; | 23 import 'package:kernel/target/targets.dart' show TargetFlags; |
| 23 import 'package:kernel/target/vm_fasta.dart' show VmFastaTarget; | 24 import 'package:kernel/target/vm_fasta.dart' show VmFastaTarget; |
| 24 import 'package:meta/meta.dart'; | 25 import 'package:meta/meta.dart'; |
| 25 | 26 |
| 27 class ByteSink implements Sink<List<int>> { |
| 28 final BytesBuilder builder = new BytesBuilder(); |
| 29 |
| 30 void add(List<int> data) { |
| 31 builder.add(data); |
| 32 } |
| 33 |
| 34 void close() {} |
| 35 } |
| 36 |
| 26 /// Implementation of [IncrementalKernelGenerator]. | 37 /// Implementation of [IncrementalKernelGenerator]. |
| 27 /// | 38 /// |
| 28 /// TODO(scheglov) Update the documentation. | 39 /// TODO(scheglov) Update the documentation. |
| 29 /// | 40 /// |
| 30 /// Theory of operation: an instance of [IncrementalResolvedAstGenerator] is | 41 /// Theory of operation: an instance of [IncrementalResolvedAstGenerator] is |
| 31 /// used to obtain resolved ASTs, and these are fed into kernel code generation | 42 /// used to obtain resolved ASTs, and these are fed into kernel code generation |
| 32 /// logic. | 43 /// logic. |
| 33 class IncrementalKernelGeneratorImpl implements IncrementalKernelGenerator { | 44 class IncrementalKernelGeneratorImpl implements IncrementalKernelGenerator { |
| 34 /// The version of data format, should be incremented on every format change. | 45 /// The version of data format, should be incremented on every format change. |
| 35 static const int DATA_VERSION = 1; | 46 static const int DATA_VERSION = 1; |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 | 261 |
| 251 // Add newly compiled libraries into DILL. | 262 // Add newly compiled libraries into DILL. |
| 252 await appendNewDillLibraries(program); | 263 await appendNewDillLibraries(program); |
| 253 | 264 |
| 254 List<Library> kernelLibraries = program.libraries | 265 List<Library> kernelLibraries = program.libraries |
| 255 .where((library) => libraryUris.contains(library.importUri)) | 266 .where((library) => libraryUris.contains(library.importUri)) |
| 256 .toList(); | 267 .toList(); |
| 257 | 268 |
| 258 _logger.run('Serialize ${kernelLibraries.length} libraries', () { | 269 _logger.run('Serialize ${kernelLibraries.length} libraries', () { |
| 259 program.uriToSource.clear(); | 270 program.uriToSource.clear(); |
| 260 List<int> bytes = | 271 List<int> bytes = _writeProgramBytes(program, kernelLibraries.contains); |
| 261 serializeProgram(program, filter: kernelLibraries.contains); | |
| 262 _byteStore.put(kernelKey, bytes); | 272 _byteStore.put(kernelKey, bytes); |
| 263 _logger.writeln('Stored ${bytes.length} bytes.'); | 273 _logger.writeln('Stored ${bytes.length} bytes.'); |
| 264 }); | 274 }); |
| 265 | 275 |
| 266 return new _LibraryCycleResult(cycle, signature, kernelLibraries); | 276 return new _LibraryCycleResult(cycle, signature, kernelLibraries); |
| 267 }); | 277 }); |
| 268 } | 278 } |
| 269 | 279 |
| 270 /// Compute exports scopes for a new strongly connected cycle of [libraries]. | 280 /// Compute exports scopes for a new strongly connected cycle of [libraries]. |
| 271 /// The [dillTarget] can be used to access libraries from previous cycles. | 281 /// The [dillTarget] can be used to access libraries from previous cycles. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 | 367 |
| 358 // The file graph might have changed, perform GC. | 368 // The file graph might have changed, perform GC. |
| 359 var removedFiles = _fsState.gc(_entryPoint); | 369 var removedFiles = _fsState.gc(_entryPoint); |
| 360 if (removedFiles.isNotEmpty && _watchFn != null) { | 370 if (removedFiles.isNotEmpty && _watchFn != null) { |
| 361 for (var removedFile in removedFiles) { | 371 for (var removedFile in removedFiles) { |
| 362 await _watchFn(removedFile.fileUri, false); | 372 await _watchFn(removedFile.fileUri, false); |
| 363 } | 373 } |
| 364 } | 374 } |
| 365 }); | 375 }); |
| 366 } | 376 } |
| 377 |
| 378 List<int> _writeProgramBytes(Program program, bool filter(Library library)) { |
| 379 ByteSink byteSink = new ByteSink(); |
| 380 new LimitedBinaryPrinter(byteSink, filter).writeProgramFile(program); |
| 381 return byteSink.builder.takeBytes(); |
| 382 } |
| 367 } | 383 } |
| 368 | 384 |
| 369 /// Compilation result for a library cycle. | 385 /// Compilation result for a library cycle. |
| 370 class _LibraryCycleResult { | 386 class _LibraryCycleResult { |
| 371 final LibraryCycle cycle; | 387 final LibraryCycle cycle; |
| 372 | 388 |
| 373 /// The signature of the result. | 389 /// The signature of the result. |
| 374 /// | 390 /// |
| 375 /// It is based on the full content of the libraries in the [cycle], and | 391 /// It is based on the full content of the libraries in the [cycle], and |
| 376 /// either API signatures of the transitive dependencies (usually), or | 392 /// either API signatures of the transitive dependencies (usually), or |
| 377 /// the full content of them (in the [cycle] has a library with a mixin | 393 /// the full content of them (in the [cycle] has a library with a mixin |
| 378 /// application). | 394 /// application). |
| 379 final String signature; | 395 final String signature; |
| 380 | 396 |
| 381 /// Kernel libraries for libraries in the [cycle]. Bodies of dependencies | 397 /// Kernel libraries for libraries in the [cycle]. Bodies of dependencies |
| 382 /// are not included, but but references to those dependencies are included. | 398 /// are not included, but but references to those dependencies are included. |
| 383 final List<Library> kernelLibraries; | 399 final List<Library> kernelLibraries; |
| 384 | 400 |
| 385 _LibraryCycleResult(this.cycle, this.signature, this.kernelLibraries); | 401 _LibraryCycleResult(this.cycle, this.signature, this.kernelLibraries); |
| 386 } | 402 } |
| 387 | 403 |
| 388 @visibleForTesting | 404 @visibleForTesting |
| 389 class _TestView { | 405 class _TestView { |
| 390 /// The list of [LibraryCycle]s compiled for the last delta. | 406 /// The list of [LibraryCycle]s compiled for the last delta. |
| 391 /// It does not include libraries which were read from the cache. | 407 /// It does not include libraries which were read from the cache. |
| 392 final List<LibraryCycle> compiledCycles = []; | 408 final List<LibraryCycle> compiledCycles = []; |
| 393 } | 409 } |
| OLD | NEW |