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 transitively visible from the | 18 /// members and classes which are indicated by [data] (which should |
19 /// included libraries. | 19 /// practically include all members and classes transitively visible from the |
| 20 /// included libraries). |
20 /// | 21 /// |
21 /// The intent is that the resulting program has the entire code that is meant | 22 /// The intent is that the resulting program has the entire code that is meant |
22 /// to be included and the minimum required to prevent dangling references and | 23 /// to be included and the minimum required to prevent dangling references and |
23 /// allow modular program transformations. | 24 /// allow modular program transformations. |
24 /// | 25 /// |
25 /// Note that the resulting program may include libraries not in [isIncluded], | 26 /// Note that the resulting program may include libraries not in [isIncluded], |
26 /// but those will be marked as external. There should be no method bodies for | 27 /// but those will be marked as external. There should be no method bodies for |
27 /// any members of those libraries. | 28 /// any members of those libraries. |
28 void trimProgram(Program program, bool isIncluded(Uri uri)) { | 29 void trimProgram(Program program, RetainedData data, bool isIncluded(Uri uri)) { |
29 var data = new RetainedDataBuilder(); | |
30 new RootsMarker(new CoreTypes(program), data).run(program, isIncluded); | |
31 new KernelOutlineShaker(data, isIncluded).transform(program); | 30 new KernelOutlineShaker(data, isIncluded).transform(program); |
32 } | 31 } |
33 | 32 |
34 /// Informs about which libraries, classes, and members should be retained by | 33 /// Informs about which libraries, classes, and members should be retained by |
35 /// the [KernelOutlineShaker] when tree-shaking. | 34 /// the [KernelOutlineShaker] when tree-shaking. |
36 abstract class RetainedData { | 35 abstract class RetainedData { |
37 /// Whether a library should be preserved and mark as external. | 36 /// Whether a library should be preserved and mark as external. |
38 bool isLibraryUsed(Library library); | 37 bool isLibraryUsed(Library library); |
39 | 38 |
40 /// Whether a class should be preserved. If a class is preserved, its | 39 /// 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... |
396 /// Types appear to be encoded directly, so we have no need to preserve | 395 /// Types appear to be encoded directly, so we have no need to preserve |
397 /// typedefs. | 396 /// typedefs. |
398 // TODO(sigmund): revisit if this is not the case, the `inputError` in | 397 // TODO(sigmund): revisit if this is not the case, the `inputError` in |
399 // [RootsMarker] is meant to detect this. | 398 // [RootsMarker] is meant to detect this. |
400 Typedef visitTypedef(Typedef node) => null; | 399 Typedef visitTypedef(Typedef node) => null; |
401 | 400 |
402 TreeNode defaultTreeNode(TreeNode node) => node; | 401 TreeNode defaultTreeNode(TreeNode node) => node; |
403 } | 402 } |
404 | 403 |
405 typedef bool Filter(Uri uri); | 404 typedef bool Filter(Uri uri); |
OLD | NEW |