| 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 '../constants/expressions.dart'; | 10 import '../constants/expressions.dart'; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 this.closedWorld = closedWorld; | 84 this.closedWorld = closedWorld; |
| 85 | 85 |
| 86 CommonElements get commonElements => closedWorld.commonElements; | 86 CommonElements get commonElements => closedWorld.commonElements; |
| 87 | 87 |
| 88 /** | 88 /** |
| 89 * Applies [f] to all elements in the universe that match | 89 * Applies [f] to all elements in the universe that match |
| 90 * [selector] and [mask]. If [f] returns false, aborts the iteration. | 90 * [selector] and [mask]. If [f] returns false, aborts the iteration. |
| 91 */ | 91 */ |
| 92 void forEachElementMatching( | 92 void forEachElementMatching( |
| 93 Selector selector, TypeMask mask, bool f(Element element)) { | 93 Selector selector, TypeMask mask, bool f(Element element)) { |
| 94 Iterable<Element> elements = | 94 Iterable<MemberEntity> elements = |
| 95 closedWorld.allFunctions.filter(selector, mask); | 95 closedWorld.allFunctions.filter(selector, mask); |
| 96 for (Element e in elements) { | 96 for (MemberElement e in elements) { |
| 97 if (!f(e.implementation)) return; | 97 if (!f(e.implementation)) return; |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 | 100 |
| 101 // TODO(johnniwinther): Make this private again. | 101 // TODO(johnniwinther): Make this private again. |
| 102 GlobalTypeInferenceElementData dataOf(AstElement element) => inTreeData | 102 GlobalTypeInferenceElementData dataOf(AstElement element) => inTreeData |
| 103 .putIfAbsent(element, () => new GlobalTypeInferenceElementData()); | 103 .putIfAbsent(element, () => new GlobalTypeInferenceElementData()); |
| 104 | 104 |
| 105 /** | 105 /** |
| 106 * Update [sideEffects] with the side effects of [callee] being | 106 * Update [sideEffects] with the side effects of [callee] being |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 'after ${info.refineCount}'); | 435 'after ${info.refineCount}'); |
| 436 }); | 436 }); |
| 437 types.allocatedClosures.forEach((TypeInformation info) { | 437 types.allocatedClosures.forEach((TypeInformation info) { |
| 438 if (info is ElementTypeInformation) { | 438 if (info is ElementTypeInformation) { |
| 439 print('${types.getInferredSignatureOf(info.element)} for ' | 439 print('${types.getInferredSignatureOf(info.element)} for ' |
| 440 '${info.element}'); | 440 '${info.element}'); |
| 441 } else if (info is ClosureTypeInformation) { | 441 } else if (info is ClosureTypeInformation) { |
| 442 print('${types.getInferredSignatureOf(info.element)} for ' | 442 print('${types.getInferredSignatureOf(info.element)} for ' |
| 443 '${info.element}'); | 443 '${info.element}'); |
| 444 } else if (info is DynamicCallSiteTypeInformation) { | 444 } else if (info is DynamicCallSiteTypeInformation) { |
| 445 for (Element target in info.targets) { | 445 for (MemberElement target in info.targets) { |
| 446 if (target is FunctionElement) { | 446 if (target is MethodElement) { |
| 447 print('${types.getInferredSignatureOf(target)} for ${target}'); | 447 print('${types.getInferredSignatureOf(target)} for ${target}'); |
| 448 } else { | 448 } else { |
| 449 print('${types.getInferredTypeOf(target).type} for ${target}'); | 449 print('${types.getInferredTypeOf(target).type} for ${target}'); |
| 450 } | 450 } |
| 451 } | 451 } |
| 452 } else if (info is StaticCallSiteTypeInformation) { | 452 } else if (info is StaticCallSiteTypeInformation) { |
| 453 ClassElement cls = info.calledElement.enclosingClass; | 453 ClassElement cls = info.calledElement.enclosingClass; |
| 454 FunctionElement callMethod = cls.lookupMember(Identifiers.call); | 454 FunctionElement callMethod = cls.lookupMember(Identifiers.call); |
| 455 print('${types.getInferredSignatureOf(callMethod)} for ${cls}'); | 455 print('${types.getInferredSignatureOf(callMethod)} for ${cls}'); |
| 456 } else { | 456 } else { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 void processLoopInformation() { | 556 void processLoopInformation() { |
| 557 types.allocatedCalls.forEach((info) { | 557 types.allocatedCalls.forEach((info) { |
| 558 if (!info.inLoop) return; | 558 if (!info.inLoop) return; |
| 559 if (info is StaticCallSiteTypeInformation) { | 559 if (info is StaticCallSiteTypeInformation) { |
| 560 closedWorldRefiner.addFunctionCalledInLoop(info.calledElement); | 560 closedWorldRefiner.addFunctionCalledInLoop(info.calledElement); |
| 561 } else if (info.mask != null && !info.mask.containsAll(closedWorld)) { | 561 } else if (info.mask != null && !info.mask.containsAll(closedWorld)) { |
| 562 // For instance methods, we only register a selector called in a | 562 // For instance methods, we only register a selector called in a |
| 563 // loop if it is a typed selector, to avoid marking too many | 563 // loop if it is a typed selector, to avoid marking too many |
| 564 // methods as being called from within a loop. This cuts down | 564 // methods as being called from within a loop. This cuts down |
| 565 // on the code bloat. | 565 // on the code bloat. |
| 566 info.targets.forEach(closedWorldRefiner.addFunctionCalledInLoop); | 566 info.targets.forEach((MemberElement element) { |
| 567 closedWorldRefiner.addFunctionCalledInLoop(element); |
| 568 }); |
| 567 } | 569 } |
| 568 }); | 570 }); |
| 569 } | 571 } |
| 570 | 572 |
| 571 void refine() { | 573 void refine() { |
| 572 while (!workQueue.isEmpty) { | 574 while (!workQueue.isEmpty) { |
| 573 if (compiler.shouldPrintProgress) { | 575 if (compiler.shouldPrintProgress) { |
| 574 reporter.log('Inferred $overallRefineCount types.'); | 576 reporter.log('Inferred $overallRefineCount types.'); |
| 575 compiler.progress.reset(); | 577 compiler.progress.reset(); |
| 576 } | 578 } |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 TypeInformation receiverType, | 878 TypeInformation receiverType, |
| 877 Element caller, | 879 Element caller, |
| 878 ArgumentsTypes arguments, | 880 ArgumentsTypes arguments, |
| 879 SideEffects sideEffects, | 881 SideEffects sideEffects, |
| 880 bool inLoop) { | 882 bool inLoop) { |
| 881 if (selector.isClosureCall) { | 883 if (selector.isClosureCall) { |
| 882 return registerCalledClosure(node, selector, mask, receiverType, caller, | 884 return registerCalledClosure(node, selector, mask, receiverType, caller, |
| 883 arguments, sideEffects, inLoop); | 885 arguments, sideEffects, inLoop); |
| 884 } | 886 } |
| 885 | 887 |
| 886 closedWorld.allFunctions.filter(selector, mask).forEach((callee) { | 888 closedWorld.allFunctions |
| 889 .filter(selector, mask) |
| 890 .forEach((MemberElement callee) { |
| 887 updateSideEffects(sideEffects, selector, callee); | 891 updateSideEffects(sideEffects, selector, callee); |
| 888 }); | 892 }); |
| 889 | 893 |
| 890 CallSiteTypeInformation info = new DynamicCallSiteTypeInformation( | 894 CallSiteTypeInformation info = new DynamicCallSiteTypeInformation( |
| 891 types.currentMember, | 895 types.currentMember, |
| 892 node, | 896 node, |
| 893 caller, | 897 caller, |
| 894 selector, | 898 selector, |
| 895 mask, | 899 mask, |
| 896 receiverType, | 900 receiverType, |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1057 /** | 1061 /** |
| 1058 * Records that the captured variable [local] is read. | 1062 * Records that the captured variable [local] is read. |
| 1059 */ | 1063 */ |
| 1060 void recordCapturedLocalRead(Local local) {} | 1064 void recordCapturedLocalRead(Local local) {} |
| 1061 | 1065 |
| 1062 /** | 1066 /** |
| 1063 * Records that the variable [local] is being updated. | 1067 * Records that the variable [local] is being updated. |
| 1064 */ | 1068 */ |
| 1065 void recordLocalUpdate(Local local, TypeInformation type) {} | 1069 void recordLocalUpdate(Local local, TypeInformation type) {} |
| 1066 } | 1070 } |
| OLD | NEW |