| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library dart2js.js_helpers.impact; |
| 6 |
| 7 import '../common/names.dart' show |
| 8 Identifiers; |
| 9 import '../compiler.dart' show |
| 10 Compiler; |
| 11 import '../dart_types.dart' show |
| 12 InterfaceType; |
| 13 import '../elements/elements.dart' show |
| 14 ClassElement, |
| 15 Element; |
| 16 |
| 17 import 'backend_helpers.dart'; |
| 18 import 'constant_system_javascript.dart'; |
| 19 import 'js_backend.dart'; |
| 20 |
| 21 /// A set of JavaScript backend dependencies. |
| 22 class BackendImpact { |
| 23 final List<Element> staticUses; |
| 24 final List<InterfaceType> instantiatedTypes; |
| 25 final List<ClassElement> instantiatedClasses; |
| 26 final List<BackendImpact> otherImpacts; |
| 27 |
| 28 BackendImpact({this.staticUses: const <Element>[], |
| 29 this.instantiatedTypes: const <InterfaceType>[], |
| 30 this.instantiatedClasses: const <ClassElement>[], |
| 31 this.otherImpacts: const <BackendImpact>[]}); |
| 32 } |
| 33 |
| 34 /// The JavaScript backend dependencies for various features. |
| 35 class BackendImpacts { |
| 36 final Compiler compiler; |
| 37 |
| 38 BackendImpacts(this.compiler); |
| 39 |
| 40 JavaScriptBackend get backend => compiler.backend; |
| 41 |
| 42 BackendHelpers get helpers => backend.helpers; |
| 43 |
| 44 BackendImpact get getRuntimeTypeArgument => new BackendImpact( |
| 45 staticUses: [ |
| 46 helpers.getRuntimeTypeArgument, |
| 47 helpers.getTypeArgumentByIndex, |
| 48 helpers.copyTypeArguments]); |
| 49 |
| 50 BackendImpact get computeSignature => new BackendImpact( |
| 51 staticUses: [ |
| 52 helpers.setRuntimeTypeInfo, |
| 53 helpers.getRuntimeTypeInfo, |
| 54 helpers.computeSignature, |
| 55 helpers.getRuntimeTypeArguments], |
| 56 instantiatedClasses: [ |
| 57 compiler.listClass]); |
| 58 |
| 59 BackendImpact get asyncBody => new BackendImpact( |
| 60 staticUses: [ |
| 61 helpers.asyncHelper, |
| 62 helpers.syncCompleterConstructor, |
| 63 helpers.streamIteratorConstructor, |
| 64 helpers.wrapBody]); |
| 65 |
| 66 BackendImpact get syncStarBody => new BackendImpact( |
| 67 staticUses: [ |
| 68 helpers.syncStarIterableConstructor, |
| 69 helpers.endOfIteration, |
| 70 helpers.yieldStar, |
| 71 helpers.syncStarUncaughtError], |
| 72 instantiatedClasses: [ |
| 73 helpers.syncStarIterable]); |
| 74 |
| 75 BackendImpact get asyncStarBody => new BackendImpact( |
| 76 staticUses: [ |
| 77 helpers.asyncStarHelper, |
| 78 helpers.streamOfController, |
| 79 helpers.yieldSingle, |
| 80 helpers.yieldStar, |
| 81 helpers.asyncStarControllerConstructor, |
| 82 helpers.streamIteratorConstructor, |
| 83 helpers.wrapBody], |
| 84 instantiatedClasses: [ |
| 85 helpers.asyncStarController]); |
| 86 |
| 87 BackendImpact get typeVariableBoundCheck => new BackendImpact( |
| 88 staticUses: [ |
| 89 helpers.throwTypeError, |
| 90 helpers.assertIsSubtype]); |
| 91 |
| 92 BackendImpact get abstractClassInstantiation => new BackendImpact( |
| 93 staticUses: [ |
| 94 helpers.throwAbstractClassInstantiationError], |
| 95 otherImpacts: [ |
| 96 needsString('Needed to encode the message.')]); |
| 97 |
| 98 BackendImpact get fallThroughError => new BackendImpact( |
| 99 staticUses: [ |
| 100 helpers.fallThroughError]); |
| 101 |
| 102 BackendImpact get asCheck => new BackendImpact( |
| 103 staticUses: [ |
| 104 helpers.throwRuntimeError]); |
| 105 |
| 106 BackendImpact get throwNoSuchMethod => new BackendImpact( |
| 107 staticUses: [ |
| 108 helpers.throwNoSuchMethod], |
| 109 otherImpacts: [ |
| 110 // Also register the types of the arguments passed to this method. |
| 111 needsList( |
| 112 'Needed to encode the arguments for throw NoSuchMethodError.'), |
| 113 needsString( |
| 114 'Needed to encode the name for throw NoSuchMethodError.')]); |
| 115 |
| 116 BackendImpact get throwRuntimeError => new BackendImpact( |
| 117 staticUses: [ |
| 118 helpers.throwRuntimeError], |
| 119 // Also register the types of the arguments passed to this method. |
| 120 instantiatedClasses: [ |
| 121 helpers.compiler.stringClass]); |
| 122 |
| 123 BackendImpact get superNoSuchMethod => new BackendImpact( |
| 124 staticUses: [ |
| 125 helpers.createInvocationMirror, |
| 126 helpers.compiler.objectClass.lookupLocalMember( |
| 127 Identifiers.noSuchMethod_)], |
| 128 otherImpacts: [ |
| 129 needsInt( |
| 130 'Needed to encode the invocation kind of super.noSuchMethod.'), |
| 131 needsList( |
| 132 'Needed to encode the arguments of super.noSuchMethod.'), |
| 133 needsString( |
| 134 'Needed to encode the name of super.noSuchMethod.')]); |
| 135 |
| 136 BackendImpact get constantMapLiteral { |
| 137 |
| 138 ClassElement find(String name) { |
| 139 return helpers.find(backend.jsHelperLibrary, name); |
| 140 } |
| 141 |
| 142 return new BackendImpact( |
| 143 instantiatedClasses: [ |
| 144 find(JavaScriptMapConstant.DART_CLASS), |
| 145 find(JavaScriptMapConstant.DART_PROTO_CLASS), |
| 146 find(JavaScriptMapConstant.DART_STRING_CLASS), |
| 147 find(JavaScriptMapConstant.DART_GENERAL_CLASS)]); |
| 148 } |
| 149 |
| 150 BackendImpact get symbolConstructor => new BackendImpact( |
| 151 staticUses: [ |
| 152 helpers.compiler.symbolValidatedConstructor]); |
| 153 |
| 154 |
| 155 BackendImpact get incDecOperation => |
| 156 needsInt('Needed for the `+ 1` or `- 1` operation of ++/--.'); |
| 157 |
| 158 /// Helper for registering that `int` is needed. |
| 159 BackendImpact needsInt(String reason) { |
| 160 // TODO(johnniwinther): Register [reason] for use in dump-info. |
| 161 return new BackendImpact( |
| 162 instantiatedClasses: [helpers.compiler.intClass]); |
| 163 } |
| 164 |
| 165 /// Helper for registering that `List` is needed. |
| 166 BackendImpact needsList(String reason) { |
| 167 // TODO(johnniwinther): Register [reason] for use in dump-info. |
| 168 return new BackendImpact( |
| 169 instantiatedClasses: [helpers.compiler.listClass]); |
| 170 } |
| 171 |
| 172 /// Helper for registering that `String` is needed. |
| 173 BackendImpact needsString(String reason) { |
| 174 // TODO(johnniwinther): Register [reason] for use in dump-info. |
| 175 return new BackendImpact( |
| 176 instantiatedClasses: [ |
| 177 helpers.compiler.stringClass]); |
| 178 } |
| 179 |
| 180 BackendImpact get assertWithoutMessage => new BackendImpact( |
| 181 staticUses: [ |
| 182 helpers.assertHelper]); |
| 183 |
| 184 BackendImpact get assertWithMessage => new BackendImpact( |
| 185 staticUses: [ |
| 186 helpers.assertTest, |
| 187 helpers.assertThrow]); |
| 188 |
| 189 BackendImpact get asyncForIn => new BackendImpact( |
| 190 staticUses: [ |
| 191 helpers.streamIteratorConstructor]); |
| 192 |
| 193 BackendImpact get stringInterpolation => new BackendImpact( |
| 194 staticUses: [ |
| 195 helpers.stringInterpolationHelper]); |
| 196 |
| 197 BackendImpact get catchStatement => new BackendImpact( |
| 198 staticUses: [ |
| 199 helpers.exceptionUnwrapper], |
| 200 instantiatedClasses: [ |
| 201 backend.jsPlainJavaScriptObjectClass, |
| 202 backend.jsUnknownJavaScriptObjectClass]); |
| 203 |
| 204 BackendImpact get throwExpression => new BackendImpact( |
| 205 // We don't know ahead of time whether we will need the throw in a |
| 206 // statement context or an expression context, so we register both |
| 207 // here, even though we may not need the throwExpression helper. |
| 208 staticUses: [ |
| 209 helpers.wrapExceptionHelper, |
| 210 helpers.throwExpressionHelper]); |
| 211 |
| 212 BackendImpact get lazyField => new BackendImpact( |
| 213 staticUses: [ |
| 214 helpers.cyclicThrowHelper]); |
| 215 |
| 216 BackendImpact get typeLiteral => new BackendImpact( |
| 217 instantiatedClasses: [ |
| 218 backend.typeImplementation], |
| 219 staticUses: [ |
| 220 helpers.createRuntimeType]); |
| 221 |
| 222 BackendImpact get stackTraceInCatch => new BackendImpact( |
| 223 staticUses: [ |
| 224 helpers.traceFromException]); |
| 225 |
| 226 BackendImpact get syncForIn => new BackendImpact( |
| 227 // The SSA builder recognizes certain for-in loops and can generate calls |
| 228 // to throwConcurrentModificationError. |
| 229 staticUses: [ |
| 230 helpers.checkConcurrentModificationError]); |
| 231 |
| 232 BackendImpact get typeVariableExpression => new BackendImpact( |
| 233 staticUses: [ |
| 234 helpers.setRuntimeTypeInfo, |
| 235 helpers.getRuntimeTypeInfo, |
| 236 helpers.runtimeTypeToString, |
| 237 helpers.createRuntimeType], |
| 238 instantiatedClasses: [ |
| 239 helpers.compiler.listClass], |
| 240 otherImpacts: [ |
| 241 getRuntimeTypeArgument, |
| 242 needsInt('Needed for accessing a type variable literal on this.')]); |
| 243 |
| 244 BackendImpact get typeCheck => new BackendImpact( |
| 245 instantiatedClasses: [ |
| 246 helpers.compiler.boolClass]); |
| 247 |
| 248 BackendImpact get checkedModeTypeCheck => new BackendImpact( |
| 249 staticUses: [ |
| 250 helpers.throwRuntimeError]); |
| 251 |
| 252 BackendImpact get malformedTypeCheck => new BackendImpact( |
| 253 staticUses: [ |
| 254 helpers.throwTypeError]); |
| 255 |
| 256 BackendImpact get genericTypeCheck => new BackendImpact( |
| 257 staticUses: [ |
| 258 helpers.checkSubtype, |
| 259 // TODO(johnniwinther): Investigate why this is needed. |
| 260 helpers.setRuntimeTypeInfo, |
| 261 helpers.getRuntimeTypeInfo], |
| 262 instantiatedClasses: [ |
| 263 helpers.compiler.listClass], |
| 264 otherImpacts: [ |
| 265 getRuntimeTypeArgument]); |
| 266 |
| 267 BackendImpact get genericCheckedModeTypeCheck => new BackendImpact( |
| 268 staticUses: [ |
| 269 helpers.assertSubtype]); |
| 270 |
| 271 BackendImpact get typeVariableTypeCheck => new BackendImpact( |
| 272 staticUses: [ |
| 273 helpers.checkSubtypeOfRuntimeType]); |
| 274 |
| 275 BackendImpact get typeVariableCheckedModeTypeCheck => new BackendImpact( |
| 276 staticUses: [ |
| 277 helpers.assertSubtypeOfRuntimeType]); |
| 278 |
| 279 BackendImpact get functionTypeCheck => new BackendImpact( |
| 280 staticUses: [ |
| 281 helpers.functionTypeTestMetaHelper]); |
| 282 |
| 283 BackendImpact get nativeTypeCheck => new BackendImpact( |
| 284 staticUses: [ |
| 285 // We will neeed to add the "$is" and "$as" properties on the |
| 286 // JavaScript object prototype, so we make sure |
| 287 // [:defineProperty:] is compiled. |
| 288 helpers.defineProperty]); |
| 289 } |
| OLD | NEW |