| OLD | NEW |
| 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 final Element tracedElement; | 8 ClosureTracerVisitor(tracedType, inferrer) : super(tracedType, inferrer); |
| 9 | |
| 10 ClosureTracerVisitor(this.tracedElement, tracedType, inferrer) | |
| 11 : super(tracedType, inferrer); | |
| 12 | 9 |
| 13 void run() { | 10 void run() { |
| 14 tracedElement.functionSignature.forEachParameter((Element parameter) { | 11 ClosureTypeInformation closure = tracedType; |
| 12 FunctionElement element = closure.element; |
| 13 element.functionSignature.forEachParameter((Element parameter) { |
| 15 ElementTypeInformation info = inferrer.types.getInferredTypeOf(parameter); | 14 ElementTypeInformation info = inferrer.types.getInferredTypeOf(parameter); |
| 16 info.abandonInferencing = false; | 15 info.abandonInferencing = false; |
| 17 }); | 16 }); |
| 18 analyze(); | 17 analyze(); |
| 19 tracedElement.functionSignature.forEachParameter((Element parameter) { | 18 element.functionSignature.forEachParameter((Element parameter) { |
| 20 ElementTypeInformation info = inferrer.types.getInferredTypeOf(parameter); | 19 ElementTypeInformation info = inferrer.types.getInferredTypeOf(parameter); |
| 21 if (continueAnalyzing) { | 20 if (continueAnalyzing) { |
| 22 info.disableHandleSpecialCases = true; | 21 info.disableHandleSpecialCases = true; |
| 23 } else { | 22 } else { |
| 24 info.giveUp(inferrer); | 23 info.giveUp(inferrer); |
| 25 } | 24 } |
| 26 }); | 25 }); |
| 27 } | 26 } |
| 28 | 27 |
| 29 visitMapTypeInformation(MapTypeInformation info) { | 28 visitMapTypeInformation(MapTypeInformation info) { |
| 30 bailout('Stored in a map'); | 29 bailout('Stored in a map'); |
| 31 } | 30 } |
| 32 | 31 |
| 33 void analyzeCall(CallSiteTypeInformation info) { | 32 void analyzeCall(CallSiteTypeInformation info) { |
| 33 ClosureTypeInformation closure = tracedType; |
| 34 FunctionElement element = closure.element; |
| 34 Selector selector = info.selector; | 35 Selector selector = info.selector; |
| 35 if (!selector.signatureApplies(tracedElement, compiler)) return; | 36 if (!selector.signatureApplies(element, compiler)) return; |
| 36 inferrer.updateParameterAssignments( | 37 inferrer.updateParameterAssignments( |
| 37 info, tracedElement, info.arguments, selector, remove: false, | 38 info, element, info.arguments, selector, remove: false, |
| 38 addToQueue: false); | 39 addToQueue: false); |
| 39 } | 40 } |
| 40 | 41 |
| 41 visitClosureCallSiteTypeInformation(ClosureCallSiteTypeInformation info) { | 42 visitClosureCallSiteTypeInformation(ClosureCallSiteTypeInformation info) { |
| 42 super.visitClosureCallSiteTypeInformation(info); | 43 super.visitClosureCallSiteTypeInformation(info); |
| 43 if (info.closure == currentUser) { | 44 if (info.closure == currentUser) { |
| 44 analyzeCall(info); | 45 analyzeCall(info); |
| 45 } else { | 46 } else { |
| 46 bailout('Passed to a closure'); | 47 bailout('Passed to a closure'); |
| 47 } | 48 } |
| 48 } | 49 } |
| 49 | 50 |
| 50 visitStaticCallSiteTypeInformation(StaticCallSiteTypeInformation info) { | 51 visitStaticCallSiteTypeInformation(StaticCallSiteTypeInformation info) { |
| 51 super.visitStaticCallSiteTypeInformation(info); | 52 super.visitStaticCallSiteTypeInformation(info); |
| 52 Element called = info.calledElement; | 53 Element called = info.calledElement; |
| 53 if (called.isForeign(compiler)) { | 54 if (called.isForeign(compiler) && called.name == 'JS') { |
| 54 String name = called.name; | 55 bailout('Used in JS ${info.call}'); |
| 55 if (name == 'JS' || name == 'DART_CLOSURE_TO_JS') { | |
| 56 bailout('Used in JS ${info.call}'); | |
| 57 } | |
| 58 } | 56 } |
| 59 if (called.isGetter() | 57 if (inferrer.types.getInferredTypeOf(called) == currentUser) { |
| 60 && info.selector != null | |
| 61 && info.selector.isCall() | |
| 62 && inferrer.types.getInferredTypeOf(called) == currentUser) { | |
| 63 // This node can be a closure call as well. For example, `foo()` | 58 // This node can be a closure call as well. For example, `foo()` |
| 64 // where `foo` is a getter. | 59 // where `foo` is a getter. |
| 65 analyzeCall(info); | 60 analyzeCall(info); |
| 66 } | 61 } |
| 67 } | 62 } |
| 68 | 63 |
| 69 bool checkIfCurrentUser(element) { | 64 bool checkIfCurrentUser(element) { |
| 70 return inferrer.types.getInferredTypeOf(element) == currentUser; | 65 return inferrer.types.getInferredTypeOf(element) == currentUser; |
| 71 } | 66 } |
| 72 | 67 |
| 73 visitDynamicCallSiteTypeInformation(DynamicCallSiteTypeInformation info) { | 68 visitDynamicCallSiteTypeInformation(DynamicCallSiteTypeInformation info) { |
| 74 super.visitDynamicCallSiteTypeInformation(info); | 69 super.visitDynamicCallSiteTypeInformation(info); |
| 75 if (info.selector.isCall()) { | 70 if (info.selector.isCall()) { |
| 76 if (info.arguments.contains(currentUser) | 71 if (info.arguments.contains(currentUser) |
| 77 && !info.targets.every((element) => element.isFunction())) { | 72 && !info.targets.every((element) => element.isFunction())) { |
| 78 bailout('Passed to a closure'); | 73 bailout('Passed to a closure'); |
| 79 } else if (info.targets.any((element) => checkIfCurrentUser(element))) { | 74 } else if (info.targets.any((element) => checkIfCurrentUser(element))) { |
| 80 analyzeCall(info); | 75 analyzeCall(info); |
| 81 } | 76 } |
| 82 } | 77 } |
| 83 } | 78 } |
| 84 } | 79 } |
| 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 } | |
| OLD | NEW |