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