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.world; | 5 library dart2js.world; |
6 | 6 |
7 import 'closure.dart' show SynthesizedCallMethodElementX; | 7 import 'closure.dart' show SynthesizedCallMethodElementX; |
8 import 'common.dart'; | 8 import 'common.dart'; |
9 import 'common/backend_api.dart' show Backend; | 9 import 'common/backend_api.dart' show Backend; |
10 import 'compiler.dart' show Compiler; | 10 import 'compiler.dart' show Compiler; |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 assert(isClosed); | 453 assert(isClosed); |
454 if (_liveMixinUses == null) { | 454 if (_liveMixinUses == null) { |
455 _liveMixinUses = new Map<ClassElement, List<MixinApplicationElement>>(); | 455 _liveMixinUses = new Map<ClassElement, List<MixinApplicationElement>>(); |
456 for (ClassElement mixin in _mixinUses.keys) { | 456 for (ClassElement mixin in _mixinUses.keys) { |
457 List<MixinApplicationElement> uses = <MixinApplicationElement>[]; | 457 List<MixinApplicationElement> uses = <MixinApplicationElement>[]; |
458 | 458 |
459 void addLiveUse(MixinApplicationElement mixinApplication) { | 459 void addLiveUse(MixinApplicationElement mixinApplication) { |
460 if (isInstantiated(mixinApplication)) { | 460 if (isInstantiated(mixinApplication)) { |
461 uses.add(mixinApplication); | 461 uses.add(mixinApplication); |
462 } else if (mixinApplication.isNamedMixinApplication) { | 462 } else if (mixinApplication.isNamedMixinApplication) { |
463 List<MixinApplicationElement> next = _mixinUses[mixinApplication]; | 463 Set<MixinApplicationElement> next = _mixinUses[mixinApplication]; |
464 if (next != null) { | 464 if (next != null) { |
465 next.forEach(addLiveUse); | 465 next.forEach(addLiveUse); |
466 } | 466 } |
467 } | 467 } |
468 } | 468 } |
469 | 469 |
470 _mixinUses[mixin].forEach(addLiveUse); | 470 _mixinUses[mixin].forEach(addLiveUse); |
471 if (uses.isNotEmpty) { | 471 if (uses.isNotEmpty) { |
472 _liveMixinUses[mixin] = uses; | 472 _liveMixinUses[mixin] = uses; |
473 } | 473 } |
(...skipping 30 matching lines...) Expand all Loading... |
504 } | 504 } |
505 | 505 |
506 final Compiler compiler; | 506 final Compiler compiler; |
507 Backend get backend => compiler.backend; | 507 Backend get backend => compiler.backend; |
508 final FunctionSet allFunctions; | 508 final FunctionSet allFunctions; |
509 final Set<Element> functionsCalledInLoop = new Set<Element>(); | 509 final Set<Element> functionsCalledInLoop = new Set<Element>(); |
510 final Map<Element, SideEffects> sideEffects = new Map<Element, SideEffects>(); | 510 final Map<Element, SideEffects> sideEffects = new Map<Element, SideEffects>(); |
511 | 511 |
512 final Set<TypedefElement> allTypedefs = new Set<TypedefElement>(); | 512 final Set<TypedefElement> allTypedefs = new Set<TypedefElement>(); |
513 | 513 |
514 final Map<ClassElement, List<MixinApplicationElement>> _mixinUses = | 514 final Map<ClassElement, Set<MixinApplicationElement>> _mixinUses = |
515 new Map<ClassElement, List<MixinApplicationElement>>(); | 515 new Map<ClassElement, Set<MixinApplicationElement>>(); |
516 Map<ClassElement, List<MixinApplicationElement>> _liveMixinUses; | 516 Map<ClassElement, List<MixinApplicationElement>> _liveMixinUses; |
517 | 517 |
518 final Map<ClassElement, Set<ClassElement>> _typesImplementedBySubclasses = | 518 final Map<ClassElement, Set<ClassElement>> _typesImplementedBySubclasses = |
519 new Map<ClassElement, Set<ClassElement>>(); | 519 new Map<ClassElement, Set<ClassElement>>(); |
520 | 520 |
521 // We keep track of subtype and subclass relationships in four | 521 // We keep track of subtype and subclass relationships in four |
522 // distinct sets to make class hierarchy analysis faster. | 522 // distinct sets to make class hierarchy analysis faster. |
523 final Map<ClassElement, ClassHierarchyNode> _classHierarchyNodes = | 523 final Map<ClassElement, ClassHierarchyNode> _classHierarchyNodes = |
524 <ClassElement, ClassHierarchyNode>{}; | 524 <ClassElement, ClassHierarchyNode>{}; |
525 final Map<ClassElement, ClassSet> _classSets = <ClassElement, ClassSet>{}; | 525 final Map<ClassElement, ClassSet> _classSets = <ClassElement, ClassSet>{}; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 return _classSets.putIfAbsent(cls, () { | 598 return _classSets.putIfAbsent(cls, () { |
599 ClassHierarchyNode node = _ensureClassHierarchyNode(cls); | 599 ClassHierarchyNode node = _ensureClassHierarchyNode(cls); |
600 ClassSet classSet = new ClassSet(node); | 600 ClassSet classSet = new ClassSet(node); |
601 | 601 |
602 for (InterfaceType type in cls.allSupertypes) { | 602 for (InterfaceType type in cls.allSupertypes) { |
603 // TODO(johnniwinther): Optimization: Avoid adding [cls] to | 603 // TODO(johnniwinther): Optimization: Avoid adding [cls] to |
604 // superclasses. | 604 // superclasses. |
605 ClassSet subtypeSet = _ensureClassSet(type.element); | 605 ClassSet subtypeSet = _ensureClassSet(type.element); |
606 subtypeSet.addSubtype(node); | 606 subtypeSet.addSubtype(node); |
607 } | 607 } |
| 608 if (cls.isMixinApplication) { |
| 609 // TODO(johnniwinther): Store this in the [ClassSet]. |
| 610 MixinApplicationElement mixinApplication = cls; |
| 611 if (mixinApplication.mixin != null) { |
| 612 // If [mixinApplication] is malformed [mixin] is `null`. |
| 613 registerMixinUse(mixinApplication, mixinApplication.mixin); |
| 614 } |
| 615 } |
| 616 |
608 return classSet; | 617 return classSet; |
609 }); | 618 }); |
610 } | 619 } |
611 | 620 |
612 void _updateSuperClassHierarchyNodeForClass(ClassHierarchyNode node) { | 621 void _updateSuperClassHierarchyNodeForClass(ClassHierarchyNode node) { |
613 // Ensure that classes implicitly implementing `Function` are in its | 622 // Ensure that classes implicitly implementing `Function` are in its |
614 // subtype set. | 623 // subtype set. |
615 ClassElement cls = node.cls; | 624 ClassElement cls = node.cls; |
616 if (cls != coreClasses.functionClass && | 625 if (cls != coreClasses.functionClass && |
617 cls.implementsFunction(coreClasses)) { | 626 cls.implementsFunction(coreClasses)) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 getClassHierarchyNode(coreClasses.objectClass) | 689 getClassHierarchyNode(coreClasses.objectClass) |
681 .printOn(sb, ' ', instantiatedOnly: cls == null, withRespectTo: cls); | 690 .printOn(sb, ' ', instantiatedOnly: cls == null, withRespectTo: cls); |
682 return sb.toString(); | 691 return sb.toString(); |
683 } | 692 } |
684 | 693 |
685 void registerMixinUse( | 694 void registerMixinUse( |
686 MixinApplicationElement mixinApplication, ClassElement mixin) { | 695 MixinApplicationElement mixinApplication, ClassElement mixin) { |
687 // TODO(johnniwinther): Add map restricted to live classes. | 696 // TODO(johnniwinther): Add map restricted to live classes. |
688 // We don't support patch classes as mixin. | 697 // We don't support patch classes as mixin. |
689 assert(mixin.isDeclaration); | 698 assert(mixin.isDeclaration); |
690 List<MixinApplicationElement> users = _mixinUses.putIfAbsent( | 699 Set<MixinApplicationElement> users = _mixinUses.putIfAbsent( |
691 mixin, () => new List<MixinApplicationElement>()); | 700 mixin, () => new Set<MixinApplicationElement>()); |
692 users.add(mixinApplication); | 701 users.add(mixinApplication); |
693 } | 702 } |
694 | 703 |
695 bool hasAnyUserDefinedGetter(Selector selector, ti.TypeMask mask) { | 704 bool hasAnyUserDefinedGetter(Selector selector, ti.TypeMask mask) { |
696 return allFunctions.filter(selector, mask).any((each) => each.isGetter); | 705 return allFunctions.filter(selector, mask).any((each) => each.isGetter); |
697 } | 706 } |
698 | 707 |
699 void registerUsedElement(Element element) { | 708 void registerUsedElement(Element element) { |
700 if (element.isInstanceMember && !element.isAbstract) { | 709 if (element.isInstanceMember && !element.isAbstract) { |
701 allFunctions.add(element); | 710 allFunctions.add(element); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 // function expressions's element. | 826 // function expressions's element. |
818 // TODO(herhut): Generate classes for function expressions earlier. | 827 // TODO(herhut): Generate classes for function expressions earlier. |
819 if (element is SynthesizedCallMethodElementX) { | 828 if (element is SynthesizedCallMethodElementX) { |
820 return getMightBePassedToApply(element.expression); | 829 return getMightBePassedToApply(element.expression); |
821 } | 830 } |
822 return functionsThatMightBePassedToApply.contains(element); | 831 return functionsThatMightBePassedToApply.contains(element); |
823 } | 832 } |
824 | 833 |
825 bool get hasClosedWorldAssumption => !compiler.options.hasIncrementalSupport; | 834 bool get hasClosedWorldAssumption => !compiler.options.hasIncrementalSupport; |
826 } | 835 } |
OLD | NEW |