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

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

Issue 1020853004: Don't generate invocation mirror code if all noSuchMethods forward to (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: add test Created 5 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « pkg/compiler/lib/src/enqueue.dart ('k') | pkg/compiler/lib/src/js_backend/js_backend.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 NoSuchMethodRegistry noSuchMethodRegistry;
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
599 bool enabledNoSuchMethod = false;
600
596 JavaScriptBackend(Compiler compiler, bool generateSourceMap) 601 JavaScriptBackend(Compiler compiler, bool generateSourceMap)
597 : namer = determineNamer(compiler), 602 : namer = determineNamer(compiler),
598 oneShotInterceptors = new Map<String, Selector>(), 603 oneShotInterceptors = new Map<String, Selector>(),
599 interceptedElements = new Map<String, Set<Element>>(), 604 interceptedElements = new Map<String, Set<Element>>(),
600 rti = new RuntimeTypes(compiler), 605 rti = new RuntimeTypes(compiler),
601 specializedGetInterceptors = new Map<String, Set<ClassElement>>(), 606 specializedGetInterceptors = new Map<String, Set<ClassElement>>(),
602 super(compiler) { 607 super(compiler) {
603 emitter = new CodeEmitterTask(compiler, namer, generateSourceMap); 608 emitter = new CodeEmitterTask(compiler, namer, generateSourceMap);
604 typeVariableHandler = new TypeVariableHandler(this); 609 typeVariableHandler = new TypeVariableHandler(this);
605 customElementsAnalysis = new CustomElementsAnalysis(this); 610 customElementsAnalysis = new CustomElementsAnalysis(this);
611 noSuchMethodRegistry = new NoSuchMethodRegistry(this);
606 constantCompilerTask = new JavaScriptConstantTask(compiler); 612 constantCompilerTask = new JavaScriptConstantTask(compiler);
607 resolutionCallbacks = new JavaScriptResolutionCallbacks(this); 613 resolutionCallbacks = new JavaScriptResolutionCallbacks(this);
608 patchResolverTask = new PatchResolverTask(compiler); 614 patchResolverTask = new PatchResolverTask(compiler);
609 functionCompiler = USE_CPS_IR 615 functionCompiler = USE_CPS_IR
610 ? new CpsFunctionCompiler( 616 ? new CpsFunctionCompiler(
611 compiler, this, generateSourceMap: generateSourceMap) 617 compiler, this, generateSourceMap: generateSourceMap)
612 : new SsaFunctionCompiler(this, generateSourceMap); 618 : new SsaFunctionCompiler(this, generateSourceMap);
613 } 619 }
614 620
615 ConstantSystem get constantSystem => constants.constantSystem; 621 ConstantSystem get constantSystem => constants.constantSystem;
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 DartType bound) { 1209 DartType bound) {
1204 rti.registerTypeVariableBoundsSubtypeCheck(typeArgument, bound); 1210 rti.registerTypeVariableBoundsSubtypeCheck(typeArgument, bound);
1205 } 1211 }
1206 1212
1207 void registerCheckDeferredIsLoaded(Registry registry) { 1213 void registerCheckDeferredIsLoaded(Registry registry) {
1208 enqueueInResolution(getCheckDeferredIsLoaded(), registry); 1214 enqueueInResolution(getCheckDeferredIsLoaded(), registry);
1209 // Also register the types of the arguments passed to this method. 1215 // Also register the types of the arguments passed to this method.
1210 enqueueClass(compiler.enqueuer.resolution, compiler.stringClass, registry); 1216 enqueueClass(compiler.enqueuer.resolution, compiler.stringClass, registry);
1211 } 1217 }
1212 1218
1213 void enableNoSuchMethod(Element context, Enqueuer world) { 1219 void registerNoSuchMethod(Element noSuchMethod) {
1220 noSuchMethodRegistry.registerNoSuchMethod(noSuchMethod);
1221 }
1222
1223 void enableNoSuchMethod(Enqueuer world) {
1214 enqueue(world, getCreateInvocationMirror(), compiler.globalDependencies); 1224 enqueue(world, getCreateInvocationMirror(), compiler.globalDependencies);
1215 world.registerInvocation(compiler.noSuchMethodSelector); 1225 world.registerInvocation(compiler.noSuchMethodSelector);
1216 // TODO(tyoverby): Send the context element to DumpInfoTask to be
1217 // blamed.
1218 } 1226 }
1219 1227
1220 void enableIsolateSupport(Enqueuer enqueuer) { 1228 void enableIsolateSupport(Enqueuer enqueuer) {
1221 // TODO(floitsch): We should also ensure that the class IsolateMessage is 1229 // TODO(floitsch): We should also ensure that the class IsolateMessage is
1222 // instantiated. Currently, just enabling isolate support works. 1230 // instantiated. Currently, just enabling isolate support works.
1223 if (compiler.mainFunction != null) { 1231 if (compiler.mainFunction != null) {
1224 // The JavaScript backend implements [Isolate.spawn] by looking up 1232 // The JavaScript backend implements [Isolate.spawn] by looking up
1225 // top-level functions by name. So all top-level function tear-off 1233 // top-level functions by name. So all top-level function tear-off
1226 // closures have a private name field. 1234 // closures have a private name field.
1227 // 1235 //
(...skipping 1168 matching lines...) Expand 10 before | Expand all | Expand 10 after
2396 return staticFields; 2404 return staticFields;
2397 } 2405 }
2398 2406
2399 /// Called when [enqueuer] is empty, but before it is closed. 2407 /// Called when [enqueuer] is empty, but before it is closed.
2400 bool onQueueEmpty(Enqueuer enqueuer, Iterable<ClassElement> recentClasses) { 2408 bool onQueueEmpty(Enqueuer enqueuer, Iterable<ClassElement> recentClasses) {
2401 // Add elements referenced only via custom elements. Return early if any 2409 // Add elements referenced only via custom elements. Return early if any
2402 // elements are added to avoid counting the elements as due to mirrors. 2410 // elements are added to avoid counting the elements as due to mirrors.
2403 customElementsAnalysis.onQueueEmpty(enqueuer); 2411 customElementsAnalysis.onQueueEmpty(enqueuer);
2404 if (!enqueuer.queueIsEmpty) return false; 2412 if (!enqueuer.queueIsEmpty) return false;
2405 2413
2414 noSuchMethodRegistry.onQueueEmpty();
2415 if (!enabledNoSuchMethod &&
2416 (noSuchMethodRegistry.hasThrowingNoSuchMethod ||
2417 noSuchMethodRegistry.hasComplexNoSuchMethod)) {
2418 enableNoSuchMethod(enqueuer);
2419 enabledNoSuchMethod = true;
2420 }
2421
2406 if (compiler.hasIncrementalSupport) { 2422 if (compiler.hasIncrementalSupport) {
2407 // Always enable tear-off closures during incremental compilation. 2423 // Always enable tear-off closures during incremental compilation.
2408 Element e = findHelper('closureFromTearOff'); 2424 Element e = findHelper('closureFromTearOff');
2409 if (e != null && !enqueuer.isProcessed(e)) { 2425 if (e != null && !enqueuer.isProcessed(e)) {
2410 registerBackendUse(e); 2426 registerBackendUse(e);
2411 enqueuer.addToWorkList(e); 2427 enqueuer.addToWorkList(e);
2412 } 2428 }
2413 } 2429 }
2414 2430
2415 if (!enqueuer.isResolutionQueue && preMirrorsMethodCount == 0) { 2431 if (!enqueuer.isResolutionQueue && preMirrorsMethodCount == 0) {
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
2847 } 2863 }
2848 } 2864 }
2849 2865
2850 /// Records that [constant] is used by the element behind [registry]. 2866 /// Records that [constant] is used by the element behind [registry].
2851 class Dependency { 2867 class Dependency {
2852 final ConstantValue constant; 2868 final ConstantValue constant;
2853 final Element annotatedElement; 2869 final Element annotatedElement;
2854 2870
2855 const Dependency(this.constant, this.annotatedElement); 2871 const Dependency(this.constant, this.annotatedElement);
2856 } 2872 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/enqueue.dart ('k') | pkg/compiler/lib/src/js_backend/js_backend.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698