| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library fasta.kernel_target; | 5 library fasta.kernel_target; |
| 6 | 6 |
| 7 import 'dart:async' show Future; | 7 import 'dart:async' show Future; |
| 8 | 8 |
| 9 import 'dart:io' show File; | 9 import 'dart:io' show File; |
| 10 | 10 |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 } | 260 } |
| 261 | 261 |
| 262 /// Build the kernel representation of the program loaded by this target. The | 262 /// Build the kernel representation of the program loaded by this target. The |
| 263 /// program will contain full bodies for the code loaded from sources, and | 263 /// program will contain full bodies for the code loaded from sources, and |
| 264 /// only references to the code loaded by the [DillTarget], which may or may | 264 /// only references to the code loaded by the [DillTarget], which may or may |
| 265 /// not include method bodies (depending on what was loaded into that target, | 265 /// not include method bodies (depending on what was loaded into that target, |
| 266 /// an outline or a full kernel program). | 266 /// an outline or a full kernel program). |
| 267 /// | 267 /// |
| 268 /// When [trimDependencies] is true, this also runs a tree-shaker that deletes | 268 /// When [trimDependencies] is true, this also runs a tree-shaker that deletes |
| 269 /// anything from the [DillTarget] that is not needed for the source program, | 269 /// anything from the [DillTarget] that is not needed for the source program, |
| 270 /// this includes function bodies and types that are not reachable. | 270 /// this includes function bodies and types that are not reachable. This |
| 271 /// option is currently in flux and the internal implementation might change. |
| 272 /// See [trimDependenciesInProgram] for more details. |
| 271 /// | 273 /// |
| 272 /// If [verify], run the default kernel verification on the resulting program. | 274 /// If [verify], run the default kernel verification on the resulting program. |
| 273 @override | 275 @override |
| 274 Future<Program> buildProgram( | 276 Future<Program> buildProgram( |
| 275 {bool verify: false, bool trimDependencies: false}) async { | 277 {bool verify: false, bool trimDependencies: false}) async { |
| 276 if (loader.first == null) return null; | 278 if (loader.first == null) return null; |
| 277 if (errors.isNotEmpty) { | 279 if (errors.isNotEmpty) { |
| 278 handleInputError(null, | 280 handleInputError(null, |
| 279 isFullProgram: true, trimDependencies: trimDependencies); | 281 isFullProgram: true, trimDependencies: trimDependencies); |
| 280 if (trimDependencies) trimDependenciesInProgram(); | 282 if (trimDependencies) trimDependenciesInProgram(); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 library.build(loader.coreLibrary); | 370 library.build(loader.coreLibrary); |
| 369 return link(<Library>[library.library]); | 371 return link(<Library>[library.library]); |
| 370 } | 372 } |
| 371 | 373 |
| 372 /// Creates a program by combining [libraries] with the libraries of | 374 /// Creates a program by combining [libraries] with the libraries of |
| 373 /// `dillTarget.loader.program`. | 375 /// `dillTarget.loader.program`. |
| 374 Program link(List<Library> libraries, {CanonicalName nameRoot}) { | 376 Program link(List<Library> libraries, {CanonicalName nameRoot}) { |
| 375 Map<String, Source> uriToSource = | 377 Map<String, Source> uriToSource = |
| 376 new Map<String, Source>.from(this.uriToSource); | 378 new Map<String, Source>.from(this.uriToSource); |
| 377 | 379 |
| 378 List<Library> extraLibraries = dillTarget.loader.libraries; | 380 libraries.addAll(dillTarget.loader.libraries); |
| 379 libraries.addAll(extraLibraries); | |
| 380 // TODO(scheglov) Should we also somehow update `uriToSource`? | 381 // TODO(scheglov) Should we also somehow update `uriToSource`? |
| 381 // uriToSource.addAll(binary.uriToSource); | 382 // uriToSource.addAll(binary.uriToSource); |
| 382 | 383 |
| 383 // TODO(ahe): Remove this line. Kernel seems to generate a default line map | 384 // TODO(ahe): Remove this line. Kernel seems to generate a default line map |
| 384 // that used when there's no fileUri on an element. Instead, ensure all | 385 // that used when there's no fileUri on an element. Instead, ensure all |
| 385 // elements have a fileUri. | 386 // elements have a fileUri. |
| 386 uriToSource[""] = new Source(<int>[0], const <int>[]); | 387 uriToSource[""] = new Source(<int>[0], const <int>[]); |
| 387 Program program = new Program( | 388 Program program = new Program( |
| 388 nameRoot: nameRoot, libraries: libraries, uriToSource: uriToSource); | 389 nameRoot: nameRoot, libraries: libraries, uriToSource: uriToSource); |
| 389 if (loader.first != null) { | 390 if (loader.first != null) { |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 | 678 |
| 678 void verify() { | 679 void verify() { |
| 679 var verifyErrors = verifyProgram(_program); | 680 var verifyErrors = verifyProgram(_program); |
| 680 errors.addAll(verifyErrors.map((error) => '$error')); | 681 errors.addAll(verifyErrors.map((error) => '$error')); |
| 681 ticker.logMs("Verified program"); | 682 ticker.logMs("Verified program"); |
| 682 } | 683 } |
| 683 | 684 |
| 684 /// Tree-shakes most code from the [dillTarget] by visiting all other | 685 /// Tree-shakes most code from the [dillTarget] by visiting all other |
| 685 /// libraries in [_program] and marking the APIs from the [dillTarget] | 686 /// libraries in [_program] and marking the APIs from the [dillTarget] |
| 686 /// libraries that are in use. | 687 /// libraries that are in use. |
| 688 /// |
| 689 /// Note: while it's likely we'll do some trimming of programs for modular |
| 690 /// compilation, it is unclear at this time when and how that trimming should |
| 691 /// happen. We are likely going to remove the extra visitor my either marking |
| 692 /// things while code is built, or by handling tree-shaking after the fact |
| 693 /// (e.g. during serialization). |
| 687 trimDependenciesInProgram() { | 694 trimDependenciesInProgram() { |
| 688 var toShake = | 695 var toShake = |
| 689 dillTarget.loader.libraries.map((lib) => lib.importUri).toSet(); | 696 dillTarget.loader.libraries.map((lib) => lib.importUri).toSet(); |
| 690 var isIncluded = (Uri uri) => !toShake.contains(uri); | 697 var isIncluded = (Uri uri) => !toShake.contains(uri); |
| 691 var data = new RetainedDataBuilder(); | 698 var data = new RetainedDataBuilder(); |
| 692 // TODO(sigmund): replace this step with data that is directly computed from | 699 // TODO(sigmund): replace this step with data that is directly computed from |
| 693 // the builders: we should know the tree-shaking roots without having to do | 700 // the builders: we should know the tree-shaking roots without having to do |
| 694 // a second visit over the tree. | 701 // a second visit over the tree. |
| 695 new RootsMarker(data).run(_program, isIncluded); | 702 new RootsMarker(data).run(_program, isIncluded); |
| 696 trimProgram(_program, data, isIncluded); | 703 trimProgram(_program, data, isIncluded); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 713 } | 720 } |
| 714 for (Constructor constructor in superclass.constructors) { | 721 for (Constructor constructor in superclass.constructors) { |
| 715 if (constructor.name.name.isEmpty) { | 722 if (constructor.name.name.isEmpty) { |
| 716 return constructor.function.requiredParameterCount == 0 | 723 return constructor.function.requiredParameterCount == 0 |
| 717 ? constructor | 724 ? constructor |
| 718 : null; | 725 : null; |
| 719 } | 726 } |
| 720 } | 727 } |
| 721 return null; | 728 return null; |
| 722 } | 729 } |
| OLD | NEW |