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

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

Issue 2603263002: Prefix resolution_types with Resolution. (Closed)
Patch Set: Rebased Created 3 years, 11 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
« no previous file with comments | « pkg/compiler/lib/src/universe/use.dart ('k') | pkg/compiler/lib/src/world.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 // TODO(johnniwinther): Move common implementation to a [WorldBuilderBase] when 150 // TODO(johnniwinther): Move common implementation to a [WorldBuilderBase] when
151 // universes and worlds have been unified. 151 // universes and worlds have been unified.
152 abstract class WorldBuilder { 152 abstract class WorldBuilder {
153 /// All directly instantiated classes, that is, classes with a generative 153 /// All directly instantiated classes, that is, classes with a generative
154 /// constructor that has been called directly and not only through a 154 /// constructor that has been called directly and not only through a
155 /// super-call. 155 /// super-call.
156 // TODO(johnniwinther): Improve semantic precision. 156 // TODO(johnniwinther): Improve semantic precision.
157 Iterable<ClassElement> get directlyInstantiatedClasses; 157 Iterable<ClassElement> get directlyInstantiatedClasses;
158 158
159 /// All types that are checked either through is, as or checked mode checks. 159 /// All types that are checked either through is, as or checked mode checks.
160 Iterable<DartType> get isChecks; 160 Iterable<ResolutionDartType> get isChecks;
161 161
162 /// Registers that [type] is checked in this universe. The unaliased type is 162 /// Registers that [type] is checked in this universe. The unaliased type is
163 /// returned. 163 /// returned.
164 DartType registerIsCheck(DartType type); 164 ResolutionDartType registerIsCheck(ResolutionDartType type);
165 165
166 /// All directly instantiated types, that is, the types of the directly 166 /// All directly instantiated types, that is, the types of the directly
167 /// instantiated classes. 167 /// instantiated classes.
168 // TODO(johnniwinther): Improve semantic precision. 168 // TODO(johnniwinther): Improve semantic precision.
169 Iterable<DartType> get instantiatedTypes; 169 Iterable<ResolutionDartType> get instantiatedTypes;
170 } 170 }
171 171
172 abstract class ResolutionWorldBuilder implements WorldBuilder, OpenWorld { 172 abstract class ResolutionWorldBuilder implements WorldBuilder, OpenWorld {
173 /// Set of (live) local functions (closures) whose signatures reference type 173 /// Set of (live) local functions (closures) whose signatures reference type
174 /// variables. 174 /// variables.
175 /// 175 ///
176 /// A live function is one whose enclosing member function has been enqueued. 176 /// A live function is one whose enclosing member function has been enqueued.
177 Iterable<Element> get closuresWithFreeTypeVariables; 177 Iterable<Element> get closuresWithFreeTypeVariables;
178 178
179 /// Set of (live) `call` methods whose signatures reference type variables. 179 /// Set of (live) `call` methods whose signatures reference type variables.
(...skipping 27 matching lines...) Expand all
207 207
208 /// The closed world computed by this world builder. 208 /// The closed world computed by this world builder.
209 /// 209 ///
210 /// This is only available after the world builder has been closed. 210 /// This is only available after the world builder has been closed.
211 ClosedWorld get closedWorldForTesting; 211 ClosedWorld get closedWorldForTesting;
212 } 212 }
213 213
214 /// The type and kind of an instantiation registered through 214 /// The type and kind of an instantiation registered through
215 /// `ResolutionWorldBuilder.registerTypeInstantiation`. 215 /// `ResolutionWorldBuilder.registerTypeInstantiation`.
216 class Instance { 216 class Instance {
217 final InterfaceType type; 217 final ResolutionInterfaceType type;
218 final Instantiation kind; 218 final Instantiation kind;
219 final bool isRedirection; 219 final bool isRedirection;
220 220
221 Instance(this.type, this.kind, {this.isRedirection: false}); 221 Instance(this.type, this.kind, {this.isRedirection: false});
222 222
223 int get hashCode { 223 int get hashCode {
224 return Hashing.objectHash( 224 return Hashing.objectHash(
225 type, Hashing.objectHash(kind, Hashing.objectHash(isRedirection))); 225 type, Hashing.objectHash(kind, Hashing.objectHash(isRedirection)));
226 } 226 }
227 227
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 /// DivElement: { 308 /// DivElement: {
309 /// DivElement abstractly, // from `new DivElement()` 309 /// DivElement abstractly, // from `new DivElement()`
310 /// }, 310 /// },
311 /// } 311 /// }
312 /// 312 ///
313 /// If the constructor is unknown, for instance for native or mirror usage, 313 /// If the constructor is unknown, for instance for native or mirror usage,
314 /// `null` is used as key. 314 /// `null` is used as key.
315 Map<ConstructorElement, Set<Instance>> instantiationMap; 315 Map<ConstructorElement, Set<Instance>> instantiationMap;
316 316
317 /// Register [type] as the instantiation [kind] using [constructor]. 317 /// Register [type] as the instantiation [kind] using [constructor].
318 void addInstantiation( 318 void addInstantiation(ConstructorElement constructor,
319 ConstructorElement constructor, InterfaceType type, Instantiation kind, 319 ResolutionInterfaceType type, Instantiation kind,
320 {bool isRedirection: false}) { 320 {bool isRedirection: false}) {
321 instantiationMap ??= <ConstructorElement, Set<Instance>>{}; 321 instantiationMap ??= <ConstructorElement, Set<Instance>>{};
322 instantiationMap 322 instantiationMap
323 .putIfAbsent(constructor, () => new Set<Instance>()) 323 .putIfAbsent(constructor, () => new Set<Instance>())
324 .add(new Instance(type, kind, isRedirection: isRedirection)); 324 .add(new Instance(type, kind, isRedirection: isRedirection));
325 switch (kind) { 325 switch (kind) {
326 case Instantiation.DIRECTLY_INSTANTIATED: 326 case Instantiation.DIRECTLY_INSTANTIATED:
327 isDirectlyInstantiated = true; 327 isDirectlyInstantiated = true;
328 break; 328 break;
329 case Instantiation.ABSTRACTLY_INSTANTIATED: 329 case Instantiation.ABSTRACTLY_INSTANTIATED:
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 final Map<String, Set<_MemberUsage>> _instanceMembersByName = 416 final Map<String, Set<_MemberUsage>> _instanceMembersByName =
417 <String, Set<_MemberUsage>>{}; 417 <String, Set<_MemberUsage>>{};
418 418
419 /// Map containing instance methods of live classes that are not yet 419 /// Map containing instance methods of live classes that are not yet
420 /// closurized. 420 /// closurized.
421 final Map<String, Set<_MemberUsage>> _instanceFunctionsByName = 421 final Map<String, Set<_MemberUsage>> _instanceFunctionsByName =
422 <String, Set<_MemberUsage>>{}; 422 <String, Set<_MemberUsage>>{};
423 423
424 /// Fields set. 424 /// Fields set.
425 final Set<Element> fieldSetters = new Set<Element>(); 425 final Set<Element> fieldSetters = new Set<Element>();
426 final Set<DartType> isChecks = new Set<DartType>(); 426 final Set<ResolutionDartType> isChecks = new Set<ResolutionDartType>();
427 427
428 /** 428 /**
429 * Set of (live) [:call:] methods whose signatures reference type variables. 429 * Set of (live) [:call:] methods whose signatures reference type variables.
430 * 430 *
431 * A live [:call:] method is one whose enclosing class has been instantiated. 431 * A live [:call:] method is one whose enclosing class has been instantiated.
432 */ 432 */
433 final Set<Element> callMethodsWithFreeTypeVariables = new Set<Element>(); 433 final Set<Element> callMethodsWithFreeTypeVariables = new Set<Element>();
434 434
435 /** 435 /**
436 * Set of (live) local functions (closures) whose signatures reference type 436 * Set of (live) local functions (closures) whose signatures reference type
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 } 519 }
520 }); 520 });
521 return classes; 521 return classes;
522 } 522 }
523 523
524 /// All directly instantiated types, that is, the types of the directly 524 /// All directly instantiated types, that is, the types of the directly
525 /// instantiated classes. 525 /// instantiated classes.
526 /// 526 ///
527 /// See [directlyInstantiatedClasses]. 527 /// See [directlyInstantiatedClasses].
528 // TODO(johnniwinther): Improve semantic precision. 528 // TODO(johnniwinther): Improve semantic precision.
529 Iterable<DartType> get instantiatedTypes { 529 Iterable<ResolutionDartType> get instantiatedTypes {
530 Set<InterfaceType> types = new Set<InterfaceType>(); 530 Set<ResolutionInterfaceType> types = new Set<ResolutionInterfaceType>();
531 getInstantiationMap().forEach((_, InstantiationInfo info) { 531 getInstantiationMap().forEach((_, InstantiationInfo info) {
532 if (info.instantiationMap != null) { 532 if (info.instantiationMap != null) {
533 for (Set<Instance> instances in info.instantiationMap.values) { 533 for (Set<Instance> instances in info.instantiationMap.values) {
534 for (Instance instance in instances) { 534 for (Instance instance in instances) {
535 types.add(instance.type); 535 types.add(instance.type);
536 } 536 }
537 } 537 }
538 } 538 }
539 }); 539 });
540 return types; 540 return types;
541 } 541 }
542 542
543 /// Returns `true` if [cls] is considered to be implemented by an 543 /// Returns `true` if [cls] is considered to be implemented by an
544 /// instantiated class, either directly, through subclasses or through 544 /// instantiated class, either directly, through subclasses or through
545 /// subtypes. The latter case only contains spurious information from 545 /// subtypes. The latter case only contains spurious information from
546 /// instantiations through factory constructors and mixins. 546 /// instantiations through factory constructors and mixins.
547 // TODO(johnniwinther): Improve semantic precision. 547 // TODO(johnniwinther): Improve semantic precision.
548 bool isImplemented(ClassElement cls) { 548 bool isImplemented(ClassElement cls) {
549 return _implementedClasses.contains(cls.declaration); 549 return _implementedClasses.contains(cls.declaration);
550 } 550 }
551 551
552 /// Register [type] as (directly) instantiated. 552 /// Register [type] as (directly) instantiated.
553 /// 553 ///
554 /// If [byMirrors] is `true`, the instantiation is through mirrors. 554 /// If [byMirrors] is `true`, the instantiation is through mirrors.
555 // TODO(johnniwinther): Fully enforce the separation between exact, through 555 // TODO(johnniwinther): Fully enforce the separation between exact, through
556 // subclass and through subtype instantiated types/classes. 556 // subclass and through subtype instantiated types/classes.
557 // TODO(johnniwinther): Support unknown type arguments for generic types. 557 // TODO(johnniwinther): Support unknown type arguments for generic types.
558 void registerTypeInstantiation( 558 void registerTypeInstantiation(
559 InterfaceType type, ClassUsedCallback classUsed, 559 ResolutionInterfaceType type, ClassUsedCallback classUsed,
560 {ConstructorElement constructor, 560 {ConstructorElement constructor,
561 bool byMirrors: false, 561 bool byMirrors: false,
562 bool isRedirection: false}) { 562 bool isRedirection: false}) {
563 ClassElement cls = type.element; 563 ClassElement cls = type.element;
564 cls.ensureResolved(_resolution); 564 cls.ensureResolved(_resolution);
565 InstantiationInfo info = 565 InstantiationInfo info =
566 _instantiationInfo.putIfAbsent(cls, () => new InstantiationInfo()); 566 _instantiationInfo.putIfAbsent(cls, () => new InstantiationInfo());
567 Instantiation kind = Instantiation.UNINSTANTIATED; 567 Instantiation kind = Instantiation.UNINSTANTIATED;
568 bool isNative = _backend.isNative(cls); 568 bool isNative = _backend.isNative(cls);
569 if (!cls.isAbstract || 569 if (!cls.isAbstract ||
(...skipping 13 matching lines...) Expand all
583 } 583 }
584 _processInstantiatedClass(cls, classUsed); 584 _processInstantiatedClass(cls, classUsed);
585 } 585 }
586 info.addInstantiation(constructor, type, kind, 586 info.addInstantiation(constructor, type, kind,
587 isRedirection: isRedirection); 587 isRedirection: isRedirection);
588 588
589 // TODO(johnniwinther): Use [_instantiationInfo] to compute this information 589 // TODO(johnniwinther): Use [_instantiationInfo] to compute this information
590 // instead. 590 // instead.
591 if (_implementedClasses.add(cls)) { 591 if (_implementedClasses.add(cls)) {
592 classUsed(cls, _getClassUsage(cls).implement()); 592 classUsed(cls, _getClassUsage(cls).implement());
593 cls.allSupertypes.forEach((InterfaceType supertype) { 593 cls.allSupertypes.forEach((ResolutionInterfaceType supertype) {
594 if (_implementedClasses.add(supertype.element)) { 594 if (_implementedClasses.add(supertype.element)) {
595 classUsed( 595 classUsed(
596 supertype.element, _getClassUsage(supertype.element).implement()); 596 supertype.element, _getClassUsage(supertype.element).implement());
597 } 597 }
598 }); 598 });
599 } 599 }
600 } 600 }
601 601
602 @override 602 @override
603 void forEachInstantiatedClass(f(ClassElement cls, InstantiationInfo info)) { 603 void forEachInstantiatedClass(f(ClassElement cls, InstantiationInfo info)) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 .forEach((ConstructorElement constructor, Set<Instance> set) { 638 .forEach((ConstructorElement constructor, Set<Instance> set) {
639 for (Instance instance in set) { 639 for (Instance instance in set) {
640 if (instance.isRedirection) { 640 if (instance.isRedirection) {
641 continue; 641 continue;
642 } 642 }
643 if (constructor == null || !constructor.isRedirectingFactory) { 643 if (constructor == null || !constructor.isRedirectingFactory) {
644 infoFor(cls) 644 infoFor(cls)
645 .addInstantiation(constructor, instance.type, instance.kind); 645 .addInstantiation(constructor, instance.type, instance.kind);
646 } else { 646 } else {
647 ConstructorElement target = constructor.effectiveTarget; 647 ConstructorElement target = constructor.effectiveTarget;
648 InterfaceType targetType = 648 ResolutionInterfaceType targetType =
649 constructor.computeEffectiveTargetType(instance.type); 649 constructor.computeEffectiveTargetType(instance.type);
650 Instantiation kind = Instantiation.DIRECTLY_INSTANTIATED; 650 Instantiation kind = Instantiation.DIRECTLY_INSTANTIATED;
651 if (target.enclosingClass.isAbstract) { 651 if (target.enclosingClass.isAbstract) {
652 // If target is a factory constructor on an abstract class. 652 // If target is a factory constructor on an abstract class.
653 kind = Instantiation.UNINSTANTIATED; 653 kind = Instantiation.UNINSTANTIATED;
654 } 654 }
655 infoFor(targetType.element) 655 infoFor(targetType.element)
656 .addInstantiation(target, targetType, kind); 656 .addInstantiation(target, targetType, kind);
657 } 657 }
658 } 658 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 ReceiverConstraint mask = dynamicUse.mask; 718 ReceiverConstraint mask = dynamicUse.mask;
719 Map<Selector, SelectorConstraints> selectors = selectorMap.putIfAbsent( 719 Map<Selector, SelectorConstraints> selectors = selectorMap.putIfAbsent(
720 name, () => new Maplet<Selector, SelectorConstraints>()); 720 name, () => new Maplet<Selector, SelectorConstraints>());
721 UniverseSelectorConstraints constraints = 721 UniverseSelectorConstraints constraints =
722 selectors.putIfAbsent(selector, () { 722 selectors.putIfAbsent(selector, () {
723 return selectorConstraintsStrategy.createSelectorConstraints(selector); 723 return selectorConstraintsStrategy.createSelectorConstraints(selector);
724 }); 724 });
725 return constraints.addReceiverConstraint(mask); 725 return constraints.addReceiverConstraint(mask);
726 } 726 }
727 727
728 DartType registerIsCheck(DartType type) { 728 ResolutionDartType registerIsCheck(ResolutionDartType type) {
729 type.computeUnaliased(_resolution); 729 type.computeUnaliased(_resolution);
730 type = type.unaliased; 730 type = type.unaliased;
731 // Even in checked mode, type annotations for return type and argument 731 // Even in checked mode, type annotations for return type and argument
732 // types do not imply type checks, so there should never be a check 732 // types do not imply type checks, so there should never be a check
733 // against the type variable of a typedef. 733 // against the type variable of a typedef.
734 isChecks.add(type); 734 isChecks.add(type);
735 return type; 735 return type;
736 } 736 }
737 737
738 void registerStaticUse(StaticUse staticUse, MemberUsedCallback memberUsed) { 738 void registerStaticUse(StaticUse staticUse, MemberUsedCallback memberUsed) {
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 return new ClassHierarchyNode(parentNode, cls); 970 return new ClassHierarchyNode(parentNode, cls);
971 }); 971 });
972 } 972 }
973 973
974 ClassSet _ensureClassSet(ClassElement cls) { 974 ClassSet _ensureClassSet(ClassElement cls) {
975 cls = cls.declaration; 975 cls = cls.declaration;
976 return _classSets.putIfAbsent(cls, () { 976 return _classSets.putIfAbsent(cls, () {
977 ClassHierarchyNode node = _ensureClassHierarchyNode(cls); 977 ClassHierarchyNode node = _ensureClassHierarchyNode(cls);
978 ClassSet classSet = new ClassSet(node); 978 ClassSet classSet = new ClassSet(node);
979 979
980 for (InterfaceType type in cls.allSupertypes) { 980 for (ResolutionInterfaceType type in cls.allSupertypes) {
981 // TODO(johnniwinther): Optimization: Avoid adding [cls] to 981 // TODO(johnniwinther): Optimization: Avoid adding [cls] to
982 // superclasses. 982 // superclasses.
983 ClassSet subtypeSet = _ensureClassSet(type.element); 983 ClassSet subtypeSet = _ensureClassSet(type.element);
984 subtypeSet.addSubtype(node); 984 subtypeSet.addSubtype(node);
985 } 985 }
986 if (cls.isMixinApplication) { 986 if (cls.isMixinApplication) {
987 // TODO(johnniwinther): Store this in the [ClassSet]. 987 // TODO(johnniwinther): Store this in the [ClassSet].
988 MixinApplicationElement mixinApplication = cls; 988 MixinApplicationElement mixinApplication = cls;
989 if (mixinApplication.mixin != null) { 989 if (mixinApplication.mixin != null) {
990 // If [mixinApplication] is malformed [mixin] is `null`. 990 // If [mixinApplication] is malformed [mixin] is `null`.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 directlyInstantiated: info.isDirectlyInstantiated, 1045 directlyInstantiated: info.isDirectlyInstantiated,
1046 abstractlyInstantiated: info.isAbstractlyInstantiated); 1046 abstractlyInstantiated: info.isAbstractlyInstantiated);
1047 1047
1048 // Walk through the superclasses, and record the types 1048 // Walk through the superclasses, and record the types
1049 // implemented by that type on the superclasses. 1049 // implemented by that type on the superclasses.
1050 ClassElement superclass = cls.superclass; 1050 ClassElement superclass = cls.superclass;
1051 while (superclass != null) { 1051 while (superclass != null) {
1052 Set<Element> typesImplementedBySubclassesOfCls = 1052 Set<Element> typesImplementedBySubclassesOfCls =
1053 typesImplementedBySubclasses.putIfAbsent( 1053 typesImplementedBySubclasses.putIfAbsent(
1054 superclass, () => new Set<ClassElement>()); 1054 superclass, () => new Set<ClassElement>());
1055 for (DartType current in cls.allSupertypes) { 1055 for (ResolutionDartType current in cls.allSupertypes) {
1056 typesImplementedBySubclassesOfCls.add(current.element); 1056 typesImplementedBySubclassesOfCls.add(current.element);
1057 } 1057 }
1058 superclass = superclass.superclass; 1058 superclass = superclass.superclass;
1059 } 1059 }
1060 } 1060 }
1061 1061
1062 // Use the [:seenClasses:] set to include non-instantiated 1062 // Use the [:seenClasses:] set to include non-instantiated
1063 // classes: if the superclass of these classes require RTI, then 1063 // classes: if the superclass of these classes require RTI, then
1064 // they also need RTI, so that a constructor passes the type 1064 // they also need RTI, so that a constructor passes the type
1065 // variables to the super constructor. 1065 // variables to the super constructor.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 /// Invariant: Elements are declaration elements. 1153 /// Invariant: Elements are declaration elements.
1154 // TODO(johnniwinther): [_directlyInstantiatedClasses] and 1154 // TODO(johnniwinther): [_directlyInstantiatedClasses] and
1155 // [_instantiatedTypes] sets should be merged. 1155 // [_instantiatedTypes] sets should be merged.
1156 final Set<ClassElement> _directlyInstantiatedClasses = 1156 final Set<ClassElement> _directlyInstantiatedClasses =
1157 new Set<ClassElement>(); 1157 new Set<ClassElement>();
1158 1158
1159 /// The set of all directly instantiated types, that is, the types of the 1159 /// The set of all directly instantiated types, that is, the types of the
1160 /// directly instantiated classes. 1160 /// directly instantiated classes.
1161 /// 1161 ///
1162 /// See [_directlyInstantiatedClasses]. 1162 /// See [_directlyInstantiatedClasses].
1163 final Set<DartType> _instantiatedTypes = new Set<DartType>(); 1163 final Set<ResolutionDartType> _instantiatedTypes =
1164 new Set<ResolutionDartType>();
1164 1165
1165 /// Classes implemented by directly instantiated classes. 1166 /// Classes implemented by directly instantiated classes.
1166 final Set<ClassElement> _implementedClasses = new Set<ClassElement>(); 1167 final Set<ClassElement> _implementedClasses = new Set<ClassElement>();
1167 1168
1168 /// The set of all referenced static fields. 1169 /// The set of all referenced static fields.
1169 /// 1170 ///
1170 /// Invariant: Elements are declaration elements. 1171 /// Invariant: Elements are declaration elements.
1171 final Set<FieldElement> allReferencedStaticFields = new Set<FieldElement>(); 1172 final Set<FieldElement> allReferencedStaticFields = new Set<FieldElement>();
1172 1173
1173 /** 1174 /**
(...skipping 26 matching lines...) Expand all
1200 /// Map containing instance members of live classes that are not yet live 1201 /// Map containing instance members of live classes that are not yet live
1201 /// themselves. 1202 /// themselves.
1202 final Map<String, Set<_MemberUsage>> _instanceMembersByName = 1203 final Map<String, Set<_MemberUsage>> _instanceMembersByName =
1203 <String, Set<_MemberUsage>>{}; 1204 <String, Set<_MemberUsage>>{};
1204 1205
1205 /// Map containing instance methods of live classes that are not yet 1206 /// Map containing instance methods of live classes that are not yet
1206 /// closurized. 1207 /// closurized.
1207 final Map<String, Set<_MemberUsage>> _instanceFunctionsByName = 1208 final Map<String, Set<_MemberUsage>> _instanceFunctionsByName =
1208 <String, Set<_MemberUsage>>{}; 1209 <String, Set<_MemberUsage>>{};
1209 1210
1210 final Set<DartType> isChecks = new Set<DartType>(); 1211 final Set<ResolutionDartType> isChecks = new Set<ResolutionDartType>();
1211 1212
1212 final SelectorConstraintsStrategy selectorConstraintsStrategy; 1213 final SelectorConstraintsStrategy selectorConstraintsStrategy;
1213 1214
1214 CodegenWorldBuilderImpl(this._backend, this.selectorConstraintsStrategy); 1215 CodegenWorldBuilderImpl(this._backend, this.selectorConstraintsStrategy);
1215 1216
1216 void open(ClosedWorld closedWorld) { 1217 void open(ClosedWorld closedWorld) {
1217 assert(invariant(NO_LOCATION_SPANNABLE, __world == null, 1218 assert(invariant(NO_LOCATION_SPANNABLE, __world == null,
1218 message: "CodegenWorldBuilder has already been opened.")); 1219 message: "CodegenWorldBuilder has already been opened."));
1219 __world = closedWorld; 1220 __world = closedWorld;
1220 } 1221 }
(...skipping 21 matching lines...) Expand all
1242 // TODO(johnniwinther): Improve semantic precision. 1243 // TODO(johnniwinther): Improve semantic precision.
1243 Iterable<ClassElement> get directlyInstantiatedClasses { 1244 Iterable<ClassElement> get directlyInstantiatedClasses {
1244 return _directlyInstantiatedClasses; 1245 return _directlyInstantiatedClasses;
1245 } 1246 }
1246 1247
1247 /// All directly instantiated types, that is, the types of the directly 1248 /// All directly instantiated types, that is, the types of the directly
1248 /// instantiated classes. 1249 /// instantiated classes.
1249 /// 1250 ///
1250 /// See [directlyInstantiatedClasses]. 1251 /// See [directlyInstantiatedClasses].
1251 // TODO(johnniwinther): Improve semantic precision. 1252 // TODO(johnniwinther): Improve semantic precision.
1252 Iterable<DartType> get instantiatedTypes => _instantiatedTypes; 1253 Iterable<ResolutionDartType> get instantiatedTypes => _instantiatedTypes;
1253 1254
1254 /// Register [type] as (directly) instantiated. 1255 /// Register [type] as (directly) instantiated.
1255 /// 1256 ///
1256 /// If [byMirrors] is `true`, the instantiation is through mirrors. 1257 /// If [byMirrors] is `true`, the instantiation is through mirrors.
1257 // TODO(johnniwinther): Fully enforce the separation between exact, through 1258 // TODO(johnniwinther): Fully enforce the separation between exact, through
1258 // subclass and through subtype instantiated types/classes. 1259 // subclass and through subtype instantiated types/classes.
1259 // TODO(johnniwinther): Support unknown type arguments for generic types. 1260 // TODO(johnniwinther): Support unknown type arguments for generic types.
1260 void registerTypeInstantiation( 1261 void registerTypeInstantiation(
1261 InterfaceType type, ClassUsedCallback classUsed, 1262 ResolutionInterfaceType type, ClassUsedCallback classUsed,
1262 {bool byMirrors: false}) { 1263 {bool byMirrors: false}) {
1263 ClassElement cls = type.element; 1264 ClassElement cls = type.element;
1264 bool isNative = _backend.isNative(cls); 1265 bool isNative = _backend.isNative(cls);
1265 _instantiatedTypes.add(type); 1266 _instantiatedTypes.add(type);
1266 if (!cls.isAbstract 1267 if (!cls.isAbstract
1267 // We can't use the closed-world assumption with native abstract 1268 // We can't use the closed-world assumption with native abstract
1268 // classes; a native abstract class may have non-abstract subclasses 1269 // classes; a native abstract class may have non-abstract subclasses
1269 // not declared to the program. Instances of these classes are 1270 // not declared to the program. Instances of these classes are
1270 // indistinguishable from the abstract class. 1271 // indistinguishable from the abstract class.
1271 || 1272 ||
1272 isNative 1273 isNative
1273 // Likewise, if this registration comes from the mirror system, 1274 // Likewise, if this registration comes from the mirror system,
1274 // all bets are off. 1275 // all bets are off.
1275 // TODO(herhut): Track classes required by mirrors separately. 1276 // TODO(herhut): Track classes required by mirrors separately.
1276 || 1277 ||
1277 byMirrors) { 1278 byMirrors) {
1278 _directlyInstantiatedClasses.add(cls); 1279 _directlyInstantiatedClasses.add(cls);
1279 _processInstantiatedClass(cls, classUsed); 1280 _processInstantiatedClass(cls, classUsed);
1280 } 1281 }
1281 1282
1282 // TODO(johnniwinther): Replace this by separate more specific mappings that 1283 // TODO(johnniwinther): Replace this by separate more specific mappings that
1283 // include the type arguments. 1284 // include the type arguments.
1284 if (_implementedClasses.add(cls)) { 1285 if (_implementedClasses.add(cls)) {
1285 classUsed(cls, _getClassUsage(cls).implement()); 1286 classUsed(cls, _getClassUsage(cls).implement());
1286 cls.allSupertypes.forEach((InterfaceType supertype) { 1287 cls.allSupertypes.forEach((ResolutionInterfaceType supertype) {
1287 if (_implementedClasses.add(supertype.element)) { 1288 if (_implementedClasses.add(supertype.element)) {
1288 classUsed( 1289 classUsed(
1289 supertype.element, _getClassUsage(supertype.element).implement()); 1290 supertype.element, _getClassUsage(supertype.element).implement());
1290 } 1291 }
1291 }); 1292 });
1292 } 1293 }
1293 } 1294 }
1294 1295
1295 bool _hasMatchingSelector(Map<Selector, SelectorConstraints> selectors, 1296 bool _hasMatchingSelector(Map<Selector, SelectorConstraints> selectors,
1296 Element member, ClosedWorld world) { 1297 Element member, ClosedWorld world) {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1399 void forEachInvokedGetter( 1400 void forEachInvokedGetter(
1400 f(String name, Map<Selector, SelectorConstraints> selectors)) { 1401 f(String name, Map<Selector, SelectorConstraints> selectors)) {
1401 _invokedGetters.forEach(f); 1402 _invokedGetters.forEach(f);
1402 } 1403 }
1403 1404
1404 void forEachInvokedSetter( 1405 void forEachInvokedSetter(
1405 f(String name, Map<Selector, SelectorConstraints> selectors)) { 1406 f(String name, Map<Selector, SelectorConstraints> selectors)) {
1406 _invokedSetters.forEach(f); 1407 _invokedSetters.forEach(f);
1407 } 1408 }
1408 1409
1409 DartType registerIsCheck(DartType type) { 1410 ResolutionDartType registerIsCheck(ResolutionDartType type) {
1410 type = type.unaliased; 1411 type = type.unaliased;
1411 // Even in checked mode, type annotations for return type and argument 1412 // Even in checked mode, type annotations for return type and argument
1412 // types do not imply type checks, so there should never be a check 1413 // types do not imply type checks, so there should never be a check
1413 // against the type variable of a typedef. 1414 // against the type variable of a typedef.
1414 isChecks.add(type); 1415 isChecks.add(type);
1415 return type; 1416 return type;
1416 } 1417 }
1417 1418
1418 void _registerStaticUse(StaticUse staticUse) { 1419 void _registerStaticUse(StaticUse staticUse) {
1419 Element element = staticUse.element; 1420 Element element = staticUse.element;
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
1966 @override 1967 @override
1967 EnumSet<MemberUse> get _originalUse => MemberUses.ALL_STATIC; 1968 EnumSet<MemberUse> get _originalUse => MemberUses.ALL_STATIC;
1968 } 1969 }
1969 1970
1970 void removeFromSet(Map<String, Set<_MemberUsage>> map, Element element) { 1971 void removeFromSet(Map<String, Set<_MemberUsage>> map, Element element) {
1971 Set<_MemberUsage> set = map[element.name]; 1972 Set<_MemberUsage> set = map[element.name];
1972 if (set == null) return; 1973 if (set == null) return;
1973 set.removeAll( 1974 set.removeAll(
1974 set.where((_MemberUsage usage) => usage.entity == element).toList()); 1975 set.where((_MemberUsage usage) => usage.entity == element).toList());
1975 } 1976 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/universe/use.dart ('k') | pkg/compiler/lib/src/world.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698