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

Side by Side Diff: pkg/compiler/lib/src/universe/world_builder.dart

Issue 2558013002: Move handling of regular static use from ResolutionEnqueuer to ResolutionWorldBuilderImpl (Closed)
Patch Set: Add TODO Created 4 years 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) 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 universe; 5 library universe;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import '../cache_strategy.dart'; 9 import '../cache_strategy.dart';
10 import '../common.dart'; 10 import '../common.dart';
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 final Map<String, Map<Selector, SelectorConstraints>> _invokedNames = 368 final Map<String, Map<Selector, SelectorConstraints>> _invokedNames =
369 <String, Map<Selector, SelectorConstraints>>{}; 369 <String, Map<Selector, SelectorConstraints>>{};
370 final Map<String, Map<Selector, SelectorConstraints>> _invokedGetters = 370 final Map<String, Map<Selector, SelectorConstraints>> _invokedGetters =
371 <String, Map<Selector, SelectorConstraints>>{}; 371 <String, Map<Selector, SelectorConstraints>>{};
372 final Map<String, Map<Selector, SelectorConstraints>> _invokedSetters = 372 final Map<String, Map<Selector, SelectorConstraints>> _invokedSetters =
373 <String, Map<Selector, SelectorConstraints>>{}; 373 <String, Map<Selector, SelectorConstraints>>{};
374 374
375 final Map<ClassElement, _ClassUsage> _processedClasses = 375 final Map<ClassElement, _ClassUsage> _processedClasses =
376 <ClassElement, _ClassUsage>{}; 376 <ClassElement, _ClassUsage>{};
377 377
378 /// Map of registers usage of instance members of live classes. 378 /// Map of registered usage of static members of live classes.
379 final Map<Entity, _StaticMemberUsage> _staticMemberUsage =
380 <Entity, _StaticMemberUsage>{};
381
382 /// Map of registered usage of instance members of live classes.
379 final Map<MemberEntity, _MemberUsage> _instanceMemberUsage = 383 final Map<MemberEntity, _MemberUsage> _instanceMemberUsage =
380 <MemberEntity, _MemberUsage>{}; 384 <MemberEntity, _MemberUsage>{};
381 385
382 /// Map containing instance members of live classes that are not yet live 386 /// Map containing instance members of live classes that are not yet live
383 /// themselves. 387 /// themselves.
384 final Map<String, Set<_MemberUsage>> _instanceMembersByName = 388 final Map<String, Set<_MemberUsage>> _instanceMembersByName =
385 <String, Set<_MemberUsage>>{}; 389 <String, Set<_MemberUsage>>{};
386 390
387 /// Map containing instance methods of live classes that are not yet 391 /// Map containing instance methods of live classes that are not yet
388 /// closurized. 392 /// closurized.
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 DartType registerIsCheck(DartType type, Resolution resolution) { 687 DartType registerIsCheck(DartType type, Resolution resolution) {
684 type.computeUnaliased(resolution); 688 type.computeUnaliased(resolution);
685 type = type.unaliased; 689 type = type.unaliased;
686 // Even in checked mode, type annotations for return type and argument 690 // Even in checked mode, type annotations for return type and argument
687 // types do not imply type checks, so there should never be a check 691 // types do not imply type checks, so there should never be a check
688 // against the type variable of a typedef. 692 // against the type variable of a typedef.
689 isChecks.add(type); 693 isChecks.add(type);
690 return type; 694 return type;
691 } 695 }
692 696
693 void registerStaticUse(StaticUse staticUse) { 697 void registerStaticUse(StaticUse staticUse, MemberUsed memberUsed) {
Harry Terkelsen 2016/12/07 21:02:00 Maybe rename this typedef to 'MemberUsedCallback'
Johnni Winther 2016/12/08 08:56:12 Done.
694 Element element = staticUse.element; 698 Element element = staticUse.element;
699 assert(invariant(element, element.isDeclaration,
700 message: "Element ${element} is not the declaration."));
701 _StaticMemberUsage usage = _staticMemberUsage.putIfAbsent(element, () {
702 if ((element.isStatic || element.isTopLevel) && element.isFunction) {
703 return new _StaticFunctionUsage(element);
704 } else {
705 return new _GeneralStaticMemberUsage(element);
706 }
707 });
708 EnumSet<MemberUse> useSet = new EnumSet<MemberUse>();
709
695 if (Elements.isStaticOrTopLevel(element) && element.isField) { 710 if (Elements.isStaticOrTopLevel(element) && element.isField) {
696 allReferencedStaticFields.add(element); 711 allReferencedStaticFields.add(element);
697 } 712 }
713 // TODO(johnniwinther): Avoid this. Currently [FIELD_GET] and
714 // [FIELD_SET] contains [BoxFieldElement]s which we cannot enqueue.
715 // Also [CLOSURE] contains [LocalFunctionElement] which we cannot
716 // enqueue.
698 switch (staticUse.kind) { 717 switch (staticUse.kind) {
699 case StaticUseKind.SUPER_FIELD_SET: 718 case StaticUseKind.FIELD_GET:
719 break;
700 case StaticUseKind.FIELD_SET: 720 case StaticUseKind.FIELD_SET:
701 fieldSetters.add(element); 721 fieldSetters.add(element);
702 break; 722 break;
723 case StaticUseKind.CLOSURE:
724 LocalFunctionElement closure = staticUse.element;
725 if (closure.type.containsTypeVariables) {
726 closuresWithFreeTypeVariables.add(closure);
727 }
728 allClosures.add(element);
729 break;
703 case StaticUseKind.SUPER_TEAR_OFF: 730 case StaticUseKind.SUPER_TEAR_OFF:
731 useSet.addAll(usage.tearOff());
704 methodsNeedingSuperGetter.add(element); 732 methodsNeedingSuperGetter.add(element);
705 break; 733 break;
734 case StaticUseKind.SUPER_FIELD_SET:
735 fieldSetters.add(element);
736 useSet.addAll(usage.normalUse());
737 break;
738 case StaticUseKind.STATIC_TEAR_OFF:
739 useSet.addAll(usage.tearOff());
740 break;
706 case StaticUseKind.GENERAL: 741 case StaticUseKind.GENERAL:
707 case StaticUseKind.DIRECT_USE: 742 case StaticUseKind.DIRECT_USE:
708 case StaticUseKind.STATIC_TEAR_OFF:
709 case StaticUseKind.FIELD_GET:
710 case StaticUseKind.CONSTRUCTOR_INVOKE: 743 case StaticUseKind.CONSTRUCTOR_INVOKE:
711 case StaticUseKind.CONST_CONSTRUCTOR_INVOKE: 744 case StaticUseKind.CONST_CONSTRUCTOR_INVOKE:
712 case StaticUseKind.REDIRECTION: 745 case StaticUseKind.REDIRECTION:
713 break; 746 useSet.addAll(usage.normalUse());
714 case StaticUseKind.CLOSURE:
715 allClosures.add(element);
716 break; 747 break;
717 case StaticUseKind.DIRECT_INVOKE: 748 case StaticUseKind.DIRECT_INVOKE:
718 invariant( 749 invariant(
719 element, 'Direct static use is not supported for resolution.'); 750 element, 'Direct static use is not supported for resolution.');
720 break; 751 break;
721 } 752 }
753 if (useSet.isNotEmpty) {
754 memberUsed(usage.entity, useSet);
755 }
722 } 756 }
723 757
724 void forgetEntity(Entity entity, Compiler compiler) { 758 void forgetEntity(Entity entity, Compiler compiler) {
725 allClosures.remove(entity); 759 allClosures.remove(entity);
726 slowDirectlyNestedClosures(entity).forEach(compiler.forgetElement); 760 slowDirectlyNestedClosures(entity).forEach(compiler.forgetElement);
727 closurizedMembers.remove(entity); 761 closurizedMembers.remove(entity);
728 fieldSetters.remove(entity); 762 fieldSetters.remove(entity);
729 _instantiationInfo.remove(entity); 763 _instantiationInfo.remove(entity);
730 764
731 void removeUsage(Set<_MemberUsage> set, Entity entity) { 765 void removeUsage(Set<_MemberUsage> set, Entity entity) {
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 class ClassUses { 1476 class ClassUses {
1443 static const EnumSet<ClassUse> NONE = const EnumSet<ClassUse>.fixed(0); 1477 static const EnumSet<ClassUse> NONE = const EnumSet<ClassUse>.fixed(0);
1444 static const EnumSet<ClassUse> INSTANTIATED_ONLY = 1478 static const EnumSet<ClassUse> INSTANTIATED_ONLY =
1445 const EnumSet<ClassUse>.fixed(1); 1479 const EnumSet<ClassUse>.fixed(1);
1446 static const EnumSet<ClassUse> IMPLEMENTED_ONLY = 1480 static const EnumSet<ClassUse> IMPLEMENTED_ONLY =
1447 const EnumSet<ClassUse>.fixed(2); 1481 const EnumSet<ClassUse>.fixed(2);
1448 static const EnumSet<ClassUse> ALL = const EnumSet<ClassUse>.fixed(3); 1482 static const EnumSet<ClassUse> ALL = const EnumSet<ClassUse>.fixed(3);
1449 } 1483 }
1450 1484
1451 typedef void ClassUsed(ClassEntity cls, EnumSet<ClassUse> useSet); 1485 typedef void ClassUsed(ClassEntity cls, EnumSet<ClassUse> useSet);
1486
1487 // TODO(johnniwinther): Merge this with [_MemberUsage].
1488 abstract class _StaticMemberUsage extends _AbstractUsage<MemberUse> {
1489 final Entity entity;
1490
1491 bool hasNormalUse = false;
1492 bool get hasClosurization => false;
1493
1494 _StaticMemberUsage.internal(this.entity);
1495
1496 EnumSet<MemberUse> normalUse() {
1497 if (hasNormalUse) {
1498 return MemberUses.NONE;
1499 }
1500 hasNormalUse = true;
1501 return _pendingUse.removeAll(MemberUses.NORMAL_ONLY);
1502 }
1503
1504 EnumSet<MemberUse> tearOff();
1505
1506 @override
1507 EnumSet<MemberUse> get _originalUse => MemberUses.NORMAL_ONLY;
1508
1509 String toString() => entity.toString();
1510 }
1511
1512 class _GeneralStaticMemberUsage extends _StaticMemberUsage {
1513 _GeneralStaticMemberUsage(Entity entity) : super.internal(entity);
1514
1515 EnumSet<MemberUse> tearOff() => normalUse();
1516 }
1517
1518 class _StaticFunctionUsage extends _StaticMemberUsage {
1519 bool hasClosurization = false;
1520
1521 _StaticFunctionUsage(Entity entity) : super.internal(entity);
1522
1523 EnumSet<MemberUse> tearOff() {
1524 if (hasClosurization) {
1525 return MemberUses.NONE;
1526 }
1527 hasNormalUse = hasClosurization = true;
1528 return _pendingUse.removeAll(MemberUses.ALL);
1529 }
1530
1531 @override
1532 EnumSet<MemberUse> get _originalUse => MemberUses.ALL;
1533 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698