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

Side by Side Diff: pkg/compiler/lib/src/ssa/builder_kernel.dart

Issue 2603263002: Prefix resolution_types with Resolution. (Closed)
Patch Set: Rebased Created 3 years, 11 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 | « pkg/compiler/lib/src/ssa/builder.dart ('k') | pkg/compiler/lib/src/ssa/codegen.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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 '../closure.dart'; 7 import '../closure.dart';
8 import '../common.dart'; 8 import '../common.dart';
9 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; 9 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem;
10 import '../common/names.dart'; 10 import '../common/names.dart';
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 final ResolvedAst resolvedAst; 94 final ResolvedAst resolvedAst;
95 final ClosedWorld closedWorld; 95 final ClosedWorld closedWorld;
96 final CodegenRegistry registry; 96 final CodegenRegistry registry;
97 97
98 /// Helper accessor for all kernel function-like targets (Procedure, 98 /// Helper accessor for all kernel function-like targets (Procedure,
99 /// FunctionExpression, FunctionDeclaration) of the inner FunctionNode itself. 99 /// FunctionExpression, FunctionDeclaration) of the inner FunctionNode itself.
100 /// If the current target is not a function-like target, _targetFunction will 100 /// If the current target is not a function-like target, _targetFunction will
101 /// be null. 101 /// be null.
102 ir.FunctionNode _targetFunction; 102 ir.FunctionNode _targetFunction;
103 103
104 /// A stack of [DartType]s that have been seen during inlining of factory 104 /// A stack of [ResolutionDartType]s that have been seen during inlining of
105 /// constructors. These types are preserved in [HInvokeStatic]s and 105 /// factory constructors. These types are preserved in [HInvokeStatic]s and
106 /// [HCreate]s inside the inline code and registered during code generation 106 /// [HCreate]s inside the inline code and registered during code generation
107 /// for these nodes. 107 /// for these nodes.
108 // TODO(karlklose): consider removing this and keeping the (substituted) types 108 // TODO(karlklose): consider removing this and keeping the (substituted) types
109 // of the type variables in an environment (like the [LocalsHandler]). 109 // of the type variables in an environment (like the [LocalsHandler]).
110 final List<DartType> currentImplicitInstantiations = <DartType>[]; 110 final List<ResolutionDartType> currentImplicitInstantiations =
111 <ResolutionDartType>[];
111 112
112 HInstruction rethrowableException; 113 HInstruction rethrowableException;
113 114
114 @override 115 @override
115 JavaScriptBackend get backend => compiler.backend; 116 JavaScriptBackend get backend => compiler.backend;
116 117
117 @override 118 @override
118 TreeElements get elements => resolvedAst.elements; 119 TreeElements get elements => resolvedAst.elements;
119 120
120 SourceInformationBuilder sourceInformationBuilder; 121 SourceInformationBuilder sourceInformationBuilder;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 var enclosing = constructor.enclosingClass; 228 var enclosing = constructor.enclosingClass;
228 if (backend.classNeedsRti(astAdapter.getElement(enclosing))) { 229 if (backend.classNeedsRti(astAdapter.getElement(enclosing))) {
229 ClassElement clsElement = 230 ClassElement clsElement =
230 astAdapter.getElement(constructor).enclosingElement; 231 astAdapter.getElement(constructor).enclosingElement;
231 enclosing.typeParameters.forEach((ir.TypeParameter typeParameter) { 232 enclosing.typeParameters.forEach((ir.TypeParameter typeParameter) {
232 var typeParamElement = astAdapter.getElement(typeParameter); 233 var typeParamElement = astAdapter.getElement(typeParameter);
233 HParameterValue param = 234 HParameterValue param =
234 addParameter(typeParamElement, commonMasks.nonNullType); 235 addParameter(typeParamElement, commonMasks.nonNullType);
235 // This is a little bit wacky (and n^2) until we make the localsHandler 236 // This is a little bit wacky (and n^2) until we make the localsHandler
236 // take Kernel DartTypes instead of just the AST DartTypes. 237 // take Kernel DartTypes instead of just the AST DartTypes.
237 var typeVariableType = clsElement.typeVariables 238 var typeVariableType = clsElement.typeVariables.firstWhere(
238 .firstWhere((TypeVariableType i) => i.name == typeParameter.name); 239 (ResolutionTypeVariableType i) => i.name == typeParameter.name);
239 localsHandler.directLocals[ 240 localsHandler.directLocals[
240 localsHandler.getTypeVariableAsLocal(typeVariableType)] = param; 241 localsHandler.getTypeVariableAsLocal(typeVariableType)] = param;
241 }); 242 });
242 } 243 }
243 } 244 }
244 245
245 /// Builds generative constructors. 246 /// Builds generative constructors.
246 /// 247 ///
247 /// Generative constructors are built in two stages. 248 /// Generative constructors are built in two stages.
248 /// 249 ///
(...skipping 20 matching lines...) Expand all
269 constructorArguments.add(value); 270 constructorArguments.add(value);
270 }, includeSuperAndInjectedMembers: true); 271 }, includeSuperAndInjectedMembers: true);
271 272
272 // TODO(het): If the class needs runtime type information, add it as a 273 // TODO(het): If the class needs runtime type information, add it as a
273 // constructor argument. 274 // constructor argument.
274 HInstruction create = new HCreate( 275 HInstruction create = new HCreate(
275 astAdapter.getClass(constructor.enclosingClass), 276 astAdapter.getClass(constructor.enclosingClass),
276 constructorArguments, 277 constructorArguments,
277 new TypeMask.nonNullExact( 278 new TypeMask.nonNullExact(
278 astAdapter.getClass(constructor.enclosingClass), closedWorld), 279 astAdapter.getClass(constructor.enclosingClass), closedWorld),
279 instantiatedTypes: <DartType>[ 280 instantiatedTypes: <ResolutionDartType>[
280 astAdapter.getClass(constructor.enclosingClass).thisType 281 astAdapter.getClass(constructor.enclosingClass).thisType
281 ], 282 ],
282 hasRtiInput: false); 283 hasRtiInput: false);
283 284
284 add(create); 285 add(create);
285 286
286 // Generate calls to the constructor bodies. 287 // Generate calls to the constructor bodies.
287 288
288 closeAndGotoExit(new HReturn(create, null)); 289 closeAndGotoExit(new HReturn(create, null));
289 closeFunction(); 290 closeFunction();
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 parameters[parameter] = argument; 404 parameters[parameter] = argument;
404 localsHandler.updateLocal(parameter, argument); 405 localsHandler.updateLocal(parameter, argument);
405 }); 406 });
406 407
407 // TODO(het): set the locals handler state as if we were inlining the 408 // TODO(het): set the locals handler state as if we were inlining the
408 // constructor. 409 // constructor.
409 _buildInitializers(constructor, fieldValues); 410 _buildInitializers(constructor, fieldValues);
410 } 411 }
411 412
412 HTypeConversion buildFunctionTypeConversion( 413 HTypeConversion buildFunctionTypeConversion(
413 HInstruction original, DartType type, int kind) { 414 HInstruction original, ResolutionDartType type, int kind) {
414 HInstruction reifiedType = buildFunctionType(type); 415 HInstruction reifiedType = buildFunctionType(type);
415 return new HTypeConversion.viaMethodOnType( 416 return new HTypeConversion.viaMethodOnType(
416 type, kind, original.instructionType, reifiedType, original); 417 type, kind, original.instructionType, reifiedType, original);
417 } 418 }
418 419
419 /// Builds a SSA graph for FunctionNodes, found in FunctionExpressions and 420 /// Builds a SSA graph for FunctionNodes, found in FunctionExpressions and
420 /// Procedures. 421 /// Procedures.
421 void buildFunctionNode(ir.FunctionNode functionNode) { 422 void buildFunctionNode(ir.FunctionNode functionNode) {
422 openFunction(); 423 openFunction();
423 if (functionNode.parent is ir.Procedure && 424 if (functionNode.parent is ir.Procedure &&
424 (functionNode.parent as ir.Procedure).kind == 425 (functionNode.parent as ir.Procedure).kind ==
425 ir.ProcedureKind.Factory) { 426 ir.ProcedureKind.Factory) {
426 _addClassTypeVariablesIfNeeded(functionNode.parent); 427 _addClassTypeVariablesIfNeeded(functionNode.parent);
427 } 428 }
428 functionNode.body.accept(this); 429 functionNode.body.accept(this);
429 closeFunction(); 430 closeFunction();
430 } 431 }
431 432
432 void addImplicitInstantiation(DartType type) { 433 void addImplicitInstantiation(ResolutionDartType type) {
433 if (type != null) { 434 if (type != null) {
434 currentImplicitInstantiations.add(type); 435 currentImplicitInstantiations.add(type);
435 } 436 }
436 } 437 }
437 438
438 void removeImplicitInstantiation(DartType type) { 439 void removeImplicitInstantiation(ResolutionDartType type) {
439 if (type != null) { 440 if (type != null) {
440 currentImplicitInstantiations.removeLast(); 441 currentImplicitInstantiations.removeLast();
441 } 442 }
442 } 443 }
443 444
444 void openFunction() { 445 void openFunction() {
445 HBasicBlock block = graph.addNewBlock(); 446 HBasicBlock block = graph.addNewBlock();
446 open(graph.entry); 447 open(graph.entry);
447 448
448 Node function; 449 Node function;
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 handleIf( 928 handleIf(
928 visitCondition: () => ifStatement.condition.accept(this), 929 visitCondition: () => ifStatement.condition.accept(this),
929 visitThen: () => ifStatement.then.accept(this), 930 visitThen: () => ifStatement.then.accept(this),
930 visitElse: () => ifStatement.otherwise?.accept(this)); 931 visitElse: () => ifStatement.otherwise?.accept(this));
931 } 932 }
932 933
933 @override 934 @override
934 void visitAsExpression(ir.AsExpression asExpression) { 935 void visitAsExpression(ir.AsExpression asExpression) {
935 asExpression.operand.accept(this); 936 asExpression.operand.accept(this);
936 HInstruction expressionInstruction = pop(); 937 HInstruction expressionInstruction = pop();
937 DartType type = astAdapter.getDartType(asExpression.type); 938 ResolutionDartType type = astAdapter.getDartType(asExpression.type);
938 if (type.isMalformed) { 939 if (type.isMalformed) {
939 if (type is MalformedType) { 940 if (type is MalformedType) {
940 ErroneousElement element = type.element; 941 ErroneousElement element = type.element;
941 generateTypeError(asExpression, element.message); 942 generateTypeError(asExpression, element.message);
942 } else { 943 } else {
943 assert(type is MethodTypeVariableType); 944 assert(type is MethodTypeVariableType);
944 stack.add(expressionInstruction); 945 stack.add(expressionInstruction);
945 } 946 }
946 } else { 947 } else {
947 HInstruction converted = typeBuilder.buildTypeConversion( 948 HInstruction converted = typeBuilder.buildTypeConversion(
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 } 1093 }
1093 1094
1094 @override 1095 @override
1095 void visitNullLiteral(ir.NullLiteral nullLiteral) { 1096 void visitNullLiteral(ir.NullLiteral nullLiteral) {
1096 stack.add(graph.addConstantNull(closedWorld)); 1097 stack.add(graph.addConstantNull(closedWorld));
1097 } 1098 }
1098 1099
1099 /// Set the runtime type information if necessary. 1100 /// Set the runtime type information if necessary.
1100 HInstruction setListRuntimeTypeInfoIfNeeded( 1101 HInstruction setListRuntimeTypeInfoIfNeeded(
1101 HInstruction object, ir.ListLiteral listLiteral) { 1102 HInstruction object, ir.ListLiteral listLiteral) {
1102 InterfaceType type = localsHandler 1103 ResolutionInterfaceType type = localsHandler
1103 .substInContext(astAdapter.getDartTypeOfListLiteral(listLiteral)); 1104 .substInContext(astAdapter.getDartTypeOfListLiteral(listLiteral));
1104 if (!backend.classNeedsRti(type.element) || type.treatAsRaw) { 1105 if (!backend.classNeedsRti(type.element) || type.treatAsRaw) {
1105 return object; 1106 return object;
1106 } 1107 }
1107 List<HInstruction> arguments = <HInstruction>[]; 1108 List<HInstruction> arguments = <HInstruction>[];
1108 for (DartType argument in type.typeArguments) { 1109 for (ResolutionDartType argument in type.typeArguments) {
1109 arguments.add(typeBuilder.analyzeTypeArgument(argument, sourceElement)); 1110 arguments.add(typeBuilder.analyzeTypeArgument(argument, sourceElement));
1110 } 1111 }
1111 // TODO(15489): Register at codegen. 1112 // TODO(15489): Register at codegen.
1112 registry?.registerInstantiation(type); 1113 registry?.registerInstantiation(type);
1113 return callSetRuntimeTypeInfoWithTypeArguments(type, arguments, object); 1114 return callSetRuntimeTypeInfoWithTypeArguments(type, arguments, object);
1114 } 1115 }
1115 1116
1116 @override 1117 @override
1117 void visitListLiteral(ir.ListLiteral listLiteral) { 1118 void visitListLiteral(ir.ListLiteral listLiteral) {
1118 HInstruction listInstruction; 1119 HInstruction listInstruction;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 } else { 1165 } else {
1165 constructor = astAdapter.mapLiteralConstructor; 1166 constructor = astAdapter.mapLiteralConstructor;
1166 HLiteralList argList = 1167 HLiteralList argList =
1167 new HLiteralList(constructorArgs, commonMasks.extendableArrayType); 1168 new HLiteralList(constructorArgs, commonMasks.extendableArrayType);
1168 add(argList); 1169 add(argList);
1169 inputs.add(argList); 1170 inputs.add(argList);
1170 } 1171 }
1171 1172
1172 assert(constructor.kind == ir.ProcedureKind.Factory); 1173 assert(constructor.kind == ir.ProcedureKind.Factory);
1173 1174
1174 InterfaceType type = localsHandler 1175 ResolutionInterfaceType type = localsHandler
1175 .substInContext(astAdapter.getDartTypeOfMapLiteral(mapLiteral)); 1176 .substInContext(astAdapter.getDartTypeOfMapLiteral(mapLiteral));
1176 1177
1177 ir.Class cls = constructor.enclosingClass; 1178 ir.Class cls = constructor.enclosingClass;
1178 1179
1179 if (backend.classNeedsRti(astAdapter.getElement(cls))) { 1180 if (backend.classNeedsRti(astAdapter.getElement(cls))) {
1180 List<HInstruction> typeInputs = <HInstruction>[]; 1181 List<HInstruction> typeInputs = <HInstruction>[];
1181 type.typeArguments.forEach((DartType argument) { 1182 type.typeArguments.forEach((ResolutionDartType argument) {
1182 typeInputs 1183 typeInputs
1183 .add(typeBuilder.analyzeTypeArgument(argument, sourceElement)); 1184 .add(typeBuilder.analyzeTypeArgument(argument, sourceElement));
1184 }); 1185 });
1185 1186
1186 // We lift this common call pattern into a helper function to save space 1187 // We lift this common call pattern into a helper function to save space
1187 // in the output. 1188 // in the output.
1188 if (typeInputs.every((HInstruction input) => input.isNull())) { 1189 if (typeInputs.every((HInstruction input) => input.isNull())) {
1189 if (constructorArgs.isEmpty) { 1190 if (constructorArgs.isEmpty) {
1190 constructor = astAdapter.mapLiteralUntypedEmptyMaker; 1191 constructor = astAdapter.mapLiteralUntypedEmptyMaker;
1191 } else { 1192 } else {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1228 @override 1229 @override
1229 void visitTypeLiteral(ir.TypeLiteral typeLiteral) { 1230 void visitTypeLiteral(ir.TypeLiteral typeLiteral) {
1230 ir.DartType type = typeLiteral.type; 1231 ir.DartType type = typeLiteral.type;
1231 if (type is ir.InterfaceType) { 1232 if (type is ir.InterfaceType) {
1232 ConstantValue constant = astAdapter.getConstantForType(type); 1233 ConstantValue constant = astAdapter.getConstantForType(type);
1233 stack.add(graph.addConstant(constant, closedWorld)); 1234 stack.add(graph.addConstant(constant, closedWorld));
1234 return; 1235 return;
1235 } 1236 }
1236 if (type is ir.TypeParameterType) { 1237 if (type is ir.TypeParameterType) {
1237 // TODO(sra): Convert the type logic here to use ir.DartType. 1238 // TODO(sra): Convert the type logic here to use ir.DartType.
1238 DartType dartType = astAdapter.getDartType(type); 1239 ResolutionDartType dartType = astAdapter.getDartType(type);
1239 dartType = localsHandler.substInContext(dartType); 1240 dartType = localsHandler.substInContext(dartType);
1240 HInstruction value = typeBuilder.analyzeTypeArgument( 1241 HInstruction value = typeBuilder.analyzeTypeArgument(
1241 dartType, sourceElement, 1242 dartType, sourceElement,
1242 sourceInformation: null); 1243 sourceInformation: null);
1243 _pushStaticInvocation(astAdapter.runtimeTypeToString, 1244 _pushStaticInvocation(astAdapter.runtimeTypeToString,
1244 <HInstruction>[value], commonMasks.stringType); 1245 <HInstruction>[value], commonMasks.stringType);
1245 _pushStaticInvocation(astAdapter.createRuntimeType, <HInstruction>[pop()], 1246 _pushStaticInvocation(astAdapter.createRuntimeType, <HInstruction>[pop()],
1246 astAdapter.createRuntimeTypeReturnType); 1247 astAdapter.createRuntimeTypeReturnType);
1247 return; 1248 return;
1248 } 1249 }
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
1925 push(new HStringConcat(inputs[0], inputs[1], commonMasks.stringType)); 1926 push(new HStringConcat(inputs[0], inputs[1], commonMasks.stringType));
1926 } 1927 }
1927 1928
1928 void _pushStaticInvocation( 1929 void _pushStaticInvocation(
1929 ir.Node target, List<HInstruction> arguments, TypeMask typeMask) { 1930 ir.Node target, List<HInstruction> arguments, TypeMask typeMask) {
1930 HInvokeStatic instruction = new HInvokeStatic( 1931 HInvokeStatic instruction = new HInvokeStatic(
1931 astAdapter.getMember(target), arguments, typeMask, 1932 astAdapter.getMember(target), arguments, typeMask,
1932 targetCanThrow: astAdapter.getCanThrow(target, closedWorld)); 1933 targetCanThrow: astAdapter.getCanThrow(target, closedWorld));
1933 if (currentImplicitInstantiations.isNotEmpty) { 1934 if (currentImplicitInstantiations.isNotEmpty) {
1934 instruction.instantiatedTypes = 1935 instruction.instantiatedTypes =
1935 new List<DartType>.from(currentImplicitInstantiations); 1936 new List<ResolutionDartType>.from(currentImplicitInstantiations);
1936 } 1937 }
1937 instruction.sideEffects = astAdapter.getSideEffects(target, closedWorld); 1938 instruction.sideEffects = astAdapter.getSideEffects(target, closedWorld);
1938 1939
1939 push(instruction); 1940 push(instruction);
1940 } 1941 }
1941 1942
1942 void _pushDynamicInvocation( 1943 void _pushDynamicInvocation(
1943 ir.Node node, TypeMask mask, List<HInstruction> arguments, 1944 ir.Node node, TypeMask mask, List<HInstruction> arguments,
1944 {Selector selector}) { 1945 {Selector selector}) {
1945 HInstruction receiver = arguments.first; 1946 HInstruction receiver = arguments.first;
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
2106 isExpression.operand.accept(this); 2107 isExpression.operand.accept(this);
2107 HInstruction expression = pop(); 2108 HInstruction expression = pop();
2108 push(buildIsNode(isExpression, isExpression.type, expression)); 2109 push(buildIsNode(isExpression, isExpression.type, expression));
2109 } 2110 }
2110 2111
2111 HInstruction buildIsNode( 2112 HInstruction buildIsNode(
2112 ir.Node node, ir.DartType type, HInstruction expression) { 2113 ir.Node node, ir.DartType type, HInstruction expression) {
2113 // Note: The call to "unalias" this type like in the original SSA builder is 2114 // Note: The call to "unalias" this type like in the original SSA builder is
2114 // unnecessary in kernel because Kernel has no notion of typedef. 2115 // unnecessary in kernel because Kernel has no notion of typedef.
2115 // TODO(efortuna): Add test for this. 2116 // TODO(efortuna): Add test for this.
2116 DartType typeValue = 2117 ResolutionDartType typeValue =
2117 localsHandler.substInContext(astAdapter.getDartType(type)); 2118 localsHandler.substInContext(astAdapter.getDartType(type));
2118 if (type is ir.InvalidType) { 2119 if (type is ir.InvalidType) {
2119 generateTypeError(node, (typeValue.element as ErroneousElement).message); 2120 generateTypeError(node, (typeValue.element as ErroneousElement).message);
2120 return new HIs.compound( 2121 return new HIs.compound(
2121 typeValue, expression, pop(), commonMasks.boolType); 2122 typeValue, expression, pop(), commonMasks.boolType);
2122 } 2123 }
2123 2124
2124 if (type is ir.FunctionType) { 2125 if (type is ir.FunctionType) {
2125 List arguments = [buildFunctionType(typeValue), expression]; 2126 List arguments = [buildFunctionType(typeValue), expression];
2126 _pushDynamicInvocation(node, null, arguments, 2127 _pushDynamicInvocation(node, null, arguments,
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
2479 kernelBuilder.open(exitBlock); 2480 kernelBuilder.open(exitBlock);
2480 enterBlock.setBlockFlow( 2481 enterBlock.setBlockFlow(
2481 new HTryBlockInformation( 2482 new HTryBlockInformation(
2482 kernelBuilder.wrapStatementGraph(bodyGraph), 2483 kernelBuilder.wrapStatementGraph(bodyGraph),
2483 exception, 2484 exception,
2484 kernelBuilder.wrapStatementGraph(catchGraph), 2485 kernelBuilder.wrapStatementGraph(catchGraph),
2485 kernelBuilder.wrapStatementGraph(finallyGraph)), 2486 kernelBuilder.wrapStatementGraph(finallyGraph)),
2486 exitBlock); 2487 exitBlock);
2487 } 2488 }
2488 } 2489 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/ssa/builder.dart ('k') | pkg/compiler/lib/src/ssa/codegen.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698