| 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 library compiler.src.inferrer.closure_tracer; | 5 library compiler.src.inferrer.closure_tracer; |
| 6 | 6 |
| 7 import '../common/names.dart' show Names; | 7 import '../common/names.dart' show Names; |
| 8 import '../elements/elements.dart'; | 8 import '../elements/elements.dart'; |
| 9 import '../js_backend/backend.dart' show JavaScriptBackend; | 9 import '../js_backend/backend.dart' show JavaScriptBackend; |
| 10 import '../types/types.dart' show TypeMask; | 10 import '../types/types.dart' show TypeMask; |
| 11 import '../universe/selector.dart' show Selector; | 11 import '../universe/selector.dart' show Selector; |
| 12 import 'debug.dart' as debug; | 12 import 'debug.dart' as debug; |
| 13 import 'inferrer_engine.dart'; | 13 import 'inferrer_engine.dart'; |
| 14 import 'node_tracer.dart'; | 14 import 'node_tracer.dart'; |
| 15 import 'type_graph_nodes.dart'; | 15 import 'type_graph_nodes.dart'; |
| 16 | 16 |
| 17 class ClosureTracerVisitor extends TracerVisitor { | 17 class ClosureTracerVisitor extends TracerVisitor { |
| 18 final Iterable<FunctionElement> tracedElements; | 18 final Iterable<MethodElement> tracedElements; |
| 19 final List<CallSiteTypeInformation> _callsToAnalyze = | 19 final List<CallSiteTypeInformation> _callsToAnalyze = |
| 20 new List<CallSiteTypeInformation>(); | 20 new List<CallSiteTypeInformation>(); |
| 21 | 21 |
| 22 ClosureTracerVisitor(this.tracedElements, ApplyableTypeInformation tracedType, | 22 ClosureTracerVisitor(this.tracedElements, ApplyableTypeInformation tracedType, |
| 23 InferrerEngine inferrer) | 23 InferrerEngine inferrer) |
| 24 : super(tracedType, inferrer); | 24 : super(tracedType, inferrer); |
| 25 | 25 |
| 26 ApplyableTypeInformation get tracedType => super.tracedType; | 26 ApplyableTypeInformation get tracedType => super.tracedType; |
| 27 | 27 |
| 28 void run() { | 28 void run() { |
| 29 analyze(); | 29 analyze(); |
| 30 if (!continueAnalyzing) return; | 30 if (!continueAnalyzing) return; |
| 31 _callsToAnalyze.forEach(_analyzeCall); | 31 _callsToAnalyze.forEach(_analyzeCall); |
| 32 for (FunctionElement e in tracedElements) { | 32 for (MethodElement e in tracedElements) { |
| 33 e.functionSignature.forEachParameter((Element parameter) { | 33 e.functionSignature.forEachParameter((Element parameter) { |
| 34 ElementTypeInformation info = | 34 ElementTypeInformation info = |
| 35 inferrer.types.getInferredTypeOfParameter(parameter); | 35 inferrer.types.getInferredTypeOfParameter(parameter); |
| 36 info.disableInferenceForClosures = false; | 36 info.disableInferenceForClosures = false; |
| 37 }); | 37 }); |
| 38 } | 38 } |
| 39 } | 39 } |
| 40 | 40 |
| 41 void _tagAsFunctionApplyTarget([String reason]) { | 41 void _tagAsFunctionApplyTarget([String reason]) { |
| 42 tracedType.mightBePassedToFunctionApply = true; | 42 tracedType.mightBePassedToFunctionApply = true; |
| 43 if (debug.VERBOSE) { | 43 if (debug.VERBOSE) { |
| 44 print("Closure $tracedType might be passed to apply: $reason"); | 44 print("Closure $tracedType might be passed to apply: $reason"); |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 | 47 |
| 48 void _registerCallForLaterAnalysis(CallSiteTypeInformation info) { | 48 void _registerCallForLaterAnalysis(CallSiteTypeInformation info) { |
| 49 _callsToAnalyze.add(info); | 49 _callsToAnalyze.add(info); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void _analyzeCall(CallSiteTypeInformation info) { | 52 void _analyzeCall(CallSiteTypeInformation info) { |
| 53 Selector selector = info.selector; | 53 Selector selector = info.selector; |
| 54 TypeMask mask = info.mask; | 54 TypeMask mask = info.mask; |
| 55 tracedElements.forEach((FunctionElement functionElement) { | 55 tracedElements.forEach((MethodElement functionElement) { |
| 56 if (!selector.callStructure | 56 if (!selector.callStructure |
| 57 .signatureApplies(functionElement.parameterStructure)) { | 57 .signatureApplies(functionElement.parameterStructure)) { |
| 58 return; | 58 return; |
| 59 } | 59 } |
| 60 inferrer.updateParameterAssignments( | 60 inferrer.updateParameterAssignments( |
| 61 info, functionElement, info.arguments, selector, mask, | 61 info, functionElement, info.arguments, selector, mask, |
| 62 remove: false, addToQueue: false); | 62 remove: false, addToQueue: false); |
| 63 }); | 63 }); |
| 64 } | 64 } |
| 65 | 65 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 } | 123 } |
| 124 } else if (info.selector.isGetter && | 124 } else if (info.selector.isGetter && |
| 125 info.selector.memberName == Names.call) { | 125 info.selector.memberName == Names.call) { |
| 126 // We are potentially tearing off ourself here | 126 // We are potentially tearing off ourself here |
| 127 addNewEscapeInformation(info); | 127 addNewEscapeInformation(info); |
| 128 } | 128 } |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 | 131 |
| 132 class StaticTearOffClosureTracerVisitor extends ClosureTracerVisitor { | 132 class StaticTearOffClosureTracerVisitor extends ClosureTracerVisitor { |
| 133 StaticTearOffClosureTracerVisitor(tracedElement, tracedType, inferrer) | 133 StaticTearOffClosureTracerVisitor( |
| 134 MethodElement tracedElement, tracedType, inferrer) |
| 134 : super([tracedElement], tracedType, inferrer); | 135 : super([tracedElement], tracedType, inferrer); |
| 135 | 136 |
| 136 @override | 137 @override |
| 137 visitStaticCallSiteTypeInformation(StaticCallSiteTypeInformation info) { | 138 visitStaticCallSiteTypeInformation(StaticCallSiteTypeInformation info) { |
| 138 super.visitStaticCallSiteTypeInformation(info); | 139 super.visitStaticCallSiteTypeInformation(info); |
| 139 if (info.calledElement == tracedElements.first && | 140 if (info.calledElement == tracedElements.first && |
| 140 info.selector != null && | 141 info.selector != null && |
| 141 info.selector.isGetter) { | 142 info.selector.isGetter) { |
| 142 addNewEscapeInformation(info); | 143 addNewEscapeInformation(info); |
| 143 } | 144 } |
| 144 } | 145 } |
| 145 } | 146 } |
| OLD | NEW |