| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'package:kernel/ast.dart' as ir; | 5 import 'package:kernel/ast.dart' as ir; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../common/names.dart'; | 8 import '../common/names.dart'; |
| 9 import '../compiler.dart'; | 9 import '../compiler.dart'; |
| 10 import '../common_elements.dart'; | 10 import '../common_elements.dart'; |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 types.allocatedClosures.forEach((dynamic info) { | 486 types.allocatedClosures.forEach((dynamic info) { |
| 487 void trace( | 487 void trace( |
| 488 Iterable<FunctionEntity> elements, ClosureTracerVisitor tracer) { | 488 Iterable<FunctionEntity> elements, ClosureTracerVisitor tracer) { |
| 489 tracer.run(); | 489 tracer.run(); |
| 490 if (!tracer.continueAnalyzing) { | 490 if (!tracer.continueAnalyzing) { |
| 491 elements.forEach((FunctionEntity element) { | 491 elements.forEach((FunctionEntity element) { |
| 492 closedWorldRefiner.registerMightBePassedToApply(element); | 492 closedWorldRefiner.registerMightBePassedToApply(element); |
| 493 if (debug.VERBOSE) { | 493 if (debug.VERBOSE) { |
| 494 print("traced closure $element as ${true} (bail)"); | 494 print("traced closure $element as ${true} (bail)"); |
| 495 } | 495 } |
| 496 forEachParameter(element, (Local parameter) { | 496 types.strategy.forEachParameter(element, (Local parameter) { |
| 497 types | 497 types |
| 498 .getInferredTypeOfParameter(parameter) | 498 .getInferredTypeOfParameter(parameter) |
| 499 .giveUp(this, clearAssignments: false); | 499 .giveUp(this, clearAssignments: false); |
| 500 }); | 500 }); |
| 501 }); | 501 }); |
| 502 bailedOutOn.addAll(elements); | 502 bailedOutOn.addAll(elements); |
| 503 return; | 503 return; |
| 504 } | 504 } |
| 505 elements | 505 elements |
| 506 .where((e) => !bailedOutOn.contains(e)) | 506 .where((e) => !bailedOutOn.contains(e)) |
| 507 .forEach((FunctionEntity element) { | 507 .forEach((FunctionEntity element) { |
| 508 forEachParameter(element, (Local parameter) { | 508 types.strategy.forEachParameter(element, (Local parameter) { |
| 509 ParameterTypeInformation info = | 509 ParameterTypeInformation info = |
| 510 types.getInferredTypeOfParameter(parameter); | 510 types.getInferredTypeOfParameter(parameter); |
| 511 info.maybeResume(); | 511 info.maybeResume(); |
| 512 workQueue.add(info); | 512 workQueue.add(info); |
| 513 }); | 513 }); |
| 514 if (tracer.tracedType.mightBePassedToFunctionApply) { | 514 if (tracer.tracedType.mightBePassedToFunctionApply) { |
| 515 closedWorldRefiner.registerMightBePassedToApply(element); | 515 closedWorldRefiner.registerMightBePassedToApply(element); |
| 516 } | 516 } |
| 517 if (debug.VERBOSE) { | 517 if (debug.VERBOSE) { |
| 518 print("traced closure $element as " | 518 print("traced closure $element as " |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 reporter.log('Added $addedInGraph elements in inferencing graph.'); | 642 reporter.log('Added $addedInGraph elements in inferencing graph.'); |
| 643 } | 643 } |
| 644 | 644 |
| 645 /// Compute a 'size' of [member] used for sorting member for the type | 645 /// Compute a 'size' of [member] used for sorting member for the type |
| 646 /// inference work-queue. Smallest members are processed first. | 646 /// inference work-queue. Smallest members are processed first. |
| 647 int computeMemberSize(MemberEntity member); | 647 int computeMemberSize(MemberEntity member); |
| 648 | 648 |
| 649 /// Returns the body node for [member]. | 649 /// Returns the body node for [member]. |
| 650 T computeMemberBody(MemberEntity member); | 650 T computeMemberBody(MemberEntity member); |
| 651 | 651 |
| 652 /// Calls [f] for each parameter of [method]. | |
| 653 void forEachParameter(FunctionEntity method, void f(Local parameter)); | |
| 654 | |
| 655 /// Returns the `call` method on [cls] or the `noSuchMethod` if [cls] doesn't | 652 /// Returns the `call` method on [cls] or the `noSuchMethod` if [cls] doesn't |
| 656 /// implement `call`. | 653 /// implement `call`. |
| 657 FunctionEntity lookupCallMethod(ClassEntity cls); | 654 FunctionEntity lookupCallMethod(ClassEntity cls); |
| 658 | 655 |
| 659 void analyze(MemberEntity element, T body, ArgumentsTypes arguments) { | 656 void analyze(MemberEntity element, T body, ArgumentsTypes arguments) { |
| 660 assert(!(element is MemberElement && !element.isDeclaration)); | 657 assert(!(element is MemberElement && !element.isDeclaration)); |
| 661 if (analyzedElements.contains(element)) return; | 658 if (analyzedElements.contains(element)) return; |
| 662 analyzedElements.add(element); | 659 analyzedElements.add(element); |
| 663 | 660 |
| 664 TypeInformation type; | 661 TypeInformation type; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 info.closurizedCount--; | 807 info.closurizedCount--; |
| 811 } else { | 808 } else { |
| 812 info.closurizedCount++; | 809 info.closurizedCount++; |
| 813 if (callee.isStatic || callee.isTopLevel) { | 810 if (callee.isStatic || callee.isTopLevel) { |
| 814 types.allocatedClosures.add(info); | 811 types.allocatedClosures.add(info); |
| 815 } else { | 812 } else { |
| 816 // We add the call-site type information here so that we | 813 // We add the call-site type information here so that we |
| 817 // can benefit from further refinement of the selector. | 814 // can benefit from further refinement of the selector. |
| 818 types.allocatedClosures.add(caller); | 815 types.allocatedClosures.add(caller); |
| 819 } | 816 } |
| 820 forEachParameter(callee, (Local parameter) { | 817 types.strategy.forEachParameter(callee, (Local parameter) { |
| 821 ParameterTypeInformation info = | 818 ParameterTypeInformation info = |
| 822 types.getInferredTypeOfParameter(parameter); | 819 types.getInferredTypeOfParameter(parameter); |
| 823 info.tagAsTearOffClosureParameter(this); | 820 info.tagAsTearOffClosureParameter(this); |
| 824 if (addToQueue) workQueue.add(info); | 821 if (addToQueue) workQueue.add(info); |
| 825 }); | 822 }); |
| 826 } | 823 } |
| 827 } else { | 824 } else { |
| 828 FunctionEntity method = callee; | 825 FunctionEntity method = callee; |
| 829 ParameterStructure parameterStructure = method.parameterStructure; | 826 ParameterStructure parameterStructure = method.parameterStructure; |
| 830 int parameterIndex = 0; | 827 int parameterIndex = 0; |
| 831 forEachParameter(callee, (Local parameter) { | 828 types.strategy.forEachParameter(callee, (Local parameter) { |
| 832 TypeInformation type; | 829 TypeInformation type; |
| 833 if (parameterIndex < parameterStructure.requiredParameters) { | 830 if (parameterIndex < parameterStructure.requiredParameters) { |
| 834 type = arguments.positional[parameterIndex]; | 831 type = arguments.positional[parameterIndex]; |
| 835 } else if (parameterStructure.namedParameters.isNotEmpty) { | 832 } else if (parameterStructure.namedParameters.isNotEmpty) { |
| 836 type = arguments.named[parameter.name]; | 833 type = arguments.named[parameter.name]; |
| 837 } else if (parameterIndex < arguments.positional.length) { | 834 } else if (parameterIndex < arguments.positional.length) { |
| 838 type = arguments.positional[parameterIndex]; | 835 type = arguments.positional[parameterIndex]; |
| 839 } | 836 } |
| 840 if (type == null) type = getDefaultTypeOfParameter(parameter); | 837 if (type == null) type = getDefaultTypeOfParameter(parameter); |
| 841 TypeInformation info = types.getInferredTypeOfParameter(parameter); | 838 TypeInformation info = types.getInferredTypeOfParameter(parameter); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1135 // Put the other operators in buckets by size, later to be added in | 1132 // Put the other operators in buckets by size, later to be added in |
| 1136 // size order. | 1133 // size order. |
| 1137 int size = computeSize(element); | 1134 int size = computeSize(element); |
| 1138 Set<MemberEntity> set = | 1135 Set<MemberEntity> set = |
| 1139 methodSizes.putIfAbsent(size, () => new Setlet<MemberEntity>()); | 1136 methodSizes.putIfAbsent(size, () => new Setlet<MemberEntity>()); |
| 1140 set.add(element); | 1137 set.add(element); |
| 1141 }); | 1138 }); |
| 1142 return methodSizes; | 1139 return methodSizes; |
| 1143 } | 1140 } |
| 1144 } | 1141 } |
| OLD | NEW |