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