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

Side by Side Diff: pkg/fletchc/lib/src/fletch_enqueuer.dart

Issue 1450393002: Roll sdk dependency to 34357cdad108dcba734949bd13bd28c76ea285e0 (Closed) Base URL: git@github.com:dart-lang/fletch.git@master
Patch Set: rebase Created 5 years, 1 month 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
OLDNEW
1 // Copyright (c) 2015, the Fletch project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Fletch 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.md file. 3 // BSD-style license that can be found in the LICENSE.md file.
4 4
5 library fletchc.fletch_enqueuer; 5 library fletchc.fletch_enqueuer;
6 6
7 import 'dart:collection' show 7 import 'dart:collection' show
8 Queue; 8 Queue;
9 9
10 import 'package:compiler/src/dart2jslib.dart' show 10 import 'package:compiler/src/common/tasks.dart' show
11 CodegenEnqueuer, 11 CompilerTask;
12 Compiler, 12
13 CompilerTask, 13 import 'package:compiler/src/universe/world_impact.dart' show
14 EnqueueTask,
15 ItemCompilationContextCreator,
16 QueueFilter,
17 Registry,
18 ResolutionEnqueuer,
19 WorkItem,
20 WorldImpact; 14 WorldImpact;
21 15
16 import 'package:compiler/src/types/types.dart' show
17 TypeMaskStrategy;
18
19 import 'package:compiler/src/enqueue.dart' show
20 ResolutionEnqueuer,
21 CodegenEnqueuer,
22 TreeShakingEnqueuerStrategy;
23
24 import 'package:compiler/src/compiler.dart' show
25 Compiler;
26
27 import 'package:compiler/src/enqueue.dart' show
28 QueueFilter,
29 EnqueueTask,
30 Enqueuer;
31
32 import 'package:compiler/src/universe/selector.dart' show
33 Selector;
34
22 import 'package:compiler/src/universe/universe.dart' show 35 import 'package:compiler/src/universe/universe.dart' show
23 CallStructure, 36 Universe;
24 Selector,
25 Universe,
26 UniverseSelector;
27 37
28 import 'package:compiler/src/dart_types.dart' show 38 import 'package:compiler/src/dart_types.dart' show
29 DartType, 39 DartType,
30 InterfaceType; 40 InterfaceType;
31 41
32 import 'package:compiler/src/elements/elements.dart' show 42 import 'package:compiler/src/elements/elements.dart' show
33 AstElement, 43 AstElement,
34 ClassElement, 44 ClassElement,
35 ConstructorElement, 45 ConstructorElement,
36 Element, 46 Element,
37 FunctionElement, 47 FunctionElement,
38 LibraryElement, 48 LibraryElement,
39 LocalFunctionElement, 49 LocalFunctionElement,
40 Name, 50 Name,
41 TypedElement; 51 TypedElement;
42 52
43 import 'package:compiler/src/resolution/resolution.dart' show 53 import 'package:compiler/src/resolution/tree_elements.dart' show
44 TreeElements; 54 TreeElements;
45 55
46 import 'package:compiler/src/util/util.dart' show 56 import 'package:compiler/src/util/util.dart' show
47 Hashing, 57 Hashing;
48 SpannableAssertionFailure;
49 58
50 import 'fletch_compiler_implementation.dart' show 59 import 'fletch_compiler_implementation.dart' show
51 FletchCompilerImplementation; 60 FletchCompilerImplementation;
52 61
53 import 'dynamic_call_enqueuer.dart' show 62 import 'dynamic_call_enqueuer.dart' show
54 Closurization, 63 Closurization,
55 DynamicCallEnqueuer, 64 DynamicCallEnqueuer,
56 UsageRecorder; 65 UsageRecorder;
57 66
58 import 'fletch_registry.dart' show 67 import 'fletch_registry.dart' show
59 ClosureKind, 68 ClosureKind,
60 FletchRegistry, 69 FletchRegistry,
61 FletchRegistryImplementation; 70 FletchRegistry;
71
72 import 'dart:developer';
73 import 'package:compiler/src/diagnostics/diagnostic_listener.dart';
74
75 import 'package:compiler/src/universe/use.dart' show
76 DynamicUse,
77 StaticUse;
78
79 import 'package:compiler/src/universe/use.dart';
80 import 'package:compiler/src/common/work.dart';
81 import 'package:compiler/src/common/resolution.dart';
82 import 'package:compiler/src/enqueue.dart';
62 83
63 part 'enqueuer_mixin.dart'; 84 part 'enqueuer_mixin.dart';
64 85
65 /// True if enqueuing of system libraries should be reported in verbose mode. 86 /// True if enqueuing of system libraries should be reported in verbose mode.
66 const bool logSystemLibraries = 87 const bool logSystemLibraries =
67 const bool.fromEnvironment("fletchc.logSystemLibraries"); 88 const bool.fromEnvironment("fletchc.logSystemLibraries");
68 89
69 /// Returns true if enqueuing of [element] should be reported in verbose 90 /// Returns true if enqueuing of [element] should be reported in verbose
70 /// mode. See [logSystemLibraries]. 91 /// mode. See [logSystemLibraries].
71 bool shouldReportEnqueuingOfElement(Compiler compiler, Element element) { 92 bool shouldReportEnqueuingOfElement(Compiler compiler, Element element) {
72 if (logSystemLibraries) return true; 93 if (logSystemLibraries) return true;
73 return compiler.inUserCode(element); 94 return compiler.inUserCode(element);
74 } 95 }
75 96
76 /// Custom enqueuer for Fletch. 97 /// Custom enqueuer for Fletch.
77 class FletchEnqueueTask extends CompilerTask implements EnqueueTask { 98 class FletchEnqueueTask extends CompilerTask implements EnqueueTask {
78 final ResolutionEnqueuer resolution; 99 final ResolutionEnqueuer resolution;
79 100
80 final FletchEnqueuer codegen; 101 final FletchEnqueuer codegen;
81 102
82 FletchEnqueueTask(FletchCompilerImplementation compiler) 103 FletchEnqueueTask(FletchCompilerImplementation compiler)
83 : resolution = new ResolutionEnqueuer( 104 : resolution = new ResolutionEnqueuer(
84 compiler, compiler.backend.createItemCompilationContext), 105 compiler, compiler.backend.createItemCompilationContext,
106 compiler.analyzeOnly && compiler.analyzeMain
107 ? const EnqueuerStrategy() : const TreeShakingEnqueuerStrategy()),
85 codegen = new FletchEnqueuer( 108 codegen = new FletchEnqueuer(
86 compiler, compiler.backend.createItemCompilationContext), 109 compiler, compiler.backend.createItemCompilationContext),
87 super(compiler) { 110 super(compiler) {
88 codegen.task = this; 111 codegen.task = this;
89 resolution.task = this; 112 resolution.task = this;
90 codegen.nativeEnqueuer = compiler.backend.nativeCodegenEnqueuer(codegen); 113 codegen.nativeEnqueuer = compiler.backend.nativeCodegenEnqueuer(codegen);
91 114
92 resolution.nativeEnqueuer = 115 resolution.nativeEnqueuer =
93 compiler.backend.nativeResolutionEnqueuer(resolution); 116 compiler.backend.nativeResolutionEnqueuer(resolution);
94 } 117 }
(...skipping 16 matching lines...) Expand all
111 134
112 bool hasEnqueuedReflectiveElements = false; 135 bool hasEnqueuedReflectiveElements = false;
113 136
114 bool hasEnqueuedReflectiveStaticFields = false; 137 bool hasEnqueuedReflectiveStaticFields = false;
115 138
116 EnqueueTask task; 139 EnqueueTask task;
117 140
118 // TODO(ahe): Get rid of this? 141 // TODO(ahe): Get rid of this?
119 var nativeEnqueuer; 142 var nativeEnqueuer;
120 143
121 final Universe universe = new Universe(); 144 final Universe universe = new Universe(const TypeMaskStrategy());
122 145
123 final Set<ElementUsage> _enqueuedUsages = new Set<ElementUsage>(); 146 final Set<ElementUsage> _enqueuedUsages = new Set<ElementUsage>();
124 final Map<Element, List<ElementUsage>> _enqueuedUsagesByElement = 147 final Map<Element, List<ElementUsage>> _enqueuedUsagesByElement =
125 <Element, List<ElementUsage>>{}; 148 <Element, List<ElementUsage>>{};
126 149
127 final Queue<ElementUsage> _pendingEnqueuedUsages = 150 final Queue<ElementUsage> _pendingEnqueuedUsages =
128 new Queue<ElementUsage>(); 151 new Queue<ElementUsage>();
129 152
130 final Set<TypeTest> _typeTests = new Set<TypeTest>(); 153 final Set<TypeTest> _typeTests = new Set<TypeTest>();
131 154
(...skipping 18 matching lines...) Expand all
150 void forgetElement(Element element) { 173 void forgetElement(Element element) {
151 List<ElementUsage> usages = _enqueuedUsagesByElement[element]; 174 List<ElementUsage> usages = _enqueuedUsagesByElement[element];
152 if (usages != null) { 175 if (usages != null) {
153 _enqueuedUsages.removeAll(usages); 176 _enqueuedUsages.removeAll(usages);
154 } 177 }
155 dynamicCallEnqueuer.forgetElement(element); 178 dynamicCallEnqueuer.forgetElement(element);
156 } 179 }
157 180
158 void registerInstantiatedType( 181 void registerInstantiatedType(
159 InterfaceType type, 182 InterfaceType type,
160 Registry registry,
161 {bool mirrorUsage: false}) { 183 {bool mirrorUsage: false}) {
162 dynamicCallEnqueuer.registerInstantiatedType(type); 184 dynamicCallEnqueuer.registerInstantiatedType(type);
163 } 185 }
164 186
165 // TODO(ahe): Remove this method. 187 // TODO(ahe): Remove this method.
166 void registerStaticUse(Element element) { 188 void registerStaticUse(StaticUse staticUse) {
167 _enqueueElement(element, null, null); 189 _enqueueElement(staticUse.element, null, null);
168 } 190 }
169 191
170 // TODO(ahe): Remove this method. 192 // TODO(ahe): Remove this method.
171 void addToWorkList(Element element) { 193 void addToWorkList(Element element) {
172 _enqueueElement(element, null, null); 194 _enqueueElement(element, null, null);
173 } 195 }
174 196
175 // TODO(ahe): Remove this method. 197 // TODO(ahe): Remove this method.
176 void forEach(_) { 198 void forEach(_) {
177 processQueue(); 199 processQueue();
178 } 200 }
179 201
180 void processQueue() { 202 void processQueue() {
181 do { 203 do {
182 do { 204 do {
183 while (!queueIsEmpty) { 205 while (!queueIsEmpty) {
184 if (!_pendingEnqueuedUsages.isEmpty) { 206 if (!_pendingEnqueuedUsages.isEmpty) {
185 ElementUsage usage = _pendingEnqueuedUsages.removeFirst(); 207 ElementUsage usage = _pendingEnqueuedUsages.removeFirst();
186 AstElement element = usage.element; 208 AstElement element = usage.element;
187 TreeElements treeElements = element.resolvedAst.elements; 209 TreeElements treeElements = element.resolvedAst.elements;
188 FletchRegistry registry = 210 FletchRegistry registry = new FletchRegistry(compiler);
189 new FletchRegistryImplementation(compiler, treeElements);
190 Selector selector = usage.selector; 211 Selector selector = usage.selector;
191 if (usage.closureKind != null) { 212 if (usage.closureKind != null) {
192 compiler.context.backend.compileClosurizationUsage( 213 compiler.context.backend.compileClosurizationUsage(
193 element, selector, treeElements, registry, usage.closureKind); 214 element, selector, treeElements, registry, usage.closureKind);
194 } else if (selector != null) { 215 } else if (selector != null) {
195 compiler.context.backend.compileElementUsage( 216 compiler.context.backend.compileElementUsage(
196 element, selector, treeElements, registry); 217 element, selector, treeElements, registry);
197 } else { 218 } else {
198 compiler.context.backend.compileElement( 219 compiler.context.backend.compileElement(
199 element, treeElements, registry); 220 element, treeElements, registry);
(...skipping 13 matching lines...) Expand all
213 234
214 bool checkNoEnqueuedInvokedInstanceMethods() { 235 bool checkNoEnqueuedInvokedInstanceMethods() {
215 // TODO(ahe): Implement 236 // TODO(ahe): Implement
216 return true; 237 return true;
217 } 238 }
218 239
219 void logSummary(log(message)) { 240 void logSummary(log(message)) {
220 // TODO(ahe): Implement this. 241 // TODO(ahe): Implement this.
221 } 242 }
222 243
223 void registerDynamicInvocation(UniverseSelector selector) { 244 void registerDynamicUse(DynamicUse use) {
224 dynamicCallEnqueuer.enqueueSelector(selector); 245 dynamicCallEnqueuer.enqueueSelector(use);
225 } 246 }
226 247
227 void applyImpact(Element element, WorldImpact worldImpact) { 248 void applyImpact(Element element, WorldImpact worldImpact) {
228 assert(worldImpact == null); 249 assert(worldImpact == null);
229 } 250 }
230 251
231 void registerDynamicGetter(UniverseSelector selector) {
232 dynamicCallEnqueuer.enqueueSelector(selector);
233 }
234
235 void registerDynamicSetter(UniverseSelector selector) {
236 dynamicCallEnqueuer.enqueueSelector(selector);
237 }
238
239 void registerIsCheck(DartType type) { 252 void registerIsCheck(DartType type) {
240 dynamicCallEnqueuer.enqueueTypeTest(type); 253 dynamicCallEnqueuer.enqueueTypeTest(type);
241 } 254 }
242 255
243 void _enqueueElement( 256 void _enqueueElement(
244 Element element, 257 Element element,
245 Selector selector, 258 Selector selector,
246 ClosureKind closureKind) { 259 ClosureKind closureKind) {
247 if (selector != null) { 260 if (selector != null) {
248 _enqueueElement(element, null, null); 261 _enqueueElement(element, null, null);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 331
319 TypeTest(ClassElement element, InterfaceType type) 332 TypeTest(ClassElement element, InterfaceType type)
320 : element = element, 333 : element = element,
321 type = type, 334 type = type,
322 hashCode = Hashing.mixHashCodeBits(element.hashCode, type.hashCode); 335 hashCode = Hashing.mixHashCodeBits(element.hashCode, type.hashCode);
323 336
324 bool operator ==(other) { 337 bool operator ==(other) {
325 return other is TypeTest && element == other.element && type == other.type; 338 return other is TypeTest && element == other.element && type == other.type;
326 } 339 }
327 } 340 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698