| 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 js_backend.backend; | 5 library js_backend.backend; |
| 6 | 6 |
| 7 import 'dart:async' show Future; | 7 import 'dart:async' show Future; |
| 8 | 8 |
| 9 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; | 9 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; |
| 10 | 10 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 import '../util/util.dart'; | 72 import '../util/util.dart'; |
| 73 import '../world.dart' show ClosedWorld, ClosedWorldRefiner; | 73 import '../world.dart' show ClosedWorld, ClosedWorldRefiner; |
| 74 import 'backend_helpers.dart'; | 74 import 'backend_helpers.dart'; |
| 75 import 'backend_impact.dart'; | 75 import 'backend_impact.dart'; |
| 76 import 'backend_serialization.dart' show JavaScriptBackendSerialization; | 76 import 'backend_serialization.dart' show JavaScriptBackendSerialization; |
| 77 import 'backend_usage.dart'; | 77 import 'backend_usage.dart'; |
| 78 import 'checked_mode_helpers.dart'; | 78 import 'checked_mode_helpers.dart'; |
| 79 import 'constant_handler_javascript.dart'; | 79 import 'constant_handler_javascript.dart'; |
| 80 import 'custom_elements_analysis.dart'; | 80 import 'custom_elements_analysis.dart'; |
| 81 import 'enqueuer.dart'; | 81 import 'enqueuer.dart'; |
| 82 import 'interceptor_data.dart' show InterceptorData; | 82 import 'interceptor_data.dart'; |
| 83 import 'js_interop_analysis.dart' show JsInteropAnalysis; | 83 import 'js_interop_analysis.dart' show JsInteropAnalysis; |
| 84 import 'lookup_map_analysis.dart' show LookupMapAnalysis; | 84 import 'lookup_map_analysis.dart' show LookupMapAnalysis; |
| 85 import 'mirrors_analysis.dart'; | 85 import 'mirrors_analysis.dart'; |
| 86 import 'mirrors_data.dart'; | 86 import 'mirrors_data.dart'; |
| 87 import 'namer.dart'; | 87 import 'namer.dart'; |
| 88 import 'native_data.dart' show NativeData; | 88 import 'native_data.dart' show NativeData; |
| 89 import 'no_such_method_registry.dart'; | 89 import 'no_such_method_registry.dart'; |
| 90 import 'patch_resolver.dart'; | 90 import 'patch_resolver.dart'; |
| 91 import 'type_variable_handler.dart'; | 91 import 'type_variable_handler.dart'; |
| 92 | 92 |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 /// Interface for serialization of backend specific data. | 432 /// Interface for serialization of backend specific data. |
| 433 JavaScriptBackendSerialization serialization; | 433 JavaScriptBackendSerialization serialization; |
| 434 | 434 |
| 435 StagedWorldImpactBuilder constantImpactsForResolution = | 435 StagedWorldImpactBuilder constantImpactsForResolution = |
| 436 new StagedWorldImpactBuilder(); | 436 new StagedWorldImpactBuilder(); |
| 437 | 437 |
| 438 StagedWorldImpactBuilder constantImpactsForCodegen = | 438 StagedWorldImpactBuilder constantImpactsForCodegen = |
| 439 new StagedWorldImpactBuilder(); | 439 new StagedWorldImpactBuilder(); |
| 440 | 440 |
| 441 final NativeData nativeData = new NativeData(); | 441 final NativeData nativeData = new NativeData(); |
| 442 InterceptorDataBuilder _interceptorDataBuilder; |
| 442 InterceptorData _interceptorData; | 443 InterceptorData _interceptorData; |
| 444 OneShotInterceptorData _oneShotInterceptorData; |
| 443 BackendUsageImpl _backendUsage; | 445 BackendUsageImpl _backendUsage; |
| 444 final MirrorsData mirrorsData; | 446 final MirrorsData mirrorsData; |
| 445 CheckedModeHelpers _checkedModeHelpers; | 447 CheckedModeHelpers _checkedModeHelpers; |
| 446 | 448 |
| 447 ResolutionEnqueuerListener _resolutionEnqueuerListener; | 449 ResolutionEnqueuerListener _resolutionEnqueuerListener; |
| 448 CodegenEnqueuerListener _codegenEnqueuerListener; | 450 CodegenEnqueuerListener _codegenEnqueuerListener; |
| 449 | 451 |
| 450 BackendHelpers helpers; | 452 BackendHelpers helpers; |
| 451 final BackendImpacts impacts; | 453 final BackendImpacts impacts; |
| 452 | 454 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 mirrorsAnalysis = new MirrorsAnalysis(this, compiler.resolution); | 489 mirrorsAnalysis = new MirrorsAnalysis(this, compiler.resolution); |
| 488 | 490 |
| 489 noSuchMethodRegistry = new NoSuchMethodRegistry(this); | 491 noSuchMethodRegistry = new NoSuchMethodRegistry(this); |
| 490 kernelTask = new KernelTask(compiler); | 492 kernelTask = new KernelTask(compiler); |
| 491 constantCompilerTask = new JavaScriptConstantTask(compiler); | 493 constantCompilerTask = new JavaScriptConstantTask(compiler); |
| 492 impactTransformer = new JavaScriptImpactTransformer(this); | 494 impactTransformer = new JavaScriptImpactTransformer(this); |
| 493 patchResolverTask = new PatchResolverTask(compiler); | 495 patchResolverTask = new PatchResolverTask(compiler); |
| 494 functionCompiler = | 496 functionCompiler = |
| 495 new SsaFunctionCompiler(this, sourceInformationStrategy, useKernel); | 497 new SsaFunctionCompiler(this, sourceInformationStrategy, useKernel); |
| 496 serialization = new JavaScriptBackendSerialization(this); | 498 serialization = new JavaScriptBackendSerialization(this); |
| 497 _interceptorData = new InterceptorData(nativeData, helpers, commonElements); | 499 _interceptorDataBuilder = |
| 500 new InterceptorDataBuilderImpl(nativeData, helpers, commonElements); |
| 498 backendClasses = new JavaScriptBackendClasses( | 501 backendClasses = new JavaScriptBackendClasses( |
| 499 compiler.elementEnvironment, helpers, nativeData, _interceptorData); | 502 compiler.elementEnvironment, helpers, nativeData); |
| 500 _resolutionEnqueuerListener = new ResolutionEnqueuerListener(this); | 503 _resolutionEnqueuerListener = new ResolutionEnqueuerListener(this); |
| 501 _codegenEnqueuerListener = new CodegenEnqueuerListener(this); | 504 _codegenEnqueuerListener = new CodegenEnqueuerListener(this); |
| 502 } | 505 } |
| 503 | 506 |
| 504 /// The [ConstantSystem] used to interpret compile-time constants for this | 507 /// The [ConstantSystem] used to interpret compile-time constants for this |
| 505 /// backend. | 508 /// backend. |
| 506 ConstantSystem get constantSystem => constants.constantSystem; | 509 ConstantSystem get constantSystem => constants.constantSystem; |
| 507 | 510 |
| 508 DiagnosticReporter get reporter => compiler.reporter; | 511 DiagnosticReporter get reporter => compiler.reporter; |
| 509 | 512 |
| 510 CommonElements get commonElements => compiler.commonElements; | 513 CommonElements get commonElements => compiler.commonElements; |
| 511 | 514 |
| 512 Resolution get resolution => compiler.resolution; | 515 Resolution get resolution => compiler.resolution; |
| 513 | 516 |
| 514 InterceptorData get interceptorData => _interceptorData; | 517 InterceptorData get interceptorData { |
| 518 assert(invariant(NO_LOCATION_SPANNABLE, _interceptorData != null, |
| 519 message: "InterceptorData has not been computed yet.")); |
| 520 return _interceptorData; |
| 521 } |
| 522 |
| 523 OneShotInterceptorData get oneShotInterceptorData { |
| 524 assert(invariant(NO_LOCATION_SPANNABLE, _oneShotInterceptorData != null, |
| 525 message: "OneShotInterceptorData has not been prepared yet.")); |
| 526 return _oneShotInterceptorData; |
| 527 } |
| 515 | 528 |
| 516 BackendUsage get backendUsage => _backendUsage; | 529 BackendUsage get backendUsage => _backendUsage; |
| 517 | 530 |
| 518 BackendUsageBuilder get backendUsageBuilder => _backendUsage; | 531 BackendUsageBuilder get backendUsageBuilder => _backendUsage; |
| 519 | 532 |
| 520 CheckedModeHelpers get checkedModeHelpers => _checkedModeHelpers; | 533 CheckedModeHelpers get checkedModeHelpers => _checkedModeHelpers; |
| 521 | 534 |
| 522 EnqueuerListener get resolutionEnqueuerListener => | 535 EnqueuerListener get resolutionEnqueuerListener => |
| 523 _resolutionEnqueuerListener; | 536 _resolutionEnqueuerListener; |
| 524 | 537 |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 | 792 |
| 780 void onResolutionComplete( | 793 void onResolutionComplete( |
| 781 ClosedWorld closedWorld, ClosedWorldRefiner closedWorldRefiner) { | 794 ClosedWorld closedWorld, ClosedWorldRefiner closedWorldRefiner) { |
| 782 for (Entity entity in compiler.enqueuer.resolution.processedEntities) { | 795 for (Entity entity in compiler.enqueuer.resolution.processedEntities) { |
| 783 processAnnotations(entity, closedWorldRefiner); | 796 processAnnotations(entity, closedWorldRefiner); |
| 784 } | 797 } |
| 785 mirrorsData.computeMembersNeededForReflection(closedWorld); | 798 mirrorsData.computeMembersNeededForReflection(closedWorld); |
| 786 rti.computeClassesNeedingRti( | 799 rti.computeClassesNeedingRti( |
| 787 compiler.enqueuer.resolution.worldBuilder, closedWorld); | 800 compiler.enqueuer.resolution.worldBuilder, closedWorld); |
| 788 _registeredMetadata.clear(); | 801 _registeredMetadata.clear(); |
| 789 interceptorData.onResolutionComplete(closedWorld); | 802 _interceptorData = |
| 803 _interceptorDataBuilder.onResolutionComplete(closedWorld); |
| 804 _oneShotInterceptorData = |
| 805 new OneShotInterceptorData(interceptorData, helpers); |
| 790 } | 806 } |
| 791 | 807 |
| 792 void onTypeInferenceComplete() { | 808 void onTypeInferenceComplete() { |
| 793 noSuchMethodRegistry.onTypeInferenceComplete(); | 809 noSuchMethodRegistry.onTypeInferenceComplete(); |
| 794 } | 810 } |
| 795 | 811 |
| 796 /// Called to register that an instantiated generic class has a call method. | 812 /// Called to register that an instantiated generic class has a call method. |
| 797 /// Any backend specific [WorldImpact] of this is returned. | 813 /// Any backend specific [WorldImpact] of this is returned. |
| 798 /// | 814 /// |
| 799 /// Note: The [callMethod] is registered even thought it doesn't reference | 815 /// Note: The [callMethod] is registered even thought it doesn't reference |
| (...skipping 1317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2117 break; | 2133 break; |
| 2118 default: | 2134 default: |
| 2119 } | 2135 } |
| 2120 } | 2136 } |
| 2121 | 2137 |
| 2122 for (String name in impact.constSymbols) { | 2138 for (String name in impact.constSymbols) { |
| 2123 backend.mirrorsData.registerConstSymbol(name); | 2139 backend.mirrorsData.registerConstSymbol(name); |
| 2124 } | 2140 } |
| 2125 | 2141 |
| 2126 for (Set<ClassElement> classes in impact.specializedGetInterceptors) { | 2142 for (Set<ClassElement> classes in impact.specializedGetInterceptors) { |
| 2127 backend.interceptorData | 2143 backend.oneShotInterceptorData |
| 2128 .registerSpecializedGetInterceptor(classes, backend.namer); | 2144 .registerSpecializedGetInterceptor(classes, backend.namer); |
| 2129 } | 2145 } |
| 2130 | 2146 |
| 2131 if (impact.usesInterceptor) { | 2147 if (impact.usesInterceptor) { |
| 2132 if (backend.codegenEnqueuer.nativeEnqueuer.hasInstantiatedNativeClasses) { | 2148 if (backend.codegenEnqueuer.nativeEnqueuer.hasInstantiatedNativeClasses) { |
| 2133 backendUsage.registerBackendImpact(transformed, impacts.interceptorUse); | 2149 backendUsage.registerBackendImpact(transformed, impacts.interceptorUse); |
| 2134 } | 2150 } |
| 2135 } | 2151 } |
| 2136 | 2152 |
| 2137 for (ClassElement element in impact.typeConstants) { | 2153 for (ClassElement element in impact.typeConstants) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2212 // performed. | 2228 // performed. |
| 2213 resolution.emptyCache(); | 2229 resolution.emptyCache(); |
| 2214 } | 2230 } |
| 2215 } | 2231 } |
| 2216 } | 2232 } |
| 2217 | 2233 |
| 2218 class JavaScriptBackendClasses implements BackendClasses { | 2234 class JavaScriptBackendClasses implements BackendClasses { |
| 2219 final ElementEnvironment _env; | 2235 final ElementEnvironment _env; |
| 2220 final BackendHelpers helpers; | 2236 final BackendHelpers helpers; |
| 2221 final NativeData _nativeData; | 2237 final NativeData _nativeData; |
| 2222 final InterceptorData _interceptorData; | |
| 2223 | 2238 |
| 2224 JavaScriptBackendClasses( | 2239 JavaScriptBackendClasses(this._env, this.helpers, this._nativeData); |
| 2225 this._env, this.helpers, this._nativeData, this._interceptorData); | |
| 2226 | 2240 |
| 2227 ClassElement get intClass => helpers.jsIntClass; | 2241 ClassElement get intClass => helpers.jsIntClass; |
| 2228 ClassElement get uint32Class => helpers.jsUInt32Class; | 2242 ClassElement get uint32Class => helpers.jsUInt32Class; |
| 2229 ClassElement get uint31Class => helpers.jsUInt31Class; | 2243 ClassElement get uint31Class => helpers.jsUInt31Class; |
| 2230 ClassElement get positiveIntClass => helpers.jsPositiveIntClass; | 2244 ClassElement get positiveIntClass => helpers.jsPositiveIntClass; |
| 2231 ClassElement get doubleClass => helpers.jsDoubleClass; | 2245 ClassElement get doubleClass => helpers.jsDoubleClass; |
| 2232 ClassElement get numClass => helpers.jsNumberClass; | 2246 ClassElement get numClass => helpers.jsNumberClass; |
| 2233 ClassElement get stringClass => helpers.jsStringClass; | 2247 ClassElement get stringClass => helpers.jsStringClass; |
| 2234 ClassElement get listClass => helpers.jsArrayClass; | 2248 ClassElement get listClass => helpers.jsArrayClass; |
| 2235 ClassElement get mutableListClass => helpers.jsMutableArrayClass; | 2249 ClassElement get mutableListClass => helpers.jsMutableArrayClass; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2254 | 2268 |
| 2255 bool isDefaultEqualityImplementation(MemberElement element) { | 2269 bool isDefaultEqualityImplementation(MemberElement element) { |
| 2256 assert(element.name == '=='); | 2270 assert(element.name == '=='); |
| 2257 ClassElement classElement = element.enclosingClass; | 2271 ClassElement classElement = element.enclosingClass; |
| 2258 return classElement == helpers.commonElements.objectClass || | 2272 return classElement == helpers.commonElements.objectClass || |
| 2259 classElement == helpers.jsInterceptorClass || | 2273 classElement == helpers.jsInterceptorClass || |
| 2260 classElement == helpers.jsNullClass; | 2274 classElement == helpers.jsNullClass; |
| 2261 } | 2275 } |
| 2262 | 2276 |
| 2263 @override | 2277 @override |
| 2264 bool isInterceptorClass(ClassElement cls) { | |
| 2265 return _interceptorData.isInterceptorClass(cls); | |
| 2266 } | |
| 2267 | |
| 2268 @override | |
| 2269 bool isNativeClass(ClassElement element) { | 2278 bool isNativeClass(ClassElement element) { |
| 2270 return _nativeData.isNative(element); | 2279 return _nativeData.isNative(element); |
| 2271 } | 2280 } |
| 2272 | 2281 |
| 2273 @override | 2282 @override |
| 2274 bool isNativeMember(MemberElement element) { | 2283 bool isNativeMember(MemberElement element) { |
| 2275 return _nativeData.isNative(element); | 2284 return _nativeData.isNative(element); |
| 2276 } | 2285 } |
| 2277 | 2286 |
| 2278 InterfaceType getConstantMapTypeFor(InterfaceType sourceType, | 2287 InterfaceType getConstantMapTypeFor(InterfaceType sourceType, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2306 EnqueuerListenerBase(this._backend); | 2315 EnqueuerListenerBase(this._backend); |
| 2307 | 2316 |
| 2308 // TODO(johnniwinther): Change these to final fields. | 2317 // TODO(johnniwinther): Change these to final fields. |
| 2309 CommonElements get commonElements => _backend.commonElements; | 2318 CommonElements get commonElements => _backend.commonElements; |
| 2310 BackendHelpers get helpers => _backend.helpers; | 2319 BackendHelpers get helpers => _backend.helpers; |
| 2311 BackendImpacts get impacts => _backend.impacts; | 2320 BackendImpacts get impacts => _backend.impacts; |
| 2312 BackendUsageBuilder get backendUsage => _backend.backendUsageBuilder; | 2321 BackendUsageBuilder get backendUsage => _backend.backendUsageBuilder; |
| 2313 CustomElementsAnalysis get customElementsAnalysis => | 2322 CustomElementsAnalysis get customElementsAnalysis => |
| 2314 _backend.customElementsAnalysis; | 2323 _backend.customElementsAnalysis; |
| 2315 NativeData get nativeData => _backend.nativeData; | 2324 NativeData get nativeData => _backend.nativeData; |
| 2316 InterceptorData get interceptorData => _backend.interceptorData; | 2325 InterceptorDataBuilder get interceptorData => |
| 2326 _backend._interceptorDataBuilder; |
| 2317 RuntimeTypes get rti => _backend.rti; | 2327 RuntimeTypes get rti => _backend.rti; |
| 2318 TypeVariableHandler get typeVariableHandler => _backend.typeVariableHandler; | 2328 TypeVariableHandler get typeVariableHandler => _backend.typeVariableHandler; |
| 2319 Resolution get resolution => _backend.resolution; | 2329 Resolution get resolution => _backend.resolution; |
| 2320 MirrorsData get mirrorsData => _backend.mirrorsData; | 2330 MirrorsData get mirrorsData => _backend.mirrorsData; |
| 2321 CompilerOptions get options => _backend.compiler.options; | 2331 CompilerOptions get options => _backend.compiler.options; |
| 2322 | 2332 |
| 2323 WorldImpact registerBoundClosure() { | 2333 WorldImpact registerBoundClosure() { |
| 2324 return backendUsage.createImpactFor(impacts.memberClosure); | 2334 return backendUsage.createImpactFor(impacts.memberClosure); |
| 2325 } | 2335 } |
| 2326 | 2336 |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2691 WorldImpact registerInstantiatedClass(ClassEntity cls) { | 2701 WorldImpact registerInstantiatedClass(ClassEntity cls) { |
| 2692 WorldImpact worldImpact = _processClass(cls, forResolution: false); | 2702 WorldImpact worldImpact = _processClass(cls, forResolution: false); |
| 2693 lookupMapAnalysis.registerInstantiatedClass(cls); | 2703 lookupMapAnalysis.registerInstantiatedClass(cls); |
| 2694 return worldImpact; | 2704 return worldImpact; |
| 2695 } | 2705 } |
| 2696 | 2706 |
| 2697 // TODO(johnniwinther): Avoid the need for accessing [_backend]. | 2707 // TODO(johnniwinther): Avoid the need for accessing [_backend]. |
| 2698 bool methodNeedsRti(FunctionElement function) => | 2708 bool methodNeedsRti(FunctionElement function) => |
| 2699 _backend.methodNeedsRti(function); | 2709 _backend.methodNeedsRti(function); |
| 2700 } | 2710 } |
| OLD | NEW |