| 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 part of js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 const VERBOSE_OPTIMIZER_HINTS = false; | 7 const VERBOSE_OPTIMIZER_HINTS = false; |
| 8 | 8 |
| 9 const bool USE_CPS_IR = const bool.fromEnvironment("USE_CPS_IR"); | 9 const bool USE_CPS_IR = const bool.fromEnvironment("USE_CPS_IR"); |
| 10 | 10 |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 | 578 |
| 579 TypeVariableHandler typeVariableHandler; | 579 TypeVariableHandler typeVariableHandler; |
| 580 | 580 |
| 581 /// Number of methods compiled before considering reflection. | 581 /// Number of methods compiled before considering reflection. |
| 582 int preMirrorsMethodCount = 0; | 582 int preMirrorsMethodCount = 0; |
| 583 | 583 |
| 584 /// Resolution and codegen support for generating table of interceptors and | 584 /// Resolution and codegen support for generating table of interceptors and |
| 585 /// constructors for custom elements. | 585 /// constructors for custom elements. |
| 586 CustomElementsAnalysis customElementsAnalysis; | 586 CustomElementsAnalysis customElementsAnalysis; |
| 587 | 587 |
| 588 /// Support for classifying `noSuchMethod` implementations. |
| 589 NoSuchMethodAnalysis noSuchMethodAnalysis; |
| 590 |
| 588 JavaScriptConstantTask constantCompilerTask; | 591 JavaScriptConstantTask constantCompilerTask; |
| 589 | 592 |
| 590 JavaScriptResolutionCallbacks resolutionCallbacks; | 593 JavaScriptResolutionCallbacks resolutionCallbacks; |
| 591 | 594 |
| 592 PatchResolverTask patchResolverTask; | 595 PatchResolverTask patchResolverTask; |
| 593 | 596 |
| 594 bool get canHandleCompilationFailed => true; | 597 bool get canHandleCompilationFailed => true; |
| 595 | 598 |
| 596 JavaScriptBackend(Compiler compiler, bool generateSourceMap) | 599 JavaScriptBackend(Compiler compiler, bool generateSourceMap) |
| 597 : namer = determineNamer(compiler), | 600 : namer = determineNamer(compiler), |
| 598 oneShotInterceptors = new Map<String, Selector>(), | 601 oneShotInterceptors = new Map<String, Selector>(), |
| 599 interceptedElements = new Map<String, Set<Element>>(), | 602 interceptedElements = new Map<String, Set<Element>>(), |
| 600 rti = new RuntimeTypes(compiler), | 603 rti = new RuntimeTypes(compiler), |
| 601 specializedGetInterceptors = new Map<String, Set<ClassElement>>(), | 604 specializedGetInterceptors = new Map<String, Set<ClassElement>>(), |
| 602 super(compiler) { | 605 super(compiler) { |
| 603 emitter = new CodeEmitterTask(compiler, namer, generateSourceMap); | 606 emitter = new CodeEmitterTask(compiler, namer, generateSourceMap); |
| 604 typeVariableHandler = new TypeVariableHandler(this); | 607 typeVariableHandler = new TypeVariableHandler(this); |
| 605 customElementsAnalysis = new CustomElementsAnalysis(this); | 608 customElementsAnalysis = new CustomElementsAnalysis(this); |
| 609 noSuchMethodAnalysis = new NoSuchMethodAnalysis(this); |
| 606 constantCompilerTask = new JavaScriptConstantTask(compiler); | 610 constantCompilerTask = new JavaScriptConstantTask(compiler); |
| 607 resolutionCallbacks = new JavaScriptResolutionCallbacks(this); | 611 resolutionCallbacks = new JavaScriptResolutionCallbacks(this); |
| 608 patchResolverTask = new PatchResolverTask(compiler); | 612 patchResolverTask = new PatchResolverTask(compiler); |
| 609 functionCompiler = USE_CPS_IR | 613 functionCompiler = USE_CPS_IR |
| 610 ? new CpsFunctionCompiler( | 614 ? new CpsFunctionCompiler( |
| 611 compiler, this, generateSourceMap: generateSourceMap) | 615 compiler, this, generateSourceMap: generateSourceMap) |
| 612 : new SsaFunctionCompiler(this, generateSourceMap); | 616 : new SsaFunctionCompiler(this, generateSourceMap); |
| 613 } | 617 } |
| 614 | 618 |
| 615 ConstantSystem get constantSystem => constants.constantSystem; | 619 ConstantSystem get constantSystem => constants.constantSystem; |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1199 DartType bound) { | 1203 DartType bound) { |
| 1200 rti.registerTypeVariableBoundsSubtypeCheck(typeArgument, bound); | 1204 rti.registerTypeVariableBoundsSubtypeCheck(typeArgument, bound); |
| 1201 } | 1205 } |
| 1202 | 1206 |
| 1203 void registerCheckDeferredIsLoaded(Registry registry) { | 1207 void registerCheckDeferredIsLoaded(Registry registry) { |
| 1204 enqueueInResolution(getCheckDeferredIsLoaded(), registry); | 1208 enqueueInResolution(getCheckDeferredIsLoaded(), registry); |
| 1205 // Also register the types of the arguments passed to this method. | 1209 // Also register the types of the arguments passed to this method. |
| 1206 enqueueClass(compiler.enqueuer.resolution, compiler.stringClass, registry); | 1210 enqueueClass(compiler.enqueuer.resolution, compiler.stringClass, registry); |
| 1207 } | 1211 } |
| 1208 | 1212 |
| 1209 void enableNoSuchMethod(Element context, Enqueuer world) { | 1213 void registerNoSuchMethod(Element noSuchMethod, Enqueuer enqueuer) { |
| 1214 noSuchMethodAnalysis.registerNoSuchMethod(noSuchMethod); |
| 1215 } |
| 1216 |
| 1217 void enableNoSuchMethod(Enqueuer world) { |
| 1210 enqueue(world, getCreateInvocationMirror(), compiler.globalDependencies); | 1218 enqueue(world, getCreateInvocationMirror(), compiler.globalDependencies); |
| 1211 world.registerInvocation(compiler.noSuchMethodSelector); | 1219 world.registerInvocation(compiler.noSuchMethodSelector); |
| 1212 // TODO(tyoverby): Send the context element to DumpInfoTask to be | |
| 1213 // blamed. | |
| 1214 } | 1220 } |
| 1215 | 1221 |
| 1216 void enableIsolateSupport(Enqueuer enqueuer) { | 1222 void enableIsolateSupport(Enqueuer enqueuer) { |
| 1217 // TODO(floitsch): We should also ensure that the class IsolateMessage is | 1223 // TODO(floitsch): We should also ensure that the class IsolateMessage is |
| 1218 // instantiated. Currently, just enabling isolate support works. | 1224 // instantiated. Currently, just enabling isolate support works. |
| 1219 if (compiler.mainFunction != null) { | 1225 if (compiler.mainFunction != null) { |
| 1220 // The JavaScript backend implements [Isolate.spawn] by looking up | 1226 // The JavaScript backend implements [Isolate.spawn] by looking up |
| 1221 // top-level functions by name. So all top-level function tear-off | 1227 // top-level functions by name. So all top-level function tear-off |
| 1222 // closures have a private name field. | 1228 // closures have a private name field. |
| 1223 // | 1229 // |
| (...skipping 1168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2392 return staticFields; | 2398 return staticFields; |
| 2393 } | 2399 } |
| 2394 | 2400 |
| 2395 /// Called when [enqueuer] is empty, but before it is closed. | 2401 /// Called when [enqueuer] is empty, but before it is closed. |
| 2396 bool onQueueEmpty(Enqueuer enqueuer, Iterable<ClassElement> recentClasses) { | 2402 bool onQueueEmpty(Enqueuer enqueuer, Iterable<ClassElement> recentClasses) { |
| 2397 // Add elements referenced only via custom elements. Return early if any | 2403 // Add elements referenced only via custom elements. Return early if any |
| 2398 // elements are added to avoid counting the elements as due to mirrors. | 2404 // elements are added to avoid counting the elements as due to mirrors. |
| 2399 customElementsAnalysis.onQueueEmpty(enqueuer); | 2405 customElementsAnalysis.onQueueEmpty(enqueuer); |
| 2400 if (!enqueuer.queueIsEmpty) return false; | 2406 if (!enqueuer.queueIsEmpty) return false; |
| 2401 | 2407 |
| 2408 noSuchMethodAnalysis.onQueueEmpty(enqueuer); |
| 2409 |
| 2402 if (compiler.hasIncrementalSupport) { | 2410 if (compiler.hasIncrementalSupport) { |
| 2403 // Always enable tear-off closures during incremental compilation. | 2411 // Always enable tear-off closures during incremental compilation. |
| 2404 Element e = findHelper('closureFromTearOff'); | 2412 Element e = findHelper('closureFromTearOff'); |
| 2405 if (e != null && !enqueuer.isProcessed(e)) { | 2413 if (e != null && !enqueuer.isProcessed(e)) { |
| 2406 registerBackendUse(e); | 2414 registerBackendUse(e); |
| 2407 enqueuer.addToWorkList(e); | 2415 enqueuer.addToWorkList(e); |
| 2408 } | 2416 } |
| 2409 } | 2417 } |
| 2410 | 2418 |
| 2411 if (!enqueuer.isResolutionQueue && preMirrorsMethodCount == 0) { | 2419 if (!enqueuer.isResolutionQueue && preMirrorsMethodCount == 0) { |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2843 } | 2851 } |
| 2844 } | 2852 } |
| 2845 | 2853 |
| 2846 /// Records that [constant] is used by the element behind [registry]. | 2854 /// Records that [constant] is used by the element behind [registry]. |
| 2847 class Dependency { | 2855 class Dependency { |
| 2848 final ConstantValue constant; | 2856 final ConstantValue constant; |
| 2849 final Element annotatedElement; | 2857 final Element annotatedElement; |
| 2850 | 2858 |
| 2851 const Dependency(this.constant, this.annotatedElement); | 2859 const Dependency(this.constant, this.annotatedElement); |
| 2852 } | 2860 } |
| OLD | NEW |