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:front_end/src/incremental/limited_ast_to_binary.dart'; |
20 import 'package:kernel/binary/ast_from_binary.dart'; | 21 import 'package:kernel/binary/ast_from_binary.dart'; |
21 import 'package:kernel/binary/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 | 130 |
130 return new DeltaProgram(program); | 131 return new DeltaProgram(program); |
131 }); | 132 }); |
132 } | 133 } |
133 | 134 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 | 216 |
216 // Add newly compiled libraries into DILL. | 217 // Add newly compiled libraries into DILL. |
217 await appendNewDillLibraries(program); | 218 await appendNewDillLibraries(program); |
218 | 219 |
219 List<Library> kernelLibraries = program.libraries | 220 List<Library> kernelLibraries = program.libraries |
220 .where((library) => libraryUris.contains(library.importUri)) | 221 .where((library) => libraryUris.contains(library.importUri)) |
221 .toList(); | 222 .toList(); |
222 | 223 |
223 _logger.run('Serialize ${kernelLibraries.length} libraries', () { | 224 _logger.run('Serialize ${kernelLibraries.length} libraries', () { |
224 program.unbindCanonicalNames(); | 225 program.unbindCanonicalNames(); |
| 226 program.uriToSource.clear(); |
225 List<int> bytes = _writeProgramBytes(program, kernelLibraries.contains); | 227 List<int> bytes = _writeProgramBytes(program, kernelLibraries.contains); |
226 _byteStore.put(kernelKey, bytes); | 228 _byteStore.put(kernelKey, bytes); |
227 _logger.writeln('Stored ${bytes.length} bytes.'); | 229 _logger.writeln('Stored ${bytes.length} bytes.'); |
228 }); | 230 }); |
229 | 231 |
230 return new _LibraryCycleResult(cycle, signature, kernelLibraries); | 232 return new _LibraryCycleResult(cycle, signature, kernelLibraries); |
231 }); | 233 }); |
232 } | 234 } |
233 | 235 |
234 /// Compute exports scopes for a new strongly connected cycle of [libraries]. | 236 /// Compute exports scopes for a new strongly connected cycle of [libraries]. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 for (var fileUri in _invalidatedFiles) { | 276 for (var fileUri in _invalidatedFiles) { |
275 var file = await _fsState.getFile(fileUri); | 277 var file = await _fsState.getFile(fileUri); |
276 await file.refresh(); | 278 await file.refresh(); |
277 } | 279 } |
278 _invalidatedFiles.clear(); | 280 _invalidatedFiles.clear(); |
279 }); | 281 }); |
280 } | 282 } |
281 | 283 |
282 List<int> _writeProgramBytes(Program program, bool filter(Library library)) { | 284 List<int> _writeProgramBytes(Program program, bool filter(Library library)) { |
283 ByteSink byteSink = new ByteSink(); | 285 ByteSink byteSink = new ByteSink(); |
284 new LibraryFilteringBinaryPrinter(byteSink, filter) | 286 new LimitedBinaryPrinter(byteSink, filter).writeProgramFile(program); |
285 .writeProgramFile(program); | |
286 return byteSink.builder.takeBytes(); | 287 return byteSink.builder.takeBytes(); |
287 } | 288 } |
288 } | 289 } |
289 | 290 |
290 /// Compilation result for a library cycle. | 291 /// Compilation result for a library cycle. |
291 class _LibraryCycleResult { | 292 class _LibraryCycleResult { |
292 final LibraryCycle cycle; | 293 final LibraryCycle cycle; |
293 | 294 |
294 /// The signature of the result. | 295 /// The signature of the result. |
295 /// | 296 /// |
296 /// Currently it is based on the full content of the transitive closure of | 297 /// Currently it is based on the full content of the transitive closure of |
297 /// the [cycle] files and all its dependencies. | 298 /// the [cycle] files and all its dependencies. |
298 /// TODO(scheglov) Not used yet. | 299 /// TODO(scheglov) Not used yet. |
299 /// TODO(scheglov) Use API signatures. | 300 /// TODO(scheglov) Use API signatures. |
300 /// TODO(scheglov) Or use tree shaking and compute signatures of outlines. | 301 /// TODO(scheglov) Or use tree shaking and compute signatures of outlines. |
301 final String signature; | 302 final String signature; |
302 | 303 |
303 /// Kernel libraries for libraries in the [cycle]. Bodies of dependencies | 304 /// Kernel libraries for libraries in the [cycle]. Bodies of dependencies |
304 /// are not included, but but references to those dependencies are included. | 305 /// are not included, but but references to those dependencies are included. |
305 final List<Library> kernelLibraries; | 306 final List<Library> kernelLibraries; |
306 | 307 |
307 _LibraryCycleResult(this.cycle, this.signature, this.kernelLibraries); | 308 _LibraryCycleResult(this.cycle, this.signature, this.kernelLibraries); |
308 } | 309 } |
OLD | NEW |