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

Side by Side Diff: pkg/compiler/lib/src/resolution/registry.dart

Issue 1146813009: Introduce WorldImpact (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 part of resolution; 5 part of resolution;
6 6
7 /// [ResolutionRegistry] collects all resolution information. It stores node 7 /// [ResolutionRegistry] collects all resolution information. It stores node
8 /// related information in a [TreeElements] mapping and registers calls with 8 /// related information in a [TreeElements] mapping and registers calls with
9 /// [Backend], [World] and [Enqueuer]. 9 /// [Backend], [World] and [Enqueuer].
10 // TODO(johnniwinther): Split this into an interface and implementation class. 10 // TODO(johnniwinther): Split this into an interface and implementation class.
11 class ResolutionRegistry extends Registry { 11
12 class EagerRegistry implements Registry {
12 final Compiler compiler; 13 final Compiler compiler;
13 final TreeElementMapping mapping; 14 final TreeElementMapping mapping;
14 15
16 EagerRegistry(this.compiler, this.mapping);
17
18 ResolutionEnqueuer get world => compiler.enqueuer.resolution;
19
20 @override
21 bool get isForResolution => true;
22
23 @override
24 Iterable<Element> get otherDependencies => mapping.otherDependencies;
25
26 @override
27 void registerDependency(Element element) {
28 mapping.registerDependency(element);
29 }
30
31 @override
32 void registerDynamicGetter(Selector selector) {
33 world.registerDynamicGetter(selector);
34 }
35
36 @override
37 void registerDynamicInvocation(Selector selector) {
38 world.registerDynamicInvocation(selector);
39 }
40
41 @override
42 void registerDynamicSetter(Selector selector) {
43 world.registerDynamicSetter(selector);
44 }
45
46 @override
47 void registerGetOfStaticFunction(FunctionElement element) {
48 world.registerGetOfStaticFunction(element);
49 }
50
51 @override
52 void registerInstantiation(InterfaceType type) {
53 // TODO(johnniwinther): Remove the need for passing `this`.
54 world.registerInstantiatedType(type, this);
55 }
56
57 @override
58 void registerStaticInvocation(Element element) {
59 registerDependency(element);
60 world.registerStaticUse(element);
61 }
62 }
63
64 class ResolutionWorldImpact implements WorldImpact {
65 final Registry registry;
66 Setlet<Selector> _dynamicInvocations;
67 Setlet<Selector> _dynamicGetters;
68 Setlet<Selector> _dynamicSetters;
69 Setlet<InterfaceType> _instantiatedTypes;
70 Setlet<Element> _staticUses;
71 Setlet<DartType> _checkedTypes;
72 Setlet<MethodElement> _closurizedFunctions;
73
74 ResolutionWorldImpact(Compiler compiler, TreeElementMapping mapping)
75 : this.registry = new EagerRegistry(compiler, mapping);
76
77 void registerDynamicGetter(Selector selector) {
78 if (_dynamicGetters == null) {
79 _dynamicGetters = new Setlet<Selector>();
80 }
81 _dynamicGetters.add(selector);
82 }
83
84 @override
85 Iterable<Selector> get dynamicGetters {
86 return _dynamicGetters != null ? _dynamicGetters : const <Selector>[];
87 }
88
89 void registerDynamicInvocation(Selector selector) {
90 if (_dynamicInvocations == null) {
91 _dynamicInvocations = new Setlet<Selector>();
92 }
93 _dynamicInvocations.add(selector);
94 }
95
96 @override
97 Iterable<Selector> get dynamicInvocations {
98 return _dynamicInvocations != null
99 ? _dynamicInvocations : const <Selector>[];
100 }
101
102 void registerDynamicSetter(Selector selector) {
103 if (_dynamicSetters == null) {
104 _dynamicSetters = new Setlet<Selector>();
105 }
106 _dynamicSetters.add(selector);
107 }
108
109 @override
110 Iterable<Selector> get dynamicSetters {
111 return _dynamicSetters != null ? _dynamicSetters : const <Selector>[];
112 }
113
114 void registerInstantiatedType(InterfaceType type) {
115 // TODO(johnniwinther): Enable this when registration doesn't require a
116 // [Registry].
117 throw new UnsupportedError(
118 'Lazy registration of instantiated not supported.');
119 if (_instantiatedTypes == null) {
120 _instantiatedTypes = new Setlet<InterfaceType>();
121 }
122 _instantiatedTypes.add(type);
123 }
124
125 @override
126 Iterable<InterfaceType> get instantiatedTypes {
127 return _instantiatedTypes != null
128 ? _instantiatedTypes : const <InterfaceType>[];
129 }
130
131 void registerStaticUse(Element element) {
132 if (_staticUses == null) {
133 _staticUses = new Setlet<Element>();
134 }
135 _staticUses.add(element);
136 }
137
138 @override
139 Iterable<Element> get staticUses {
140 return _staticUses != null ? _staticUses : const <Element>[];
141 }
142
143 void registerCheckedType(DartType type) {
144 if (_checkedTypes == null) {
145 _checkedTypes = new Setlet<DartType>();
146 }
147 _checkedTypes.add(type);
148 }
149
150 @override
151 Iterable<DartType> get checkedTypes {
152 return _checkedTypes != null
153 ? _checkedTypes : const <DartType>[];
154 }
155
156 void registerClosurizedFunction(MethodElement element) {
157 if (_closurizedFunctions == null) {
158 _closurizedFunctions = new Setlet<MethodElement>();
159 }
160 _closurizedFunctions.add(element);
161 }
162
163 @override
164 Iterable<MethodElement> get closurizedFunctions {
165 return _closurizedFunctions != null
166 ? _closurizedFunctions : const <MethodElement>[];
167 }
168 }
169
170 class ResolutionRegistry implements Registry {
171 final Compiler compiler;
172 final TreeElementMapping mapping;
173 final ResolutionWorldImpact worldImpact;
174
15 ResolutionRegistry(Compiler compiler, Element element) 175 ResolutionRegistry(Compiler compiler, Element element)
16 : this.internal(compiler, _ensureTreeElements(element)); 176 : this.internal(compiler, _ensureTreeElements(element));
17 177
18 ResolutionRegistry.internal(this.compiler, this.mapping); 178 ResolutionRegistry.internal(Compiler compiler, TreeElementMapping mapping)
179 : this.compiler = compiler,
180 this.mapping = mapping,
181 this.worldImpact = new ResolutionWorldImpact(compiler, mapping);
19 182
20 bool get isForResolution => true; 183 bool get isForResolution => true;
21 184
22 ResolutionEnqueuer get world => compiler.enqueuer.resolution; 185 ResolutionEnqueuer get world => compiler.enqueuer.resolution;
23 186
24 World get universe => compiler.world; 187 World get universe => compiler.world;
25 188
26 Backend get backend => compiler.backend; 189 Backend get backend => compiler.backend;
27 190
28 ////////////////////////////////////////////////////////////////////////////// 191 //////////////////////////////////////////////////////////////////////////////
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 void registerPotentialMutationIn(Node contextNode, VariableElement element, 346 void registerPotentialMutationIn(Node contextNode, VariableElement element,
184 Node mutationNode) { 347 Node mutationNode) {
185 mapping.registerPotentialMutationIn(contextNode, element, mutationNode); 348 mapping.registerPotentialMutationIn(contextNode, element, mutationNode);
186 } 349 }
187 350
188 ////////////////////////////////////////////////////////////////////////////// 351 //////////////////////////////////////////////////////////////////////////////
189 // Various Backend/Enqueuer/World registration. 352 // Various Backend/Enqueuer/World registration.
190 ////////////////////////////////////////////////////////////////////////////// 353 //////////////////////////////////////////////////////////////////////////////
191 354
192 void registerStaticUse(Element element) { 355 void registerStaticUse(Element element) {
193 world.registerStaticUse(element); 356 worldImpact.registerStaticUse(element);
194 } 357 }
195 358
196 void registerImplicitSuperCall(FunctionElement superConstructor) { 359 void registerImplicitSuperCall(FunctionElement superConstructor) {
197 universe.registerImplicitSuperCall(this, superConstructor); 360 universe.registerImplicitSuperCall(this, superConstructor);
198 } 361 }
199 362
363 // TODO(johnniwinther): Remove this.
364 // Use [registerInstantiatedType] of `rawType` instead.
365 @deprecated
200 void registerInstantiatedClass(ClassElement element) { 366 void registerInstantiatedClass(ClassElement element) {
201 world.registerInstantiatedClass(element, this); 367 element.ensureResolved(compiler);
368 registerInstantiatedType(element.rawType);
202 } 369 }
203 370
204 void registerLazyField() { 371 void registerLazyField() {
205 backend.resolutionCallbacks.onLazyField(this); 372 backend.resolutionCallbacks.onLazyField(this);
206 } 373 }
207 374
208 void registerMetadataConstant(MetadataAnnotation metadata, 375 void registerMetadataConstant(MetadataAnnotation metadata,
209 Element annotatedElement) { 376 Element annotatedElement) {
210 backend.registerMetadataConstant(metadata, annotatedElement, this); 377 backend.registerMetadataConstant(metadata, annotatedElement, this);
211 } 378 }
212 379
213 void registerThrowRuntimeError() { 380 void registerThrowRuntimeError() {
214 backend.resolutionCallbacks.onThrowRuntimeError(this); 381 backend.resolutionCallbacks.onThrowRuntimeError(this);
215 } 382 }
216 383
217 void registerTypeVariableBoundCheck() { 384 void registerTypeVariableBoundCheck() {
218 backend.resolutionCallbacks.onTypeVariableBoundCheck(this); 385 backend.resolutionCallbacks.onTypeVariableBoundCheck(this);
219 } 386 }
220 387
221 void registerThrowNoSuchMethod() { 388 void registerThrowNoSuchMethod() {
222 backend.resolutionCallbacks.onThrowNoSuchMethod(this); 389 backend.resolutionCallbacks.onThrowNoSuchMethod(this);
223 } 390 }
224 391
225 void registerIsCheck(DartType type) { 392 void registerIsCheck(DartType type) {
226 world.registerIsCheck(type, this); 393 worldImpact.registerCheckedType(type);
227 backend.resolutionCallbacks.onIsCheck(type, this); 394 backend.resolutionCallbacks.onIsCheck(type, this);
228 } 395 }
229 396
230 void registerAsCheck(DartType type) { 397 void registerAsCheck(DartType type) {
231 registerIsCheck(type); 398 registerIsCheck(type);
232 backend.resolutionCallbacks.onAsCheck(type, this); 399 backend.resolutionCallbacks.onAsCheck(type, this);
233 } 400 }
234 401
235 void registerClosure(LocalFunctionElement element) { 402 void registerClosure(LocalFunctionElement element) {
236 world.registerClosure(element, this); 403 world.registerClosure(element, this);
237 } 404 }
238 405
239 void registerSuperUse(Node node) { 406 void registerSuperUse(Node node) {
240 mapping.addSuperUse(node); 407 mapping.addSuperUse(node);
241 } 408 }
242 409
243 void registerDynamicInvocation(Selector selector) { 410 void registerDynamicInvocation(Selector selector) {
244 world.registerDynamicInvocation(selector); 411 worldImpact.registerDynamicInvocation(selector);
245 } 412 }
246 413
247 void registerSuperNoSuchMethod() { 414 void registerSuperNoSuchMethod() {
248 backend.resolutionCallbacks.onSuperNoSuchMethod(this); 415 backend.resolutionCallbacks.onSuperNoSuchMethod(this);
249 } 416 }
250 417
251 void registerClassUsingVariableExpression(ClassElement element) { 418 void registerClassUsingVariableExpression(ClassElement element) {
252 backend.registerClassUsingVariableExpression(element); 419 backend.registerClassUsingVariableExpression(element);
253 } 420 }
254 421
255 void registerTypeVariableExpression() { 422 void registerTypeVariableExpression() {
256 backend.resolutionCallbacks.onTypeVariableExpression(this); 423 backend.resolutionCallbacks.onTypeVariableExpression(this);
257 } 424 }
258 425
259 void registerTypeLiteral(Send node, DartType type) { 426 void registerTypeLiteral(Send node, DartType type) {
260 mapping.setType(node, type); 427 mapping.setType(node, type);
261 backend.resolutionCallbacks.onTypeLiteral(type, this); 428 backend.resolutionCallbacks.onTypeLiteral(type, this);
262 world.registerInstantiatedClass(compiler.typeClass, this); 429 world.registerInstantiatedType(compiler.coreTypes.typeType, this);
263 } 430 }
264 431
265 void registerMapLiteral(Node node, DartType type, bool isConstant) { 432 void registerMapLiteral(Node node, DartType type, bool isConstant) {
266 setType(node, type); 433 setType(node, type);
267 backend.resolutionCallbacks.onMapLiteral(this, type, isConstant); 434 backend.resolutionCallbacks.onMapLiteral(this, type, isConstant);
268 } 435 }
269 436
270 // TODO(johnniwinther): Remove the [ResolverVisitor] dependency. Its only 437 // TODO(johnniwinther): Remove the [ResolverVisitor] dependency. Its only
271 // needed to lookup types in the current scope. 438 // needed to lookup types in the current scope.
272 void registerJsCall(Node node, ResolverVisitor visitor) { 439 void registerJsCall(Node node, ResolverVisitor visitor) {
273 world.registerJsCall(node, visitor); 440 world.registerJsCall(node, visitor);
274 } 441 }
275 442
276 // TODO(johnniwinther): Remove the [ResolverVisitor] dependency. Its only 443 // TODO(johnniwinther): Remove the [ResolverVisitor] dependency. Its only
277 // needed to lookup types in the current scope. 444 // needed to lookup types in the current scope.
278 void registerJsEmbeddedGlobalCall(Node node, ResolverVisitor visitor) { 445 void registerJsEmbeddedGlobalCall(Node node, ResolverVisitor visitor) {
279 world.registerJsEmbeddedGlobalCall(node, visitor); 446 world.registerJsEmbeddedGlobalCall(node, visitor);
280 } 447 }
281 448
282 // TODO(johnniwinther): Remove the [ResolverVisitor] dependency. Its only 449 // TODO(johnniwinther): Remove the [ResolverVisitor] dependency. Its only
283 // needed to lookup types in the current scope. 450 // needed to lookup types in the current scope.
284 void registerJsBuiltinCall(Node node, ResolverVisitor visitor) { 451 void registerJsBuiltinCall(Node node, ResolverVisitor visitor) {
285 world.registerJsBuiltinCall(node, visitor); 452 world.registerJsBuiltinCall(node, visitor);
286 } 453 }
287 454
288 void registerGetOfStaticFunction(FunctionElement element) { 455 void registerGetOfStaticFunction(FunctionElement element) {
289 world.registerGetOfStaticFunction(element); 456 worldImpact.registerClosurizedFunction(element);
457 //world.registerGetOfStaticFunction(element);
karlklose 2015/06/01 10:50:24 Remove code in comments (also below).
Johnni Winther 2015/06/01 11:50:37 Done.
290 } 458 }
291 459
292 void registerDynamicGetter(Selector selector) { 460 void registerDynamicGetter(Selector selector) {
293 world.registerDynamicGetter(selector); 461 worldImpact.registerDynamicGetter(selector);
462 //world.registerDynamicGetter(selector);
294 } 463 }
295 464
296 void registerDynamicSetter(Selector selector) { 465 void registerDynamicSetter(Selector selector) {
297 world.registerDynamicSetter(selector); 466 worldImpact.registerDynamicSetter(selector);
467 //world.registerDynamicSetter(selector);
298 } 468 }
299 469
300 void registerConstSymbol(String name) { 470 void registerConstSymbol(String name) {
301 backend.registerConstSymbol(name, this); 471 backend.registerConstSymbol(name, this);
302 } 472 }
303 473
304 void registerSymbolConstructor() { 474 void registerSymbolConstructor() {
305 backend.resolutionCallbacks.onSymbolConstructor(this); 475 backend.resolutionCallbacks.onSymbolConstructor(this);
306 } 476 }
307 477
308 void registerInstantiatedType(InterfaceType type) { 478 void registerInstantiatedType(InterfaceType type) {
479 //worldImpact.registerInstantiatedType(type);
309 world.registerInstantiatedType(type, this); 480 world.registerInstantiatedType(type, this);
310 } 481 }
311 482
312 void registerAbstractClassInstantiation() { 483 void registerAbstractClassInstantiation() {
313 backend.resolutionCallbacks.onAbstractClassInstantiation(this); 484 backend.resolutionCallbacks.onAbstractClassInstantiation(this);
314 } 485 }
315 486
316 void registerNewSymbol() { 487 void registerNewSymbol() {
317 backend.registerNewSymbol(this); 488 backend.registerNewSymbol(this);
318 } 489 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 } 526 }
356 527
357 void registerDependency(Element element) { 528 void registerDependency(Element element) {
358 mapping.registerDependency(element); 529 mapping.registerDependency(element);
359 } 530 }
360 531
361 Setlet<Element> get otherDependencies => mapping.otherDependencies; 532 Setlet<Element> get otherDependencies => mapping.otherDependencies;
362 533
363 void registerStaticInvocation(Element element) { 534 void registerStaticInvocation(Element element) {
364 if (element == null) return; 535 if (element == null) return;
365 world.addToWorkList(element); 536 registerStaticUse(element);
366 registerDependency(element);
367 } 537 }
368 538
369 void registerInstantiation(InterfaceType type) { 539 void registerInstantiation(InterfaceType type) {
540 //worldImpact.registerInstantiatedType(type);
370 world.registerInstantiatedType(type, this); 541 world.registerInstantiatedType(type, this);
371 } 542 }
372 543
373 void registerAssert(Send node) { 544 void registerAssert(Send node) {
374 mapping.setAssert(node); 545 mapping.setAssert(node);
375 backend.resolutionCallbacks.onAssert(node, this); 546 backend.resolutionCallbacks.onAssert(node, this);
376 } 547 }
377 548
378 bool isAssert(Send node) { 549 bool isAssert(Send node) {
379 return mapping.isAssert(node); 550 return mapping.isAssert(node);
380 } 551 }
381 552
382 void registerSendStructure(Send node, SendStructure sendStructure) { 553 void registerSendStructure(Send node, SendStructure sendStructure) {
383 mapping.setSendStructure(node, sendStructure); 554 mapping.setSendStructure(node, sendStructure);
384 } 555 }
385 556
386 void registerAsyncMarker(FunctionElement element) { 557 void registerAsyncMarker(FunctionElement element) {
387 backend.registerAsyncMarker(element, world, this); 558 backend.registerAsyncMarker(element, world, this);
388 } 559 }
389 560
390 void registerAsyncForIn(AsyncForIn node) { 561 void registerAsyncForIn(AsyncForIn node) {
391 backend.resolutionCallbacks.onAsyncForIn(node, this); 562 backend.resolutionCallbacks.onAsyncForIn(node, this);
392 } 563 }
393 } 564 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/native/enqueue.dart ('k') | pkg/compiler/lib/src/resolution/resolution_common.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698