| 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 ClosureClassElement, SynthesizedCallMethodElementX; | 7 import 'closure.dart' show ClosureClassElement, SynthesizedCallMethodElementX; |
| 8 import 'common/backend_api.dart' show BackendClasses; | 8 import 'common/backend_api.dart' show BackendClasses; |
| 9 import 'common.dart'; | 9 import 'common.dart'; |
| 10 import 'constants/constant_system.dart'; | 10 import 'constants/constant_system.dart'; |
| 11 import 'common_elements.dart' show CommonElements; | 11 import 'common_elements.dart' show CommonElements; |
| 12 import 'elements/entities.dart'; | 12 import 'elements/entities.dart'; |
| 13 import 'elements/elements.dart' | 13 import 'elements/elements.dart' |
| 14 show | 14 show |
| 15 ClassElement, | 15 ClassElement, |
| 16 Element, | 16 Element, |
| 17 FunctionElement, | 17 FunctionElement, |
| 18 MemberElement, | 18 MemberElement, |
| 19 MixinApplicationElement, | 19 MixinApplicationElement, |
| 20 TypedefElement, | 20 TypedefElement, |
| 21 FieldElement; | 21 FieldElement; |
| 22 import 'elements/resolution_types.dart'; | 22 import 'elements/resolution_types.dart'; |
| 23 import 'js_backend/backend.dart' show JavaScriptBackend; | 23 import 'js_backend/backend.dart' show JavaScriptBackend; |
| 24 import 'js_backend/interceptor_data.dart' show InterceptorData; | 24 import 'js_backend/interceptor_data.dart' show InterceptorData; |
| 25 import 'js_backend/native_data.dart' show NativeClassData; | 25 import 'js_backend/native_data.dart' show NativeData; |
| 26 import 'ordered_typeset.dart'; | 26 import 'ordered_typeset.dart'; |
| 27 import 'types/masks.dart' show CommonMasks, FlatTypeMask, TypeMask; | 27 import 'types/masks.dart' show CommonMasks, FlatTypeMask, TypeMask; |
| 28 import 'universe/class_set.dart'; | 28 import 'universe/class_set.dart'; |
| 29 import 'universe/function_set.dart' show FunctionSet, FunctionSetBuilder; | 29 import 'universe/function_set.dart' show FunctionSet, FunctionSetBuilder; |
| 30 import 'universe/selector.dart' show Selector; | 30 import 'universe/selector.dart' show Selector; |
| 31 import 'universe/side_effects.dart' show SideEffects; | 31 import 'universe/side_effects.dart' show SideEffects; |
| 32 import 'universe/world_builder.dart' show ResolutionWorldBuilder; | 32 import 'universe/world_builder.dart' show ResolutionWorldBuilder; |
| 33 import 'util/util.dart' show Link; | 33 import 'util/util.dart' show Link; |
| 34 | 34 |
| 35 /// Common superinterface for [OpenWorld] and [ClosedWorld]. | 35 /// Common superinterface for [OpenWorld] and [ClosedWorld]. |
| 36 abstract class World {} | 36 abstract class World {} |
| 37 | 37 |
| 38 /// The [ClosedWorld] represents the information known about a program when | 38 /// The [ClosedWorld] represents the information known about a program when |
| 39 /// compiling with closed-world semantics. | 39 /// compiling with closed-world semantics. |
| 40 /// | 40 /// |
| 41 /// Given the entrypoint of an application, we can track what's reachable from | 41 /// Given the entrypoint of an application, we can track what's reachable from |
| 42 /// it, what functions are called, what classes are allocated, which native | 42 /// it, what functions are called, what classes are allocated, which native |
| 43 /// JavaScript types are touched, what language features are used, and so on. | 43 /// JavaScript types are touched, what language features are used, and so on. |
| 44 /// This precise knowledge about what's live in the program is later used in | 44 /// This precise knowledge about what's live in the program is later used in |
| 45 /// optimizations and other compiler decisions during code generation. | 45 /// optimizations and other compiler decisions during code generation. |
| 46 abstract class ClosedWorld implements World { | 46 abstract class ClosedWorld implements World { |
| 47 /// Access to core classes used by the backend. | 47 /// Access to core classes used by the backend. |
| 48 BackendClasses get backendClasses; | 48 BackendClasses get backendClasses; |
| 49 | 49 |
| 50 NativeData get nativeData; |
| 51 |
| 50 InterceptorData get interceptorData; | 52 InterceptorData get interceptorData; |
| 51 | 53 |
| 52 CommonElements get commonElements; | 54 CommonElements get commonElements; |
| 53 | 55 |
| 54 CommonMasks get commonMasks; | 56 CommonMasks get commonMasks; |
| 55 | 57 |
| 56 ConstantSystem get constantSystem; | 58 ConstantSystem get constantSystem; |
| 57 | 59 |
| 58 /// Returns `true` if [cls] is either directly or indirectly instantiated. | 60 /// Returns `true` if [cls] is either directly or indirectly instantiated. |
| 59 bool isInstantiated(ClassEntity cls); | 61 bool isInstantiated(ClassEntity cls); |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 this._resolverWorld = resolutionWorldBuilder, | 441 this._resolverWorld = resolutionWorldBuilder, |
| 440 this._allTypedefs = allTypedefs, | 442 this._allTypedefs = allTypedefs, |
| 441 this._mixinUses = mixinUses, | 443 this._mixinUses = mixinUses, |
| 442 this._typesImplementedBySubclasses = typesImplementedBySubclasses, | 444 this._typesImplementedBySubclasses = typesImplementedBySubclasses, |
| 443 this._classHierarchyNodes = classHierarchyNodes, | 445 this._classHierarchyNodes = classHierarchyNodes, |
| 444 this._classSets = classSets { | 446 this._classSets = classSets { |
| 445 _commonMasks = new CommonMasks(this); | 447 _commonMasks = new CommonMasks(this); |
| 446 _allFunctions = functionSetBuilder.close(this); | 448 _allFunctions = functionSetBuilder.close(this); |
| 447 } | 449 } |
| 448 | 450 |
| 449 NativeClassData get _nativeClassData => _backend.nativeClassData; | 451 NativeData get nativeData => _backend.nativeData; |
| 450 | 452 |
| 451 @override | 453 @override |
| 452 ClosedWorld get closedWorld => this; | 454 ClosedWorld get closedWorld => this; |
| 453 | 455 |
| 454 /// Cache of [FlatTypeMask]s grouped by the 8 possible values of the | 456 /// Cache of [FlatTypeMask]s grouped by the 8 possible values of the |
| 455 /// `FlatTypeMask.flags` property. | 457 /// `FlatTypeMask.flags` property. |
| 456 final List<Map<ClassElement, TypeMask>> _canonicalizedTypeMasks = | 458 final List<Map<ClassElement, TypeMask>> _canonicalizedTypeMasks = |
| 457 new List<Map<ClassElement, TypeMask>>.filled(8, null); | 459 new List<Map<ClassElement, TypeMask>>.filled(8, null); |
| 458 | 460 |
| 459 FunctionSet get allFunctions => _allFunctions; | 461 FunctionSet get allFunctions => _allFunctions; |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 if (classSet == null) { | 709 if (classSet == null) { |
| 708 // Vacuously true. | 710 // Vacuously true. |
| 709 return true; | 711 return true; |
| 710 } | 712 } |
| 711 return classSet.hasOnlyInstantiatedSubclasses; | 713 return classSet.hasOnlyInstantiatedSubclasses; |
| 712 } | 714 } |
| 713 | 715 |
| 714 @override | 716 @override |
| 715 ClassElement getLubOfInstantiatedSubclasses(ClassElement cls) { | 717 ClassElement getLubOfInstantiatedSubclasses(ClassElement cls) { |
| 716 assert(isClosed); | 718 assert(isClosed); |
| 717 if (_nativeClassData.isJsInteropClass(cls)) { | 719 if (nativeData.isJsInteropClass(cls)) { |
| 718 return _backend.helpers.jsJavaScriptObjectClass; | 720 return _backend.helpers.jsJavaScriptObjectClass; |
| 719 } | 721 } |
| 720 ClassHierarchyNode hierarchy = _classHierarchyNodes[cls.declaration]; | 722 ClassHierarchyNode hierarchy = _classHierarchyNodes[cls.declaration]; |
| 721 return hierarchy != null | 723 return hierarchy != null |
| 722 ? hierarchy.getLubOfInstantiatedSubclasses() | 724 ? hierarchy.getLubOfInstantiatedSubclasses() |
| 723 : null; | 725 : null; |
| 724 } | 726 } |
| 725 | 727 |
| 726 @override | 728 @override |
| 727 ClassElement getLubOfInstantiatedSubtypes(ClassElement cls) { | 729 ClassElement getLubOfInstantiatedSubtypes(ClassElement cls) { |
| 728 assert(isClosed); | 730 assert(isClosed); |
| 729 if (_nativeClassData.isJsInteropClass(cls)) { | 731 if (nativeData.isJsInteropClass(cls)) { |
| 730 return _backend.helpers.jsJavaScriptObjectClass; | 732 return _backend.helpers.jsJavaScriptObjectClass; |
| 731 } | 733 } |
| 732 ClassSet classSet = _classSets[cls.declaration]; | 734 ClassSet classSet = _classSets[cls.declaration]; |
| 733 return classSet != null ? classSet.getLubOfInstantiatedSubtypes() : null; | 735 return classSet != null ? classSet.getLubOfInstantiatedSubtypes() : null; |
| 734 } | 736 } |
| 735 | 737 |
| 736 /// Returns an iterable over the common supertypes of the [classes]. | 738 /// Returns an iterable over the common supertypes of the [classes]. |
| 737 Iterable<ClassElement> commonSupertypesOf(Iterable<ClassElement> classes) { | 739 Iterable<ClassElement> commonSupertypesOf(Iterable<ClassElement> classes) { |
| 738 assert(isClosed); | 740 assert(isClosed); |
| 739 Iterator<ClassElement> iterator = classes.iterator; | 741 Iterator<ClassElement> iterator = classes.iterator; |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1089 void addFunctionCalledInLoop(Element element) { | 1091 void addFunctionCalledInLoop(Element element) { |
| 1090 functionsCalledInLoop.add(element.declaration); | 1092 functionsCalledInLoop.add(element.declaration); |
| 1091 } | 1093 } |
| 1092 | 1094 |
| 1093 bool isCalledInLoop(Element element) { | 1095 bool isCalledInLoop(Element element) { |
| 1094 return functionsCalledInLoop.contains(element.declaration); | 1096 return functionsCalledInLoop.contains(element.declaration); |
| 1095 } | 1097 } |
| 1096 | 1098 |
| 1097 bool fieldNeverChanges(MemberElement element) { | 1099 bool fieldNeverChanges(MemberElement element) { |
| 1098 if (!element.isField) return false; | 1100 if (!element.isField) return false; |
| 1099 if (_nativeClassData.isNativeMember(element)) { | 1101 if (nativeData.isNativeMember(element)) { |
| 1100 // Some native fields are views of data that may be changed by operations. | 1102 // Some native fields are views of data that may be changed by operations. |
| 1101 // E.g. node.firstChild depends on parentNode.removeBefore(n1, n2). | 1103 // E.g. node.firstChild depends on parentNode.removeBefore(n1, n2). |
| 1102 // TODO(sra): Refine the effect classification so that native effects are | 1104 // TODO(sra): Refine the effect classification so that native effects are |
| 1103 // distinct from ordinary Dart effects. | 1105 // distinct from ordinary Dart effects. |
| 1104 return false; | 1106 return false; |
| 1105 } | 1107 } |
| 1106 | 1108 |
| 1107 if (element.isFinal || element.isConst) { | 1109 if (element.isFinal || element.isConst) { |
| 1108 return true; | 1110 return true; |
| 1109 } | 1111 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1190 return getMightBePassedToApply(element.expression); | 1192 return getMightBePassedToApply(element.expression); |
| 1191 } | 1193 } |
| 1192 return functionsThatMightBePassedToApply.contains(element); | 1194 return functionsThatMightBePassedToApply.contains(element); |
| 1193 } | 1195 } |
| 1194 | 1196 |
| 1195 @override | 1197 @override |
| 1196 bool getCurrentlyKnownMightBePassedToApply(Element element) { | 1198 bool getCurrentlyKnownMightBePassedToApply(Element element) { |
| 1197 return getMightBePassedToApply(element); | 1199 return getMightBePassedToApply(element); |
| 1198 } | 1200 } |
| 1199 } | 1201 } |
| OLD | NEW |