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

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

Issue 2938853004: Rename ClosureClassMaps to ClosureDataLookup (Closed)
Patch Set: . Created 3 years, 6 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/graph_builder.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; 9 import '../common/codegen.dart' show CodegenRegistry;
10 import '../common/names.dart'; 10 import '../common/names.dart';
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 final MemberEntity targetElement; 51 final MemberEntity targetElement;
52 52
53 /// The root node of [targetElement]. This is used as the key into the 53 /// The root node of [targetElement]. This is used as the key into the
54 /// [startFunction] of the locals handler. 54 /// [startFunction] of the locals handler.
55 // TODO(johnniwinther,efortuna): Avoid the need for AST nodes in the locals 55 // TODO(johnniwinther,efortuna): Avoid the need for AST nodes in the locals
56 // handler. 56 // handler.
57 final Node functionNode; 57 final Node functionNode;
58 final ClosedWorld closedWorld; 58 final ClosedWorld closedWorld;
59 final CodegenWorldBuilder _worldBuilder; 59 final CodegenWorldBuilder _worldBuilder;
60 final CodegenRegistry registry; 60 final CodegenRegistry registry;
61 final ClosureClassMaps closureToClassMapper; 61 final ClosureDataLookup closureDataLookup;
62 62
63 /// Helper accessor for all kernel function-like targets (Procedure, 63 /// Helper accessor for all kernel function-like targets (Procedure,
64 /// FunctionExpression, FunctionDeclaration) of the inner FunctionNode itself. 64 /// FunctionExpression, FunctionDeclaration) of the inner FunctionNode itself.
65 /// If the current target is not a function-like target, _targetFunction will 65 /// If the current target is not a function-like target, _targetFunction will
66 /// be null. 66 /// be null.
67 ir.FunctionNode _targetFunction; 67 ir.FunctionNode _targetFunction;
68 68
69 /// A stack of [ResolutionDartType]s that have been seen during inlining of 69 /// A stack of [ResolutionDartType]s that have been seen during inlining of
70 /// factory constructors. These types are preserved in [HInvokeStatic]s and 70 /// factory constructors. These types are preserved in [HInvokeStatic]s and
71 /// [HCreate]s inside the inline code and registered during code generation 71 /// [HCreate]s inside the inline code and registered during code generation
(...skipping 30 matching lines...) Expand all
102 this.targetElement, 102 this.targetElement,
103 ClassEntity contextClass, 103 ClassEntity contextClass,
104 this.target, 104 this.target,
105 this.compiler, 105 this.compiler,
106 this._elementMap, 106 this._elementMap,
107 this._typeInferenceMap, 107 this._typeInferenceMap,
108 this.localsMap, 108 this.localsMap,
109 this.closedWorld, 109 this.closedWorld,
110 this._worldBuilder, 110 this._worldBuilder,
111 this.registry, 111 this.registry,
112 this.closureToClassMapper, 112 this.closureDataLookup,
113 // TODO(het): Should sourceInformationBuilder be in GraphBuilder? 113 // TODO(het): Should sourceInformationBuilder be in GraphBuilder?
114 this.sourceInformationBuilder, 114 this.sourceInformationBuilder,
115 this.functionNode, 115 this.functionNode,
116 {bool targetIsConstructorBody: false}) 116 {bool targetIsConstructorBody: false})
117 : this._targetIsConstructorBody = targetIsConstructorBody { 117 : this._targetIsConstructorBody = targetIsConstructorBody {
118 this.loopHandler = new KernelLoopHandler(this); 118 this.loopHandler = new KernelLoopHandler(this);
119 typeBuilder = new TypeBuilder(this); 119 typeBuilder = new TypeBuilder(this);
120 graph.element = targetElement; 120 graph.element = targetElement;
121 graph.sourceInformation = 121 graph.sourceInformation =
122 sourceInformationBuilder.buildVariableDeclaration(); 122 sourceInformationBuilder.buildVariableDeclaration();
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 } 332 }
333 333
334 // Provide the parameters to the generative constructor body. 334 // Provide the parameters to the generative constructor body.
335 body.function.positionalParameters.forEach(handleParameter); 335 body.function.positionalParameters.forEach(handleParameter);
336 body.function.namedParameters.toList() 336 body.function.namedParameters.toList()
337 ..sort(namedOrdering) 337 ..sort(namedOrdering)
338 ..forEach(handleParameter); 338 ..forEach(handleParameter);
339 339
340 // If there are locals that escape (i.e. mutated in closures), we pass the 340 // If there are locals that escape (i.e. mutated in closures), we pass the
341 // box to the constructor. 341 // box to the constructor.
342 ClosureAnalysisInfo scopeData = closureToClassMapper 342 ClosureAnalysisInfo scopeData = closureDataLookup
343 .getClosureAnalysisInfo(constructorElement.resolvedAst.node); 343 .getClosureAnalysisInfo(constructorElement.resolvedAst.node);
344 if (scopeData.requiresContextBox()) { 344 if (scopeData.requiresContextBox()) {
345 bodyCallInputs.add(localsHandler.readLocal(scopeData.context)); 345 bodyCallInputs.add(localsHandler.readLocal(scopeData.context));
346 } 346 }
347 347
348 // Pass type arguments. 348 // Pass type arguments.
349 ir.Class currentClass = body.enclosingClass; 349 ir.Class currentClass = body.enclosingClass;
350 if (backend.rtiNeed.classNeedsRti(_elementMap.getClass(currentClass))) { 350 if (backend.rtiNeed.classNeedsRti(_elementMap.getClass(currentClass))) {
351 for (ir.DartType typeParameter in currentClass.thisType.typeArguments) { 351 for (ir.DartType typeParameter in currentClass.thisType.typeArguments) {
352 HInstruction argument = localsHandler.readLocal(localsHandler 352 HInstruction argument = localsHandler.readLocal(localsHandler
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 590
591 constructor.function.positionalParameters.forEach(handleParameter); 591 constructor.function.positionalParameters.forEach(handleParameter);
592 constructor.function.namedParameters.toList() 592 constructor.function.namedParameters.toList()
593 ..sort(namedOrdering) 593 ..sort(namedOrdering)
594 ..forEach(handleParameter); 594 ..forEach(handleParameter);
595 595
596 // Set the locals handler state as if we were inlining the constructor. 596 // Set the locals handler state as if we were inlining the constructor.
597 ConstructorEntity astElement = _elementMap.getConstructor(constructor); 597 ConstructorEntity astElement = _elementMap.getConstructor(constructor);
598 ClosureRepresentationInfo oldClosureData = localsHandler.closureData; 598 ClosureRepresentationInfo oldClosureData = localsHandler.closureData;
599 ClosureRepresentationInfo newClosureData = 599 ClosureRepresentationInfo newClosureData =
600 closureToClassMapper.getClosureRepresentationInfo(astElement); 600 closureDataLookup.getClosureRepresentationInfo(astElement);
601 if (astElement is ConstructorElement) { 601 if (astElement is ConstructorElement) {
602 // TODO(johnniwinther): Support constructor (body) entities. 602 // TODO(johnniwinther): Support constructor (body) entities.
603 ResolvedAst resolvedAst = astElement.resolvedAst; 603 ResolvedAst resolvedAst = astElement.resolvedAst;
604 localsHandler.closureData = newClosureData; 604 localsHandler.closureData = newClosureData;
605 if (resolvedAst.kind == ResolvedAstKind.PARSED) { 605 if (resolvedAst.kind == ResolvedAstKind.PARSED) {
606 localsHandler.enterScope( 606 localsHandler.enterScope(
607 closureToClassMapper.getClosureAnalysisInfo(resolvedAst.node), 607 closureDataLookup.getClosureAnalysisInfo(resolvedAst.node),
608 forGenerativeConstructorBody: 608 forGenerativeConstructorBody:
609 astElement.isGenerativeConstructorBody); 609 astElement.isGenerativeConstructorBody);
610 } 610 }
611 } 611 }
612 inlinedFrom(astElement, () { 612 inlinedFrom(astElement, () {
613 _buildInitializers(constructor, constructorChain, fieldValues); 613 _buildInitializers(constructor, constructorChain, fieldValues);
614 }); 614 });
615 localsHandler.closureData = oldClosureData; 615 localsHandler.closureData = oldClosureData;
616 } 616 }
617 617
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 function.namedParameters.toList() 688 function.namedParameters.toList()
689 ..sort(namedOrdering) 689 ..sort(namedOrdering)
690 ..forEach(handleParameter); 690 ..forEach(handleParameter);
691 } 691 }
692 692
693 HBasicBlock block = graph.addNewBlock(); 693 HBasicBlock block = graph.addNewBlock();
694 open(graph.entry); 694 open(graph.entry);
695 695
696 localsHandler.startFunction( 696 localsHandler.startFunction(
697 targetElement, 697 targetElement,
698 closureToClassMapper.getClosureRepresentationInfo(targetElement), 698 closureDataLookup.getClosureRepresentationInfo(targetElement),
699 closureToClassMapper.getClosureAnalysisInfo(functionNode), 699 closureDataLookup.getClosureAnalysisInfo(functionNode),
700 parameterMap, 700 parameterMap,
701 isGenerativeConstructorBody: _targetIsConstructorBody); 701 isGenerativeConstructorBody: _targetIsConstructorBody);
702 close(new HGoto()).addSuccessor(block); 702 close(new HGoto()).addSuccessor(block);
703 703
704 open(block); 704 open(block);
705 } 705 }
706 706
707 void closeFunction() { 707 void closeFunction() {
708 if (!isAborted()) closeAndGotoExit(new HGoto()); 708 if (!isAborted()) closeAndGotoExit(new HGoto());
709 graph.finalize(); 709 graph.finalize();
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 } 893 }
894 } 894 }
895 895
896 void buildBody() { 896 void buildBody() {
897 forStatement.body.accept(this); 897 forStatement.body.accept(this);
898 } 898 }
899 899
900 loopHandler.handleLoop( 900 loopHandler.handleLoop(
901 forStatement, 901 forStatement,
902 localsMap.getClosureRepresentationInfoForLoop( 902 localsMap.getClosureRepresentationInfoForLoop(
903 closureToClassMapper, forStatement), 903 closureDataLookup, forStatement),
904 buildInitializer, 904 buildInitializer,
905 buildCondition, 905 buildCondition,
906 buildUpdate, 906 buildUpdate,
907 buildBody); 907 buildBody);
908 } 908 }
909 909
910 @override 910 @override
911 void visitForInStatement(ir.ForInStatement forInStatement) { 911 void visitForInStatement(ir.ForInStatement forInStatement) {
912 if (forInStatement.isAsync) { 912 if (forInStatement.isAsync) {
913 _buildAsyncForIn(forInStatement); 913 _buildAsyncForIn(forInStatement);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 HInstruction one = graph.addConstantInt(1, closedWorld); 1022 HInstruction one = graph.addConstantInt(1, closedWorld);
1023 HInstruction addInstruction = 1023 HInstruction addInstruction =
1024 new HAdd(index, one, null, commonMasks.positiveIntType); 1024 new HAdd(index, one, null, commonMasks.positiveIntType);
1025 add(addInstruction); 1025 add(addInstruction);
1026 localsHandler.updateLocal(indexVariable, addInstruction); 1026 localsHandler.updateLocal(indexVariable, addInstruction);
1027 } 1027 }
1028 1028
1029 loopHandler.handleLoop( 1029 loopHandler.handleLoop(
1030 forInStatement, 1030 forInStatement,
1031 localsMap.getClosureRepresentationInfoForLoop( 1031 localsMap.getClosureRepresentationInfoForLoop(
1032 closureToClassMapper, forInStatement), 1032 closureDataLookup, forInStatement),
1033 buildInitializer, 1033 buildInitializer,
1034 buildCondition, 1034 buildCondition,
1035 buildUpdate, 1035 buildUpdate,
1036 buildBody); 1036 buildBody);
1037 } 1037 }
1038 1038
1039 _buildForInIterator(ir.ForInStatement forInStatement) { 1039 _buildForInIterator(ir.ForInStatement forInStatement) {
1040 // Generate a structure equivalent to: 1040 // Generate a structure equivalent to:
1041 // Iterator<E> $iter = <iterable>.iterator; 1041 // Iterator<E> $iter = <iterable>.iterator;
1042 // while ($iter.moveNext()) { 1042 // while ($iter.moveNext()) {
(...skipping 30 matching lines...) Expand all
1073 // Hint to name loop value after name of loop variable. 1073 // Hint to name loop value after name of loop variable.
1074 if (loopVariableLocal is! SyntheticLocal) { 1074 if (loopVariableLocal is! SyntheticLocal) {
1075 value.sourceElement ??= loopVariableLocal; 1075 value.sourceElement ??= loopVariableLocal;
1076 } 1076 }
1077 forInStatement.body.accept(this); 1077 forInStatement.body.accept(this);
1078 } 1078 }
1079 1079
1080 loopHandler.handleLoop( 1080 loopHandler.handleLoop(
1081 forInStatement, 1081 forInStatement,
1082 localsMap.getClosureRepresentationInfoForLoop( 1082 localsMap.getClosureRepresentationInfoForLoop(
1083 closureToClassMapper, forInStatement), 1083 closureDataLookup, forInStatement),
1084 buildInitializer, 1084 buildInitializer,
1085 buildCondition, 1085 buildCondition,
1086 () {}, 1086 () {},
1087 buildBody); 1087 buildBody);
1088 } 1088 }
1089 1089
1090 void _buildAsyncForIn(ir.ForInStatement forInStatement) { 1090 void _buildAsyncForIn(ir.ForInStatement forInStatement) {
1091 // The async-for is implemented with a StreamIterator. 1091 // The async-for is implemented with a StreamIterator.
1092 HInstruction streamIterator; 1092 HInstruction streamIterator;
1093 1093
(...skipping 26 matching lines...) Expand all
1120 } 1120 }
1121 1121
1122 void buildUpdate() {} 1122 void buildUpdate() {}
1123 1123
1124 // Creates a synthetic try/finally block in case anything async goes amiss. 1124 // Creates a synthetic try/finally block in case anything async goes amiss.
1125 TryCatchFinallyBuilder tryBuilder = new TryCatchFinallyBuilder(this); 1125 TryCatchFinallyBuilder tryBuilder = new TryCatchFinallyBuilder(this);
1126 // Build fake try body: 1126 // Build fake try body:
1127 loopHandler.handleLoop( 1127 loopHandler.handleLoop(
1128 forInStatement, 1128 forInStatement,
1129 localsMap.getClosureRepresentationInfoForLoop( 1129 localsMap.getClosureRepresentationInfoForLoop(
1130 closureToClassMapper, forInStatement), 1130 closureDataLookup, forInStatement),
1131 buildInitializer, 1131 buildInitializer,
1132 buildCondition, 1132 buildCondition,
1133 buildUpdate, 1133 buildUpdate,
1134 buildBody); 1134 buildBody);
1135 1135
1136 void finalizerFunction() { 1136 void finalizerFunction() {
1137 _pushDynamicInvocation(forInStatement, null, [streamIterator], 1137 _pushDynamicInvocation(forInStatement, null, [streamIterator],
1138 selector: Selectors.cancel); 1138 selector: Selectors.cancel);
1139 add(new HAwait(pop(), closedWorld.commonMasks.dynamicType)); 1139 add(new HAwait(pop(), closedWorld.commonMasks.dynamicType));
1140 } 1140 }
(...skipping 30 matching lines...) Expand all
1171 void visitWhileStatement(ir.WhileStatement whileStatement) { 1171 void visitWhileStatement(ir.WhileStatement whileStatement) {
1172 assert(isReachable); 1172 assert(isReachable);
1173 HInstruction buildCondition() { 1173 HInstruction buildCondition() {
1174 whileStatement.condition.accept(this); 1174 whileStatement.condition.accept(this);
1175 return popBoolified(); 1175 return popBoolified();
1176 } 1176 }
1177 1177
1178 loopHandler.handleLoop( 1178 loopHandler.handleLoop(
1179 whileStatement, 1179 whileStatement,
1180 localsMap.getClosureRepresentationInfoForLoop( 1180 localsMap.getClosureRepresentationInfoForLoop(
1181 closureToClassMapper, whileStatement), 1181 closureDataLookup, whileStatement),
1182 () {}, 1182 () {},
1183 buildCondition, 1183 buildCondition,
1184 () {}, () { 1184 () {}, () {
1185 whileStatement.body.accept(this); 1185 whileStatement.body.accept(this);
1186 }); 1186 });
1187 } 1187 }
1188 1188
1189 @override 1189 @override
1190 visitDoStatement(ir.DoStatement doStatement) { 1190 visitDoStatement(ir.DoStatement doStatement) {
1191 // TODO(efortuna): I think this can be rewritten using 1191 // TODO(efortuna): I think this can be rewritten using
1192 // LoopHandler.handleLoop with some tricks about when the "update" happens. 1192 // LoopHandler.handleLoop with some tricks about when the "update" happens.
1193 LocalsHandler savedLocals = new LocalsHandler.from(localsHandler); 1193 LocalsHandler savedLocals = new LocalsHandler.from(localsHandler);
1194 LoopClosureRepresentationInfo loopClosureInfo = localsMap 1194 LoopClosureRepresentationInfo loopClosureInfo = localsMap
1195 .getClosureRepresentationInfoForLoop(closureToClassMapper, doStatement); 1195 .getClosureRepresentationInfoForLoop(closureDataLookup, doStatement);
1196 localsHandler.startLoop(loopClosureInfo); 1196 localsHandler.startLoop(loopClosureInfo);
1197 JumpHandler jumpHandler = loopHandler.beginLoopHeader(doStatement); 1197 JumpHandler jumpHandler = loopHandler.beginLoopHeader(doStatement);
1198 HLoopInformation loopInfo = current.loopInformation; 1198 HLoopInformation loopInfo = current.loopInformation;
1199 HBasicBlock loopEntryBlock = current; 1199 HBasicBlock loopEntryBlock = current;
1200 HBasicBlock bodyEntryBlock = current; 1200 HBasicBlock bodyEntryBlock = current;
1201 JumpTarget target = localsMap.getJumpTarget(doStatement); 1201 JumpTarget target = localsMap.getJumpTarget(doStatement);
1202 bool hasContinues = target != null && target.isContinueTarget; 1202 bool hasContinues = target != null && target.isContinueTarget;
1203 if (hasContinues) { 1203 if (hasContinues) {
1204 // Add extra block to hang labels on. 1204 // Add extra block to hang labels on.
1205 // It doesn't currently work if they are on the same block as the 1205 // It doesn't currently work if they are on the same block as the
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
1706 switchStatement.cases, 1706 switchStatement.cases,
1707 getConstants, 1707 getConstants,
1708 (_) => false, // No case is default. 1708 (_) => false, // No case is default.
1709 buildSwitchCase); 1709 buildSwitchCase);
1710 } 1710 }
1711 1711
1712 void buildLoop() { 1712 void buildLoop() {
1713 loopHandler.handleLoop( 1713 loopHandler.handleLoop(
1714 switchStatement, 1714 switchStatement,
1715 localsMap.getClosureRepresentationInfoForLoop( 1715 localsMap.getClosureRepresentationInfoForLoop(
1716 closureToClassMapper, switchStatement), 1716 closureDataLookup, switchStatement),
1717 () {}, 1717 () {},
1718 buildCondition, 1718 buildCondition,
1719 () {}, 1719 () {},
1720 buildSwitch); 1720 buildSwitch);
1721 } 1721 }
1722 1722
1723 if (hasDefault) { 1723 if (hasDefault) {
1724 buildLoop(); 1724 buildLoop();
1725 } else { 1725 } else {
1726 // If the switch statement has no default case, surround the loop with 1726 // If the switch statement has no default case, surround the loop with
(...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after
2827 } else { 2827 } else {
2828 push(new HInvokeDynamicMethod( 2828 push(new HInvokeDynamicMethod(
2829 selector, mask, inputs, type, isIntercepted)); 2829 selector, mask, inputs, type, isIntercepted));
2830 } 2830 }
2831 } 2831 }
2832 2832
2833 @override 2833 @override
2834 visitFunctionNode(ir.FunctionNode node) { 2834 visitFunctionNode(ir.FunctionNode node) {
2835 Local methodElement = _elementMap.getLocalFunction(node); 2835 Local methodElement = _elementMap.getLocalFunction(node);
2836 ClosureRepresentationInfo closureInfo = 2836 ClosureRepresentationInfo closureInfo =
2837 closureToClassMapper.getClosureRepresentationInfo(methodElement); 2837 closureDataLookup.getClosureRepresentationInfo(methodElement);
2838 ClassEntity closureClassEntity = closureInfo.closureClassEntity; 2838 ClassEntity closureClassEntity = closureInfo.closureClassEntity;
2839 2839
2840 List<HInstruction> capturedVariables = <HInstruction>[]; 2840 List<HInstruction> capturedVariables = <HInstruction>[];
2841 closureInfo.createdFieldEntities.forEach((Local capturedLocal) { 2841 closureInfo.createdFieldEntities.forEach((Local capturedLocal) {
2842 assert(capturedLocal != null); 2842 assert(capturedLocal != null);
2843 capturedVariables.add(localsHandler.readLocal(capturedLocal)); 2843 capturedVariables.add(localsHandler.readLocal(capturedLocal));
2844 }); 2844 });
2845 2845
2846 TypeMask type = new TypeMask.nonNullExact(closureClassEntity, closedWorld); 2846 TypeMask type = new TypeMask.nonNullExact(closureClassEntity, closedWorld);
2847 // TODO(efortuna): Add source information here. 2847 // TODO(efortuna): Add source information here.
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
3471 enterBlock.setBlockFlow( 3471 enterBlock.setBlockFlow(
3472 new HTryBlockInformation( 3472 new HTryBlockInformation(
3473 kernelBuilder.wrapStatementGraph(bodyGraph), 3473 kernelBuilder.wrapStatementGraph(bodyGraph),
3474 exception, 3474 exception,
3475 kernelBuilder.wrapStatementGraph(catchGraph), 3475 kernelBuilder.wrapStatementGraph(catchGraph),
3476 kernelBuilder.wrapStatementGraph(finallyGraph)), 3476 kernelBuilder.wrapStatementGraph(finallyGraph)),
3477 exitBlock); 3477 exitBlock);
3478 kernelBuilder.inTryStatement = previouslyInTryStatement; 3478 kernelBuilder.inTryStatement = previouslyInTryStatement;
3479 } 3479 }
3480 } 3480 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/ssa/builder.dart ('k') | pkg/compiler/lib/src/ssa/graph_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698