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

Side by Side Diff: pkg/compiler/lib/src/inferrer/inferrer_engine.dart

Issue 3002313002: Use KernelTypeGraphBuilder in KernelInferrerEngine (Closed)
Patch Set: Created 3 years, 3 months 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
OLDNEW
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 ClosedWorldRefiner get closedWorldRefiner; 62 ClosedWorldRefiner get closedWorldRefiner;
63 JavaScriptBackend get backend => compiler.backend; 63 JavaScriptBackend get backend => compiler.backend;
64 OptimizerHintsForTests get optimizerHints => backend.optimizerHints; 64 OptimizerHintsForTests get optimizerHints => backend.optimizerHints;
65 DiagnosticReporter get reporter => compiler.reporter; 65 DiagnosticReporter get reporter => compiler.reporter;
66 CommonMasks get commonMasks => closedWorld.commonMasks; 66 CommonMasks get commonMasks => closedWorld.commonMasks;
67 CommonElements get commonElements => closedWorld.commonElements; 67 CommonElements get commonElements => closedWorld.commonElements;
68 68
69 TypeSystem<T> get types; 69 TypeSystem<T> get types;
70 Map<T, TypeInformation> get concreteTypes; 70 Map<T, TypeInformation> get concreteTypes;
71 71
72 /// Parallel structure for concreteTypes.
73 // TODO(efortuna): Remove concreteTypes and/or parameterize InferrerEngine by
74 // ir.Node or ast.Node type. Then remove this in favor of `concreteTypes`.
75 Map<ir.Node, TypeInformation> get concreteKernelTypes;
76
77 FunctionEntity get mainElement; 72 FunctionEntity get mainElement;
78 73
79 void runOverAllElements(); 74 void runOverAllElements();
80 75
81 void analyze(MemberEntity member, T node, ArgumentsTypes arguments); 76 void analyze(MemberEntity member, T node, ArgumentsTypes arguments);
82 void analyzeListAndEnqueue(ListTypeInformation info); 77 void analyzeListAndEnqueue(ListTypeInformation info);
83 void analyzeMapAndEnqueue(MapTypeInformation info); 78 void analyzeMapAndEnqueue(MapTypeInformation info);
84 79
85 /// Notifies to the inferrer that [analyzedElement] can have return type 80 /// Notifies to the inferrer that [analyzedElement] can have return type
86 /// [newType]. [currentType] is the type the [ElementGraphBuilder] currently 81 /// [newType]. [currentType] is the type the [ElementGraphBuilder] currently
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 } 621 }
627 dump?.afterAnalysis(); 622 dump?.afterAnalysis();
628 623
629 reporter.log('Inferred $overallRefineCount types.'); 624 reporter.log('Inferred $overallRefineCount types.');
630 625
631 processLoopInformation(); 626 processLoopInformation();
632 } 627 }
633 628
634 /// Call [analyze] for all live members. 629 /// Call [analyze] for all live members.
635 void analyzeAllElements() { 630 void analyzeAllElements() {
636 sortMembers(compiler, computeMemberSize).forEach((MemberEntity member) { 631 sortMembers(closedWorld.processedMembers, computeMemberSize)
632 .forEach((MemberEntity member) {
637 if (compiler.shouldPrintProgress) { 633 if (compiler.shouldPrintProgress) {
638 reporter.log('Added $addedInGraph elements in inferencing graph.'); 634 reporter.log('Added $addedInGraph elements in inferencing graph.');
639 compiler.progress.reset(); 635 compiler.progress.reset();
640 } 636 }
641 // This also forces the creation of the [ElementTypeInformation] to ensure 637 // This also forces the creation of the [ElementTypeInformation] to ensure
642 // it is in the graph. 638 // it is in the graph.
643 T body = computeMemberBody(member); 639 T body = computeMemberBody(member);
644 types.withMember(member, () => analyze(member, body, null)); 640 types.withMember(member, () => analyze(member, body, null));
645 }); 641 });
646 reporter.log('Added $addedInGraph elements in inferencing graph.'); 642 reporter.log('Added $addedInGraph elements in inferencing graph.');
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 return types.dynamicType; 1108 return types.dynamicType;
1113 } else { 1109 } else {
1114 return returnTypeOfMember(element); 1110 return returnTypeOfMember(element);
1115 } 1111 }
1116 } 1112 }
1117 1113
1118 // Sorts the resolved elements by size. We do this for this inferrer 1114 // Sorts the resolved elements by size. We do this for this inferrer
1119 // to get the same results for [ListTracer] compared to the 1115 // to get the same results for [ListTracer] compared to the
1120 // [SimpleTypesInferrer]. 1116 // [SimpleTypesInferrer].
1121 static Iterable<MemberEntity> sortMembers( 1117 static Iterable<MemberEntity> sortMembers(
1122 Compiler compiler, int computeSize(MemberEntity member)) { 1118 Iterable<MemberEntity> members, int computeSize(MemberEntity member)) {
1123 Map<int, Set<MemberEntity>> methodSizes = 1119 Map<int, Set<MemberEntity>> methodSizes =
1124 groupMembers(compiler, computeSize); 1120 groupMembers(members, computeSize);
1125 int max = methodSizes.keys.fold(0, (a, b) => a > b ? a : b); 1121 int max = methodSizes.keys.fold(0, (a, b) => a > b ? a : b);
1126 List<MemberEntity> result = <MemberEntity>[]; 1122 List<MemberEntity> result = <MemberEntity>[];
1127 for (int i = 0; i <= max; i++) { 1123 for (int i = 0; i <= max; i++) {
1128 Set<MemberEntity> set = methodSizes[i]; 1124 Set<MemberEntity> set = methodSizes[i];
1129 if (set != null) result.addAll(set); 1125 if (set != null) result.addAll(set);
1130 } 1126 }
1131 return result; 1127 return result;
1132 } 1128 }
1133 1129
1134 static Map<int, Set<MemberEntity>> groupMembers( 1130 static Map<int, Set<MemberEntity>> groupMembers(
1135 Compiler compiler, int computeSize(MemberEntity member)) { 1131 Iterable<MemberEntity> members, int computeSize(MemberEntity member)) {
1136 Map<int, Set<MemberEntity>> methodSizes = <int, Set<MemberEntity>>{}; 1132 Map<int, Set<MemberEntity>> methodSizes = <int, Set<MemberEntity>>{};
1137 compiler.enqueuer.resolution.processedEntities 1133 members.forEach((MemberEntity element) {
1138 .forEach((MemberEntity element) {
1139 if (element.isAbstract) return; 1134 if (element.isAbstract) return;
1140 // Put the other operators in buckets by size, later to be added in 1135 // Put the other operators in buckets by size, later to be added in
1141 // size order. 1136 // size order.
1142 int size = computeSize(element); 1137 int size = computeSize(element);
1143 Set<MemberEntity> set = 1138 Set<MemberEntity> set =
1144 methodSizes.putIfAbsent(size, () => new Setlet<MemberEntity>()); 1139 methodSizes.putIfAbsent(size, () => new Setlet<MemberEntity>());
1145 set.add(element); 1140 set.add(element);
1146 }); 1141 });
1147 return methodSizes; 1142 return methodSizes;
1148 } 1143 }
1149 } 1144 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698