Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: pkg/kernel/lib/transformations/treeshaker.dart

Issue 2904203002: Extract ClassHierarchyImpl implementation from ClassHierarchy. (Closed)
Patch Set: Rename ClassHierarchyImpl to ClosedWorldClassHierarchy. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/kernel/lib/class_hierarchy.dart ('k') | pkg/kernel/test/class_hierarchy_bench.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 kernel.tree_shaker; 5 library kernel.tree_shaker;
6 6
7 import '../ast.dart'; 7 import '../ast.dart';
8 import '../class_hierarchy.dart'; 8 import '../class_hierarchy.dart';
9 import '../core_types.dart'; 9 import '../core_types.dart';
10 import '../type_environment.dart'; 10 import '../type_environment.dart';
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 /// The tree shaker computes the following in a fixed-point iteration: 82 /// The tree shaker computes the following in a fixed-point iteration:
83 /// - a set of instantiated classes 83 /// - a set of instantiated classes
84 /// - for each member, a set of potential host classes 84 /// - for each member, a set of potential host classes
85 /// - a set of names used in dynamic dispatch not on `this` 85 /// - a set of names used in dynamic dispatch not on `this`
86 /// 86 ///
87 /// If the `dart:mirrors` library is used then nothing will be tree-shaken. 87 /// If the `dart:mirrors` library is used then nothing will be tree-shaken.
88 // 88 //
89 // TODO(asgerf): Tree shake unused instance fields. 89 // TODO(asgerf): Tree shake unused instance fields.
90 class TreeShaker { 90 class TreeShaker {
91 final Program program; 91 final Program program;
92 final ClassHierarchy hierarchy; 92 final ClosedWorldClassHierarchy hierarchy;
93 final CoreTypes coreTypes; 93 final CoreTypes coreTypes;
94 final bool strongMode; 94 final bool strongMode;
95 final List<ProgramRoot> programRoots; 95 final List<ProgramRoot> programRoots;
96 96
97 /// Map from classes to set of names that have been dispatched with that class 97 /// Map from classes to set of names that have been dispatched with that class
98 /// as the static receiver type (meaning any subtype of that class can be 98 /// as the static receiver type (meaning any subtype of that class can be
99 /// the potential concrete receiver). 99 /// the potential concrete receiver).
100 /// 100 ///
101 /// The map is implemented as a list, indexed by 101 /// The map is implemented as a list, indexed by
102 /// [ClassHierarchy.getClassIndex]. 102 /// [ClassHierarchy.getClassIndex].
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 } 201 }
202 202
203 /// Applies the tree shaking results to the program. 203 /// Applies the tree shaking results to the program.
204 /// 204 ///
205 /// This removes unused classes, members, and hierarchy data. 205 /// This removes unused classes, members, and hierarchy data.
206 void transform(Program program) { 206 void transform(Program program) {
207 if (isUsingMirrors) return; // Give up if using mirrors. 207 if (isUsingMirrors) return; // Give up if using mirrors.
208 new _TreeShakingTransformer(this).transform(program); 208 new _TreeShakingTransformer(this).transform(program);
209 } 209 }
210 210
211 TreeShaker._internal(this.program, ClassHierarchy hierarchy, this.coreTypes, 211 TreeShaker._internal(this.program, ClosedWorldClassHierarchy hierarchy,
212 this.strongMode, this.programRoots) 212 this.coreTypes, this.strongMode, this.programRoots)
213 : this.hierarchy = hierarchy, 213 : this.hierarchy = hierarchy,
214 this._dispatchedNames = new List<Set<Name>>(hierarchy.classes.length), 214 this._dispatchedNames = new List<Set<Name>>(hierarchy.classes.length),
215 this._usedMembersWithHost = 215 this._usedMembersWithHost =
216 new List<Set<Member>>(hierarchy.classes.length), 216 new List<Set<Member>>(hierarchy.classes.length),
217 this._classRetention = new List<ClassRetention>.filled( 217 this._classRetention = new List<ClassRetention>.filled(
218 hierarchy.classes.length, ClassRetention.None) { 218 hierarchy.classes.length, ClassRetention.None) {
219 _visitor = new _TreeShakerVisitor(this); 219 _visitor = new _TreeShakerVisitor(this);
220 _covariantVisitor = new _ExternalTypeVisitor(this, isCovariant: true); 220 _covariantVisitor = new _ExternalTypeVisitor(this, isCovariant: true);
221 _contravariantVisitor = 221 _contravariantVisitor =
222 new _ExternalTypeVisitor(this, isContravariant: true); 222 new _ExternalTypeVisitor(this, isContravariant: true);
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 classNode == coreTypes.futureClass || 1082 classNode == coreTypes.futureClass ||
1083 classNode == coreTypes.streamClass || 1083 classNode == coreTypes.streamClass ||
1084 classNode == coreTypes.listClass || 1084 classNode == coreTypes.listClass ||
1085 classNode == coreTypes.mapClass; 1085 classNode == coreTypes.mapClass;
1086 } 1086 }
1087 } 1087 }
1088 1088
1089 /// Exception that is thrown to stop the tree shaking analysis when a use 1089 /// Exception that is thrown to stop the tree shaking analysis when a use
1090 /// of `dart:mirrors` is found. 1090 /// of `dart:mirrors` is found.
1091 class _UsingMirrorsException {} 1091 class _UsingMirrorsException {}
OLDNEW
« no previous file with comments | « pkg/kernel/lib/class_hierarchy.dart ('k') | pkg/kernel/test/class_hierarchy_bench.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698