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

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

Issue 2975323002: Renamed some scoping classes to make their usage clearer. (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 | « pkg/compiler/lib/src/ssa/builder.dart ('k') | pkg/compiler/lib/src/ssa/kernel_ast_adapter.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 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 CapturedScope scopeData =
349 closureDataLookup.getClosureScope(constructorElement); 349 closureDataLookup.getCapturedScope(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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 ScopeInfo oldScopeInfo = localsHandler.scopeInfo; 608 ScopeInfo oldScopeInfo = localsHandler.scopeInfo;
609 ScopeInfo newScopeInfo = closureDataLookup.getScopeInfo(element); 609 ScopeInfo newScopeInfo = closureDataLookup.getScopeInfo(element);
610 localsHandler.scopeInfo = newScopeInfo; 610 localsHandler.scopeInfo = newScopeInfo;
611 localsHandler.enterScope(closureDataLookup.getClosureScope(element)); 611 localsHandler.enterScope(closureDataLookup.getCapturedScope(element));
612 inlinedFrom(element, () { 612 inlinedFrom(element, () {
613 _buildInitializers(constructor, constructorChain, fieldValues); 613 _buildInitializers(constructor, constructorChain, fieldValues);
614 }); 614 });
615 localsHandler.scopeInfo = oldScopeInfo; 615 localsHandler.scopeInfo = oldScopeInfo;
616 } 616 }
617 617
618 /// Builds generative constructor body. 618 /// Builds generative constructor body.
619 void buildConstructorBody(ir.Constructor constructor) { 619 void buildConstructorBody(ir.Constructor constructor) {
620 openFunction(constructor.function); 620 openFunction(constructor.function);
621 _addClassTypeVariablesIfNeeded(constructor); 621 _addClassTypeVariablesIfNeeded(constructor);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 closureDataLookup.getScopeInfo(targetElement), 698 closureDataLookup.getScopeInfo(targetElement),
699 closureDataLookup.getClosureScope(targetElement), 699 closureDataLookup.getCapturedScope(targetElement),
700 parameterMap, 700 parameterMap,
701 isGenerativeConstructorBody: targetElement is ConstructorBodyEntity); 701 isGenerativeConstructorBody: targetElement is ConstructorBodyEntity);
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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 } 886 }
887 } 887 }
888 888
889 void buildBody() { 889 void buildBody() {
890 forStatement.body.accept(this); 890 forStatement.body.accept(this);
891 } 891 }
892 892
893 JumpTarget jumpTarget = localsMap.getJumpTargetForFor(forStatement); 893 JumpTarget jumpTarget = localsMap.getJumpTargetForFor(forStatement);
894 loopHandler.handleLoop( 894 loopHandler.handleLoop(
895 forStatement, 895 forStatement,
896 localsMap.getLoopClosureScope(closureDataLookup, forStatement), 896 localsMap.getCapturedLoopScope(closureDataLookup, forStatement),
897 jumpTarget, 897 jumpTarget,
898 buildInitializer, 898 buildInitializer,
899 buildCondition, 899 buildCondition,
900 buildUpdate, 900 buildUpdate,
901 buildBody); 901 buildBody);
902 } 902 }
903 903
904 @override 904 @override
905 void visitForInStatement(ir.ForInStatement forInStatement) { 905 void visitForInStatement(ir.ForInStatement forInStatement) {
906 if (forInStatement.isAsync) { 906 if (forInStatement.isAsync) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 HInstruction index = localsHandler.readLocal(indexVariable); 1015 HInstruction index = localsHandler.readLocal(indexVariable);
1016 HInstruction one = graph.addConstantInt(1, closedWorld); 1016 HInstruction one = graph.addConstantInt(1, closedWorld);
1017 HInstruction addInstruction = 1017 HInstruction addInstruction =
1018 new HAdd(index, one, null, commonMasks.positiveIntType); 1018 new HAdd(index, one, null, commonMasks.positiveIntType);
1019 add(addInstruction); 1019 add(addInstruction);
1020 localsHandler.updateLocal(indexVariable, addInstruction); 1020 localsHandler.updateLocal(indexVariable, addInstruction);
1021 } 1021 }
1022 1022
1023 loopHandler.handleLoop( 1023 loopHandler.handleLoop(
1024 forInStatement, 1024 forInStatement,
1025 localsMap.getLoopClosureScope(closureDataLookup, forInStatement), 1025 localsMap.getCapturedLoopScope(closureDataLookup, forInStatement),
1026 localsMap.getJumpTargetForForIn(forInStatement), 1026 localsMap.getJumpTargetForForIn(forInStatement),
1027 buildInitializer, 1027 buildInitializer,
1028 buildCondition, 1028 buildCondition,
1029 buildUpdate, 1029 buildUpdate,
1030 buildBody); 1030 buildBody);
1031 } 1031 }
1032 1032
1033 _buildForInIterator(ir.ForInStatement forInStatement) { 1033 _buildForInIterator(ir.ForInStatement forInStatement) {
1034 // Generate a structure equivalent to: 1034 // Generate a structure equivalent to:
1035 // Iterator<E> $iter = <iterable>.iterator; 1035 // Iterator<E> $iter = <iterable>.iterator;
(...skipping 30 matching lines...) Expand all
1066 localsHandler.updateLocal(loopVariableLocal, value); 1066 localsHandler.updateLocal(loopVariableLocal, value);
1067 // Hint to name loop value after name of loop variable. 1067 // Hint to name loop value after name of loop variable.
1068 if (loopVariableLocal is! SyntheticLocal) { 1068 if (loopVariableLocal is! SyntheticLocal) {
1069 value.sourceElement ??= loopVariableLocal; 1069 value.sourceElement ??= loopVariableLocal;
1070 } 1070 }
1071 forInStatement.body.accept(this); 1071 forInStatement.body.accept(this);
1072 } 1072 }
1073 1073
1074 loopHandler.handleLoop( 1074 loopHandler.handleLoop(
1075 forInStatement, 1075 forInStatement,
1076 localsMap.getLoopClosureScope(closureDataLookup, forInStatement), 1076 localsMap.getCapturedLoopScope(closureDataLookup, forInStatement),
1077 localsMap.getJumpTargetForForIn(forInStatement), 1077 localsMap.getJumpTargetForForIn(forInStatement),
1078 buildInitializer, 1078 buildInitializer,
1079 buildCondition, 1079 buildCondition,
1080 () {}, 1080 () {},
1081 buildBody); 1081 buildBody);
1082 } 1082 }
1083 1083
1084 void _buildAsyncForIn(ir.ForInStatement forInStatement) { 1084 void _buildAsyncForIn(ir.ForInStatement forInStatement) {
1085 // The async-for is implemented with a StreamIterator. 1085 // The async-for is implemented with a StreamIterator.
1086 HInstruction streamIterator; 1086 HInstruction streamIterator;
(...skipping 26 matching lines...) Expand all
1113 forInStatement.body.accept(this); 1113 forInStatement.body.accept(this);
1114 } 1114 }
1115 1115
1116 void buildUpdate() {} 1116 void buildUpdate() {}
1117 1117
1118 // 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.
1119 TryCatchFinallyBuilder tryBuilder = new TryCatchFinallyBuilder(this); 1119 TryCatchFinallyBuilder tryBuilder = new TryCatchFinallyBuilder(this);
1120 // Build fake try body: 1120 // Build fake try body:
1121 loopHandler.handleLoop( 1121 loopHandler.handleLoop(
1122 forInStatement, 1122 forInStatement,
1123 localsMap.getLoopClosureScope(closureDataLookup, forInStatement), 1123 localsMap.getCapturedLoopScope(closureDataLookup, forInStatement),
1124 localsMap.getJumpTargetForForIn(forInStatement), 1124 localsMap.getJumpTargetForForIn(forInStatement),
1125 buildInitializer, 1125 buildInitializer,
1126 buildCondition, 1126 buildCondition,
1127 buildUpdate, 1127 buildUpdate,
1128 buildBody); 1128 buildBody);
1129 1129
1130 void finalizerFunction() { 1130 void finalizerFunction() {
1131 _pushDynamicInvocation(forInStatement, null, [streamIterator], 1131 _pushDynamicInvocation(forInStatement, null, [streamIterator],
1132 selector: Selectors.cancel); 1132 selector: Selectors.cancel);
1133 add(new HAwait(pop(), closedWorld.commonMasks.dynamicType)); 1133 add(new HAwait(pop(), closedWorld.commonMasks.dynamicType));
(...skipping 30 matching lines...) Expand all
1164 @override 1164 @override
1165 void visitWhileStatement(ir.WhileStatement whileStatement) { 1165 void visitWhileStatement(ir.WhileStatement whileStatement) {
1166 assert(isReachable); 1166 assert(isReachable);
1167 HInstruction buildCondition() { 1167 HInstruction buildCondition() {
1168 whileStatement.condition.accept(this); 1168 whileStatement.condition.accept(this);
1169 return popBoolified(); 1169 return popBoolified();
1170 } 1170 }
1171 1171
1172 loopHandler.handleLoop( 1172 loopHandler.handleLoop(
1173 whileStatement, 1173 whileStatement,
1174 localsMap.getLoopClosureScope(closureDataLookup, whileStatement), 1174 localsMap.getCapturedLoopScope(closureDataLookup, whileStatement),
1175 localsMap.getJumpTargetForWhile(whileStatement), 1175 localsMap.getJumpTargetForWhile(whileStatement),
1176 () {}, 1176 () {},
1177 buildCondition, 1177 buildCondition,
1178 () {}, () { 1178 () {}, () {
1179 whileStatement.body.accept(this); 1179 whileStatement.body.accept(this);
1180 }); 1180 });
1181 } 1181 }
1182 1182
1183 @override 1183 @override
1184 visitDoStatement(ir.DoStatement doStatement) { 1184 visitDoStatement(ir.DoStatement doStatement) {
1185 // TODO(efortuna): I think this can be rewritten using 1185 // TODO(efortuna): I think this can be rewritten using
1186 // LoopHandler.handleLoop with some tricks about when the "update" happens. 1186 // LoopHandler.handleLoop with some tricks about when the "update" happens.
1187 LocalsHandler savedLocals = new LocalsHandler.from(localsHandler); 1187 LocalsHandler savedLocals = new LocalsHandler.from(localsHandler);
1188 LoopClosureScope loopClosureInfo = 1188 CapturedLoopScope loopClosureInfo =
1189 localsMap.getLoopClosureScope(closureDataLookup, doStatement); 1189 localsMap.getCapturedLoopScope(closureDataLookup, doStatement);
1190 localsHandler.startLoop(loopClosureInfo); 1190 localsHandler.startLoop(loopClosureInfo);
1191 JumpTarget target = localsMap.getJumpTargetForDo(doStatement); 1191 JumpTarget target = localsMap.getJumpTargetForDo(doStatement);
1192 JumpHandler jumpHandler = loopHandler.beginLoopHeader(doStatement, target); 1192 JumpHandler jumpHandler = loopHandler.beginLoopHeader(doStatement, target);
1193 HLoopInformation loopInfo = current.loopInformation; 1193 HLoopInformation loopInfo = current.loopInformation;
1194 HBasicBlock loopEntryBlock = current; 1194 HBasicBlock loopEntryBlock = current;
1195 HBasicBlock bodyEntryBlock = current; 1195 HBasicBlock bodyEntryBlock = current;
1196 bool hasContinues = target != null && target.isContinueTarget; 1196 bool hasContinues = target != null && target.isContinueTarget;
1197 if (hasContinues) { 1197 if (hasContinues) {
1198 // Add extra block to hang labels on. 1198 // Add extra block to hang labels on.
1199 // 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
1717 buildExpression, 1717 buildExpression,
1718 switchStatement.cases, 1718 switchStatement.cases,
1719 getConstants, 1719 getConstants,
1720 (_) => false, // No case is default. 1720 (_) => false, // No case is default.
1721 buildSwitchCase); 1721 buildSwitchCase);
1722 } 1722 }
1723 1723
1724 void buildLoop() { 1724 void buildLoop() {
1725 loopHandler.handleLoop( 1725 loopHandler.handleLoop(
1726 switchStatement, 1726 switchStatement,
1727 localsMap.getLoopClosureScope(closureDataLookup, switchStatement), 1727 localsMap.getCapturedLoopScope(closureDataLookup, switchStatement),
1728 switchTarget, 1728 switchTarget,
1729 () {}, 1729 () {},
1730 buildCondition, 1730 buildCondition,
1731 () {}, 1731 () {},
1732 buildSwitch); 1732 buildSwitch);
1733 } 1733 }
1734 1734
1735 if (hasDefault) { 1735 if (hasDefault) {
1736 buildLoop(); 1736 buildLoop();
1737 } else { 1737 } else {
(...skipping 1778 matching lines...) Expand 10 before | Expand all | Expand 10 after
3516 enterBlock.setBlockFlow( 3516 enterBlock.setBlockFlow(
3517 new HTryBlockInformation( 3517 new HTryBlockInformation(
3518 kernelBuilder.wrapStatementGraph(bodyGraph), 3518 kernelBuilder.wrapStatementGraph(bodyGraph),
3519 exception, 3519 exception,
3520 kernelBuilder.wrapStatementGraph(catchGraph), 3520 kernelBuilder.wrapStatementGraph(catchGraph),
3521 kernelBuilder.wrapStatementGraph(finallyGraph)), 3521 kernelBuilder.wrapStatementGraph(finallyGraph)),
3522 exitBlock); 3522 exitBlock);
3523 kernelBuilder.inTryStatement = previouslyInTryStatement; 3523 kernelBuilder.inTryStatement = previouslyInTryStatement;
3524 } 3524 }
3525 } 3525 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/ssa/builder.dart ('k') | pkg/compiler/lib/src/ssa/kernel_ast_adapter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698