| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import '../common.dart'; | 5 import '../common.dart'; |
| 6 import '../common/resolution.dart' show Resolution; |
| 7 import '../compiler.dart' show GlobalDependencyRegistry; |
| 6 import '../core_types.dart'; | 8 import '../core_types.dart'; |
| 7 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
| 10 import '../elements/resolution_types.dart'; |
| 11 import '../universe/selector.dart'; |
| 12 import '../universe/use.dart'; |
| 13 import '../universe/world_impact.dart' |
| 14 show WorldImpact, WorldImpactBuilder, WorldImpactBuilderImpl; |
| 8 import 'backend_helpers.dart'; | 15 import 'backend_helpers.dart'; |
| 16 import 'backend_impact.dart'; |
| 9 | 17 |
| 10 class BackendUsage { | 18 class BackendUsage { |
| 11 final CommonElements commonElements; | 19 final CommonElements commonElements; |
| 12 final BackendHelpers helpers; | 20 final BackendHelpers helpers; |
| 21 final Resolution resolution; |
| 22 final GlobalDependencyRegistry globalDependencies; |
| 13 | 23 |
| 14 /// List of elements that the backend may use. | 24 /// List of elements that the backend may use. |
| 15 final Set<Element> helpersUsed = new Set<Element>(); | 25 final Set<Element> helpersUsed = new Set<Element>(); |
| 16 | 26 |
| 17 bool needToInitializeIsolateAffinityTag = false; | 27 bool needToInitializeIsolateAffinityTag = false; |
| 18 bool needToInitializeDispatchProperty = false; | 28 bool needToInitializeDispatchProperty = false; |
| 19 | 29 |
| 20 BackendUsage(this.commonElements, this.helpers); | 30 BackendUsage(this.commonElements, this.helpers, this.resolution, |
| 31 this.globalDependencies); |
| 21 | 32 |
| 22 /// The backend must *always* call this method when enqueuing an | 33 /// The backend must *always* call this method when enqueuing an |
| 23 /// element. Calls done by the backend are not seen by global | 34 /// element. Calls done by the backend are not seen by global |
| 24 /// optimizations, so they would make these optimizations unsound. | 35 /// optimizations, so they would make these optimizations unsound. |
| 25 /// Therefore we need to collect the list of helpers the backend may | 36 /// Therefore we need to collect the list of helpers the backend may |
| 26 /// use. | 37 /// use. |
| 27 // TODO(johnniwinther): Replace this with a more precise modelling; type | 38 // TODO(johnniwinther): Replace this with a more precise modelling; type |
| 28 // inference of these elements is disabled. | 39 // inference of these elements is disabled. |
| 29 Element registerBackendUse(Element element) { | 40 Element registerBackendUse(Element element) { |
| 30 if (element == null) return null; | 41 if (element == null) return null; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 } | 89 } |
| 79 | 90 |
| 80 bool usedByBackend(Element element) { | 91 bool usedByBackend(Element element) { |
| 81 if (element.isRegularParameter || | 92 if (element.isRegularParameter || |
| 82 element.isInitializingFormal || | 93 element.isInitializingFormal || |
| 83 element.isField) { | 94 element.isField) { |
| 84 if (usedByBackend(element.enclosingElement)) return true; | 95 if (usedByBackend(element.enclosingElement)) return true; |
| 85 } | 96 } |
| 86 return helpersUsed.contains(element.declaration); | 97 return helpersUsed.contains(element.declaration); |
| 87 } | 98 } |
| 99 |
| 100 WorldImpact createImpactFor(BackendImpact impact) { |
| 101 WorldImpactBuilderImpl impactBuilder = new WorldImpactBuilderImpl(); |
| 102 registerBackendImpact(impactBuilder, impact); |
| 103 return impactBuilder; |
| 104 } |
| 105 |
| 106 void registerBackendStaticUse( |
| 107 WorldImpactBuilder worldImpact, MethodElement element, |
| 108 {bool isGlobal: false}) { |
| 109 registerBackendUse(element); |
| 110 worldImpact.registerStaticUse( |
| 111 // TODO(johnniwinther): Store the correct use in impacts. |
| 112 new StaticUse.foreignUse(element)); |
| 113 if (isGlobal) { |
| 114 globalDependencies.registerDependency(element); |
| 115 } |
| 116 } |
| 117 |
| 118 void registerBackendInstantiation( |
| 119 WorldImpactBuilder worldImpact, ClassElement cls, |
| 120 {bool isGlobal: false}) { |
| 121 cls.ensureResolved(resolution); |
| 122 registerBackendUse(cls); |
| 123 worldImpact.registerTypeUse(new TypeUse.instantiation(cls.rawType)); |
| 124 if (isGlobal) { |
| 125 globalDependencies.registerDependency(cls); |
| 126 } |
| 127 } |
| 128 |
| 129 void registerBackendImpact( |
| 130 WorldImpactBuilder worldImpact, BackendImpact backendImpact) { |
| 131 for (Element staticUse in backendImpact.staticUses) { |
| 132 assert(staticUse != null); |
| 133 registerBackendStaticUse(worldImpact, staticUse); |
| 134 } |
| 135 for (Element staticUse in backendImpact.globalUses) { |
| 136 assert(staticUse != null); |
| 137 registerBackendStaticUse(worldImpact, staticUse, isGlobal: true); |
| 138 } |
| 139 for (Selector selector in backendImpact.dynamicUses) { |
| 140 assert(selector != null); |
| 141 worldImpact.registerDynamicUse(new DynamicUse(selector, null)); |
| 142 } |
| 143 for (ResolutionInterfaceType instantiatedType |
| 144 in backendImpact.instantiatedTypes) { |
| 145 registerBackendUse(instantiatedType.element); |
| 146 worldImpact.registerTypeUse(new TypeUse.instantiation(instantiatedType)); |
| 147 } |
| 148 for (ClassElement cls in backendImpact.instantiatedClasses) { |
| 149 registerBackendInstantiation(worldImpact, cls); |
| 150 } |
| 151 for (ClassElement cls in backendImpact.globalClasses) { |
| 152 registerBackendInstantiation(worldImpact, cls, isGlobal: true); |
| 153 } |
| 154 for (BackendImpact otherImpact in backendImpact.otherImpacts) { |
| 155 registerBackendImpact(worldImpact, otherImpact); |
| 156 } |
| 157 for (BackendFeature feature in backendImpact.features) { |
| 158 switch (feature) { |
| 159 case BackendFeature.needToInitializeDispatchProperty: |
| 160 needToInitializeDispatchProperty = true; |
| 161 break; |
| 162 case BackendFeature.needToInitializeIsolateAffinityTag: |
| 163 needToInitializeIsolateAffinityTag = true; |
| 164 break; |
| 165 } |
| 166 } |
| 167 } |
| 88 } | 168 } |
| OLD | NEW |