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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/inferrer/closure_tracer.dart

Issue 112103007: Trace static tear-off closures. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years 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 | « no previous file | sdk/lib/_internal/compiler/implementation/inferrer/type_graph_inferrer.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 type_graph_inferrer; 5 part of type_graph_inferrer;
6 6
7 class ClosureTracerVisitor extends TracerVisitor { 7 class ClosureTracerVisitor extends TracerVisitor {
8 ClosureTracerVisitor(tracedType, inferrer) : super(tracedType, inferrer); 8 final Element tracedElement;
9
10 ClosureTracerVisitor(this.tracedElement, tracedType, inferrer)
11 : super(tracedType, inferrer);
9 12
10 void run() { 13 void run() {
11 ClosureTypeInformation closure = tracedType; 14 tracedElement.functionSignature.forEachParameter((Element parameter) {
12 FunctionElement element = closure.element;
13 element.functionSignature.forEachParameter((Element parameter) {
14 ElementTypeInformation info = inferrer.types.getInferredTypeOf(parameter); 15 ElementTypeInformation info = inferrer.types.getInferredTypeOf(parameter);
15 info.abandonInferencing = false; 16 info.abandonInferencing = false;
16 }); 17 });
17 analyze(); 18 analyze();
18 element.functionSignature.forEachParameter((Element parameter) { 19 tracedElement.functionSignature.forEachParameter((Element parameter) {
19 ElementTypeInformation info = inferrer.types.getInferredTypeOf(parameter); 20 ElementTypeInformation info = inferrer.types.getInferredTypeOf(parameter);
20 if (continueAnalyzing) { 21 if (continueAnalyzing) {
21 info.disableHandleSpecialCases = true; 22 info.disableHandleSpecialCases = true;
22 } else { 23 } else {
23 info.giveUp(inferrer); 24 info.giveUp(inferrer);
24 } 25 }
25 }); 26 });
26 } 27 }
27 28
28 visitMapTypeInformation(MapTypeInformation info) { 29 visitMapTypeInformation(MapTypeInformation info) {
29 bailout('Stored in a map'); 30 bailout('Stored in a map');
30 } 31 }
31 32
32 void analyzeCall(CallSiteTypeInformation info) { 33 void analyzeCall(CallSiteTypeInformation info) {
33 ClosureTypeInformation closure = tracedType;
34 FunctionElement element = closure.element;
35 Selector selector = info.selector; 34 Selector selector = info.selector;
36 if (!selector.signatureApplies(element, compiler)) return; 35 if (!selector.signatureApplies(tracedElement, compiler)) return;
37 inferrer.updateParameterAssignments( 36 inferrer.updateParameterAssignments(
38 info, element, info.arguments, selector, remove: false, 37 info, tracedElement, info.arguments, selector, remove: false,
39 addToQueue: false); 38 addToQueue: false);
40 } 39 }
41 40
42 visitClosureCallSiteTypeInformation(ClosureCallSiteTypeInformation info) { 41 visitClosureCallSiteTypeInformation(ClosureCallSiteTypeInformation info) {
43 super.visitClosureCallSiteTypeInformation(info); 42 super.visitClosureCallSiteTypeInformation(info);
44 if (info.closure == currentUser) { 43 if (info.closure == currentUser) {
45 analyzeCall(info); 44 analyzeCall(info);
46 } else { 45 } else {
47 bailout('Passed to a closure'); 46 bailout('Passed to a closure');
48 } 47 }
49 } 48 }
50 49
51 visitStaticCallSiteTypeInformation(StaticCallSiteTypeInformation info) { 50 visitStaticCallSiteTypeInformation(StaticCallSiteTypeInformation info) {
52 super.visitStaticCallSiteTypeInformation(info); 51 super.visitStaticCallSiteTypeInformation(info);
53 Element called = info.calledElement; 52 Element called = info.calledElement;
54 if (called.isForeign(compiler) && called.name == 'JS') { 53 if (called.isForeign(compiler)) {
55 bailout('Used in JS ${info.call}'); 54 String name = called.name;
55 if (name == 'JS' || name == 'DART_CLOSURE_TO_JS') {
56 bailout('Used in JS ${info.call}');
57 }
56 } 58 }
57 if (inferrer.types.getInferredTypeOf(called) == currentUser) { 59 if (called.isGetter()
60 && info.selector != null
61 && info.selector.isCall()
62 && inferrer.types.getInferredTypeOf(called) == currentUser) {
58 // This node can be a closure call as well. For example, `foo()` 63 // This node can be a closure call as well. For example, `foo()`
59 // where `foo` is a getter. 64 // where `foo` is a getter.
60 analyzeCall(info); 65 analyzeCall(info);
61 } 66 }
62 } 67 }
63 68
64 bool checkIfCurrentUser(element) { 69 bool checkIfCurrentUser(element) {
65 return inferrer.types.getInferredTypeOf(element) == currentUser; 70 return inferrer.types.getInferredTypeOf(element) == currentUser;
66 } 71 }
67 72
68 visitDynamicCallSiteTypeInformation(DynamicCallSiteTypeInformation info) { 73 visitDynamicCallSiteTypeInformation(DynamicCallSiteTypeInformation info) {
69 super.visitDynamicCallSiteTypeInformation(info); 74 super.visitDynamicCallSiteTypeInformation(info);
70 if (info.selector.isCall()) { 75 if (info.selector.isCall()) {
71 if (info.arguments.contains(currentUser) 76 if (info.arguments.contains(currentUser)
72 && !info.targets.every((element) => element.isFunction())) { 77 && !info.targets.every((element) => element.isFunction())) {
73 bailout('Passed to a closure'); 78 bailout('Passed to a closure');
74 } else if (info.targets.any((element) => checkIfCurrentUser(element))) { 79 } else if (info.targets.any((element) => checkIfCurrentUser(element))) {
75 analyzeCall(info); 80 analyzeCall(info);
76 } 81 }
77 } 82 }
78 } 83 }
79 } 84 }
85
86 class StaticTearOffClosureTracerVisitor extends ClosureTracerVisitor {
87 StaticTearOffClosureTracerVisitor(tracedElement, tracedType, inferrer)
88 : super(tracedElement, tracedType, inferrer);
89
90 visitStaticCallSiteTypeInformation(StaticCallSiteTypeInformation info) {
91 super.visitStaticCallSiteTypeInformation(info);
92 if (info.calledElement == tracedElement
93 && info.selector != null
94 && info.selector.isGetter()) {
95 addNewEscapeInformation(info);
96 }
97 }
98 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/inferrer/type_graph_inferrer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698