OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.js_helpers.impact; | 5 library dart2js.js_helpers.impact; |
6 | 6 |
7 import '../common/names.dart' show | 7 import '../common/names.dart' show |
8 Identifiers; | 8 Identifiers; |
9 import '../compiler.dart' show | 9 import '../compiler.dart' show |
10 Compiler; | 10 Compiler; |
| 11 import '../core_types.dart' show |
| 12 CoreClasses; |
11 import '../dart_types.dart' show | 13 import '../dart_types.dart' show |
12 InterfaceType; | 14 InterfaceType; |
13 import '../elements/elements.dart' show | 15 import '../elements/elements.dart' show |
14 ClassElement, | 16 ClassElement, |
15 Element; | 17 Element; |
16 | 18 |
17 import 'backend_helpers.dart'; | 19 import 'backend_helpers.dart'; |
18 import 'constant_system_javascript.dart'; | 20 import 'constant_system_javascript.dart'; |
19 import 'js_backend.dart'; | 21 import 'js_backend.dart'; |
20 | 22 |
(...skipping 13 matching lines...) Expand all Loading... |
34 /// The JavaScript backend dependencies for various features. | 36 /// The JavaScript backend dependencies for various features. |
35 class BackendImpacts { | 37 class BackendImpacts { |
36 final Compiler compiler; | 38 final Compiler compiler; |
37 | 39 |
38 BackendImpacts(this.compiler); | 40 BackendImpacts(this.compiler); |
39 | 41 |
40 JavaScriptBackend get backend => compiler.backend; | 42 JavaScriptBackend get backend => compiler.backend; |
41 | 43 |
42 BackendHelpers get helpers => backend.helpers; | 44 BackendHelpers get helpers => backend.helpers; |
43 | 45 |
| 46 CoreClasses get coreClasses => compiler.coreClasses; |
| 47 |
44 BackendImpact get getRuntimeTypeArgument => new BackendImpact( | 48 BackendImpact get getRuntimeTypeArgument => new BackendImpact( |
45 staticUses: [ | 49 staticUses: [ |
46 helpers.getRuntimeTypeArgument, | 50 helpers.getRuntimeTypeArgument, |
47 helpers.getTypeArgumentByIndex, | 51 helpers.getTypeArgumentByIndex, |
48 helpers.copyTypeArguments]); | 52 helpers.copyTypeArguments]); |
49 | 53 |
50 BackendImpact get computeSignature => new BackendImpact( | 54 BackendImpact get computeSignature => new BackendImpact( |
51 staticUses: [ | 55 staticUses: [ |
52 helpers.setRuntimeTypeInfo, | 56 helpers.setRuntimeTypeInfo, |
53 helpers.getRuntimeTypeInfo, | 57 helpers.getRuntimeTypeInfo, |
54 helpers.computeSignature, | 58 helpers.computeSignature, |
55 helpers.getRuntimeTypeArguments], | 59 helpers.getRuntimeTypeArguments], |
56 instantiatedClasses: [ | 60 instantiatedClasses: [ |
57 compiler.listClass]); | 61 coreClasses.listClass]); |
58 | 62 |
59 BackendImpact get asyncBody => new BackendImpact( | 63 BackendImpact get asyncBody => new BackendImpact( |
60 staticUses: [ | 64 staticUses: [ |
61 helpers.asyncHelper, | 65 helpers.asyncHelper, |
62 helpers.syncCompleterConstructor, | 66 helpers.syncCompleterConstructor, |
63 helpers.streamIteratorConstructor, | 67 helpers.streamIteratorConstructor, |
64 helpers.wrapBody]); | 68 helpers.wrapBody]); |
65 | 69 |
66 BackendImpact get syncStarBody => new BackendImpact( | 70 BackendImpact get syncStarBody => new BackendImpact( |
67 staticUses: [ | 71 staticUses: [ |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 needsList( | 115 needsList( |
112 'Needed to encode the arguments for throw NoSuchMethodError.'), | 116 'Needed to encode the arguments for throw NoSuchMethodError.'), |
113 needsString( | 117 needsString( |
114 'Needed to encode the name for throw NoSuchMethodError.')]); | 118 'Needed to encode the name for throw NoSuchMethodError.')]); |
115 | 119 |
116 BackendImpact get throwRuntimeError => new BackendImpact( | 120 BackendImpact get throwRuntimeError => new BackendImpact( |
117 staticUses: [ | 121 staticUses: [ |
118 helpers.throwRuntimeError], | 122 helpers.throwRuntimeError], |
119 // Also register the types of the arguments passed to this method. | 123 // Also register the types of the arguments passed to this method. |
120 instantiatedClasses: [ | 124 instantiatedClasses: [ |
121 helpers.compiler.stringClass]); | 125 coreClasses.stringClass]); |
122 | 126 |
123 BackendImpact get superNoSuchMethod => new BackendImpact( | 127 BackendImpact get superNoSuchMethod => new BackendImpact( |
124 staticUses: [ | 128 staticUses: [ |
125 helpers.createInvocationMirror, | 129 helpers.createInvocationMirror, |
126 helpers.compiler.objectClass.lookupLocalMember( | 130 coreClasses.objectClass.lookupLocalMember(Identifiers.noSuchMethod_)], |
127 Identifiers.noSuchMethod_)], | |
128 otherImpacts: [ | 131 otherImpacts: [ |
129 needsInt( | 132 needsInt( |
130 'Needed to encode the invocation kind of super.noSuchMethod.'), | 133 'Needed to encode the invocation kind of super.noSuchMethod.'), |
131 needsList( | 134 needsList( |
132 'Needed to encode the arguments of super.noSuchMethod.'), | 135 'Needed to encode the arguments of super.noSuchMethod.'), |
133 needsString( | 136 needsString( |
134 'Needed to encode the name of super.noSuchMethod.')]); | 137 'Needed to encode the name of super.noSuchMethod.')]); |
135 | 138 |
136 BackendImpact get constantMapLiteral { | 139 BackendImpact get constantMapLiteral { |
137 | 140 |
138 ClassElement find(String name) { | 141 ClassElement find(String name) { |
139 return helpers.find(backend.jsHelperLibrary, name); | 142 return helpers.find(backend.jsHelperLibrary, name); |
140 } | 143 } |
141 | 144 |
142 return new BackendImpact( | 145 return new BackendImpact( |
143 instantiatedClasses: [ | 146 instantiatedClasses: [ |
144 find(JavaScriptMapConstant.DART_CLASS), | 147 find(JavaScriptMapConstant.DART_CLASS), |
145 find(JavaScriptMapConstant.DART_PROTO_CLASS), | 148 find(JavaScriptMapConstant.DART_PROTO_CLASS), |
146 find(JavaScriptMapConstant.DART_STRING_CLASS), | 149 find(JavaScriptMapConstant.DART_STRING_CLASS), |
147 find(JavaScriptMapConstant.DART_GENERAL_CLASS)]); | 150 find(JavaScriptMapConstant.DART_GENERAL_CLASS)]); |
148 } | 151 } |
149 | 152 |
150 BackendImpact get symbolConstructor => new BackendImpact( | 153 BackendImpact get symbolConstructor => new BackendImpact( |
151 staticUses: [ | 154 staticUses: [ |
152 helpers.compiler.symbolValidatedConstructor]); | 155 helpers.compiler.symbolValidatedConstructor]); |
153 | 156 |
154 BackendImpact get constSymbol => new BackendImpact( | 157 BackendImpact get constSymbol => new BackendImpact( |
155 instantiatedClasses: [ | 158 instantiatedClasses: [ |
156 compiler.symbolClass], | 159 coreClasses.symbolClass], |
157 staticUses: [ | 160 staticUses: [ |
158 compiler.symbolConstructor.declaration]); | 161 compiler.symbolConstructor.declaration]); |
159 | 162 |
160 BackendImpact get incDecOperation => | 163 BackendImpact get incDecOperation => |
161 needsInt('Needed for the `+ 1` or `- 1` operation of ++/--.'); | 164 needsInt('Needed for the `+ 1` or `- 1` operation of ++/--.'); |
162 | 165 |
163 /// Helper for registering that `int` is needed. | 166 /// Helper for registering that `int` is needed. |
164 BackendImpact needsInt(String reason) { | 167 BackendImpact needsInt(String reason) { |
165 // TODO(johnniwinther): Register [reason] for use in dump-info. | 168 // TODO(johnniwinther): Register [reason] for use in dump-info. |
166 return new BackendImpact( | 169 return new BackendImpact( |
167 instantiatedClasses: [helpers.compiler.intClass]); | 170 instantiatedClasses: [coreClasses.intClass]); |
168 } | 171 } |
169 | 172 |
170 /// Helper for registering that `List` is needed. | 173 /// Helper for registering that `List` is needed. |
171 BackendImpact needsList(String reason) { | 174 BackendImpact needsList(String reason) { |
172 // TODO(johnniwinther): Register [reason] for use in dump-info. | 175 // TODO(johnniwinther): Register [reason] for use in dump-info. |
173 return new BackendImpact( | 176 return new BackendImpact( |
174 instantiatedClasses: [helpers.compiler.listClass]); | 177 instantiatedClasses: [coreClasses.listClass]); |
175 } | 178 } |
176 | 179 |
177 /// Helper for registering that `String` is needed. | 180 /// Helper for registering that `String` is needed. |
178 BackendImpact needsString(String reason) { | 181 BackendImpact needsString(String reason) { |
179 // TODO(johnniwinther): Register [reason] for use in dump-info. | 182 // TODO(johnniwinther): Register [reason] for use in dump-info. |
180 return new BackendImpact( | 183 return new BackendImpact( |
181 instantiatedClasses: [ | 184 instantiatedClasses: [ |
182 helpers.compiler.stringClass]); | 185 coreClasses.stringClass]); |
183 } | 186 } |
184 | 187 |
185 BackendImpact get assertWithoutMessage => new BackendImpact( | 188 BackendImpact get assertWithoutMessage => new BackendImpact( |
186 staticUses: [ | 189 staticUses: [ |
187 helpers.assertHelper]); | 190 helpers.assertHelper]); |
188 | 191 |
189 BackendImpact get assertWithMessage => new BackendImpact( | 192 BackendImpact get assertWithMessage => new BackendImpact( |
190 staticUses: [ | 193 staticUses: [ |
191 helpers.assertTest, | 194 helpers.assertTest, |
192 helpers.assertThrow]); | 195 helpers.assertThrow]); |
(...skipping 26 matching lines...) Expand all Loading... |
219 helpers.cyclicThrowHelper]); | 222 helpers.cyclicThrowHelper]); |
220 | 223 |
221 BackendImpact get typeLiteral => new BackendImpact( | 224 BackendImpact get typeLiteral => new BackendImpact( |
222 instantiatedClasses: [ | 225 instantiatedClasses: [ |
223 backend.typeImplementation], | 226 backend.typeImplementation], |
224 staticUses: [ | 227 staticUses: [ |
225 helpers.createRuntimeType]); | 228 helpers.createRuntimeType]); |
226 | 229 |
227 BackendImpact get stackTraceInCatch => new BackendImpact( | 230 BackendImpact get stackTraceInCatch => new BackendImpact( |
228 instantiatedClasses: [ | 231 instantiatedClasses: [ |
229 helpers.compiler.stackTraceClass], | 232 coreClasses.stackTraceClass], |
230 staticUses: [ | 233 staticUses: [ |
231 helpers.traceFromException]); | 234 helpers.traceFromException]); |
232 | 235 |
233 BackendImpact get syncForIn => new BackendImpact( | 236 BackendImpact get syncForIn => new BackendImpact( |
234 // The SSA builder recognizes certain for-in loops and can generate calls | 237 // The SSA builder recognizes certain for-in loops and can generate calls |
235 // to throwConcurrentModificationError. | 238 // to throwConcurrentModificationError. |
236 staticUses: [ | 239 staticUses: [ |
237 helpers.checkConcurrentModificationError]); | 240 helpers.checkConcurrentModificationError]); |
238 | 241 |
239 BackendImpact get typeVariableExpression => new BackendImpact( | 242 BackendImpact get typeVariableExpression => new BackendImpact( |
240 staticUses: [ | 243 staticUses: [ |
241 helpers.setRuntimeTypeInfo, | 244 helpers.setRuntimeTypeInfo, |
242 helpers.getRuntimeTypeInfo, | 245 helpers.getRuntimeTypeInfo, |
243 helpers.runtimeTypeToString, | 246 helpers.runtimeTypeToString, |
244 helpers.createRuntimeType], | 247 helpers.createRuntimeType], |
245 instantiatedClasses: [ | 248 instantiatedClasses: [ |
246 helpers.compiler.listClass], | 249 coreClasses.listClass], |
247 otherImpacts: [ | 250 otherImpacts: [ |
248 getRuntimeTypeArgument, | 251 getRuntimeTypeArgument, |
249 needsInt('Needed for accessing a type variable literal on this.')]); | 252 needsInt('Needed for accessing a type variable literal on this.')]); |
250 | 253 |
251 BackendImpact get typeCheck => new BackendImpact( | 254 BackendImpact get typeCheck => new BackendImpact( |
252 instantiatedClasses: [ | 255 instantiatedClasses: [ |
253 helpers.compiler.boolClass]); | 256 coreClasses.boolClass]); |
254 | 257 |
255 BackendImpact get checkedModeTypeCheck => new BackendImpact( | 258 BackendImpact get checkedModeTypeCheck => new BackendImpact( |
256 staticUses: [ | 259 staticUses: [ |
257 helpers.throwRuntimeError]); | 260 helpers.throwRuntimeError]); |
258 | 261 |
259 BackendImpact get malformedTypeCheck => new BackendImpact( | 262 BackendImpact get malformedTypeCheck => new BackendImpact( |
260 staticUses: [ | 263 staticUses: [ |
261 helpers.throwTypeError]); | 264 helpers.throwTypeError]); |
262 | 265 |
263 BackendImpact get genericTypeCheck => new BackendImpact( | 266 BackendImpact get genericTypeCheck => new BackendImpact( |
264 staticUses: [ | 267 staticUses: [ |
265 helpers.checkSubtype, | 268 helpers.checkSubtype, |
266 // TODO(johnniwinther): Investigate why this is needed. | 269 // TODO(johnniwinther): Investigate why this is needed. |
267 helpers.setRuntimeTypeInfo, | 270 helpers.setRuntimeTypeInfo, |
268 helpers.getRuntimeTypeInfo], | 271 helpers.getRuntimeTypeInfo], |
269 instantiatedClasses: [ | 272 instantiatedClasses: [ |
270 helpers.compiler.listClass], | 273 coreClasses.listClass], |
271 otherImpacts: [ | 274 otherImpacts: [ |
272 getRuntimeTypeArgument]); | 275 getRuntimeTypeArgument]); |
273 | 276 |
274 BackendImpact get genericCheckedModeTypeCheck => new BackendImpact( | 277 BackendImpact get genericCheckedModeTypeCheck => new BackendImpact( |
275 staticUses: [ | 278 staticUses: [ |
276 helpers.assertSubtype]); | 279 helpers.assertSubtype]); |
277 | 280 |
278 BackendImpact get typeVariableTypeCheck => new BackendImpact( | 281 BackendImpact get typeVariableTypeCheck => new BackendImpact( |
279 staticUses: [ | 282 staticUses: [ |
280 helpers.checkSubtypeOfRuntimeType]); | 283 helpers.checkSubtypeOfRuntimeType]); |
281 | 284 |
282 BackendImpact get typeVariableCheckedModeTypeCheck => new BackendImpact( | 285 BackendImpact get typeVariableCheckedModeTypeCheck => new BackendImpact( |
283 staticUses: [ | 286 staticUses: [ |
284 helpers.assertSubtypeOfRuntimeType]); | 287 helpers.assertSubtypeOfRuntimeType]); |
285 | 288 |
286 BackendImpact get functionTypeCheck => new BackendImpact( | 289 BackendImpact get functionTypeCheck => new BackendImpact( |
287 staticUses: [ | 290 staticUses: [ |
288 helpers.functionTypeTestMetaHelper]); | 291 helpers.functionTypeTestMetaHelper]); |
289 | 292 |
290 BackendImpact get nativeTypeCheck => new BackendImpact( | 293 BackendImpact get nativeTypeCheck => new BackendImpact( |
291 staticUses: [ | 294 staticUses: [ |
292 // We will neeed to add the "$is" and "$as" properties on the | 295 // We will neeed to add the "$is" and "$as" properties on the |
293 // JavaScript object prototype, so we make sure | 296 // JavaScript object prototype, so we make sure |
294 // [:defineProperty:] is compiled. | 297 // [:defineProperty:] is compiled. |
295 helpers.defineProperty]); | 298 helpers.defineProperty]); |
296 | 299 |
297 BackendImpact get closure => new BackendImpact( | 300 BackendImpact get closure => new BackendImpact( |
298 instantiatedClasses: [ | 301 instantiatedClasses: [ |
299 helpers.compiler.functionClass]); | 302 coreClasses.functionClass]); |
300 } | 303 } |
OLD | NEW |