OLD | NEW |
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 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 } | 338 } |
339 | 339 |
340 // Provide the parameters to the generative constructor body. | 340 // Provide the parameters to the generative constructor body. |
341 body.function.positionalParameters.forEach(handleParameter); | 341 body.function.positionalParameters.forEach(handleParameter); |
342 body.function.namedParameters.toList() | 342 body.function.namedParameters.toList() |
343 ..sort(namedOrdering) | 343 ..sort(namedOrdering) |
344 ..forEach(handleParameter); | 344 ..forEach(handleParameter); |
345 | 345 |
346 // If there are locals that escape (i.e. mutated in closures), we pass the | 346 // If there are locals that escape (i.e. mutated in closures), we pass the |
347 // box to the constructor. | 347 // box to the constructor. |
348 ClosureScope scopeData = | 348 ScopeInClosure scopeData = |
349 closureDataLookup.getClosureScope(constructorElement); | 349 closureDataLookup.getScopeInClosure(constructorElement); |
350 if (scopeData.requiresContextBox) { | 350 if (scopeData.requiresContextBox) { |
351 bodyCallInputs.add(localsHandler.readLocal(scopeData.context)); | 351 bodyCallInputs.add(localsHandler.readLocal(scopeData.context)); |
352 } | 352 } |
353 | 353 |
354 // Pass type arguments. | 354 // Pass type arguments. |
355 ir.Class currentClass = body.enclosingClass; | 355 ir.Class currentClass = body.enclosingClass; |
356 if (closedWorld.rtiNeed | 356 if (closedWorld.rtiNeed |
357 .classNeedsRti(_elementMap.getClass(currentClass))) { | 357 .classNeedsRti(_elementMap.getClass(currentClass))) { |
358 for (ir.DartType typeParameter in currentClass.thisType.typeArguments) { | 358 for (ir.DartType typeParameter in currentClass.thisType.typeArguments) { |
359 HInstruction argument = localsHandler.readLocal(localsHandler | 359 HInstruction argument = localsHandler.readLocal(localsHandler |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 localsHandler.updateLocal(parameter, argument); | 598 localsHandler.updateLocal(parameter, argument); |
599 } | 599 } |
600 | 600 |
601 constructor.function.positionalParameters.forEach(handleParameter); | 601 constructor.function.positionalParameters.forEach(handleParameter); |
602 constructor.function.namedParameters.toList() | 602 constructor.function.namedParameters.toList() |
603 ..sort(namedOrdering) | 603 ..sort(namedOrdering) |
604 ..forEach(handleParameter); | 604 ..forEach(handleParameter); |
605 | 605 |
606 // Set the locals handler state as if we were inlining the constructor. | 606 // Set the locals handler state as if we were inlining the constructor. |
607 ConstructorEntity element = _elementMap.getConstructor(constructor); | 607 ConstructorEntity element = _elementMap.getConstructor(constructor); |
608 ClosureRepresentationInfo oldScopeInfo = localsHandler.scopeInfo; | 608 ScopeInfo oldScopeInfo = localsHandler.scopeInfo; |
609 ClosureRepresentationInfo newScopeInfo = | 609 ScopeInfo newScopeInfo = closureDataLookup.getScopeInfo(element); |
610 closureDataLookup.getScopeInfo(element); | |
611 localsHandler.scopeInfo = newScopeInfo; | 610 localsHandler.scopeInfo = newScopeInfo; |
612 localsHandler.enterScope(closureDataLookup.getClosureScope(element)); | 611 localsHandler.enterScope(closureDataLookup.getScopeInClosure(element)); |
613 inlinedFrom(element, () { | 612 inlinedFrom(element, () { |
614 _buildInitializers(constructor, constructorChain, fieldValues); | 613 _buildInitializers(constructor, constructorChain, fieldValues); |
615 }); | 614 }); |
616 localsHandler.scopeInfo = oldScopeInfo; | 615 localsHandler.scopeInfo = oldScopeInfo; |
617 } | 616 } |
618 | 617 |
619 /// Builds generative constructor body. | 618 /// Builds generative constructor body. |
620 void buildConstructorBody(ir.Constructor constructor) { | 619 void buildConstructorBody(ir.Constructor constructor) { |
621 openFunction(constructor.function); | 620 openFunction(constructor.function); |
622 _addClassTypeVariablesIfNeeded(constructor); | 621 _addClassTypeVariablesIfNeeded(constructor); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 ..sort(namedOrdering) | 689 ..sort(namedOrdering) |
691 ..forEach(handleParameter); | 690 ..forEach(handleParameter); |
692 } | 691 } |
693 | 692 |
694 HBasicBlock block = graph.addNewBlock(); | 693 HBasicBlock block = graph.addNewBlock(); |
695 open(graph.entry); | 694 open(graph.entry); |
696 | 695 |
697 localsHandler.startFunction( | 696 localsHandler.startFunction( |
698 targetElement, | 697 targetElement, |
699 closureDataLookup.getScopeInfo(targetElement), | 698 closureDataLookup.getScopeInfo(targetElement), |
700 closureDataLookup.getClosureScope(targetElement), | 699 closureDataLookup.getScopeInClosure(targetElement), |
701 parameterMap, | 700 parameterMap, |
702 isGenerativeConstructorBody: targetElement is ConstructorBodyEntity); | 701 isGenerativeConstructorBody: targetElement is ConstructorBodyEntity); |
703 close(new HGoto()).addSuccessor(block); | 702 close(new HGoto()).addSuccessor(block); |
704 | 703 |
705 open(block); | 704 open(block); |
706 } | 705 } |
707 | 706 |
708 void closeFunction() { | 707 void closeFunction() { |
709 if (!isAborted()) closeAndGotoExit(new HGoto()); | 708 if (!isAborted()) closeAndGotoExit(new HGoto()); |
710 graph.finalize(); | 709 graph.finalize(); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 } | 886 } |
888 } | 887 } |
889 | 888 |
890 void buildBody() { | 889 void buildBody() { |
891 forStatement.body.accept(this); | 890 forStatement.body.accept(this); |
892 } | 891 } |
893 | 892 |
894 JumpTarget jumpTarget = localsMap.getJumpTargetForFor(forStatement); | 893 JumpTarget jumpTarget = localsMap.getJumpTargetForFor(forStatement); |
895 loopHandler.handleLoop( | 894 loopHandler.handleLoop( |
896 forStatement, | 895 forStatement, |
897 localsMap.getLoopClosureScope(closureDataLookup, forStatement), | 896 localsMap.getLoopScopeInClosure(closureDataLookup, forStatement), |
898 jumpTarget, | 897 jumpTarget, |
899 buildInitializer, | 898 buildInitializer, |
900 buildCondition, | 899 buildCondition, |
901 buildUpdate, | 900 buildUpdate, |
902 buildBody); | 901 buildBody); |
903 } | 902 } |
904 | 903 |
905 @override | 904 @override |
906 void visitForInStatement(ir.ForInStatement forInStatement) { | 905 void visitForInStatement(ir.ForInStatement forInStatement) { |
907 if (forInStatement.isAsync) { | 906 if (forInStatement.isAsync) { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 HInstruction index = localsHandler.readLocal(indexVariable); | 1015 HInstruction index = localsHandler.readLocal(indexVariable); |
1017 HInstruction one = graph.addConstantInt(1, closedWorld); | 1016 HInstruction one = graph.addConstantInt(1, closedWorld); |
1018 HInstruction addInstruction = | 1017 HInstruction addInstruction = |
1019 new HAdd(index, one, null, commonMasks.positiveIntType); | 1018 new HAdd(index, one, null, commonMasks.positiveIntType); |
1020 add(addInstruction); | 1019 add(addInstruction); |
1021 localsHandler.updateLocal(indexVariable, addInstruction); | 1020 localsHandler.updateLocal(indexVariable, addInstruction); |
1022 } | 1021 } |
1023 | 1022 |
1024 loopHandler.handleLoop( | 1023 loopHandler.handleLoop( |
1025 forInStatement, | 1024 forInStatement, |
1026 localsMap.getLoopClosureScope(closureDataLookup, forInStatement), | 1025 localsMap.getLoopScopeInClosure(closureDataLookup, forInStatement), |
1027 localsMap.getJumpTargetForForIn(forInStatement), | 1026 localsMap.getJumpTargetForForIn(forInStatement), |
1028 buildInitializer, | 1027 buildInitializer, |
1029 buildCondition, | 1028 buildCondition, |
1030 buildUpdate, | 1029 buildUpdate, |
1031 buildBody); | 1030 buildBody); |
1032 } | 1031 } |
1033 | 1032 |
1034 _buildForInIterator(ir.ForInStatement forInStatement) { | 1033 _buildForInIterator(ir.ForInStatement forInStatement) { |
1035 // Generate a structure equivalent to: | 1034 // Generate a structure equivalent to: |
1036 // Iterator<E> $iter = <iterable>.iterator; | 1035 // Iterator<E> $iter = <iterable>.iterator; |
(...skipping 30 matching lines...) Expand all Loading... |
1067 localsHandler.updateLocal(loopVariableLocal, value); | 1066 localsHandler.updateLocal(loopVariableLocal, value); |
1068 // Hint to name loop value after name of loop variable. | 1067 // Hint to name loop value after name of loop variable. |
1069 if (loopVariableLocal is! SyntheticLocal) { | 1068 if (loopVariableLocal is! SyntheticLocal) { |
1070 value.sourceElement ??= loopVariableLocal; | 1069 value.sourceElement ??= loopVariableLocal; |
1071 } | 1070 } |
1072 forInStatement.body.accept(this); | 1071 forInStatement.body.accept(this); |
1073 } | 1072 } |
1074 | 1073 |
1075 loopHandler.handleLoop( | 1074 loopHandler.handleLoop( |
1076 forInStatement, | 1075 forInStatement, |
1077 localsMap.getLoopClosureScope(closureDataLookup, forInStatement), | 1076 localsMap.getLoopScopeInClosure(closureDataLookup, forInStatement), |
1078 localsMap.getJumpTargetForForIn(forInStatement), | 1077 localsMap.getJumpTargetForForIn(forInStatement), |
1079 buildInitializer, | 1078 buildInitializer, |
1080 buildCondition, | 1079 buildCondition, |
1081 () {}, | 1080 () {}, |
1082 buildBody); | 1081 buildBody); |
1083 } | 1082 } |
1084 | 1083 |
1085 void _buildAsyncForIn(ir.ForInStatement forInStatement) { | 1084 void _buildAsyncForIn(ir.ForInStatement forInStatement) { |
1086 // The async-for is implemented with a StreamIterator. | 1085 // The async-for is implemented with a StreamIterator. |
1087 HInstruction streamIterator; | 1086 HInstruction streamIterator; |
(...skipping 26 matching lines...) Expand all Loading... |
1114 forInStatement.body.accept(this); | 1113 forInStatement.body.accept(this); |
1115 } | 1114 } |
1116 | 1115 |
1117 void buildUpdate() {} | 1116 void buildUpdate() {} |
1118 | 1117 |
1119 // Creates a synthetic try/finally block in case anything async goes amiss. | 1118 // Creates a synthetic try/finally block in case anything async goes amiss. |
1120 TryCatchFinallyBuilder tryBuilder = new TryCatchFinallyBuilder(this); | 1119 TryCatchFinallyBuilder tryBuilder = new TryCatchFinallyBuilder(this); |
1121 // Build fake try body: | 1120 // Build fake try body: |
1122 loopHandler.handleLoop( | 1121 loopHandler.handleLoop( |
1123 forInStatement, | 1122 forInStatement, |
1124 localsMap.getLoopClosureScope(closureDataLookup, forInStatement), | 1123 localsMap.getLoopScopeInClosure(closureDataLookup, forInStatement), |
1125 localsMap.getJumpTargetForForIn(forInStatement), | 1124 localsMap.getJumpTargetForForIn(forInStatement), |
1126 buildInitializer, | 1125 buildInitializer, |
1127 buildCondition, | 1126 buildCondition, |
1128 buildUpdate, | 1127 buildUpdate, |
1129 buildBody); | 1128 buildBody); |
1130 | 1129 |
1131 void finalizerFunction() { | 1130 void finalizerFunction() { |
1132 _pushDynamicInvocation(forInStatement, null, [streamIterator], | 1131 _pushDynamicInvocation(forInStatement, null, [streamIterator], |
1133 selector: Selectors.cancel); | 1132 selector: Selectors.cancel); |
1134 add(new HAwait(pop(), closedWorld.commonMasks.dynamicType)); | 1133 add(new HAwait(pop(), closedWorld.commonMasks.dynamicType)); |
(...skipping 30 matching lines...) Expand all Loading... |
1165 @override | 1164 @override |
1166 void visitWhileStatement(ir.WhileStatement whileStatement) { | 1165 void visitWhileStatement(ir.WhileStatement whileStatement) { |
1167 assert(isReachable); | 1166 assert(isReachable); |
1168 HInstruction buildCondition() { | 1167 HInstruction buildCondition() { |
1169 whileStatement.condition.accept(this); | 1168 whileStatement.condition.accept(this); |
1170 return popBoolified(); | 1169 return popBoolified(); |
1171 } | 1170 } |
1172 | 1171 |
1173 loopHandler.handleLoop( | 1172 loopHandler.handleLoop( |
1174 whileStatement, | 1173 whileStatement, |
1175 localsMap.getLoopClosureScope(closureDataLookup, whileStatement), | 1174 localsMap.getLoopScopeInClosure(closureDataLookup, whileStatement), |
1176 localsMap.getJumpTargetForWhile(whileStatement), | 1175 localsMap.getJumpTargetForWhile(whileStatement), |
1177 () {}, | 1176 () {}, |
1178 buildCondition, | 1177 buildCondition, |
1179 () {}, () { | 1178 () {}, () { |
1180 whileStatement.body.accept(this); | 1179 whileStatement.body.accept(this); |
1181 }); | 1180 }); |
1182 } | 1181 } |
1183 | 1182 |
1184 @override | 1183 @override |
1185 visitDoStatement(ir.DoStatement doStatement) { | 1184 visitDoStatement(ir.DoStatement doStatement) { |
1186 // TODO(efortuna): I think this can be rewritten using | 1185 // TODO(efortuna): I think this can be rewritten using |
1187 // LoopHandler.handleLoop with some tricks about when the "update" happens. | 1186 // LoopHandler.handleLoop with some tricks about when the "update" happens. |
1188 LocalsHandler savedLocals = new LocalsHandler.from(localsHandler); | 1187 LocalsHandler savedLocals = new LocalsHandler.from(localsHandler); |
1189 LoopClosureScope loopClosureInfo = | 1188 LoopScopeInClosure loopClosureInfo = |
1190 localsMap.getLoopClosureScope(closureDataLookup, doStatement); | 1189 localsMap.getLoopScopeInClosure(closureDataLookup, doStatement); |
1191 localsHandler.startLoop(loopClosureInfo); | 1190 localsHandler.startLoop(loopClosureInfo); |
1192 JumpTarget target = localsMap.getJumpTargetForDo(doStatement); | 1191 JumpTarget target = localsMap.getJumpTargetForDo(doStatement); |
1193 JumpHandler jumpHandler = loopHandler.beginLoopHeader(doStatement, target); | 1192 JumpHandler jumpHandler = loopHandler.beginLoopHeader(doStatement, target); |
1194 HLoopInformation loopInfo = current.loopInformation; | 1193 HLoopInformation loopInfo = current.loopInformation; |
1195 HBasicBlock loopEntryBlock = current; | 1194 HBasicBlock loopEntryBlock = current; |
1196 HBasicBlock bodyEntryBlock = current; | 1195 HBasicBlock bodyEntryBlock = current; |
1197 bool hasContinues = target != null && target.isContinueTarget; | 1196 bool hasContinues = target != null && target.isContinueTarget; |
1198 if (hasContinues) { | 1197 if (hasContinues) { |
1199 // Add extra block to hang labels on. | 1198 // Add extra block to hang labels on. |
1200 // It doesn't currently work if they are on the same block as the | 1199 // It doesn't currently work if they are on the same block as the |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1718 buildExpression, | 1717 buildExpression, |
1719 switchStatement.cases, | 1718 switchStatement.cases, |
1720 getConstants, | 1719 getConstants, |
1721 (_) => false, // No case is default. | 1720 (_) => false, // No case is default. |
1722 buildSwitchCase); | 1721 buildSwitchCase); |
1723 } | 1722 } |
1724 | 1723 |
1725 void buildLoop() { | 1724 void buildLoop() { |
1726 loopHandler.handleLoop( | 1725 loopHandler.handleLoop( |
1727 switchStatement, | 1726 switchStatement, |
1728 localsMap.getLoopClosureScope(closureDataLookup, switchStatement), | 1727 localsMap.getLoopScopeInClosure(closureDataLookup, switchStatement), |
1729 switchTarget, | 1728 switchTarget, |
1730 () {}, | 1729 () {}, |
1731 buildCondition, | 1730 buildCondition, |
1732 () {}, | 1731 () {}, |
1733 buildSwitch); | 1732 buildSwitch); |
1734 } | 1733 } |
1735 | 1734 |
1736 if (hasDefault) { | 1735 if (hasDefault) { |
1737 buildLoop(); | 1736 buildLoop(); |
1738 } else { | 1737 } else { |
(...skipping 1778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3517 enterBlock.setBlockFlow( | 3516 enterBlock.setBlockFlow( |
3518 new HTryBlockInformation( | 3517 new HTryBlockInformation( |
3519 kernelBuilder.wrapStatementGraph(bodyGraph), | 3518 kernelBuilder.wrapStatementGraph(bodyGraph), |
3520 exception, | 3519 exception, |
3521 kernelBuilder.wrapStatementGraph(catchGraph), | 3520 kernelBuilder.wrapStatementGraph(catchGraph), |
3522 kernelBuilder.wrapStatementGraph(finallyGraph)), | 3521 kernelBuilder.wrapStatementGraph(finallyGraph)), |
3523 exitBlock); | 3522 exitBlock); |
3524 kernelBuilder.inTryStatement = previouslyInTryStatement; | 3523 kernelBuilder.inTryStatement = previouslyInTryStatement; |
3525 } | 3524 } |
3526 } | 3525 } |
OLD | NEW |