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

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

Issue 2981643002: Use TypeSystemStrategy to separate Element/Ast from TypeSystem (Closed)
Patch Set: Created 3 years, 5 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
« no previous file with comments | « no previous file | pkg/compiler/lib/src/inferrer/type_system.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 '../constants/expressions.dart'; 10 import '../constants/expressions.dart';
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 final Set<ConstructorElement> generativeConstructorsExposingThis = 75 final Set<ConstructorElement> generativeConstructorsExposingThis =
76 new Set<ConstructorElement>(); 76 new Set<ConstructorElement>();
77 77
78 /// Data computed internally within elements, like the type-mask of a send a 78 /// Data computed internally within elements, like the type-mask of a send a
79 /// list allocation, or a for-in loop. 79 /// list allocation, or a for-in loop.
80 final Map<MemberElement, GlobalTypeInferenceElementData> _memberData = 80 final Map<MemberElement, GlobalTypeInferenceElementData> _memberData =
81 new Map<MemberElement, GlobalTypeInferenceElementData>(); 81 new Map<MemberElement, GlobalTypeInferenceElementData>();
82 82
83 InferrerEngine(this.compiler, ClosedWorld closedWorld, 83 InferrerEngine(this.compiler, ClosedWorld closedWorld,
84 this.closedWorldRefiner, this.mainElement) 84 this.closedWorldRefiner, this.mainElement)
85 : this.types = new TypeSystem<ast.Node>(closedWorld), 85 : this.types = new TypeSystem<ast.Node>(
86 closedWorld, const TypeSystemStrategyImpl()),
86 this.closedWorld = closedWorld; 87 this.closedWorld = closedWorld;
87 88
88 CommonElements get commonElements => closedWorld.commonElements; 89 CommonElements get commonElements => closedWorld.commonElements;
89 90
90 /** 91 /**
91 * Applies [f] to all elements in the universe that match 92 * Applies [f] to all elements in the universe that match
92 * [selector] and [mask]. If [f] returns false, aborts the iteration. 93 * [selector] and [mask]. If [f] returns false, aborts the iteration.
93 */ 94 */
94 void forEachElementMatching( 95 void forEachElementMatching(
95 Selector selector, TypeMask mask, bool f(Element element)) { 96 Selector selector, TypeMask mask, bool f(Element element)) {
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 /** 1117 /**
1117 * Records that the captured variable [local] is read. 1118 * Records that the captured variable [local] is read.
1118 */ 1119 */
1119 void recordCapturedLocalRead(Local local) {} 1120 void recordCapturedLocalRead(Local local) {}
1120 1121
1121 /** 1122 /**
1122 * Records that the variable [local] is being updated. 1123 * Records that the variable [local] is being updated.
1123 */ 1124 */
1124 void recordLocalUpdate(Local local, TypeInformation type) {} 1125 void recordLocalUpdate(Local local, TypeInformation type) {}
1125 } 1126 }
1127
1128 class TypeSystemStrategyImpl implements TypeSystemStrategy<ast.Node> {
1129 const TypeSystemStrategyImpl();
1130
1131 @override
1132 MemberTypeInformation createMemberTypeInformation(
1133 covariant MemberElement member) {
1134 assert(member.isDeclaration, failedAt(member));
1135 if (member.isField) {
1136 FieldElement field = member;
1137 return new FieldTypeInformation(field, field.type);
1138 } else if (member.isGetter) {
1139 GetterElement getter = member;
1140 return new GetterTypeInformation(getter, getter.type);
1141 } else if (member.isSetter) {
1142 SetterElement setter = member;
1143 return new SetterTypeInformation(setter);
1144 } else if (member.isFunction) {
1145 MethodElement method = member;
1146 return new MethodTypeInformation(method, method.type);
1147 } else {
1148 ConstructorElement constructor = member;
1149 if (constructor.isFactoryConstructor) {
1150 return new FactoryConstructorTypeInformation(
1151 constructor, constructor.type);
1152 } else {
1153 return new GenerativeConstructorTypeInformation(constructor);
1154 }
1155 }
1156 }
1157
1158 @override
1159 ParameterTypeInformation createParameterTypeInformation(
1160 covariant ParameterElement parameter, TypeSystem<ast.Node> types) {
1161 assert(parameter.isImplementation, failedAt(parameter));
1162 FunctionTypedElement function = parameter.functionDeclaration.declaration;
1163 if (function.isLocal) {
1164 LocalFunctionElement localFunction = function;
1165 MethodElement callMethod = localFunction.callMethod;
1166 return new ParameterTypeInformation.localFunction(
1167 types.getInferredTypeOfMember(callMethod),
1168 parameter,
1169 parameter.type,
1170 callMethod);
1171 } else if (function.isInstanceMember) {
1172 MethodElement method = function;
1173 return new ParameterTypeInformation.instanceMember(
1174 types.getInferredTypeOfMember(method),
1175 parameter,
1176 parameter.type,
1177 method,
1178 new ParameterAssignments());
1179 } else {
1180 MethodElement method = function;
1181 return new ParameterTypeInformation.static(
1182 types.getInferredTypeOfMember(method),
1183 parameter,
1184 parameter.type,
1185 method,
1186 // TODO(johnniwinther): Is this still valid now that initializing
1187 // formals also introduce locals?
1188 isInitializingFormal: parameter.isInitializingFormal);
1189 }
1190 }
1191
1192 @override
1193 void forEachParameter(
1194 covariant MethodElement function, void f(Local parameter)) {
1195 MethodElement impl = function.implementation;
1196 FunctionSignature signature = impl.functionSignature;
1197 signature.forEachParameter((FormalElement _parameter) {
1198 ParameterElement parameter = _parameter;
1199 f(parameter);
1200 });
1201 }
1202
1203 @override
1204 bool checkMapNode(ast.Node node) {
1205 return node is ast.LiteralMap;
1206 }
1207
1208 @override
1209 bool checkListNode(ast.Node node) {
1210 return node is ast.LiteralList || node is ast.Send;
1211 }
1212
1213 @override
1214 bool checkLoopPhiNode(ast.Node node) {
1215 return node is ast.Loop || node is ast.SwitchStatement;
1216 }
1217
1218 @override
1219 bool checkPhiNode(ast.Node node) {
1220 return true;
1221 }
1222
1223 @override
1224 bool checkClassEntity(covariant ClassElement cls) {
1225 return cls.isDeclaration;
1226 }
1227 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/inferrer/type_system.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698