| 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.js.enqueue; | 5 library dart2js.js.enqueue; |
| 6 | 6 |
| 7 import 'dart:collection' show Queue; | 7 import 'dart:collection' show Queue; |
| 8 | 8 |
| 9 import '../common/backend_api.dart' show Backend; | 9 import '../common/backend_api.dart' show Backend; |
| 10 import '../common/codegen.dart' show CodegenWorkItem; | 10 import '../common/codegen.dart' show CodegenWorkItem; |
| 11 import '../common/names.dart' show Identifiers; | 11 import '../common/names.dart' show Identifiers; |
| 12 import '../common/tasks.dart' show CompilerTask; | 12 import '../common/tasks.dart' show CompilerTask; |
| 13 import '../common/work.dart' show WorkItem; | 13 import '../common/work.dart' show WorkItem; |
| 14 import '../common.dart'; | 14 import '../common.dart'; |
| 15 import '../compiler.dart' show Compiler; | 15 import '../compiler.dart' show Compiler; |
| 16 import '../dart_types.dart' show DartType, InterfaceType; | 16 import '../dart_types.dart' show DartType, InterfaceType; |
| 17 import '../elements/elements.dart' | 17 import '../elements/elements.dart' |
| 18 show | 18 show |
| 19 ClassElement, | 19 ClassElement, |
| 20 Element, | 20 Element, |
| 21 Elements, | |
| 22 Entity, | 21 Entity, |
| 23 FunctionElement, | 22 FunctionElement, |
| 24 LibraryElement, | |
| 25 Member, | |
| 26 MemberElement, | 23 MemberElement, |
| 27 MethodElement, | 24 MethodElement, |
| 28 Name, | 25 TypedElement; |
| 29 TypedElement, | 26 import '../elements/entities.dart'; |
| 30 TypedefElement; | |
| 31 import '../enqueue.dart'; | 27 import '../enqueue.dart'; |
| 32 import '../js/js.dart' as js; | 28 import '../js/js.dart' as js; |
| 33 import '../native/native.dart' as native; | 29 import '../native/native.dart' as native; |
| 34 import '../options.dart'; | 30 import '../options.dart'; |
| 35 import '../types/types.dart' show TypeMaskStrategy; | 31 import '../types/types.dart' show TypeMaskStrategy; |
| 36 import '../universe/selector.dart' show Selector; | 32 import '../universe/selector.dart' show Selector; |
| 37 import '../universe/world_builder.dart'; | 33 import '../universe/world_builder.dart'; |
| 38 import '../universe/use.dart' | 34 import '../universe/use.dart' |
| 39 show DynamicUse, StaticUse, StaticUseKind, TypeUse, TypeUseKind; | 35 show DynamicUse, StaticUse, StaticUseKind, TypeUse, TypeUseKind; |
| 40 import '../universe/world_impact.dart' | 36 import '../universe/world_impact.dart' |
| 41 show ImpactUseCase, ImpactStrategy, WorldImpact, WorldImpactVisitor; | 37 show ImpactUseCase, WorldImpact, WorldImpactVisitor; |
| 42 import '../util/util.dart' show Setlet; | 38 import '../util/util.dart' show Setlet; |
| 43 import '../world.dart'; | 39 import '../world.dart'; |
| 44 | 40 |
| 45 /// [Enqueuer] which is specific to code generation. | 41 /// [Enqueuer] which is specific to code generation. |
| 46 class CodegenEnqueuer extends EnqueuerImpl { | 42 class CodegenEnqueuer extends EnqueuerImpl { |
| 47 final String name; | 43 final String name; |
| 48 @deprecated | 44 @deprecated |
| 49 final Compiler _compiler; // TODO(ahe): Remove this dependency. | 45 final Compiler _compiler; // TODO(ahe): Remove this dependency. |
| 50 final EnqueuerStrategy strategy; | 46 final EnqueuerStrategy strategy; |
| 51 final Map<String, Set<Element>> _instanceMembersByName = | 47 final Map<String, Set<Element>> _instanceMembersByName = |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 return false; | 339 return false; |
| 344 }); | 340 }); |
| 345 } | 341 } |
| 346 } | 342 } |
| 347 | 343 |
| 348 void processStaticUse(StaticUse staticUse) { | 344 void processStaticUse(StaticUse staticUse) { |
| 349 Element element = staticUse.element; | 345 Element element = staticUse.element; |
| 350 assert(invariant(element, element.isDeclaration, | 346 assert(invariant(element, element.isDeclaration, |
| 351 message: "Element ${element} is not the declaration.")); | 347 message: "Element ${element} is not the declaration.")); |
| 352 _universe.registerStaticUse(staticUse); | 348 _universe.registerStaticUse(staticUse); |
| 353 applyImpact(_backend.registerStaticUse(element, forResolution: false)); | 349 applyImpact(_backend.registerUsedElement(element, forResolution: false)); |
| 354 bool addElement = true; | 350 bool addElement = true; |
| 355 switch (staticUse.kind) { | 351 switch (staticUse.kind) { |
| 356 case StaticUseKind.STATIC_TEAR_OFF: | 352 case StaticUseKind.STATIC_TEAR_OFF: |
| 357 applyImpact(_backend.registerGetOfStaticFunction()); | 353 applyImpact(_backend.registerGetOfStaticFunction()); |
| 358 break; | 354 break; |
| 359 case StaticUseKind.FIELD_GET: | 355 case StaticUseKind.FIELD_GET: |
| 360 case StaticUseKind.FIELD_SET: | 356 case StaticUseKind.FIELD_SET: |
| 361 case StaticUseKind.CLOSURE: | 357 case StaticUseKind.CLOSURE: |
| 362 // TODO(johnniwinther): Avoid this. Currently [FIELD_GET] and | 358 // TODO(johnniwinther): Avoid this. Currently [FIELD_GET] and |
| 363 // [FIELD_SET] contains [BoxFieldElement]s which we cannot enqueue. | 359 // [FIELD_SET] contains [BoxFieldElement]s which we cannot enqueue. |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 return _backend.onQueueEmpty(this, recentClasses); | 456 return _backend.onQueueEmpty(this, recentClasses); |
| 461 } | 457 } |
| 462 | 458 |
| 463 void logSummary(log(message)) { | 459 void logSummary(log(message)) { |
| 464 log('Compiled ${generatedCode.length} methods.'); | 460 log('Compiled ${generatedCode.length} methods.'); |
| 465 nativeEnqueuer.logSummary(log); | 461 nativeEnqueuer.logSummary(log); |
| 466 } | 462 } |
| 467 | 463 |
| 468 String toString() => 'Enqueuer($name)'; | 464 String toString() => 'Enqueuer($name)'; |
| 469 | 465 |
| 470 void _forgetElement(Element element) { | |
| 471 _universe.forgetElement(element, _compiler); | |
| 472 _processedClasses.remove(element); | |
| 473 _instanceMembersByName[element.name]?.remove(element); | |
| 474 _instanceFunctionsByName[element.name]?.remove(element); | |
| 475 } | |
| 476 | |
| 477 ImpactUseCase get impactUse => IMPACT_USE; | 466 ImpactUseCase get impactUse => IMPACT_USE; |
| 478 | 467 |
| 479 bool isProcessed(Element member) => | 468 bool isProcessed(Element member) => |
| 480 member.isAbstract || generatedCode.containsKey(member); | 469 member.isAbstract || generatedCode.containsKey(member); |
| 481 | 470 |
| 482 void _registerNoSuchMethod(Element element) { | 471 void _registerNoSuchMethod(Element element) { |
| 483 if (!_enabledNoSuchMethod && _backend.enabledNoSuchMethod) { | 472 if (!_enabledNoSuchMethod && _backend.enabledNoSuchMethod) { |
| 484 applyImpact(_backend.enableNoSuchMethod()); | 473 applyImpact(_backend.enableNoSuchMethod()); |
| 485 _enabledNoSuchMethod = true; | 474 _enabledNoSuchMethod = true; |
| 486 } | 475 } |
| 487 } | 476 } |
| 488 | 477 |
| 489 void forgetElement(Element element, Compiler compiler) { | 478 void forgetEntity(Element element, Compiler compiler) { |
| 490 _forgetElement(element); | 479 _universe.forgetElement(element, _compiler); |
| 480 _processedClasses.remove(element); |
| 481 _instanceMembersByName[element.name]?.remove(element); |
| 482 _instanceFunctionsByName[element.name]?.remove(element); |
| 491 generatedCode.remove(element); | 483 generatedCode.remove(element); |
| 492 if (element is MemberElement) { | 484 if (element is MemberElement) { |
| 493 for (Element closure in element.nestedClosures) { | 485 for (Element closure in element.nestedClosures) { |
| 494 generatedCode.remove(closure); | 486 generatedCode.remove(closure); |
| 495 removeFromSet(_instanceMembersByName, closure); | 487 removeFromSet(_instanceMembersByName, closure); |
| 496 removeFromSet(_instanceFunctionsByName, closure); | 488 removeFromSet(_instanceFunctionsByName, closure); |
| 497 } | 489 } |
| 498 } | 490 } |
| 499 } | 491 } |
| 500 | 492 |
| 501 @override | 493 @override |
| 502 Iterable<Entity> get processedEntities => generatedCode.keys; | 494 Iterable<Entity> get processedEntities => generatedCode.keys; |
| 503 | 495 |
| 504 @override | 496 @override |
| 505 Iterable<ClassElement> get processedClasses => _processedClasses; | 497 Iterable<ClassEntity> get processedClasses => _processedClasses; |
| 506 } | 498 } |
| 507 | 499 |
| 508 void removeFromSet(Map<String, Set<Element>> map, Element element) { | 500 void removeFromSet(Map<String, Set<Element>> map, Element element) { |
| 509 Set<Element> set = map[element.name]; | 501 Set<Element> set = map[element.name]; |
| 510 if (set == null) return; | 502 if (set == null) return; |
| 511 set.remove(element); | 503 set.remove(element); |
| 512 } | 504 } |
| OLD | NEW |