| 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 /// A transformation to create a self-contained modular kernel without | 5 /// A transformation to create a self-contained modular kernel without |
| 6 /// unnecessary references to other libraries. | 6 /// unnecessary references to other libraries. |
| 7 library fasta.kernel.kernel_outline_shaker; | 7 library fasta.kernel.kernel_outline_shaker; |
| 8 | 8 |
| 9 import 'package:kernel/ast.dart'; | 9 import 'package:kernel/ast.dart'; |
| 10 import 'package:kernel/core_types.dart'; | 10 import 'package:kernel/core_types.dart'; |
| 11 | 11 |
| 12 import '../errors.dart' show internalError; | 12 import '../errors.dart' show internalError; |
| 13 | 13 |
| 14 /// Removes unnecessary libraries, classes, and members from [program]. | 14 /// Removes unnecessary libraries, classes, and members from [program]. |
| 15 /// | 15 /// |
| 16 /// This applies a simple "tree-shaking" technique: the full body of libraries | 16 /// This applies a simple "tree-shaking" technique: the full body of libraries |
| 17 /// whose URI match [isIncluded] is preserved, and so is the outline of the | 17 /// whose URI match [isIncluded] is preserved, and so is the outline of the |
| 18 /// members and classes which are indicated by [data] (which should | 18 /// members and classes which are transitively visible from the |
| 19 /// practically include all members and classes transitively visible from the | 19 /// included libraries. |
| 20 /// included libraries). | |
| 21 /// | 20 /// |
| 22 /// The intent is that the resulting program has the entire code that is meant | 21 /// The intent is that the resulting program has the entire code that is meant |
| 23 /// to be included and the minimum required to prevent dangling references and | 22 /// to be included and the minimum required to prevent dangling references and |
| 24 /// allow modular program transformations. | 23 /// allow modular program transformations. |
| 25 /// | 24 /// |
| 26 /// Note that the resulting program may include libraries not in [isIncluded], | 25 /// Note that the resulting program may include libraries not in [isIncluded], |
| 27 /// but those will be marked as external. There should be no method bodies for | 26 /// but those will be marked as external. There should be no method bodies for |
| 28 /// any members of those libraries. | 27 /// any members of those libraries. |
| 29 void trimProgram(Program program, RetainedData data, bool isIncluded(Uri uri)) { | 28 void trimProgram(Program program, bool isIncluded(Uri uri)) { |
| 29 var data = new RetainedDataBuilder(); |
| 30 new RootsMarker(new CoreTypes(program), data).run(program, isIncluded); |
| 30 new KernelOutlineShaker(data, isIncluded).transform(program); | 31 new KernelOutlineShaker(data, isIncluded).transform(program); |
| 31 } | 32 } |
| 32 | 33 |
| 33 /// Informs about which libraries, classes, and members should be retained by | 34 /// Informs about which libraries, classes, and members should be retained by |
| 34 /// the [KernelOutlineShaker] when tree-shaking. | 35 /// the [KernelOutlineShaker] when tree-shaking. |
| 35 abstract class RetainedData { | 36 abstract class RetainedData { |
| 36 /// Whether a library should be preserved and mark as external. | 37 /// Whether a library should be preserved and mark as external. |
| 37 bool isLibraryUsed(Library library); | 38 bool isLibraryUsed(Library library); |
| 38 | 39 |
| 39 /// Whether a class should be preserved. If a class is preserved, its | 40 /// Whether a class should be preserved. If a class is preserved, its |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 /// Types appear to be encoded directly, so we have no need to preserve | 396 /// Types appear to be encoded directly, so we have no need to preserve |
| 396 /// typedefs. | 397 /// typedefs. |
| 397 // TODO(sigmund): revisit if this is not the case, the `inputError` in | 398 // TODO(sigmund): revisit if this is not the case, the `inputError` in |
| 398 // [RootsMarker] is meant to detect this. | 399 // [RootsMarker] is meant to detect this. |
| 399 Typedef visitTypedef(Typedef node) => null; | 400 Typedef visitTypedef(Typedef node) => null; |
| 400 | 401 |
| 401 TreeNode defaultTreeNode(TreeNode node) => node; | 402 TreeNode defaultTreeNode(TreeNode node) => node; |
| 402 } | 403 } |
| 403 | 404 |
| 404 typedef bool Filter(Uri uri); | 405 typedef bool Filter(Uri uri); |
| OLD | NEW |