| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 dart2js.enqueue; | 5 library dart2js.enqueue; |
| 6 | 6 |
| 7 import 'dart:collection' show Queue; | 7 import 'dart:collection' show Queue; |
| 8 | 8 |
| 9 import 'common/resolution.dart' show Resolution; | 9 import 'common/resolution.dart' show Resolution; |
| 10 import 'common/tasks.dart' show CompilerTask; | 10 import 'common/tasks.dart' show CompilerTask; |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 271 |
| 272 /// Callback for applying the use of a [member]. | 272 /// Callback for applying the use of a [member]. |
| 273 void _applyMemberUse(Entity member, EnumSet<MemberUse> useSet) { | 273 void _applyMemberUse(Entity member, EnumSet<MemberUse> useSet) { |
| 274 if (useSet.contains(MemberUse.NORMAL)) { | 274 if (useSet.contains(MemberUse.NORMAL)) { |
| 275 _addToWorkList(member); | 275 _addToWorkList(member); |
| 276 } | 276 } |
| 277 if (useSet.contains(MemberUse.CLOSURIZE_INSTANCE)) { | 277 if (useSet.contains(MemberUse.CLOSURIZE_INSTANCE)) { |
| 278 _registerClosurizedMember(member); | 278 _registerClosurizedMember(member); |
| 279 } | 279 } |
| 280 if (useSet.contains(MemberUse.CLOSURIZE_STATIC)) { | 280 if (useSet.contains(MemberUse.CLOSURIZE_STATIC)) { |
| 281 applyImpact(listener.registerGetOfStaticFunction()); | 281 applyImpact(listener.registerGetOfStaticFunction(), |
| 282 impactSource: 'get of static function'); |
| 282 } | 283 } |
| 283 } | 284 } |
| 284 | 285 |
| 285 /// Callback for applying the use of a [cls]. | 286 /// Callback for applying the use of a [cls]. |
| 286 void _applyClassUse(ClassEntity cls, EnumSet<ClassUse> useSet) { | 287 void _applyClassUse(ClassEntity cls, EnumSet<ClassUse> useSet) { |
| 287 if (useSet.contains(ClassUse.INSTANTIATED)) { | 288 if (useSet.contains(ClassUse.INSTANTIATED)) { |
| 288 _recentClasses.add(cls); | 289 _recentClasses.add(cls); |
| 289 _worldBuilder.processClassMembers(cls, _applyMemberUse); | 290 _worldBuilder.processClassMembers(cls, _applyMemberUse); |
| 290 // We only tell the backend once that [cls] was instantiated, so | 291 // We only tell the backend once that [cls] was instantiated, so |
| 291 // any additional dependencies must be treated as global | 292 // any additional dependencies must be treated as global |
| 292 // dependencies. | 293 // dependencies. |
| 293 applyImpact(listener.registerInstantiatedClass(cls)); | 294 applyImpact(listener.registerInstantiatedClass(cls), |
| 295 impactSource: 'instantiated class'); |
| 294 } | 296 } |
| 295 if (useSet.contains(ClassUse.IMPLEMENTED)) { | 297 if (useSet.contains(ClassUse.IMPLEMENTED)) { |
| 296 applyImpact(listener.registerImplementedClass(cls)); | 298 applyImpact(listener.registerImplementedClass(cls), |
| 299 impactSource: 'implemented class'); |
| 297 } | 300 } |
| 298 } | 301 } |
| 299 | 302 |
| 300 void processDynamicUse(DynamicUse dynamicUse) { | 303 void processDynamicUse(DynamicUse dynamicUse) { |
| 301 task.measure(() { | 304 task.measure(() { |
| 302 _worldBuilder.registerDynamicUse(dynamicUse, _applyMemberUse); | 305 _worldBuilder.registerDynamicUse(dynamicUse, _applyMemberUse); |
| 303 }); | 306 }); |
| 304 } | 307 } |
| 305 | 308 |
| 306 void processConstantUse(ConstantUse constantUse) { | 309 void processConstantUse(ConstantUse constantUse) { |
| 307 task.measure(() { | 310 task.measure(() { |
| 308 if (_worldBuilder.registerConstantUse(constantUse)) { | 311 if (_worldBuilder.registerConstantUse(constantUse)) { |
| 309 applyImpact(listener.registerUsedConstant(constantUse.value)); | 312 applyImpact(listener.registerUsedConstant(constantUse.value), |
| 313 impactSource: 'constant use'); |
| 310 _recentConstants = true; | 314 _recentConstants = true; |
| 311 } | 315 } |
| 312 }); | 316 }); |
| 313 } | 317 } |
| 314 | 318 |
| 315 void processStaticUse(StaticUse staticUse) { | 319 void processStaticUse(StaticUse staticUse) { |
| 316 _worldBuilder.registerStaticUse(staticUse, _applyMemberUse); | 320 _worldBuilder.registerStaticUse(staticUse, _applyMemberUse); |
| 317 // TODO(johnniwinther): Add `ResolutionWorldBuilder.registerConstructorUse` | 321 // TODO(johnniwinther): Add `ResolutionWorldBuilder.registerConstructorUse` |
| 318 // for these: | 322 // for these: |
| 319 switch (staticUse.kind) { | 323 switch (staticUse.kind) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 break; | 369 break; |
| 366 } | 370 } |
| 367 } | 371 } |
| 368 | 372 |
| 369 void _registerIsCheck(DartType type) { | 373 void _registerIsCheck(DartType type) { |
| 370 _worldBuilder.registerIsCheck(type); | 374 _worldBuilder.registerIsCheck(type); |
| 371 } | 375 } |
| 372 | 376 |
| 373 void _registerClosurizedMember(MemberEntity element) { | 377 void _registerClosurizedMember(MemberEntity element) { |
| 374 assert(element.isInstanceMember); | 378 assert(element.isInstanceMember); |
| 375 applyImpact(listener.registerClosurizedMember(element)); | 379 applyImpact(listener.registerClosurizedMember(element), |
| 380 impactSource: 'closurized member'); |
| 376 _worldBuilder.registerClosurizedMember(element); | 381 _worldBuilder.registerClosurizedMember(element); |
| 377 } | 382 } |
| 378 | 383 |
| 379 void forEach(void f(WorkItem work)) { | 384 void forEach(void f(WorkItem work)) { |
| 380 do { | 385 do { |
| 381 while (_queue.isNotEmpty) { | 386 while (_queue.isNotEmpty) { |
| 382 // TODO(johnniwinther): Find an optimal process order. | 387 // TODO(johnniwinther): Find an optimal process order. |
| 383 WorkItem work = _queue.removeLast(); | 388 WorkItem work = _queue.removeLast(); |
| 384 if (!_processedEntities.contains(work.element)) { | 389 if (!_processedEntities.contains(work.element)) { |
| 385 strategy.processWorkItem(f, work); | 390 strategy.processWorkItem(f, work); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 void _addToWorkList(MemberEntity entity) { | 435 void _addToWorkList(MemberEntity entity) { |
| 431 if (_processedEntities.contains(entity)) return; | 436 if (_processedEntities.contains(entity)) return; |
| 432 WorkItem workItem = _workItemBuilder.createWorkItem(entity); | 437 WorkItem workItem = _workItemBuilder.createWorkItem(entity); |
| 433 if (workItem == null) return; | 438 if (workItem == null) return; |
| 434 | 439 |
| 435 if (queueIsClosed) { | 440 if (queueIsClosed) { |
| 436 throw new SpannableAssertionFailure( | 441 throw new SpannableAssertionFailure( |
| 437 entity, "Resolution work list is closed. Trying to add $entity."); | 442 entity, "Resolution work list is closed. Trying to add $entity."); |
| 438 } | 443 } |
| 439 | 444 |
| 440 applyImpact(listener.registerUsedElement(entity)); | 445 applyImpact(listener.registerUsedElement(entity), |
| 446 impactSource: 'used element'); |
| 441 _worldBuilder.registerUsedElement(entity); | 447 _worldBuilder.registerUsedElement(entity); |
| 442 _queue.add(workItem); | 448 _queue.add(workItem); |
| 443 } | 449 } |
| 444 | 450 |
| 445 /// Adds an action to the deferred task queue. | 451 /// Adds an action to the deferred task queue. |
| 446 /// The action is performed the next time the resolution queue has been | 452 /// The action is performed the next time the resolution queue has been |
| 447 /// emptied. | 453 /// emptied. |
| 448 /// | 454 /// |
| 449 /// The queue is processed in FIFO order. | 455 /// The queue is processed in FIFO order. |
| 450 void addDeferredAction(DeferredAction deferredAction) { | 456 void addDeferredAction(DeferredAction deferredAction) { |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 @override | 615 @override |
| 610 WorkItem createWorkItem(MemberElement element) { | 616 WorkItem createWorkItem(MemberElement element) { |
| 611 assert(invariant(element, element.isDeclaration)); | 617 assert(invariant(element, element.isDeclaration)); |
| 612 if (element.isMalformed) return null; | 618 if (element.isMalformed) return null; |
| 613 | 619 |
| 614 assert(invariant(element, element is AnalyzableElement, | 620 assert(invariant(element, element is AnalyzableElement, |
| 615 message: 'Element $element is not analyzable.')); | 621 message: 'Element $element is not analyzable.')); |
| 616 return _resolution.createWorkItem(element); | 622 return _resolution.createWorkItem(element); |
| 617 } | 623 } |
| 618 } | 624 } |
| OLD | NEW |