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 import 'dart:io'; |
7 | 7 |
8 import 'package:front_end/file_system.dart'; | 8 import 'package:front_end/file_system.dart'; |
9 import 'package:front_end/incremental_kernel_generator.dart'; | 9 import 'package:front_end/incremental_kernel_generator.dart'; |
10 import 'package:front_end/src/base/api_signature.dart'; | 10 import 'package:front_end/src/base/api_signature.dart'; |
11 import 'package:front_end/src/base/performace_logger.dart'; | 11 import 'package:front_end/src/base/performace_logger.dart'; |
12 import 'package:front_end/src/base/processed_options.dart'; | 12 import 'package:front_end/src/base/processed_options.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/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/ast_to_binary.dart'; | 21 import 'package:kernel/binary/limited_ast_to_binary.dart'; |
22 import 'package:kernel/kernel.dart' hide Source; | 22 import 'package:kernel/kernel.dart' hide Source; |
23 | 23 |
24 dynamic unimplemented() { | 24 dynamic unimplemented() { |
25 // TODO(paulberry): get rid of this. | 25 // TODO(paulberry): get rid of this. |
26 throw new UnimplementedError(); | 26 throw new UnimplementedError(); |
27 } | 27 } |
28 | 28 |
29 class ByteSink implements Sink<List<int>> { | 29 class ByteSink implements Sink<List<int>> { |
30 final BytesBuilder builder = new BytesBuilder(); | 30 final BytesBuilder builder = new BytesBuilder(); |
31 | 31 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 114 |
115 Program program = new Program(nameRoot: nameRoot); | 115 Program program = new Program(nameRoot: nameRoot); |
116 | 116 |
117 // Add affected libraries (with different signatures). | 117 // Add affected libraries (with different signatures). |
118 for (_LibraryCycleResult result in results) { | 118 for (_LibraryCycleResult result in results) { |
119 for (Library library in result.kernelLibraries) { | 119 for (Library library in result.kernelLibraries) { |
120 Uri uri = library.importUri; | 120 Uri uri = library.importUri; |
121 if (_latestSignature[uri] != result.signature) { | 121 if (_latestSignature[uri] != result.signature) { |
122 _latestSignature[uri] = result.signature; | 122 _latestSignature[uri] = result.signature; |
123 program.libraries.add(library); | 123 program.libraries.add(library); |
| 124 library.parent = program; |
124 } | 125 } |
125 } | 126 } |
126 } | 127 } |
127 | 128 |
128 // TODO(scheglov) Add libraries which import changed libraries. | 129 // TODO(scheglov) Add libraries which import changed libraries. |
129 // For now the corresponding test works because we use full library | 130 // For now the corresponding test works because we use full library |
130 // contents to compute signatures (not just API parts). So, every library | 131 // contents to compute signatures (not just API parts). So, every library |
131 // that imports a changed one, is affected. | 132 // that imports a changed one, is affected. |
132 | 133 |
133 return new DeltaProgram(program); | 134 return new DeltaProgram(program); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 | 219 |
219 // Add newly compiled libraries into DILL. | 220 // Add newly compiled libraries into DILL. |
220 await appendNewDillLibraries(program); | 221 await appendNewDillLibraries(program); |
221 | 222 |
222 List<Library> kernelLibraries = program.libraries | 223 List<Library> kernelLibraries = program.libraries |
223 .where((library) => libraryUris.contains(library.importUri)) | 224 .where((library) => libraryUris.contains(library.importUri)) |
224 .toList(); | 225 .toList(); |
225 | 226 |
226 _logger.run('Serialize ${kernelLibraries.length} libraries', () { | 227 _logger.run('Serialize ${kernelLibraries.length} libraries', () { |
227 program.unbindCanonicalNames(); | 228 program.unbindCanonicalNames(); |
| 229 program.uriToSource.clear(); |
228 List<int> bytes = _writeProgramBytes(program, kernelLibraries.contains); | 230 List<int> bytes = _writeProgramBytes(program, kernelLibraries.contains); |
229 _byteStore.put(kernelKey, bytes); | 231 _byteStore.put(kernelKey, bytes); |
230 _logger.writeln('Stored ${bytes.length} bytes.'); | 232 _logger.writeln('Stored ${bytes.length} bytes.'); |
231 }); | 233 }); |
232 | 234 |
233 return new _LibraryCycleResult(cycle, signature, kernelLibraries); | 235 return new _LibraryCycleResult(cycle, signature, kernelLibraries); |
234 }); | 236 }); |
235 } | 237 } |
236 | 238 |
237 /// Compute exports scopes for a new strongly connected cycle of [libraries]. | 239 /// Compute exports scopes for a new strongly connected cycle of [libraries]. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 for (var fileUri in _invalidatedFiles) { | 279 for (var fileUri in _invalidatedFiles) { |
278 var file = await _fsState.getFile(fileUri); | 280 var file = await _fsState.getFile(fileUri); |
279 await file.refresh(); | 281 await file.refresh(); |
280 } | 282 } |
281 _invalidatedFiles.clear(); | 283 _invalidatedFiles.clear(); |
282 }); | 284 }); |
283 } | 285 } |
284 | 286 |
285 List<int> _writeProgramBytes(Program program, bool filter(Library library)) { | 287 List<int> _writeProgramBytes(Program program, bool filter(Library library)) { |
286 ByteSink byteSink = new ByteSink(); | 288 ByteSink byteSink = new ByteSink(); |
287 new LibraryFilteringBinaryPrinter(byteSink, filter) | 289 new LimitedBinaryPrinter(byteSink, filter).writeProgramFile(program); |
288 .writeProgramFile(program); | |
289 return byteSink.builder.takeBytes(); | 290 return byteSink.builder.takeBytes(); |
290 } | 291 } |
291 } | 292 } |
292 | 293 |
293 /// Compilation result for a library cycle. | 294 /// Compilation result for a library cycle. |
294 class _LibraryCycleResult { | 295 class _LibraryCycleResult { |
295 final LibraryCycle cycle; | 296 final LibraryCycle cycle; |
296 | 297 |
297 /// The signature of the result. | 298 /// The signature of the result. |
298 /// | 299 /// |
299 /// Currently it is based on the full content of the transitive closure of | 300 /// Currently it is based on the full content of the transitive closure of |
300 /// the [cycle] files and all its dependencies. | 301 /// the [cycle] files and all its dependencies. |
301 /// TODO(scheglov) Not used yet. | 302 /// TODO(scheglov) Not used yet. |
302 /// TODO(scheglov) Use API signatures. | 303 /// TODO(scheglov) Use API signatures. |
303 /// TODO(scheglov) Or use tree shaking and compute signatures of outlines. | 304 /// TODO(scheglov) Or use tree shaking and compute signatures of outlines. |
304 final String signature; | 305 final String signature; |
305 | 306 |
306 /// Kernel libraries for libraries in the [cycle]. Bodies of dependencies | 307 /// Kernel libraries for libraries in the [cycle]. Bodies of dependencies |
307 /// are not included, but but references to those dependencies are included. | 308 /// are not included, but but references to those dependencies are included. |
308 final List<Library> kernelLibraries; | 309 final List<Library> kernelLibraries; |
309 | 310 |
310 _LibraryCycleResult(this.cycle, this.signature, this.kernelLibraries); | 311 _LibraryCycleResult(this.cycle, this.signature, this.kernelLibraries); |
311 } | 312 } |
OLD | NEW |