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 | 6 |
7 import 'package:front_end/file_system.dart'; | 7 import 'package:front_end/file_system.dart'; |
8 import 'package:front_end/src/base/api_signature.dart'; | 8 import 'package:front_end/src/base/api_signature.dart'; |
9 import 'package:front_end/src/base/performace_logger.dart'; | 9 import 'package:front_end/src/base/performace_logger.dart'; |
10 import 'package:front_end/src/base/processed_options.dart'; | 10 import 'package:front_end/src/base/processed_options.dart'; |
11 import 'package:front_end/src/byte_store/byte_store.dart'; | 11 import 'package:front_end/src/byte_store/byte_store.dart'; |
12 import 'package:front_end/src/fasta/compiler_context.dart'; | 12 import 'package:front_end/src/fasta/compiler_context.dart'; |
13 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'; |
16 import 'package:front_end/src/fasta/kernel/utils.dart'; | 15 import 'package:front_end/src/fasta/kernel/utils.dart'; |
17 import 'package:front_end/src/fasta/ticker.dart'; | 16 import 'package:front_end/src/fasta/ticker.dart'; |
18 import 'package:front_end/src/fasta/uri_translator.dart'; | 17 import 'package:front_end/src/fasta/uri_translator.dart'; |
19 import 'package:front_end/src/incremental/file_state.dart'; | 18 import 'package:front_end/src/incremental/file_state.dart'; |
20 import 'package:kernel/binary/ast_from_binary.dart'; | 19 import 'package:kernel/binary/ast_from_binary.dart'; |
21 import 'package:kernel/core_types.dart'; | 20 import 'package:kernel/core_types.dart'; |
22 import 'package:kernel/kernel.dart' hide Source; | 21 import 'package:kernel/kernel.dart' hide Source; |
23 import 'package:kernel/src/incremental_class_hierarchy.dart'; | 22 import 'package:kernel/src/incremental_class_hierarchy.dart'; |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 // We need kernel libraries for these URIs. | 218 // We need kernel libraries for these URIs. |
220 var libraryUris = new Set<Uri>(); | 219 var libraryUris = new Set<Uri>(); |
221 var libraryUriToFile = <Uri, FileState>{}; | 220 var libraryUriToFile = <Uri, FileState>{}; |
222 for (FileState library in cycle.libraries) { | 221 for (FileState library in cycle.libraries) { |
223 Uri uri = library.uri; | 222 Uri uri = library.uri; |
224 libraryUris.add(uri); | 223 libraryUris.add(uri); |
225 libraryUriToFile[uri] = library; | 224 libraryUriToFile[uri] = library; |
226 } | 225 } |
227 | 226 |
228 Future<Null> appendNewDillLibraries(Program program) async { | 227 Future<Null> appendNewDillLibraries(Program program) async { |
229 List<DillLibraryBuilder> libraryBuilders = dillTarget.loader | 228 dillTarget.loader.appendLibraries(program, libraryUris.contains); |
230 .appendLibraries(program, (uri) => libraryUris.contains(uri)); | |
231 | |
232 // Compute local scopes. | |
233 await dillTarget.buildOutlines(); | 229 await dillTarget.buildOutlines(); |
234 | |
235 // Compute export scopes. | |
236 _computeExportScopes(dillTarget, libraryUriToFile, libraryBuilders); | |
237 } | 230 } |
238 | 231 |
239 // Check if there is already a bundle with these libraries. | 232 // Check if there is already a bundle with these libraries. |
240 List<int> bytes = _byteStore.get(kernelKey); | 233 List<int> bytes = _byteStore.get(kernelKey); |
241 if (bytes != null) { | 234 if (bytes != null) { |
242 return _logger.runAsync('Read serialized libraries', () async { | 235 return _logger.runAsync('Read serialized libraries', () async { |
243 var program = new Program(nameRoot: nameRoot); | 236 var program = new Program(nameRoot: nameRoot); |
244 var reader = new BinaryBuilder(bytes); | 237 var reader = new BinaryBuilder(bytes); |
245 reader.readProgram(program); | 238 reader.readProgram(program); |
246 | 239 |
(...skipping 30 matching lines...) Expand all Loading... |
277 List<int> bytes = | 270 List<int> bytes = |
278 serializeProgram(program, filter: kernelLibraries.contains); | 271 serializeProgram(program, filter: kernelLibraries.contains); |
279 _byteStore.put(kernelKey, bytes); | 272 _byteStore.put(kernelKey, bytes); |
280 _logger.writeln('Stored ${bytes.length} bytes.'); | 273 _logger.writeln('Stored ${bytes.length} bytes.'); |
281 }); | 274 }); |
282 | 275 |
283 return new LibraryCycleResult(cycle, signature, kernelLibraries); | 276 return new LibraryCycleResult(cycle, signature, kernelLibraries); |
284 }); | 277 }); |
285 } | 278 } |
286 | 279 |
287 /// Compute exports scopes for a new strongly connected cycle of [libraries]. | |
288 /// The [dillTarget] can be used to access libraries from previous cycles. | |
289 /// TODO(scheglov) Remove/replace this when Kernel has export scopes. | |
290 void _computeExportScopes(DillTarget dillTarget, | |
291 Map<Uri, FileState> uriToFile, List<DillLibraryBuilder> libraries) { | |
292 bool wasChanged = false; | |
293 do { | |
294 wasChanged = false; | |
295 for (DillLibraryBuilder library in libraries) { | |
296 FileState file = uriToFile[library.uri]; | |
297 for (NamespaceExport export in file.exports) { | |
298 DillLibraryBuilder exportedLibrary = | |
299 dillTarget.loader.read(export.library.uri, -1, accessor: library); | |
300 if (exportedLibrary != null) { | |
301 exportedLibrary.exportScope.forEach((name, member) { | |
302 if (export.isExposed(name) && | |
303 library.addToExportScope(name, member)) { | |
304 wasChanged = true; | |
305 } | |
306 }); | |
307 } else { | |
308 // TODO(scheglov) How to handle this? | |
309 } | |
310 } | |
311 } | |
312 } while (wasChanged); | |
313 } | |
314 | |
315 /// Compute salt and put into [_salt]. | 280 /// Compute salt and put into [_salt]. |
316 void _computeSalt() { | 281 void _computeSalt() { |
317 var saltBuilder = new ApiSignature(); | 282 var saltBuilder = new ApiSignature(); |
318 saltBuilder.addInt(DATA_VERSION); | 283 saltBuilder.addInt(DATA_VERSION); |
319 saltBuilder.addBool(_options.strongMode); | 284 saltBuilder.addBool(_options.strongMode); |
320 if (_sdkOutlineBytes != null) { | 285 if (_sdkOutlineBytes != null) { |
321 saltBuilder.addBytes(_sdkOutlineBytes); | 286 saltBuilder.addBytes(_sdkOutlineBytes); |
322 } | 287 } |
323 _salt = saltBuilder.toByteList(); | 288 _salt = saltBuilder.toByteList(); |
324 } | 289 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 | 384 |
420 LibraryCycleResult(this.cycle, this.signature, this.kernelLibraries); | 385 LibraryCycleResult(this.cycle, this.signature, this.kernelLibraries); |
421 } | 386 } |
422 | 387 |
423 @visibleForTesting | 388 @visibleForTesting |
424 class _TestView { | 389 class _TestView { |
425 /// The list of [LibraryCycle]s compiled for the last delta. | 390 /// The list of [LibraryCycle]s compiled for the last delta. |
426 /// It does not include libraries which were read from the cache. | 391 /// It does not include libraries which were read from the cache. |
427 final List<LibraryCycle> compiledCycles = []; | 392 final List<LibraryCycle> compiledCycles = []; |
428 } | 393 } |
OLD | NEW |