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

Side by Side Diff: pkg/compiler/lib/src/js_backend/backend_usage.dart

Issue 2814453005: Merge CommonElements and BackendHelpers! (Closed)
Patch Set: merge with head Created 3 years, 8 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
OLDNEW
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_elements.dart'; 6 import '../common_elements.dart';
7 import '../elements/elements.dart' show Element; 7 import '../elements/elements.dart' show Element;
8 import '../elements/entities.dart'; 8 import '../elements/entities.dart';
9 import '../elements/types.dart'; 9 import '../elements/types.dart';
10 import '../util/util.dart' show Setlet; 10 import '../util/util.dart' show Setlet;
11 import 'backend_helpers.dart';
12 import 'backend_impact.dart'; 11 import 'backend_impact.dart';
13 12
14 abstract class BackendUsage { 13 abstract class BackendUsage {
15 bool needToInitializeIsolateAffinityTag; 14 bool needToInitializeIsolateAffinityTag;
16 bool needToInitializeDispatchProperty; 15 bool needToInitializeDispatchProperty;
17 16
18 /// Returns `true` if [element] is a function called by the backend. 17 /// Returns `true` if [element] is a function called by the backend.
19 bool isFunctionUsedByBackend(FunctionEntity element); 18 bool isFunctionUsedByBackend(FunctionEntity element);
20 19
21 /// Returns `true` if [element] is an instance field of a class instantiated 20 /// Returns `true` if [element] is an instance field of a class instantiated
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 bool isFunctionApplyUsed; 80 bool isFunctionApplyUsed;
82 81
83 /// `true` if `noSuchMethod` is used. 82 /// `true` if `noSuchMethod` is used.
84 bool isNoSuchMethodUsed; 83 bool isNoSuchMethodUsed;
85 84
86 BackendUsage close(); 85 BackendUsage close();
87 } 86 }
88 87
89 class BackendUsageBuilderImpl implements BackendUsageBuilder { 88 class BackendUsageBuilderImpl implements BackendUsageBuilder {
90 final CommonElements _commonElements; 89 final CommonElements _commonElements;
91 final BackendHelpers _helpers;
92 // TODO(johnniwinther): Remove the need for these. 90 // TODO(johnniwinther): Remove the need for these.
93 Setlet<FunctionEntity> _globalFunctionDependencies; 91 Setlet<FunctionEntity> _globalFunctionDependencies;
94 Setlet<ClassEntity> _globalClassDependencies; 92 Setlet<ClassEntity> _globalClassDependencies;
95 93
96 /// List of methods that the backend may use. 94 /// List of methods that the backend may use.
97 final Set<FunctionEntity> _helperFunctionsUsed = new Set<FunctionEntity>(); 95 final Set<FunctionEntity> _helperFunctionsUsed = new Set<FunctionEntity>();
98 96
99 /// List of classes that the backend may use. 97 /// List of classes that the backend may use.
100 final Set<ClassEntity> _helperClassesUsed = new Set<ClassEntity>(); 98 final Set<ClassEntity> _helperClassesUsed = new Set<ClassEntity>();
101 99
(...skipping 11 matching lines...) Expand all
113 111
114 /// `true` if the `dart:isolate` library is in use. 112 /// `true` if the `dart:isolate` library is in use.
115 bool isIsolateInUse = false; 113 bool isIsolateInUse = false;
116 114
117 /// `true` if `Function.apply` is used. 115 /// `true` if `Function.apply` is used.
118 bool isFunctionApplyUsed = false; 116 bool isFunctionApplyUsed = false;
119 117
120 /// `true` if `noSuchMethod` is used. 118 /// `true` if `noSuchMethod` is used.
121 bool isNoSuchMethodUsed = false; 119 bool isNoSuchMethodUsed = false;
122 120
123 BackendUsageBuilderImpl(this._commonElements, this._helpers); 121 BackendUsageBuilderImpl(this._commonElements);
124 122
125 @override 123 @override
126 void registerBackendFunctionUse(FunctionEntity element) { 124 void registerBackendFunctionUse(FunctionEntity element) {
127 assert(invariant(element, _isValidBackendUse(element), 125 assert(invariant(element, _isValidBackendUse(element),
128 message: "Backend use of $element is not allowed.")); 126 message: "Backend use of $element is not allowed."));
129 _helperFunctionsUsed.add(element); 127 _helperFunctionsUsed.add(element);
130 } 128 }
131 129
132 @override 130 @override
133 void registerBackendClassUse(ClassEntity element) { 131 void registerBackendClassUse(ClassEntity element) {
134 assert(invariant(element, _isValidBackendUse(element), 132 assert(invariant(element, _isValidBackendUse(element),
135 message: "Backend use of $element is not allowed.")); 133 message: "Backend use of $element is not allowed."));
136 _helperClassesUsed.add(element); 134 _helperClassesUsed.add(element);
137 } 135 }
138 136
139 bool _isValidBackendUse(Entity element) { 137 bool _isValidBackendUse(Entity element) {
140 if (_isValidEntity(element)) return true; 138 if (_isValidEntity(element)) return true;
141 if (element is Element) { 139 if (element is Element) {
142 assert(invariant(element, element.isDeclaration, 140 assert(invariant(element, element.isDeclaration,
143 message: "Backend use $element must be the declaration.")); 141 message: "Backend use $element must be the declaration."));
144 if (element.implementationLibrary.isPatch || 142 if (element.implementationLibrary.isPatch ||
145 // Needed to detect deserialized injected elements, that is 143 // Needed to detect deserialized injected elements, that is
146 // element declared in patch files. 144 // element declared in patch files.
147 (element.library.isPlatformLibrary && 145 (element.library.isPlatformLibrary &&
148 element.sourcePosition.uri.path 146 element.sourcePosition.uri.path
149 .contains('_internal/js_runtime/lib/')) || 147 .contains('_internal/js_runtime/lib/')) ||
150 element.library == _helpers.jsHelperLibrary || 148 element.library == _commonElements.jsHelperLibrary ||
151 element.library == _helpers.interceptorsLibrary || 149 element.library == _commonElements.interceptorsLibrary ||
152 element.library == _helpers.isolateHelperLibrary) { 150 element.library == _commonElements.isolateHelperLibrary) {
153 // TODO(johnniwinther): We should be more precise about these. 151 // TODO(johnniwinther): We should be more precise about these.
154 return true; 152 return true;
155 } else { 153 } else {
154 print('mah source position path ${element.sourcePosition.uri.path}');
Johnni Winther 2017/04/11 09:16:00 Remove?
Emily Fortuna 2017/04/11 21:31:35 ooops, yes, thank you!
156 return false; 155 return false;
157 } 156 }
158 } 157 }
159 // TODO(johnniwinther): Support remaining checks on [Entity]s. 158 // TODO(johnniwinther): Support remaining checks on [Entity]s.
160 return true; 159 return true;
161 } 160 }
162 161
163 bool _isValidEntity(Entity element) { 162 bool _isValidEntity(Entity element) {
164 if (element is ConstructorEntity && 163 if (element is ConstructorEntity &&
165 (element == _helpers.streamIteratorConstructor || 164 (element == _commonElements.streamIteratorConstructor ||
166 _commonElements.isSymbolConstructor(element) || 165 _commonElements.isSymbolConstructor(element) ||
167 _helpers.isSymbolValidatedConstructor(element) || 166 _commonElements.isSymbolValidatedConstructor(element) ||
168 element == _helpers.syncCompleterConstructor)) { 167 element == _commonElements.syncCompleterConstructor)) {
169 // TODO(johnniwinther): These are valid but we could be more precise. 168 // TODO(johnniwinther): These are valid but we could be more precise.
170 return true; 169 return true;
171 } else if (element == _commonElements.symbolClass || 170 } else if (element == _commonElements.symbolClass ||
172 element == _helpers.objectNoSuchMethod) { 171 element == _commonElements.objectNoSuchMethod) {
173 // TODO(johnniwinther): These are valid but we could be more precise. 172 // TODO(johnniwinther): These are valid but we could be more precise.
174 return true; 173 return true;
175 } else if (element == _commonElements.listClass || 174 } else if (element == _commonElements.listClass ||
176 element == _helpers.mapLiteralClass || 175 element == _commonElements.mapLiteralClass ||
177 element == _commonElements.functionClass || 176 element == _commonElements.functionClass ||
178 element == _commonElements.stringClass) { 177 element == _commonElements.stringClass) {
179 // TODO(johnniwinther): Avoid these. 178 // TODO(johnniwinther): Avoid these.
180 return true; 179 return true;
181 } else if (element == _helpers.genericNoSuchMethod || 180 } else if (element == _commonElements.genericNoSuchMethod ||
182 element == _helpers.unresolvedConstructorError || 181 element == _commonElements.unresolvedConstructorError ||
183 element == _helpers.malformedTypeError) { 182 element == _commonElements.malformedTypeError) {
184 return true; 183 return true;
185 } 184 }
186 return false; 185 return false;
187 } 186 }
188 187
189 void _processBackendStaticUse(FunctionEntity element, 188 void _processBackendStaticUse(FunctionEntity element,
190 {bool isGlobal: false}) { 189 {bool isGlobal: false}) {
191 registerBackendFunctionUse(element); 190 registerBackendFunctionUse(element);
192 if (isGlobal) { 191 if (isGlobal) {
193 registerGlobalFunctionDependency(element); 192 registerGlobalFunctionDependency(element);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 _needToInitializeDispatchProperty = true; 227 _needToInitializeDispatchProperty = true;
229 break; 228 break;
230 case BackendFeature.needToInitializeIsolateAffinityTag: 229 case BackendFeature.needToInitializeIsolateAffinityTag:
231 _needToInitializeIsolateAffinityTag = true; 230 _needToInitializeIsolateAffinityTag = true;
232 break; 231 break;
233 } 232 }
234 } 233 }
235 } 234 }
236 235
237 void registerUsedMember(MemberEntity member) { 236 void registerUsedMember(MemberEntity member) {
238 if (member == _helpers.getIsolateAffinityTagMarker) { 237 if (member == _commonElements.getIsolateAffinityTagMarker) {
239 _needToInitializeIsolateAffinityTag = true; 238 _needToInitializeIsolateAffinityTag = true;
240 } else if (member == _helpers.requiresPreambleMarker) { 239 } else if (member == _commonElements.requiresPreambleMarker) {
241 requiresPreamble = true; 240 requiresPreamble = true;
242 } else if (member == _helpers.invokeOnMethod) { 241 } else if (member == _commonElements.invokeOnMethod) {
243 isInvokeOnUsed = true; 242 isInvokeOnUsed = true;
244 } else if (_commonElements.isFunctionApplyMethod(member)) { 243 } else if (_commonElements.isFunctionApplyMethod(member)) {
245 isFunctionApplyUsed = true; 244 isFunctionApplyUsed = true;
246 } 245 }
247 } 246 }
248 247
249 void registerGlobalFunctionDependency(FunctionEntity element) { 248 void registerGlobalFunctionDependency(FunctionEntity element) {
250 assert(element != null); 249 assert(element != null);
251 if (_globalFunctionDependencies == null) { 250 if (_globalFunctionDependencies == null) {
252 _globalFunctionDependencies = new Setlet<FunctionEntity>(); 251 _globalFunctionDependencies = new Setlet<FunctionEntity>();
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 return _helperClassesUsed.contains(element.enclosingClass); 338 return _helperClassesUsed.contains(element.enclosingClass);
340 } 339 }
341 340
342 @override 341 @override
343 Iterable<FunctionEntity> get globalFunctionDependencies => 342 Iterable<FunctionEntity> get globalFunctionDependencies =>
344 _globalFunctionDependencies; 343 _globalFunctionDependencies;
345 344
346 @override 345 @override
347 Iterable<ClassEntity> get globalClassDependencies => _globalClassDependencies; 346 Iterable<ClassEntity> get globalClassDependencies => _globalClassDependencies;
348 } 347 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698